ap-dev 1.1.8 → 1.1.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,644 @@
1
+ <template>
2
+ <ap-container>
3
+ <ap-aside margin="1111">
4
+ <div class="layout-aside-header">
5
+ <div class="layout-aside-header-title">
6
+ 字段类型
7
+ </div>
8
+ <div class="layout-aside-header-icon">
9
+ <i class="el-icon-plus" @click="addTable" />
10
+ <i class="el-icon-edit-outline" @click="editTable" />
11
+ <i class="el-icon-delete" @click="deleteTable" />
12
+ <el-popover ref="popoverRef" placement="bottom" trigger="click">
13
+ <el-button-group>
14
+ <el-button type="primary" icon="el-icon-top" @click="sortTypeBefore">上移</el-button>
15
+ <el-button type="primary" icon="el-icon-bottom" @click="sortTypeAfter">下移</el-button>
16
+ <el-button type="primary" icon="el-icon-s-operation" @click="sortTypeByIndex">
17
+ 一键排序
18
+ </el-button>
19
+ </el-button-group>
20
+ <i slot="reference" class="el-icon-sort" />
21
+ </el-popover>
22
+ </div>
23
+ </div>
24
+ <div>
25
+ <el-input v-model="filterText" placeholder="关键字过滤" />
26
+ </div>
27
+ <div v-loading="loadingTreeFlag" class="layout-aside-content">
28
+ <el-tree
29
+ ref="typeTree"
30
+ class="filter-tree"
31
+ node-key="fdId"
32
+ :data="typeTreeList"
33
+ :props="defaultProps"
34
+ default-expand-all
35
+ show-checkbox
36
+ :check-on-click-node="true"
37
+ :highlight-current="true"
38
+ :expand-on-click-node="false"
39
+ :check-strictly="false"
40
+ :filter-node-method="filterNode"
41
+ @check="nodeClickEvent"
42
+ />
43
+ </div>
44
+ </ap-aside>
45
+ <ap-split-panel />
46
+ <ap-container>
47
+ <ap-header margin="1110">
48
+ <el-form
49
+ ref="searchFormRef"
50
+ :model="searchForm"
51
+ :inline="true"
52
+ class="layout-header-form"
53
+ >
54
+ <el-form-item label="搜索:" class="layout-header-form-item" prop="likeStr">
55
+ <el-input v-model="searchForm.likeStr" placeholder="字段名/注释" />
56
+ </el-form-item>
57
+ </el-form>
58
+ <el-button type="primary" @click="searchEvent">查询</el-button>
59
+ </ap-header>
60
+ <ap-main margin="0110">
61
+ <ap-table ref="devDbFieldGrid" :options.sync="tableOpt" />
62
+ </ap-main>
63
+ </ap-container>
64
+
65
+
66
+ <el-dialog
67
+ :title="dialogTitle"
68
+ :visible.sync="dialogVisible"
69
+ width="35%"
70
+ >
71
+ <el-form ref="dialogForm" :model="dialogForm" :rules="dialogFormRules" label-width="80px">
72
+
73
+ <el-form-item label="父类别">
74
+ <el-select v-model="dialogForm.fdParentId" filterable placeholder="请选择父节点">
75
+ <el-option label="无" value="" />
76
+ <el-option
77
+ v-for="item in typeList"
78
+ :key="item.fdId"
79
+ :label="item.fdName"
80
+ :value="item.fdId"
81
+ />
82
+ </el-select>
83
+ </el-form-item>
84
+
85
+ <el-form-item label="类别名称" prop="fdName">
86
+ <el-input v-model="dialogForm.fdName" />
87
+ </el-form-item>
88
+
89
+ <el-form-item label="排序" prop="fdSort">
90
+ <el-input-number v-model="dialogForm.fdSort" controls-position="right" />
91
+ </el-form-item>
92
+ </el-form>
93
+
94
+
95
+ <span slot="footer" class="dialog-footer">
96
+ <el-button @click="dialogVisible = false">取 消</el-button>
97
+ <el-button type="primary" @click="saveTable">确 定</el-button>
98
+ </span>
99
+ </el-dialog>
100
+ </ap-container>
101
+ </template>
102
+
103
+ <script>
104
+ import { convertToArrayData, convertToTreeData } from 'ap-util/util/DataUtil'
105
+
106
+ export default {
107
+ name: 'DevDbField',
108
+ data() {
109
+ const columns = [
110
+ {
111
+ prop: 'fdFieldTypeId',
112
+ label: '字段类型',
113
+ type: 'select',
114
+ addDefaultValue: this.addDefaultValueFn,
115
+ selectOptionsRemote: 'typeList',
116
+ selectOptionsKey: { label: 'fdName', value: 'fdId' },
117
+ rules: [
118
+ { required: true, message: '请选择类型' }
119
+ ]
120
+ },
121
+ {
122
+ prop: 'fdName',
123
+ label: '字段名称',
124
+ type: 'input',
125
+ rules: [
126
+ { required: true, message: '字段名称必填' },
127
+ { min: 1, max: 30, message: '长度在 1 到 30 个字符' }
128
+ ]
129
+ },
130
+ {
131
+ prop: 'fdComment',
132
+ label: '默认注释',
133
+ type: 'input',
134
+ rules: [
135
+ { required: true, message: '字段注释必填' },
136
+ { min: 1, max: 30, message: '长度在 1 到 30 个字符' }
137
+ ]
138
+ }, {
139
+ prop: 'fdDataType',
140
+ label: '数据类型',
141
+ type: 'select',
142
+ selectOptions: [
143
+ {
144
+ label: '常用',
145
+ options: [
146
+ { label: 'char(255)', value: 'char' },
147
+ { label: 'varchar(6.5万)', value: 'varchar' },
148
+ { label: 'tinyint(255)', value: 'tinyint' },
149
+ { label: 'datetime(年月日时分秒)', value: 'datetime' }
150
+ ]
151
+ },
152
+ {
153
+ label: '字符串',
154
+ options: [
155
+ { label: 'char(255)', value: 'char' },
156
+ { label: 'varchar(6.5万)', value: 'varchar' },
157
+ { label: 'text(长文本)', value: 'text' }
158
+ ]
159
+ },
160
+ {
161
+ label: '整型数值',
162
+ options: [
163
+ { label: 'tinyint(255)', value: 'tinyint' },
164
+ { label: 'smallint(6.5万)', value: 'smallint' },
165
+ { label: 'mediumint(1.6千万)', value: 'mediumint' },
166
+ { label: 'int(4.2亿)', value: 'int' },
167
+ { label: 'bigint(极大)', value: 'bigint' }
168
+ ]
169
+ },
170
+ {
171
+ label: '浮点数值',
172
+ options: [
173
+ { label: 'float(单精度)', value: 'float' },
174
+ { label: 'double(双精度)', value: 'double' },
175
+ { label: 'decimal(小数值)', value: 'decimal' }
176
+ ]
177
+ },
178
+ {
179
+ label: '日期时间',
180
+ options: [
181
+ { label: 'date(年月日)', value: 'date' },
182
+ { label: 'time(时分秒)', value: 'time' },
183
+ { label: 'year(年)', value: 'year' },
184
+ { label: 'datetime(年月日时分秒)', value: 'datetime' },
185
+ { label: 'timestamp(时间戳)', value: 'timestamp' }
186
+ ]
187
+ }
188
+ ],
189
+ selectFilterable: true,
190
+ selectIsGroup: true,
191
+ selectPlaceholder: '选择数据类型',
192
+ rules: [
193
+ { required: true, message: '数据类型必选' }
194
+ ]
195
+ }, {
196
+ prop: 'fdSort',
197
+ label: '排序',
198
+ type: 'inputNumber',
199
+ inputNumberMin: 0,
200
+ // inputNumberMax: 10,
201
+ sortable: true,
202
+ rules: [
203
+ { required: true, message: '请输入排序' }
204
+ ],
205
+ addDefaultValue: 0
206
+ }, {
207
+ prop: 'fdDeleted',
208
+ label: '删除',
209
+ type: 'input',
210
+ hide: true,
211
+ addDefaultValue: 0
212
+ }]
213
+ const tableOpt = {
214
+ title: '字段列表',
215
+ columns: columns,
216
+ pagination: {
217
+ pageSizes: [30, 60, 90],
218
+ pageSize: 30
219
+ },
220
+ dataUrl: '/apd/db/DevDbField/getTDevDbFieldGridList',
221
+ saveUrl: '/apd/db/DevDbField/saveTDevDbFieldGridData',
222
+ editPk: 'fdId',
223
+ deletePk: 'fdId',
224
+ deleteUrl: '/apd/db/DevDbField/deleteTDevDbFieldByFdId',
225
+ toolbarBtn: ['add', 'edit', 'del', 'cancel', 'refresh', 'save', 'separator',
226
+ {
227
+ btnType: 'primary',
228
+ text: '上移',
229
+ icon: 'el-icon-top',
230
+ onClick: () => {
231
+ this.sortBefore()
232
+ }
233
+ },
234
+ {
235
+ btnType: 'primary',
236
+ text: '下移',
237
+ icon: 'el-icon-bottom',
238
+ onClick: () => {
239
+ this.sortAfter()
240
+ }
241
+ },
242
+ {
243
+ btnType: 'primary',
244
+ text: '一键排序',
245
+ icon: 'el-icon-s-operation',
246
+ onClick: () => {
247
+ this.doSortByIndex()
248
+ }
249
+ }, , {
250
+ btnType: 'info',
251
+ text: '帮助',
252
+ icon: 'el-icon-question',
253
+ onClick: () => {
254
+ this.openHelp()
255
+ }
256
+ }],
257
+ initData: false,
258
+ beforeAdd: this.beforeAddFn,
259
+ params: () => {
260
+ return {
261
+ fdFieldTypeIds: this.selectedFieldTypeIds,
262
+ likeStr: this.searchForm.likeStr
263
+ }
264
+ }
265
+ }
266
+
267
+ return {
268
+ // ----- 左侧树 -----
269
+ loadingTreeFlag: false,
270
+ filterText: '',
271
+ typeTreeList: [],
272
+ defaultProps: {
273
+ children: 'children',
274
+ label: 'fdName'
275
+ },
276
+ selectedFieldTypeIds: '',
277
+ // ----- dialog -----
278
+ typeList: [],
279
+ dialogVisible: false,
280
+ dialogTitle: '', // dialog标题
281
+ isAddDialog: true, // 添加类型dialog
282
+ dialogForm: {
283
+ fdName: '',
284
+ fdParentId: '',
285
+ fdId: '',
286
+ fdSort: undefined
287
+ },
288
+ dialogFormRules: {
289
+ fdSort: [
290
+ { type: 'number', message: '请输入数字', trigger: 'change' }
291
+ ],
292
+ fdName: [
293
+ { required: true, message: '请输入类型名称', trigger: 'blur' },
294
+ { min: 1, max: 10, message: '长度在 1 到 10 个字符', trigger: 'blur' }
295
+ ]
296
+ },
297
+ // ----- 表格 -----
298
+ searchForm: {
299
+ listStr: ''
300
+ },
301
+ tableOpt: tableOpt
302
+ }
303
+ },
304
+ watch: {
305
+ filterText(val) {
306
+ this.$refs.typeTree.filter(val)
307
+ }
308
+ },
309
+ created() {
310
+ this.loadTreeData()
311
+ },
312
+ methods: {
313
+ // 左侧树:加载数据
314
+ loadTreeData() {
315
+ this.loadingTreeFlag = true
316
+ this.$request({
317
+ url: '/apd/db/DevDbField/getDbFieldTypeList',
318
+ method: 'post'
319
+ }).then(response => {
320
+ this.typeList = JSON.parse(JSON.stringify(response.data))
321
+ this.typeTreeList = convertToTreeData(response.data, {
322
+ idKey: 'fdId',
323
+ parentKey: 'fdParentId',
324
+ childrenKey: 'children'
325
+ })
326
+ }).finally(() => {
327
+ this.loadingTreeFlag = false
328
+ })
329
+ },
330
+ // 左侧树:初始化数据
331
+ initTreeData() {
332
+ // 重置当前选择节点
333
+ this.$refs.typeTree.setCurrentKey()
334
+ this.loadTreeData()
335
+ },
336
+ // 左侧树:过滤节点
337
+ filterNode(value, data) {
338
+ if (!value) return true
339
+ return data.fdName.indexOf(value) !== -1
340
+ },
341
+ // 选择勾选事件
342
+ nodeClickEvent(data, node, comp) {
343
+ const parentKeys = this.$refs.typeTree.getHalfCheckedKeys()
344
+ const selectKeys = this.$refs.typeTree.getCheckedKeys(false)
345
+ this.selectedFieldTypeIds = parentKeys.concat(selectKeys).join(',')
346
+ this.$refs.devDbFieldGrid.refresh()
347
+ },
348
+ // dialog:重置表单
349
+ resetDialogForm() {
350
+ this.dialogForm = {
351
+ fdName: '',
352
+ fdParentId: '',
353
+ fdId: '',
354
+ fdSort: null
355
+ }
356
+ },
357
+ getCurrentNode() {
358
+ return this.$refs.typeTree.getCurrentNode() || {}
359
+ },
360
+ // dialog:添加数据
361
+ addTable() {
362
+ this.resetDialogForm()
363
+ this.dialogVisible = true
364
+ this.dialogTitle = '添加字段类型'
365
+ this.isAddDialog = true
366
+ this.dialogForm.fdParentId = this.getCurrentNode().fdId
367
+ },
368
+ // dialog:编辑数据
369
+ editTable() {
370
+ const currentNodeFdId = this.getCurrentNode().fdId
371
+ if (!currentNodeFdId) {
372
+ this.$message.error('请选择需要编辑的数据!')
373
+ return
374
+ }
375
+
376
+ this.resetDialogForm()
377
+ this.dialogVisible = true
378
+ this.dialogTitle = '编辑字段类型'
379
+ this.isAddDialog = false
380
+ this.dialogForm.fdId = currentNodeFdId
381
+
382
+ this.$request({
383
+ url: '/apd/db/DevDbField/getDbFieldTypeByFdId',
384
+ method: 'post',
385
+ data: {
386
+ fdId: currentNodeFdId
387
+ }
388
+ }).then(response => {
389
+ this.dialogForm.fdId = response.data.fdId
390
+ this.dialogForm.fdName = response.data.fdName
391
+ this.dialogForm.fdParentId = response.data.fdParentId
392
+ this.dialogForm.fdSort = response.data.fdSort
393
+ })
394
+ },
395
+ // 删除类型数据
396
+ deleteTable() {
397
+ const currentNode = this.getCurrentNode()
398
+ const currentNodeFdId = currentNode.fdId
399
+ if (!currentNodeFdId) {
400
+ this.$message.error('请选择需要删除的数据!')
401
+ return
402
+ }
403
+
404
+ this.$confirm(`确定要删除【${currentNode.fdName}】?`, '提示', {
405
+ confirmButtonText: '确定',
406
+ cancelButtonText: '取消',
407
+ type: 'warning'
408
+ }).then(() => {
409
+ this.$request({
410
+ url: '/apd/db/DevDbField/deleteDbFieldType',
411
+ method: 'post',
412
+ data: {
413
+ fdId: currentNodeFdId
414
+ }
415
+ }).then(response => {
416
+ this.$message.success(`删除成功!已删除${response.data}条数据!`)
417
+ this.initTreeData()
418
+ })
419
+ })
420
+ },
421
+ checkTypeSort() {
422
+ const currentNode = this.getCurrentNode()
423
+ if (currentNode == null) {
424
+ this.$message.error(`请选择需要操作的节点!`)
425
+ return null
426
+ }
427
+ return currentNode
428
+ },
429
+ // 修改排序
430
+ doTypeSortChange(rowFdId, rowFdSort, exchangeRowFdId, exchangeRowFdSort) {
431
+ this.$request({
432
+ url: '/apd/db/DevDbField/updateDbFieldTypeSort',
433
+ method: 'post',
434
+ data: { rowFdId, rowFdSort, exchangeRowFdId, exchangeRowFdSort }
435
+ }).then(response => {
436
+ this.$message.success(`修改成功!`)
437
+ this.$refs.popoverRef.doClose()
438
+ this.loadTreeData()
439
+ })
440
+ },
441
+ // 排序调整:向上
442
+ sortTypeBefore() {
443
+ const currentNode = this.checkTypeSort()
444
+ if (currentNode == null) {
445
+ return
446
+ }
447
+
448
+ const arrayData = convertToArrayData(this.typeTreeList)
449
+ let currentNodeIndex = 0
450
+ for (let i = 0; i < arrayData.length; i++) {
451
+ if (arrayData[i].fdId == currentNode.fdId) {
452
+ currentNodeIndex = i
453
+ break
454
+ }
455
+ }
456
+ if (currentNodeIndex == 0) {
457
+ this.$message.success(`已经是第一个啦!`)
458
+ return
459
+ }
460
+
461
+ const exchangeRow = arrayData[currentNodeIndex - 1]
462
+
463
+ this.doTypeSortChange(currentNode.fdId, exchangeRow.fdSort, exchangeRow.fdId, currentNode.fdSort)
464
+ },
465
+ // 排序调整:向下
466
+ sortTypeAfter() {
467
+ const currentNode = this.checkTypeSort()
468
+ if (currentNode == null) {
469
+ return
470
+ }
471
+ const arrayData = convertToArrayData(this.typeTreeList)
472
+ let currentNodeIndex = 0
473
+ for (let i = 0; i < arrayData.length; i++) {
474
+ if (arrayData[i].fdId == currentNode.fdId) {
475
+ currentNodeIndex = i
476
+ break
477
+ }
478
+ }
479
+
480
+ if (currentNodeIndex == arrayData.length - 1) {
481
+ this.$message.success(`字段已经是最后一个啦!`)
482
+ return
483
+ }
484
+
485
+ const exchangeRow = arrayData[currentNodeIndex + 1]
486
+
487
+ this.doTypeSortChange(currentNode.fdId, exchangeRow.fdSort, exchangeRow.fdId, currentNode.fdSort)
488
+ },
489
+ // 一键排序
490
+ sortTypeByIndex() {
491
+ const arrayData = convertToArrayData(this.typeTreeList)
492
+ const list = []
493
+ for (let i = 0; i < arrayData.length; i++) {
494
+ list.push({
495
+ fdId: arrayData[i].fdId,
496
+ fdSort: i + 1
497
+ })
498
+ }
499
+ this.$request({
500
+ url: '/apd/db/DevDbField/updateDbFieldTypeSortList',
501
+ method: 'post',
502
+ data: { list: JSON.stringify(list) }
503
+ }).then(response => {
504
+ this.$message.success(`排序成功!`)
505
+ this.$refs.popoverRef.doClose()
506
+ this.loadTreeData()
507
+ })
508
+ },
509
+ // dialog:保存类型数据
510
+ saveTable() {
511
+ this.$refs.dialogForm.validate((valid) => {
512
+ if (!valid) {
513
+ this.$message.error(`数据校验失败,请重新填写信息!`)
514
+ return false
515
+ }
516
+ if (this.isAddDialog) {
517
+ // 添加数据
518
+ this.$request({
519
+ url: '/apd/db/DevDbField/insertDbFieldType',
520
+ method: 'post',
521
+ data: this.dialogForm
522
+ }).then(response => {
523
+ this.$message.success(`添加成功!已添加${response.data}条数据!`)
524
+ this.dialogVisible = false
525
+ this.initTreeData()
526
+ })
527
+ } else {
528
+ // 更新数据
529
+ this.$request({
530
+ url: '/apd/db/DevDbField/updateDbFieldType',
531
+ method: 'post',
532
+ data: this.dialogForm
533
+ }).then(response => {
534
+ this.$message.success(`更新成功!已更新${response.data}条数据!`)
535
+ this.dialogVisible = false
536
+ this.initTreeData()
537
+ })
538
+ }
539
+ })
540
+ },
541
+ // 添加行:数据类型默认值
542
+ beforeAddFn() {
543
+ const fdFieldTypeIds = this.selectedFieldTypeIds
544
+ if (fdFieldTypeIds == null || fdFieldTypeIds == '') {
545
+ this.$message.error(`请先选择字段类型!`)
546
+ return false
547
+ }
548
+ return true
549
+ },
550
+ addDefaultValueFn() {
551
+ return this.getCurrentNode().fdId
552
+ },
553
+ checkSort() {
554
+ const selection = this.$refs.devDbFieldGrid.getSelection()
555
+ if (selection.length == 0) {
556
+ this.$message.error(`请选择需要操作的行!`)
557
+ return null
558
+ } else if (selection.length > 1) {
559
+ this.$message.error(`只能选择一行!`)
560
+ return null
561
+ }
562
+ return selection[0]
563
+ },
564
+ // 修改排序
565
+ doSortChange(rowFdId, rowFdSort, exchangeRowFdId, exchangeRowFdSort) {
566
+ this.$request({
567
+ url: '/apd/db/DevDbField/updateDbFieldSort',
568
+ method: 'post',
569
+ data: { rowFdId, rowFdSort, exchangeRowFdId, exchangeRowFdSort }
570
+ }).then(response => {
571
+ this.$message.success(`修改成功!`)
572
+ this.$refs.devDbFieldGrid.refresh()
573
+ })
574
+ },
575
+ // 排序调整:向上
576
+ sortBefore() {
577
+ const rowData = this.checkSort()
578
+ if (rowData == null) {
579
+ return
580
+ }
581
+ const dataIdx = rowData.dataIdx
582
+ if (dataIdx == 1) {
583
+ this.$message.success(`字段已经是第一个啦!`)
584
+ return
585
+ }
586
+
587
+ const exchangeRow = this.tableOpt.data[dataIdx - 2]
588
+
589
+ this.doSortChange(rowData.fdId, exchangeRow.fdSort, exchangeRow.fdId, rowData.fdSort)
590
+ },
591
+ // 排序调整:向下
592
+ sortAfter() {
593
+ const rowData = this.checkSort()
594
+ if (rowData == null) {
595
+ return
596
+ }
597
+ const dataIdx = rowData.dataIdx
598
+ if (dataIdx >= this.tableOpt.data.length) {
599
+ this.$message.success(`字段已经是最后一个啦!`)
600
+ return
601
+ }
602
+ const exchangeRow = this.tableOpt.data[dataIdx]
603
+
604
+ this.doSortChange(rowData.fdId, exchangeRow.fdSort, exchangeRow.fdId, rowData.fdSort)
605
+ },
606
+ doSortByIndex() {
607
+ const data = this.$refs.devDbFieldGrid.getData()
608
+ const list = []
609
+ for (let i = 0; i < data.length; i++) {
610
+ list.push({
611
+ fdId: data[i].fdId,
612
+ fdSort: data[i].dataIdx
613
+ })
614
+ }
615
+ this.$request({
616
+ url: '/apd/db/DevDbField/updateDbFieldSortList',
617
+ method: 'post',
618
+ data: { list: JSON.stringify(list) }
619
+ }).then(response => {
620
+ this.$message.success(`排序成功!`)
621
+ this.$refs.devDbFieldGrid.refresh()
622
+ })
623
+ },
624
+ searchEvent() {
625
+ this.$refs.devDbFieldGrid.refresh()
626
+ },
627
+ openHelp() {
628
+ const msg = `
629
+ <b>一、通用字段:</b><br>
630
+ 1、标识类型(0、1):放在【默认-标识】下。<br>
631
+ 2、日期:放在【默认-日期】下。<br>
632
+ 3、字符串、数字:放在【默认-常用】下。<br>
633
+ 注意:只要是比较通用的字段,都应该放在【默认】的分类下。<br>
634
+ <b>二、特殊字段:</b><br>
635
+ 1、字段是业务模块特有的,放在【业务】下的模块。如:固定资产编码fd_asset_type_code,应该放在固定资产下。<br>
636
+ `
637
+ this.$alert(msg, '字段规范说明', { dangerouslyUseHTMLString: true })
638
+ }
639
+ }
640
+ }
641
+ </script>
642
+
643
+ <style scoped>
644
+ </style>