张晓波
2023-09-19 164694c47c35d6654df69b533e8dbf8b5423efc5
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
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
<template>
  <div class="main">
    <div class="main_header">
      <div class="header_item">
        <el-input v-model="menuName" clearable placeholder="请输入菜单名称"></el-input>
      </div>
      <div class="header_item">
        <el-button v-if="showButton('search')" icon="el-icon-search" @click="searchWechatMenuList(true)">查询</el-button>
        <el-button class="search_btn" v-if="showButton('insert')" icon="el-icon-plus" @click="propInsert()">新增</el-button>
        <el-button v-if="showButton('insert')" icon="el-icon-setting" @click="propUserConfig(1)">管服配置菜单</el-button>
        <el-button v-if="showButton('insert')" icon="el-icon-setting" @click="propUserConfig(2)">劳务配置菜单</el-button>
      </div>
    </div>
    <div class="main_content">
      <el-table
        v-loading="loading"
        :data="wechatList"
        height="100%">
        <el-table-column label="序号" width="60" align="center">
          <template #default="scope">
            <span>{{(pageNum - 1) * pageSize + scope.$index + 1}}</span>
          </template>
        </el-table-column>
        <el-table-column prop="menuTagName" label="标签名称" align="center"></el-table-column>
        <el-table-column prop="menuName" label="菜单名称" align="center"></el-table-column>
        <el-table-column prop="sort" label="菜单排序" align="center"></el-table-column>
        <el-table-column prop="createTime" label="创建时间" align="center"></el-table-column>
        <el-table-column label="操作" align="center" width="200">
          <template #default="{ row }">
            <el-button class="table_btn" size="mini" v-if="showButton('update')" @click="propUpdate(row)">修改</el-button>
            <el-button class="delete_btn" size="mini" v-if="showButton('delete')" @click="deleteInfo(row)">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="main_footer">
      <el-pagination
        background
        @current-change="changePageNum"
        @size-change="changePageSize"
        :current-page="pageNum"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total">
      </el-pagination>
    </div>
    <!-- 新增 修改 -->
    <el-dialog
      class="prop_dialog"
      :title="asyncTitle ? '新增菜单' : '修改菜单信息'"
      :visible.sync="asyncWechat"
      width="35%">
      <el-form ref="form" :model="formWechat" :rules="rulesWechat" label-width="auto" class="rule_form">
        <el-form-item label="菜单名称:" prop="menuName">
          <el-input v-model="formWechat.menuName" clearable placeholder="请输入菜单名称"></el-input>
        </el-form-item>
        <el-form-item label="菜单排序:" prop="sort">
          <el-input-number 
            v-model="formWechat.sort" 
            placeholder="请输入菜单排序"
            :controls="false"
            :precision="0"
            :min="0">
          </el-input-number>
        </el-form-item>
        <el-form-item label="菜单类型:" prop="menuType">
          <el-radio-group v-model="formWechat.menuType" @change="changeTips">
            <el-radio :label="1">管服人员</el-radio>
            <el-radio :label="2">劳务人员</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="菜单标签:" prop="menuTag" v-if="showTips">
          <el-select v-model="formWechat.menuTag" clearable placeholder="请选择菜单标签">
            <el-option
              v-for="item in menuTagData"
              :key="item.id"
              :label="item.tagName" 
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="菜单路径:">
          <el-input v-model="formWechat.menuUrl" clearable placeholder="请输入菜单路径"></el-input>
        </el-form-item>
        <el-form-item label="菜单图标:">
          <upload-image :file-list="formWechat.menuIcon"  @delectImage="delectImage" :disabled="false">
            <template #info>
              <span>支持jpg、png、gif格式文件</span>
            </template>
          </upload-image>
        </el-form-item>
      </el-form>
      <div slot="footer">
        <el-button @click="asyncWechat = false">取 消</el-button>
        <el-button @click="asyncTitle ? submitInsertForm() : submitUpdateForm()">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 配置权限 -->
    <el-dialog
      class="prop_dialog"
      title="配置权限"
      :visible.sync="asyncConfig"
      width="35%">
      <div class="dialog_role_menu">
        <div class="role_menu_item">
          <el-radio-group v-model="radioValue" @input="changeRoleInfo">
              <el-radio 
                v-for="item in roleRideoList"
                :key="item.roleId"
                :label="item.roleId">
                {{item.roleName}}
              </el-radio>
            </el-radio-group>
        </div>
        <div class="role_menu_item">
          <el-checkbox-group v-model="checkValue">
            <el-checkbox 
              v-for="item in menuCheckData"
              :key="item.menuId"
              :label="item.menuId"
              :checked="item.selected === 1">
              {{item.menuName}}
            </el-checkbox>
          </el-checkbox-group>
        </div>
      </div>
      <div slot="footer">
        <el-button @click="asyncConfig = false">取 消</el-button>
        <el-button class="submit_btn" @click="submitConfigMenu()">提 交</el-button>
      </div>
    </el-dialog>
  </div>
