田源
2024-12-17 aeff7b0782847a1fda77f96624b97b53e2f99e1a
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
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
<template>
  <basic-container>
    <avue-crud
      ref="crud"
      :data="data"
      :option="option"
      :table-loading="loading"
      @refresh-change="getTableList"
      @selection-change="selectChange"
      @row-click="rowClickHandler">
      <template slot="menuLeft" slot-scope="scope">
        <el-button v-if="permissionList.addBtn" icon="el-icon-plus" plain size="small" type="primary" @click="addClickHandler">创建</el-button>
        <el-button v-if="permissionList.importBtn" icon="el-icon-upload2" plain size="small" type="primary" @click="uploadClickHandler">导入
        </el-button>
        <el-button v-if="permissionList.exportBtn" icon="el-icon-download" plain size="small" type="primary" @click="exportClickHandler">导出
        </el-button>
        <el-button v-if="permissionList.viewTheScopeBtn" icon="el-icon-view" plain size="small" type="primary"
                   @click="checkViewClickHandler">查看使用范围
        </el-button>
      </template>
      <template slot="menu" slot-scope="scope">
        <el-button v-if="permissionList.editBtn" icon="el-icon-edit" size="small" type="text" @click="editClickHandler(scope.row)">编辑
        </el-button>
        <el-button v-if="permissionList.delBtn" icon="el-icon-delete" size="small" type="text" @click="delClickHandler(scope.row)">删除
        </el-button>
      </template>
    </avue-crud>
    <!-- 新增 修改 -->
    <el-dialog
      v-dialogDrag
      :title="dialogTitle === 'add' ? '创建' : '修改'"
      :visible.sync="visible"
      append-to-body="true"
      class="avue-dialog"
      width="800px"
      @close="visibleCloseHandler"
    >
      <el-form ref="form" size="small" :model="form" :rules="rules" label-width="95px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="名称:" prop="id">
              <el-input v-model="form.id"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="标签:" prop="name">
              <el-input v-model="form.name"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="跳跃字符:" prop="jumpCharacter">
              <el-input v-model="form.jumpCharacter"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="初始值:" prop="initialValue">
              <el-input v-model="form.initialValue"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="步长:" prop="stepLength">
              <el-input-number v-model="form.stepLength" :max="9" :min="1" label="描述文字"></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="前缀:" prop="prefixion">
              <el-input v-model="form.prefixion"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="后缀:" prop="suffix">
              <el-input v-model="form.suffix"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="描述:" prop="description">
              <el-input v-model="form.description" :rows="2" type="textarea"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
      <span slot="footer" class="dialog-footer">
         <el-button type="primary" @click="addSaveHandler">确 定</el-button>
         <el-button @click="visibleCloseHandler">取 消</el-button>
        </span>
    </el-dialog>
 
    <!-- 导入 -->
    <upload-file ref="upload" :fileType="upFileType" :fileUrl="fileUrl" :tipList="tipList" title="导入"
                 @updata="getTableList"></upload-file>
 
    <!-- 查看使用范围 -->
    <el-dialog
      v-dialogDrag
      :visible.sync="checkViewVisible"
      append-to-body="true"
      class="avue-dialog"
      title="查看使用范围"
      width="60%"
    >
      <avue-crud
        ref="checkViewCrud"
        :data="checkViewData"
        :option="checkViewOption"
        :table-loading="checkViewLoading"
        @search-change="checkHandleSearch"
        @search-reset="checkHandleReset"
      >
      </avue-crud>
    </el-dialog>
  </basic-container>
</template>
 
<script>
import {
  getVersionRuleAllList,
  addVersionRule,
  updateVersionRule,
  deleteVersionRule,
  exportVersionRule,
  getUsedVersionRuleList
} from "@/api/modeling/version/api";
import func from "@/util/func";
import basicOption from "@/util/basic-option";
import {mapGetters} from "vuex";
 
