banner.php 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <?php defined('YII_ENV') or exit('Access Denied'); ?>
  2. <style>
  3. .form-body {
  4. padding: 20px 0;
  5. background-color: #fff;
  6. margin-bottom: 20px;
  7. padding-right: 50%;
  8. }
  9. .form-button {
  10. margin: 0!important;
  11. }
  12. .form-button .el-form-item__content {
  13. margin-left: 0!important;
  14. }
  15. .button-item {
  16. padding: 9px 25px;
  17. }
  18. .text {
  19. cursor: pointer;
  20. color: #419EFB;
  21. }
  22. </style>
  23. <section id="app" v-cloak>
  24. <el-card class="box-card" shadow="never" style="border:0" body-style="background-color: #f3f3f3;padding: 10px 0 0;">
  25. <div slot="header" class="clearfix">
  26. <div flex="cross:center box:first">
  27. <div><span @click="$navigate({r:'course/default/bannar'})" class="text">广告设置</span>/添加广告</div>
  28. </div>
  29. </div>
  30. <div class="form-body" >
  31. <el-form :model="ruleForm" label-width="80px" v-loading="loading" :rules="formRules" ref="ruleForm">
  32. <el-form-item label="广告名称" size="small" prop="title">
  33. <el-input v-model="ruleForm.title" auto-complete="off"></el-input>
  34. </el-form-item>
  35. <el-form-item label="排序" size="small" prop="sort">
  36. <el-input v-model="ruleForm.sort" auto-complete="off"></el-input>
  37. </el-form-item>
  38. <el-form-item label="跳转链接" size="small" prop="pic_link">
  39. <!-- <el-input v-model="ruleForm.pic_link" auto-complete="off" placeholder="(请填写完整)格式:https://www.baidu.com"></el-input> -->
  40. <el-input v-model="ruleForm.pic_link" placeholder="点击选择链接" readonly size="small">
  41. <com-pick-link slot="append" @selected="linkSelected">
  42. <el-button size="small">选择链接</el-button>
  43. </com-pick-link>
  44. </el-input>
  45. </el-form-item>
  46. <el-form-item label="是否启用" prop="is_show">
  47. <el-switch
  48. v-model="ruleForm.is_show"
  49. active-value="1"
  50. inactive-value="0"
  51. inactive-text="不启用"
  52. active-text="启用"
  53. >
  54. </el-switch>
  55. </el-form-item>
  56. <el-form-item prop="pic_path">
  57. <label slot="label">
  58. <span>广告图片</span>
  59. <el-tooltip effect="dark" content="上传图片,建议尺寸:750 * 300" placement="top">
  60. <i class="el-icon-info"></i>
  61. </el-tooltip>
  62. </label>
  63. <com-attachment v-model="ruleForm.pic_path" :multiple="false" :max="1">
  64. <el-tooltip class="item" effect="dark" content="建议尺寸:750 * 300" placement="top">
  65. <el-button size="mini">选择图片</el-button>
  66. </el-tooltip>
  67. <!-- <span style="margin-left: 35px; color:red">建议尺寸:750 * 300</span> -->
  68. </com-attachment>
  69. <div class="customize-share-title">
  70. <com-image mode="aspectFill" width='80px' height='80px'
  71. :src="ruleForm.pic_path ? ruleForm.pic_path : ''"></com-image>
  72. <el-button v-if="ruleForm.pic_path" class="del-btn" size="mini"
  73. type="danger" icon="el-icon-close" circle
  74. @click="ruleForm.pic_path = ''"></el-button>
  75. </div>
  76. <!-- <el-button @click="app_share.dialog = true;app_share.type = 'pic_bg'"
  77. type="text">查看图例
  78. </el-button> -->
  79. </el-form-item>
  80. <div flex="dir:right">
  81. <div>
  82. <el-button class="button-item" type="primary" size="small" :loading=btnLoading @click="submit('ruleForm')">提交</el-button>
  83. </div>
  84. </div>
  85. </el-form>
  86. </div>
  87. </el-card>
  88. </section>
  89. <script>
  90. const app = new Vue({
  91. el: '#app',
  92. data() {
  93. return {
  94. loading: false,
  95. btnLoading: false,
  96. ruleForm: {
  97. title:'',
  98. sort:'',
  99. is_show: '',
  100. pic_path:'',
  101. pic_link: '',
  102. },
  103. formRules: {
  104. title: [
  105. { required: true, pattern:/\S/, message: '名称不能为空', trigger: 'blur' },
  106. { min: 1, max: 30, message: "分类名称长度在2-255个字符内" }
  107. ],
  108. sort: [
  109. { required: true, pattern: /^[0-9]\d{0,8}$/, message: '排序必须在9位整数内' }
  110. ],
  111. // pic_link: [
  112. // { required: true, pattern:/\S/, message: '请填写广告跳转链接', trigger: 'blur' },
  113. // {pattern: /^(https?:\/\/(([a-zA-Z0-9]+-?)+[a-zA-Z0-9]+\.)+[a-zA-Z]+)(:\d+)?(\/.*)?(\?.*)?(#.*)?$/, message: '链接格式不合法', trigger: 'blur'}
  114. // ],
  115. is_show: [{ required: true, message: '请选择是否启用广告', trigger: 'blur' }],
  116. pic_path: [
  117. { required: true, message: '请上传图片', trigger: 'blur' }
  118. ],
  119. },
  120. };
  121. },
  122. methods: {
  123. linkSelected(list) {
  124. // console.log(list);
  125. if (!list.length) {
  126. this.ruleForm.pic_link = '';
  127. return false;
  128. }
  129. var link = list[0].value;
  130. if (list[0].params && list[0].params.length) {
  131. var param = list[0].params[0].key + '=' + list[0].params[0].value;
  132. link = link + '?' + param;
  133. }
  134. this.ruleForm.pic_link = link;
  135. return ;
  136. },
  137. submit(formName) {
  138. this.$refs[formName].validate((valid, obj) => {
  139. // console.log(valid, obj);return null;
  140. if (valid) {
  141. this.btnLoading = true;
  142. request({
  143. params: {
  144. r: 'plugin/course/admin/bannar/create',
  145. },
  146. data: this.ruleForm,
  147. method: 'post'
  148. }).then(e => {
  149. this.btnLoading = false;
  150. if (e.data.code == 0) {
  151. const h = this.$createElement;
  152. this.$message({
  153. message: e.data.msg,
  154. type: 'success'
  155. });
  156. setTimeout(function(){
  157. navigateTo({ r: 'plugin/course/admin/bannar/index' });
  158. },300);
  159. } else {
  160. this.$message({
  161. message: e.data.msg,
  162. type: 'error'
  163. });
  164. }
  165. }).catch(e => {
  166. this.btnLoading = false;
  167. this.$message.error(e.data.msg);
  168. });
  169. }else{
  170. var msg = '';
  171. for (let index in obj) {
  172. msg = msg + '*' + obj[index][0].message + ' ';
  173. }
  174. this.$message({
  175. message: msg,
  176. type: 'error'
  177. });
  178. return false;
  179. }
  180. });
  181. },
  182. // getTopicForm() {
  183. // this.loading = true;
  184. // let _this = this;
  185. // request({
  186. // params: {
  187. // r: 'mall/topic-type/edit',
  188. // id: getQuery('id'),
  189. // },
  190. // method: 'get'
  191. // }).then(e => {
  192. // this.loading = false;
  193. // if (e.data.code == 0) {
  194. // _this.form = e.data.data;
  195. // }
  196. // }).catch(e => {
  197. // this.loading = false;
  198. // this.$alert(e.data.msg, '提示', {
  199. // confirmButtonText: '确定'
  200. // })
  201. // });
  202. // },
  203. },
  204. mounted() {
  205. // this.getTopicForm();
  206. }
  207. })
  208. </script>