</template>
 
<script>
import { buttonPinia } from '../../pinia';
import { throttle } from '../../plugins/public';
import UploadImage from '../../components/uploadImage.vue';
  export default {
    data() {
      return {
        showTips:false,//是否展示菜单标签
        menuName: '',
        loading: false,
        total: 0,
        pageNum: 1,
        pageSize: 10,
        wechatList: [],
        asyncTitle: true, // true 新增  false  修改
        asyncWechat: false, // 弹窗
        formWechat: {
          menuIcon: []
        }, // 表单信息
        rulesWechat: {
          menuName: [{
            required: true,
            message: '请输入菜单名称',
            trigger: 'blur'
          }],
          sort: [{
            required: true,
            message: '请输入菜单排序',
            trigger: 'blur'
          }],
          menuTag: [{
            required: true,
            message: '请选择菜单标签',
            trigger: ['blur', 'change']
          }],
          menuType: [{
            required: true,
            message: '请选择菜单类型',
            trigger: ['blur', 'change']
          }]
        }, // 表单校验规则
        menuTagData: [],
        asyncConfig: false, // 配置权限菜单
        roleRideoList: [],
        menuCheckData: [],
        radioValue: '',
        checkValue: [],
        userType: '',
      }
    },
    components: {
      UploadImage
    },
    mounted() {
      this.searchWechatMenuList(true);
    },
    methods: {
      //判断是否展示菜单标签
      changeTips(val){
        if(val === 1){
          this.showTips = true
        }else{
          this.showTips = false
        }
      },
      // 获取菜单标签信息
      async getWechatTagData() {
        const { data } = await this.$api.System.getWechatTagData();
        this.menuTagData = data;
      },
      // 获取角色信息
      async getRoleInfo() {
        const { data } = await this.$api.System.getAllRolesInfo({})
        this.roleRideoList = data;
      },
      // 根据角色信息获取菜单
      async getUserWechatMneuList(roleId, menuType) {
        const { data } = await this.$api.System.getUserWechatMneuList({
          roleId: roleId,
          menuType: menuType,
          menuName: ''
        })
        return data;
      },
      // 查询微信小程序菜单列表
      searchWechatMenuList(bol) {
        if(bol) {
          this.pageNum = 1;
        }
        this.loading = true;
        this.wechatList = [];
        this.$api.System.searchWechatMenuList({
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          menuName: this.menuName
        }).then((res) => {
          if(res.success) {
            this.total = res.data.total;
            this.wechatList = res.data.list;
          }
          this.loading = false;
        }).catch(() => {
          this.loading = false;
        });
      },
      // 配置权限
      propUserConfig(number) {
        this.userType = number;
        this.asyncConfig = true;
      },
      // 打开添加信息
      propInsert() {
        this.asyncTitle = true;
        this.asyncWechat = true;
      },
      // 打开修改信息
      propUpdate(row) {
        this.$set(this.formWechat, 'menuId', row.menuId);
        this.$set(this.formWechat, 'menuName', row.menuName);
        this.$set(this.formWechat, 'sort', row.sort);
        this.$set(this.formWechat, 'menuUrl', row.menuUrl);
        this.$set(this.formWechat, 'menuTag', row.menuTag);
        this.$set(this.formWechat, 'menuType', row.menuType);
        this.$set(this.formWechat, 'menuIcon', row.menuIcon ? [{
          id: 1,
          url:`https://pipe.thhy-tj.com/${row.menuIcon}`,
          name:row.menuIcon
        }] : []);
        this.asyncTitle = false;
        this.asyncWechat = true;
      },
      // 删除菜单信息
      deleteInfo(row) {
        this.$confirm("该操作将删除该菜单信息,是否继续删除?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
       })
       .then(() => {
         this.$api.System.deleteWechatMenuInfo({
          menuId: row.menuId
        }).then(res => {
          if(res.success) {
            this.searchWechatMenuList(true);
            this.$message.success("删除成功!");
          } else {
            this.$message.warning(res.statusMsg);
          }
        })
       })
       .catch(() => {
         this.$message.warning("您已取消");
       })
      },
      // 删除图片
      delectImage(item) {
        let uploadId = item.id;
        this.formWechat.menuIcon.splice(
          this.formWechat.menuIcon.findIndex(itm => itm.id === uploadId),1
        );
        this.$message.success("删除成功!");
      },
      // 选择角色
      changeRoleInfo(data) {
        this.checkValue = [];
        this.menuCheckData = [];
        this.getUserWechatMneuList(data, this.userType).then((data) => {
          this.$nextTick(() => {
            this.menuCheckData = data;
          })
        })
      },
      // 提交配置信息
      submitConfigMenu: throttle(function() {
        this.$api.System.userConfigWechatMenu({
          roleId: this.radioValue,
          menuIds: this.checkValue.join(',')
        }).then((res) => {
          if(res.success) {
            this.$message.success('配置成功!');
            this.asyncConfig = false;
          } else {
            this.$message.warning(res.statusMsg);
          }
        })
      }, 3000),
      // 提交添加信息
      submitInsertForm: throttle(function() {
        this.$refs.form.validate((valid) => {
          if(valid) {
            const params = Object.assign({}, this.formWechat);
            params.menuIcon = params.menuIcon.length > 0 ? params.menuIcon[0].name : '';
            this.$api.System.insertWechatMenuInfo(params).then((res) => {
              if(res.success) {
                this.asyncWechat = false;
                this.$message.success('添加成功!');
                this.searchWechatMenuList(true);
              } else {
                this.$message.warning(res.statusMsg);
              }
            })
          }
        })
      }, 3000),
      // 提交修改信息
      submitUpdateForm: throttle(function() {
        this.$refs.form.validate((valid) => {
          if(valid) {
            const params = Object.assign({}, this.formWechat);
            params.menuIcon = params.menuIcon.length > 0 ? params.menuIcon[0].name : '';
            this.$api.System.insertWechatMenuInfo(params).then((res) => {
              if(res.success) {
                this.asyncWechat = false;
                this.$message.success('修改成功!');
                this.searchWechatMenuList(true);
              } else {
                this.$message.warning(res.statusMsg);
              }
            })
          }
        })
      }, 3000),
      // 切换页码
      changePageNum(page) {
        this.pageNum = page;
        this.searchWechatMenuList();
      },
      // 切换每页条数
      changePageSize(size) {
        this.pageSize = size;
        this.searchWechatMenuList();
      },
      // 判断按钮权限信息
      showButton(str) {
        const pinia = buttonPinia();
        return pinia.$state.buttonInfo.includes(str);
      }
    },
    watch: {
      asyncWechat(bol) {
        if(bol) {
          this.getWechatTagData();
        } else {
          this.formWechat = {
            menuIcon: []
          };
          this.$refs.form.resetFields();
        }
      },
      asyncConfig(bol) {
        if(bol) {
          this.getRoleInfo();
        } else {
          this.userType = '';
          this.radioValue = '';
          this.checkValue = [];
          this.roleRideoList = [];
          this.menuCheckData = [];
        }
      }
    }
  }
</script>
 
<style lang="scss" scoped>
@import '@/style/layout-main.scss';
 
.dialog_role_menu {
  display: flex;
  padding: 20px 0 0;
   min-height: 400px;
  overflow-y: auto;
  // background: #F49E4E;
 
  .role_menu_item {
    position: relative;
    flex: 1;
    padding: 20px 10px;
    border: 1px solid #0A496D;
 
    &::before {
      content: '角色列表';
      position: absolute;
      top: -25px;
      left: 0;
      color: #FFFFFF;
    }
 
    &:last-child {
      margin-left: 30px;
      flex: 2;
 
      &::before {
        content: '菜单列表';
        position: absolute;
        top: -25px;
        left: 0;
        color: #FFFFFF;
      }
    }
 
    /deep/ .el-radio-group {
      display: flex;
      flex-direction: column;
    }
 
    /deep/ .el-checkbox-group {
      display: flex;
      flex-direction: column;
    }
 
    /deep/ .el-checkbox {
      margin-bottom: 10px;
    }
  }
}
  ::v-deep .el-radio {
    padding: 8px !important;
  }
 
  // ::v-deep .el-radio-group {
  //   display: flex;
  //   align-items: center;
  // }
</style>