export default {
  name: "index",
  data() {
    return {
      loading: false,
      data: [],
      option: {
        ...basicOption,
        addBtn: false,
        editBtn: false,
        delBtn: false,
        calcHeight: -30,
        column: [
          {
            label: '名称',
            prop: 'id',
            sortable: true,
          },
          {
            label: '标签',
            prop: 'name',
            sortable: true,
          },
          {
            label: '跳跃字符',
            prop: 'jumpCharacter',
            sortable: true,
          },
          {
            label: '初始值',
            prop: 'initialValue',
            sortable: true,
          },
          {
            label: '步长',
            prop: 'stepLength',
            sortable: true,
          },
          {
            label: '前缀',
            prop: 'prefixion',
            sortable: true,
          },
          {
            label: '后缀',
            prop: 'suffix',
            sortable: true,
          },
          {
            label: '描述',
            prop: 'description',
            sortable: true,
          },
        ]
      },
      checkViewVisible: false,
      checkViewData: [],
      checkViewDataSearch: [],
      checkViewLoading: false,
      checkViewOption: {
        ...basicOption,
        addBtn: false,
        menu: false,
        searchMenuSpan: 8,
        refreshBtn: false,
        selection: false,
        header:false,
        column: [
          {
            label: '名称',
            prop: 'versionRuleName',
            sortable: true,
          },
          {
            label: '来源',
            prop: 'source',
            sortable: true,
            search: true
          },
          {
            label: '说明',
            prop: 'description',
          }
        ]
      },
      tipList: [
        "名称不能为空且只能输入英文字符",
        "跳跃字符只能输入数字或字母,并且以英文逗号分隔",
        "初始值只能输入数字、字母或英文符号",
        "步长不能为空且必须为1-9的整数",
      ],
      upFileType: ['xls', 'xlsx'],
      fileUrl: 'api/revisionRuleController/importVersionRules',
      rules: {
        id: [
          {required: true, message: '请输入名称', trigger: 'blur'},
          {pattern: /^[a-zA-Z]+$/, message: '只能输入英文字符', trigger: 'blur'}
        ],
        initialValue: [
          {required: true, message: '请输入初始值', trigger: 'blur'},
          {pattern: /^[a-zA-Z0-9!@#$%^&*()_+{}\[\]:;"'<>,.?/\\|-]*$/, message: '只能输入数字、字母或英文符号', trigger: 'blur'}
        ],
        jumpCharacter: [
          {required: true, message: '请输入跳跃字符', trigger: 'blur'},
          {pattern: /^[a-zA-Z0-9]+(?:,[a-zA-Z0-9]+)*$/, message: '只能输入数字或字母,并且以逗号分隔', trigger: 'blur'}
        ]
      },
      form: {
        id: '',
        name: '',
        jumpCharacter: '',
        initialValue: '',
        stepLength: 1,
        prefixion: '',
        suffix: '',
        description: ''
      },
      visible: false,
      dialogTitle: '',
      nodeRow: {},
      treeData: [],
      treeOption: {
        height: 'auto',
        defaultExpandAll: false,
        menu: false,
        addBtn: false,
        props: {
          label: 'id',
          value: 'id',
          children: 'children'
        }
      },
      descriptionOption: {
        labelStyle: 'text-align:center;width:120px',
        contentStyle: 'width:240px;text-align:center;word-break;break-all;'
      },
      icons: {
        id: 'el-icon-finished',
        name: 'el-icon-tickets',
        jump: 'el-icon-mouse',
        init: 'el-icon-s-promotion',
        length: 'el-icon-collection-tag',
        left: 'el-icon-caret-left',
        right: 'el-icon-caret-right',
        desc: 'el-icon-chat-line-square'
      },
      selectList: [],
      lastIndex: null,
    }
  },
  computed:{
    ...mapGetters(["permission"]),
    permissionList() {
      return {
        addBtn: this.vaildData(this.permission[this.$route.query.id].ADD, false),
        delBtn: this.vaildData(this.permission[this.$route.query.id].DELETE, false),
        editBtn: this.vaildData(this.permission[this.$route.query.id].EDIT, false),
        exportBtn: this.vaildData(this.permission[this.$route.query.id].EXPORT, false),
        importBtn: this.vaildData(this.permission[this.$route.query.id].IMPORT, false),
        viewTheScopeBtn: this.vaildData(this.permission[this.$route.query.id].viewTheScope, false),
      };
    },
  },
  created() {
    this.getTableList();
  },
  methods: {
    // 左侧树查询
    getTableList() {
      this.loading = true;
      getVersionRuleAllList().then(res => {
        const data = res.data.data;
        this.data = data;
        this.loading = false;
      }).catch(err => {
        this.$message.error(err)
      });
    },
 
    // 创建按钮
    addClickHandler() {
      this.dialogTitle = 'add';
      this.visible = true;
    },
 
    // 修改按钮
    editClickHandler(row) {
      this.form = {...row};
      this.visible = true;
      this.dialogTitle = 'edit';
    },
 
    // 新增修改对话框关闭
    visibleCloseHandler() {
      const form = {
        id: '',
        name: '',
        jumpCharacter: '',
        initialValue: '',
        stepLength: 1,
        prefixion: '',
        suffix: '',
        description: ''
      }
      this.form = form;
      this.visible = false;
      this.$refs.form.clearValidate();
    },
 
    // 新增 编辑 保存
    addSaveHandler() {
      const saveFunction = this.dialogTitle === 'add' ? addVersionRule : updateVersionRule;
      this.$refs.form.validate((valid) => {
        if (valid) {
          saveFunction(this.form).then(res => {
            if (res.data.code === 200) {
              this.$message.success(res.data.obj);
              this.getTableList();
              this.visible = false;
            } else {
              this.$message.error(res.data.obj);
            }
          }).catch(error => {
            this.$message.error(error);
          });
        } else {
          return false;
        }
      });
    },
 
    // 删除按钮
    delClickHandler(row) {
      this.$confirm('您确定要删除所选择的数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const list = [row];
        deleteVersionRule(list).then(res => {
          if (res.data.code === 200) {
            this.$message.success(res.data.obj);
            this.getTableList();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
 
    // 导出
    exportClickHandler() {
      if (this.selectList.length <= 0) {
        this.$message.error('请至少选择一条数据!');
        return;
      }
 
      if (this.selectList.length > 1) {
        this.$message.error('只能选择一条数据!');
        return;
      }
 
      exportVersionRule({vrNames: this.selectList[0].id}).then(res => {
        func.downloadFileByBlobHandler(res);
        this.$message.success('导出成功');
      }).catch(err => {
        this.$message.error(err);
      })
    },
 
    // 导入
    uploadClickHandler() {
      this.$refs.upload.visible = true;
    },
 
    // 查看使用范围
    checkViewClickHandler() {
      if (this.selectList.length <= 0) {
        this.$message.error('请至少选择一条数据!');
        return;
      }
 
      if (this.selectList.length > 1) {
        this.$message.error('只能选择一条数据!');
        return;
      }
      getUsedVersionRuleList({vrName: this.selectList[0].id}).then(res => {
        if (res.data.code === 200) {
          this.checkViewVisible = true;
          const data = res.data.data;
          this.checkViewData = res.data.data;
          this.checkViewDataSearch = res.data.data;
        }
      })
    },
 
    // 查看使用范围查询
    checkHandleSearch(params, done) {
      const {source} = params;
 
      if (!params.source) {
        this.checkViewData = this.checkViewDataSearch;
        return done();
      }
      ;
 
      this.checkViewData = this.checkViewDataSearch.filter(item => {
        return item.source && item.source.includes(source);
      });
 
      done();
 
    },
 
    // 查看使用范围重置
    checkHandleReset() {
      this.checkViewData = this.checkViewDataSearch;
    },
 
    // 选择框
    selectChange(row) {
      this.selectList = row;
    },
 
    // 点击行
    rowClickHandler(row) {
      func.rowClickHandler(
        row,
        this.$refs.crud,
        this.lastIndex,
        (newIndex) => {
          this.lastIndex = newIndex;
        },
        () => {
          this.selectList = [];
        }
      );
    },
 
  }
}
</script>
 
<style lang="scss" scoped>
::v-deep {
  .el-scrollbar__wrap {
    overflow: auto !important;
  }
  .el-input-number--small {
    width: 100%;
  }
}
</style>