jazz
2022-03-03 adf10a882ee565d6a5c37ba07a9e8ec2289ccf34
提交 | 用户 | age
3ca1b1 1 // 轮播图管理
037956 2 <template>
L 3   <div class="app-container">
4     <!-- 操作区 ↓↓↓↓↓↓↓↓↓↓ -->
5     <el-row :gutter="10" class="mb8">
6       <el-col :span="1.5">
7         <el-button
8           v-if="getAuthValueFN('banner_add')"
9           type="primary"
10           icon="el-icon-plus"
11           size="mini"
12           @click="showDialog('add')"
13         >新增</el-button>
14       </el-col>
15     </el-row>
16     <!-- 操作区 ↑↑↑↑↑↑↑↑↑↑ -->
17
18     <el-table :data="list">
19       <el-table-column type="index" label="序号" align="center" width="60" />
20       <el-table-column label="图片" prop="imgUrl" align="center" min-width="120">
21         <template slot-scope="scope">
fd98d3 22           <el-image :src="scope.row.imgUrl" style="width:80px;height:80px" fit="contain" :preview-src-list="[scope.row.imgUrl]">
L 23             <div slot="error" class="image-slot">
24               <!-- 图片显示失败图标 -->
25               <img src="https://cube.elemecdn.com/e/fd/0fc7d20532fdaf769a25683617711png.png" style="width:80px;height:80px">
26             </div>
27           </el-image>
037956 28         </template>
L 29       </el-table-column>
3ca1b1 30       <el-table-column prop="jumpType" label="跳转类型" align="center" min-width="120">
L 31         <template slot-scope="scope">
32           {{ ['不跳转','小程序页面','H5页面','其他小程序'][scope.row.jumpType] }}
33         </template>
34       </el-table-column>
35       <el-table-column prop="orderNum" label="排序号" align="center" />
36       <el-table-column prop="createTime" label="创建时间" align="center" min-width="120" />
037956 37       <el-table-column label="操作" align="center" class-name="small-padding fixed-width" min-width="100">
L 38         <template slot-scope="scope">
39           <el-button
40             v-if="getAuthValueFN('banner_edit')"
41             size="mini"
42             type="text"
43             icon="el-icon-edit"
44             @click="handleEdit(scope.row)"
45           >编辑</el-button>
46           <el-button
47             v-if="getAuthValueFN('banner_del')"
48             size="mini"
49             type="text warn"
50             icon="el-icon-delete"
51             @click="handleDelete(scope.row)"
52           >删除</el-button>
53         </template>
54       </el-table-column>
55     </el-table>
56
57     <pagination
58       v-show="total>0"
59       :total="total"
60       :page.sync="pageNum"
61       :limit.sync="pageSize"
62       @pagination="getList"
63     />
64
65     <!-- 新增&编辑 -->
4dde14 66     <el-dialog v-el-drag-dialog :title="dialogData.type=='add'?'新增轮播图':'编辑轮播图'" width="500px" :visible.sync="isShowDialog" append-to-body :before-close="hideDialog" :close-on-click-modal="false">
9f32bd 67       <el-form :ref="formName" :model="dialogData" label-width="120px" :rules="rules" size="small">
L 68         <el-form-item label="排序号:" prop="orderNum">
36b711 69           <el-input v-model="dialogData.orderNum" placeholder="请输入排序号" maxlength="10" />
037956 70         </el-form-item>
89cecf 71         <el-form-item ref="uploadFormItem" prop="uploadImgs">
C 72           <span slot="label">
73             <!-- 尺寸 -->
74             轮播图:<br><span style="color: #999;font-size: 12px">(xxx*xxx像素)</span>
75           </span>
133cfa 76           <!-- 上传图片组件(单图) -->
3fccf2 77           <UploadSingleImg
037956 78             ref="refUploadImg"
3fccf2 79             v-model="dialogData.uploadImgs"
L 80             @change.capture="$refs[formName].clearValidate()"
81           />
037956 82         </el-form-item>
9f32bd 83         <el-form-item label="跳转类型:" prop="jumpType">
L 84           <el-select
85             v-model="dialogData.jumpType"
86             clearable
87             placeholder="请选择跳转类型"
88             class="com-edit-input"
89           >
90             <el-option v-for="item in jumpTypeOpt" :key="item.value" :label="item.label" :value="item.value" />
91           </el-select>
92         </el-form-item>
93         <el-form-item v-if="dialogData.jumpType" label="跳转链接:" prop="jumpUrl">
36b711 94           <el-input v-model="dialogData.jumpUrl" placeholder="请输入跳转链接" class="com-edit-input" maxlength="100" />
9f32bd 95         </el-form-item>
L 96         <el-form-item v-if="dialogData.jumpType===3" label="appId:" prop="jumpMpId">
36b711 97           <el-input v-model="dialogData.jumpMpId" placeholder="请输入小程序appId" class="com-edit-input" maxlength="50" />
9f32bd 98         </el-form-item>
L 99         <el-form-item v-if="dialogData.jumpType===3" label="小程序版本:" prop="envVersion">
100           <el-select
101             v-model="dialogData.envVersion"
102             clearable
103             placeholder="请选择小程序版本"
104             class="com-edit-input"
cf8a75 105             @change="handleJumpTypeChange"
9f32bd 106           >
L 107             <el-option v-for="item in envVersionOpt" :key="item.value" :label="item.label" :value="item.value" />
108           </el-select>
109         </el-form-item>
110         <el-form-item v-if="dialogData.jumpType===3" label="额外数据:" prop="extraData">
36b711 111           <el-input v-model="dialogData.extraData" placeholder="请输入小程序额外数据" class="com-edit-input" maxlength="50" />
9f32bd 112         </el-form-item>
037956 113       </el-form>
L 114       <div slot="footer" class="dialog-footer">
115         <el-button @click="hideDialog">取消</el-button>
116         <el-button type="primary" @click="handleSave(dialogData.type)">确定</el-button>
117       </div>
118     </el-dialog>
119
120     <!-- upload放大图片 -->
121     <el-dialog :visible.sync="uploadPreviewVisible" style="text-align:center">
122       <img style="max-width:100%" :src="uploadPreviewUrl" alt="">
123     </el-dialog>
124   </div>
125 </template>
126
127 <script>
128
129 import mixin_Upload from '@/mixins/upload.js'
9f32bd 130 import mixin_bannerOpts from '@/mixins/bannerOpts.js' // 通用轮播图下拉选项
3fccf2 131 import UploadSingleImg from '@/components_simple/UploadSingleImg'
037956 132 export default {
L 133   name: 'Equipment',
3fccf2 134   components: { UploadSingleImg },
9f32bd 135   mixins: [mixin_Upload, mixin_bannerOpts],
037956 136   data() {
L 137     return {
138       list: [], // 设备列表
139
140       // 分页 ↓↓↓↓↓↓↓↓↓↓
141       total: 0,
142       pageNum: 1,
143       pageSize: 20,
144       // 分页 ↑↑↑↑↑↑↑↑↑↑
145
30a172 146       jumpTypeOpt: [
L 147         { label: '不跳转', value: 0 },
148         { label: '小程序页面', value: 1 },
149         { label: 'H5页面', value: 2 },
150         { label: '其它小程序', value: 3 }
151       ],
152
153       envVersionOpt: [
154         { label: '开发版', value: 'develop' },
155         { label: '体验版', value: 'trial' },
156         { label: '正式版', value: 'release' }
157       ],
158
037956 159       // 显示弹窗
L 160       isShowDialog: false,
161
162       // 表单校验
163       rules: {
164         orderNum: [
165           { required: true, message: '排序号不能为空', trigger: 'change' }
166         ],
167         uploadImgs: [
9f32bd 168           { required: true, message: '轮播图片不能为空', trigger: 'change' }
L 169         ],
170         jumpType: [
171           { required: true, message: '跳转类型不能为空', trigger: 'change' }
172         ],
173         jumpUrl: [
174           { required: true, message: '跳转链接不能为空', trigger: 'change' }
175         ],
176         jumpMpId: [
177           { required: true, message: '跳转小程序appId不能为空', trigger: 'change' }
178         ],
179         envVersion: [
180           { required: true, message: '跳转小程序版本不能为空', trigger: 'change' }
037956 181         ]
L 182       },
183
184       // 表单名称
185       formName: 'dialogForm',
186       // 弹窗表单
187       dialogData: {
188         // 上传图片
189         uploadImgs: []
190       }
191
192     }
193   },
194   mounted() {
195     this.init()
196   },
197   methods: {
198     // 初始化
199     init() {
200       this.getList()
201     },
202
203     // 获取列表
204     getList() {
205       var { pageNum, pageSize } = this
206       const params = {
207         pageNum: pageNum,
208         pageSize: pageSize
209       }
210
211       this.postFN({
212         url: 'admin/banner/list',
213         params: params,
214         mockData: {
215           code: 100,
216           msg: '',
217           data: {
218             list: [{
219               'imgUrl': 'https://profile.csdnimg.cn/0/1/7/3_weixin_38373875',
220               'jumpUrl': '123',
221               'jumpType': 0,
222               'orderNum': 1,
223               'createTime': '2020-02-02 02:00:00'
224             }],
225             total: 100
226           }
227         }
228       }, (inf) => {
229         this.list = inf.list || []
230         this.total = inf.total
231       })
232     },
233     // 重新获取列表
234     reGetList() {
235       this.pageNum = 1
236       this.getList()
237     },
238     // 删除
239     handleDelete(item) {
240       // 打开二次确认弹窗
241       this.$confirm('是否确认删除该轮播图?', '提示', {
242         confirmButtonText: '确定',
243         cancelButtonText: '取消',
244         type: 'warning'
245       }).then(() => {
246         // 确定回调
247         this.postFN({
248           url: 'admin/banner/del',
249           params: {
250             id: item.id
251           },
252           mockData: {
253             code: 100,
254             msg: '',
255             data: {}
256           }
257         }, () => {
258           this.getList()
259           this.$messageSuc('删除成功')
260         })
261       }).catch(() => {})
262     },
263     // 编辑
264     handleEdit(item) {
265       this.showDialog('edit', item)
266     },
cf8a75 267     // 跳转类型为【不跳转】时,清空其余跳转字段
C 268     handleJumpTypeChange() {
269       if (this.dialogData.jumpType === 0) {
270         this.dialogData.jumpUrl = ''
271         this.dialogData.jumpMpId = ''
272         this.dialogData.envVersion = ''
273         this.dialogData.extraData = ''
274       }
275     },
037956 276     // 显示弹框
L 277     showDialog(type, item) {
278       let dialogData = {}
279
280       this.isShowDialog = true
281       this.$nextTick(() => {
282         if (type === 'add') {
283           dialogData = {
284             type: 'add',
285             orderNum: 1,
286             uploadImgs: []
287           }
288         } else {
289           dialogData = {
290             type: 'edit',
291             ...item
292           }
293           dialogData.uploadImgs = [{ url: item.imgUrl, status: 'success' }]
294         }
295         this.dialogData = dialogData
296         this.$refs[this.formName].resetFields()
297       })
298     },
299     // 隐藏弹框
300     hideDialog() {
301       this.$refs[this.formName].resetFields()
302       this.isShowDialog = false
303     },
304     // 提交
305     handleSave(type) {
306       // 验证
307       this.$refs[this.formName].validate((valid) => {
308         if (valid) {
309           // 上传图片
3fccf2 310           this.$refs.refUploadImg.runUploadImg((imgUrl) => {
L 311             imgUrl && this.$set(this.dialogData, 'imgUrl', imgUrl)
037956 312             this.submit(type)
L 313           })
314         }
315       })
316     },
317     submit(type) {
318       const url = type === 'add' ? 'admin/banner/add' : 'admin/banner/edit'
319       const dialogData = this.dialogData
320       const params = {
321         orderNum: dialogData.orderNum,
9f32bd 322         imgUrl: dialogData.imgUrl,
L 323         jumpType: dialogData.jumpType
037956 324       }
9f32bd 325       if (dialogData.jumpUrl) params.jumpUrl = dialogData.jumpUrl
L 326       if (dialogData.jumpMpId) params.jumpMpId = dialogData.jumpMpId
327       if (dialogData.envVersion) params.envVersion = dialogData.envVersion
328       if (dialogData.extraData) params.extraData = dialogData.extraData
329
037956 330       if (dialogData.type === 'edit') {
L 331         params.id = dialogData.id
332       }
333       this.postFN({
334         url,
335         params,
336         mockData: {
337           code: 100, data: {
338
339           }
340         }
341       }, inf => {
342         this.$messageSuc('保存成功')
343         this.hideDialog()
b82c1e 344         type === 'add' ? this.reGetList() : this.getList()
037956 345       })
L 346     }
347   }
348 }
349 </script>
350
351 <style lang="scss" scoped>
352
353 </style>