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