fast-crud-ui3 1.5.16 → 1.5.18-beta

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.
Files changed (168) hide show
  1. package/lib/assets/fonts/iconfont.d.ts +0 -0
  2. package/lib/components/checkbox-group/index.d.ts +2 -0
  3. package/lib/components/checkbox-group/src/fast-checkbox-group.d.ts +72 -0
  4. package/lib/components/content-dialog/index.d.ts +2 -0
  5. package/lib/components/content-dialog/src/fast-cell-content.d.ts +83 -0
  6. package/lib/components/json-viewer/index.d.ts +2 -0
  7. package/lib/components/json-viewer/src/fast-json-viewer.d.ts +48 -0
  8. package/lib/components/mapping.d.ts +5 -0
  9. package/lib/components/object-picker/index.d.ts +2 -0
  10. package/lib/components/object-picker/src/fast-object-picker.d.ts +132 -0
  11. package/lib/components/select/index.d.ts +2 -0
  12. package/lib/components/select/src/fast-select.d.ts +83 -0
  13. package/lib/components/table/index.d.ts +2 -0
  14. package/lib/components/table/src/RowConfirm.d.ts +39 -0
  15. package/lib/components/table/src/dynamic-filter-form.d.ts +118 -0
  16. package/lib/components/table/src/dynamic-filter-list.d.ts +57 -0
  17. package/lib/components/table/src/easy-filter.d.ts +118 -0
  18. package/lib/components/table/src/export-confirm.d.ts +12 -0
  19. package/lib/components/table/src/quick-filter-form.d.ts +42 -0
  20. package/lib/components/table/src/row-form.d.ts +33 -0
  21. package/lib/components/table/src/stored-filter-manager.d.ts +55 -0
  22. package/lib/components/table/src/stored-filter.d.ts +37 -0
  23. package/lib/components/table/src/table-head-cell.d.ts +9 -0
  24. package/lib/components/table/src/table.d.ts +507 -0
  25. package/lib/components/table/src/util.d.ts +77 -0
  26. package/lib/components/table-column/config.d.ts +5 -0
  27. package/lib/components/table-column/index.d.ts +2 -0
  28. package/lib/components/table-column/src/table-column.d.ts +256 -0
  29. package/lib/components/table-column-date-picker/config.d.ts +5 -0
  30. package/lib/components/table-column-date-picker/index.d.ts +2 -0
  31. package/lib/components/table-column-date-picker/src/table-column-date-picker.d.ts +173 -0
  32. package/lib/components/table-column-file/config.d.ts +5 -0
  33. package/lib/components/table-column-file/index.d.ts +2 -0
  34. package/lib/components/table-column-file/src/table-column-file.d.ts +285 -0
  35. package/lib/components/table-column-img/config.d.ts +5 -0
  36. package/lib/components/table-column-img/index.d.ts +2 -0
  37. package/lib/components/table-column-img/src/table-column-img.d.ts +285 -0
  38. package/lib/components/table-column-input/config.d.ts +5 -0
  39. package/lib/components/table-column-input/index.d.ts +2 -0
  40. package/lib/components/table-column-input/src/table-column-input.d.ts +173 -0
  41. package/lib/components/table-column-number/config.d.ts +5 -0
  42. package/lib/components/table-column-number/index.d.ts +2 -0
  43. package/lib/components/table-column-number/src/table-column-number.d.ts +173 -0
  44. package/lib/components/table-column-object/config.d.ts +5 -0
  45. package/lib/components/table-column-object/index.d.ts +2 -0
  46. package/lib/components/table-column-object/src/table-column-object.d.ts +315 -0
  47. package/lib/components/table-column-select/config.d.ts +5 -0
  48. package/lib/components/table-column-select/index.d.ts +2 -0
  49. package/lib/components/table-column-select/src/table-column-select.d.ts +276 -0
  50. package/lib/components/table-column-switch/config.d.ts +5 -0
  51. package/lib/components/table-column-switch/index.d.ts +2 -0
  52. package/lib/components/table-column-switch/src/table-column-switch.d.ts +175 -0
  53. package/lib/components/table-column-textarea/config.d.ts +5 -0
  54. package/lib/components/table-column-textarea/index.d.ts +2 -0
  55. package/lib/components/table-column-textarea/src/table-column-textarea.d.ts +173 -0
  56. package/lib/components/table-column-time-picker/config.d.ts +5 -0
  57. package/lib/components/table-column-time-picker/index.d.ts +2 -0
  58. package/lib/components/table-column-time-picker/src/table-column-time-picker.d.ts +173 -0
  59. package/lib/components/upload/index.d.ts +2 -0
  60. package/lib/components/upload/src/fast-upload.d.ts +120 -0
  61. package/lib/fast-crud-ui3.cjs.js +44 -17
  62. package/lib/fast-crud-ui3.es.js +9991 -5946
  63. package/lib/fast-crud-ui3.umd.js +44 -17
  64. package/lib/global.d.ts +42 -0
  65. package/lib/index.d.ts +56 -0
  66. package/lib/mixins/table-column.d.ts +104 -0
  67. package/lib/mixins/upload.d.ts +15 -0
  68. package/lib/model/cond.d.ts +48 -0
  69. package/lib/model/editComponentConfig.d.ts +25 -0
  70. package/lib/model/fastTableOption.d.ts +513 -0
  71. package/lib/model/filterComponentConfig.d.ts +55 -0
  72. package/lib/model/opt.d.ts +20 -0
  73. package/lib/model/order.d.ts +28 -0
  74. package/lib/model/pageQuery.d.ts +43 -0
  75. package/lib/model/query.d.ts +101 -0
  76. package/lib/model/rel.d.ts +5 -0
  77. package/lib/style.css +1 -1
  78. package/lib/util/cache.d.ts +17 -0
  79. package/lib/util/dialog.d.ts +49 -0
  80. package/lib/util/escape.d.ts +7 -0
  81. package/lib/util/http.d.ts +8 -0
  82. package/lib/util/pick.d.ts +9 -0
  83. package/lib/util/util.d.ts +311 -0
  84. package/package.json +19 -5
  85. package/packages/assets/fonts/iconfont.css +163 -0
  86. package/packages/assets/fonts/iconfont.js +1 -0
  87. package/packages/assets/fonts/iconfont.ttf +0 -0
  88. package/packages/assets/fonts/iconfont.woff +0 -0
  89. package/packages/assets/fonts/iconfont.woff2 +0 -0
  90. package/packages/components/checkbox-group/index.js +7 -0
  91. package/packages/components/checkbox-group/src/fast-checkbox-group.vue +83 -0
  92. package/packages/components/content-dialog/index.js +7 -0
  93. package/packages/components/content-dialog/src/fast-cell-content.vue +115 -0
  94. package/packages/components/json-viewer/index.js +7 -0
  95. package/packages/components/json-viewer/src/fast-json-viewer.vue +54 -0
  96. package/packages/components/mapping.js +95 -0
  97. package/packages/components/object-picker/index.js +7 -0
  98. package/packages/components/object-picker/src/fast-object-picker.vue +170 -0
  99. package/packages/components/select/index.js +7 -0
  100. package/packages/components/select/src/fast-select.vue +90 -0
  101. package/packages/components/table/index.js +7 -0
  102. package/packages/components/table/src/RowConfirm.vue +87 -0
  103. package/packages/components/table/src/dynamic-filter-form.vue +253 -0
  104. package/packages/components/table/src/dynamic-filter-list.vue +172 -0
  105. package/packages/components/table/src/easy-filter.vue +129 -0
  106. package/packages/components/table/src/export-confirm.vue +55 -0
  107. package/packages/components/table/src/quick-filter-form.vue +140 -0
  108. package/packages/components/table/src/row-form.vue +137 -0
  109. package/packages/components/table/src/stored-filter-manager.vue +240 -0
  110. package/packages/components/table/src/stored-filter.vue +180 -0
  111. package/packages/components/table/src/table-head-cell.vue +41 -0
  112. package/packages/components/table/src/table.vue +1309 -0
  113. package/packages/components/table/src/util.js +496 -0
  114. package/packages/components/table-column/config.js +64 -0
  115. package/packages/components/table-column/index.js +7 -0
  116. package/packages/components/table-column/src/table-column.vue +44 -0
  117. package/packages/components/table-column-date-picker/config.js +139 -0
  118. package/packages/components/table-column-date-picker/index.js +7 -0
  119. package/packages/components/table-column-date-picker/src/table-column-date-picker.vue +54 -0
  120. package/packages/components/table-column-file/config.js +83 -0
  121. package/packages/components/table-column-file/index.js +7 -0
  122. package/packages/components/table-column-file/src/table-column-file.vue +79 -0
  123. package/packages/components/table-column-img/config.js +83 -0
  124. package/packages/components/table-column-img/index.js +7 -0
  125. package/packages/components/table-column-img/src/table-column-img.vue +82 -0
  126. package/packages/components/table-column-input/config.js +77 -0
  127. package/packages/components/table-column-input/index.js +7 -0
  128. package/packages/components/table-column-input/src/table-column-input.vue +60 -0
  129. package/packages/components/table-column-number/config.js +89 -0
  130. package/packages/components/table-column-number/index.js +7 -0
  131. package/packages/components/table-column-number/src/table-column-number.vue +54 -0
  132. package/packages/components/table-column-object/config.js +66 -0
  133. package/packages/components/table-column-object/index.js +7 -0
  134. package/packages/components/table-column-object/src/table-column-object.vue +75 -0
  135. package/packages/components/table-column-select/config.js +67 -0
  136. package/packages/components/table-column-select/index.js +7 -0
  137. package/packages/components/table-column-select/src/table-column-select.vue +101 -0
  138. package/packages/components/table-column-switch/config.js +55 -0
  139. package/packages/components/table-column-switch/index.js +7 -0
  140. package/packages/components/table-column-switch/src/table-column-switch.vue +82 -0
  141. package/packages/components/table-column-textarea/config.js +77 -0
  142. package/packages/components/table-column-textarea/index.js +7 -0
  143. package/packages/components/table-column-textarea/src/table-column-textarea.vue +56 -0
  144. package/packages/components/table-column-time-picker/config.js +62 -0
  145. package/packages/components/table-column-time-picker/index.js +7 -0
  146. package/packages/components/table-column-time-picker/src/table-column-time-picker.vue +53 -0
  147. package/packages/components/upload/index.js +7 -0
  148. package/packages/components/upload/src/fast-upload.vue +272 -0
  149. package/packages/global.d.ts +42 -0
  150. package/packages/index.js +145 -0
  151. package/packages/mixins/table-column.js +133 -0
  152. package/packages/mixins/upload.js +14 -0
  153. package/packages/model/cond.js +74 -0
  154. package/packages/model/editComponentConfig.js +72 -0
  155. package/packages/model/fastTableOption.js +769 -0
  156. package/packages/model/filterComponentConfig.js +191 -0
  157. package/packages/model/opt.js +21 -0
  158. package/packages/model/order.js +37 -0
  159. package/packages/model/pageQuery.js +52 -0
  160. package/packages/model/query.js +161 -0
  161. package/packages/model/rel.js +5 -0
  162. package/packages/style.scss +5 -0
  163. package/packages/util/cache.js +92 -0
  164. package/packages/util/dialog.js +133 -0
  165. package/packages/util/escape.js +34 -0
  166. package/packages/util/http.js +18 -0
  167. package/packages/util/pick.js +92 -0
  168. package/packages/util/util.js +892 -0
@@ -0,0 +1,145 @@
1
+ import FastCheckboxGroup from "./components/checkbox-group";
2
+ import FastCellContent from "./components/content-dialog/src/fast-cell-content.vue";
3
+ import FastJsonViewer from "./components/json-viewer/src/fast-json-viewer.vue";
4
+ import FastSelect from "./components/select";
5
+ import FastUpload from "./components/upload";
6
+ import FastObjectPicker from './components/object-picker'
7
+ import FastTable from './components/table'
8
+ import FastTableColumn from './components/table-column'
9
+ import FastTableColumnDatePicker from './components/table-column-date-picker'
10
+ import FastTableColumnImg from './components/table-column-img'
11
+ import FastTableColumnFile from './components/table-column-file'
12
+ import FastTableColumnInput from './components/table-column-input'
13
+ import FastTableColumnNumber from './components/table-column-number'
14
+ import FastTableColumnObject from './components/table-column-object'
15
+ import FastTableColumnSelect from './components/table-column-select'
16
+ import FastTableColumnSwitch from './components/table-column-switch'
17
+ import FastTableColumnTextarea from './components/table-column-textarea'
18
+ import FastTableColumnTimePicker from './components/table-column-time-picker'
19
+ import {openDialog} from "./util/dialog";
20
+ import {pick} from "./util/pick";
21
+ import "./style.scss"
22
+ import FastTableOption from "./model/fastTableOption.js";
23
+ import Opt from './model/opt.js'
24
+ import Cond from './model/cond.js'
25
+ import Order from './model/order.js'
26
+ import Query from './model/query.js'
27
+ import PageQuery from './model/pageQuery.js'
28
+ import {
29
+ isEmpty,
30
+ isString,
31
+ isNumber,
32
+ isArray,
33
+ ifBlank,
34
+ isFunction,
35
+ isObject,
36
+ isBoolean,
37
+ isNull,
38
+ isUndefined,
39
+ defaultIfEmpty,
40
+ defaultIfBlank,
41
+ camelCaseTo,
42
+ caseToCamel,
43
+ clear,
44
+ deepClone,
45
+ merge,
46
+ coverMerge
47
+ } from "./util/util";
48
+
49
+ const components = [
50
+ FastCheckboxGroup,
51
+ FastSelect,
52
+ FastUpload,
53
+ FastObjectPicker,
54
+ FastTable,
55
+ FastTableColumn,
56
+ FastTableColumnDatePicker,
57
+ FastTableColumnFile,
58
+ FastTableColumnImg,
59
+ FastTableColumnInput,
60
+ FastTableColumnNumber,
61
+ FastTableColumnObject,
62
+ FastTableColumnSelect,
63
+ FastTableColumnSwitch,
64
+ FastTableColumnTextarea,
65
+ FastTableColumnTimePicker
66
+ ];
67
+
68
+ const directives = [
69
+ ]
70
+
71
+ // 全局应用上下文
72
+ let globalAppContext = null
73
+ const install = function (app, opts = {}) {
74
+ globalAppContext = app._context // 保存上下文
75
+ if (opts.hasOwnProperty('$http')) {
76
+ FastTableOption.$http = opts.$http
77
+ }
78
+ if (opts.hasOwnProperty('$router')) {
79
+ FastTableOption.$router = opts.$router
80
+ }
81
+ components.forEach(component => {
82
+ app.component(component.name, component);
83
+ });
84
+ directives.forEach(directive => {
85
+ app.use(directive)
86
+ })
87
+ };
88
+
89
+ const util = {
90
+ isEmpty,
91
+ isString,
92
+ isNumber,
93
+ isArray,
94
+ ifBlank,
95
+ isFunction,
96
+ isObject,
97
+ isBoolean,
98
+ isNull,
99
+ isUndefined,
100
+ defaultIfEmpty,
101
+ defaultIfBlank,
102
+ camelCaseTo,
103
+ caseToCamel,
104
+ clear,
105
+ deepClone,
106
+ merge,
107
+ coverMerge,
108
+ openDialog,
109
+ pick
110
+ }
111
+
112
+ export {
113
+ FastCheckboxGroup,
114
+ FastCellContent,
115
+ FastJsonViewer,
116
+ FastSelect,
117
+ FastUpload,
118
+ FastObjectPicker,
119
+ FastTable,
120
+ FastTableColumn,
121
+ FastTableColumnDatePicker,
122
+ FastTableColumnFile,
123
+ FastTableColumnImg,
124
+ FastTableColumnInput,
125
+ FastTableColumnNumber,
126
+ FastTableColumnObject,
127
+ FastTableColumnSelect,
128
+ FastTableColumnSwitch,
129
+ FastTableColumnTextarea,
130
+ FastTableColumnTimePicker,
131
+ FastTableOption,
132
+ Opt,
133
+ PageQuery,
134
+ Query,
135
+ Order,
136
+ Cond,
137
+ util
138
+ }
139
+
140
+ // 获取App上下文
141
+ export const getAppContext = () => globalAppContext
142
+
143
+ export default {
144
+ install
145
+ };
@@ -0,0 +1,133 @@
1
+ import {colEditable} from "../components/table/src/util"
2
+ import FastTableHeadCell from "../components/table/src/table-head-cell.vue"
3
+ import FastCellContent from "../components/content-dialog/src/fast-cell-content.vue";
4
+ import {convertKeyFromCaseToCamel, replaceKey} from "../util/util.js";
5
+
6
+ export default {
7
+ inject: ['openDynamicFilterForm', 'tableStyle', 'context'],
8
+ emits: ['change', 'focus', 'blur', 'input', 'clear'],
9
+ components: {FastTableHeadCell, FastCellContent},
10
+ props: {
11
+ prop: {
12
+ type: String,
13
+ required: true
14
+ },
15
+ label: {
16
+ type: String,
17
+ required: true
18
+ },
19
+ // 值为Boolean且为true时, 则将单元格内容作为链接地址; 值为字符串其非空时,将值作为跳转地址,且以超链接的形式展示单元格内容, 并支持点击, 值支持路由地址、路由名、绝对地址
20
+ link: {
21
+ type: [Boolean, String],
22
+ default: () => false
23
+ },
24
+ // 以实现某一列不显示, 仍然可以参与生成筛选项
25
+ hidden: {
26
+ type: Boolean,
27
+ default: () => false
28
+ },
29
+ // 此列是否支持过滤. 若为false, 则简筛、快筛、动筛都将不支持。此优先级高于quickFilter和dynamicFilter
30
+ filter: {
31
+ type: [Boolean, Number],
32
+ default: () => true
33
+ },
34
+ // 此列是否支持快筛
35
+ quickFilter: {
36
+ type: [Boolean, Number],
37
+ default: () => false
38
+ },
39
+ quickFilterBlock: {
40
+ type: Boolean,
41
+ default: () => false
42
+ },
43
+ // 快筛更多配置: 解决筛选项级联问题
44
+ quickFilterConfig: Object, // {onChange: Function, onClick: Function}
45
+ // 此列是否支持动筛: 若为false, 则列头不可点击
46
+ dynamicFilter: {
47
+ type: Boolean,
48
+ default: () => true
49
+ },
50
+ /**
51
+ * 1.5.12 是否唯一, 若为true, 新增或更新时, 会校验此值的唯一性(前后端均校验)
52
+ */
53
+ unique: {
54
+ type: Boolean,
55
+ default: () => false
56
+ },
57
+ // deprecated: 1.6.0
58
+ firstFilter: {
59
+ type: Boolean,
60
+ default: () => false
61
+ },
62
+ showOverflowTooltip: {
63
+ type: Boolean,
64
+ default: () => false
65
+ },
66
+ /**
67
+ * 显示的字符长度, 超长时会显示"...", 并支持弹窗预览完整信息
68
+ */
69
+ showLength: {
70
+ type: Number,
71
+ default: () => Number.MAX_VALUE
72
+ }
73
+ },
74
+ data() {
75
+ let attrs = convertKeyFromCaseToCamel(this.$attrs, '-');
76
+ attrs = replaceKey(attrs, '_q')
77
+ attrs = replaceKey(attrs, '_e')
78
+ return {
79
+ columnProp: {
80
+ ...attrs,
81
+ prop: this.prop,
82
+ label: this.label,
83
+ filter: this.filter,
84
+ dynamicFilter: this.dynamicFilter,
85
+ order: '' // '', 'asc', 'desc'
86
+ }
87
+ }
88
+ },
89
+ methods: {
90
+ /**
91
+ * 是否展示编辑模式
92
+ * @param fatRow
93
+ * @param column element原生列配置
94
+ * @param $index 当前行索引
95
+ * @returns {boolean}
96
+ */
97
+ canEdit(fatRow, column, $index) {
98
+ return colEditable.call(this.context !== null && this.context !== undefined ? this.context : this, fatRow, column.property);
99
+ },
100
+ showLabel(fatRow) {
101
+ const {row, editRow, status} = fatRow;
102
+ return status === 'normal' ? row[this.prop] : editRow[this.prop];
103
+ },
104
+ headCellClick(column) {
105
+ if (this.filter !== false && this.dynamicFilter !== false) {
106
+ this.openDynamicFilterForm(this.columnProp)
107
+ }
108
+ },
109
+ // change事件上抛并触发验证
110
+ handleChange(val, scope) {
111
+ this.$emit('change', val, scope);
112
+ const {column, $index, row: {editRow, config}} = scope;
113
+ const {property} = column;
114
+ const ref = this.$refs[property + $index];
115
+ const {eventMethods: {valid} = {}, props} = config[property]
116
+ if (valid) {
117
+ valid(val, editRow, ref, props);
118
+ }
119
+ },
120
+ handleFocus(event, scope) {
121
+ this.$emit('focus', event, scope)
122
+ },
123
+ handleBlur(event, scope) {
124
+ this.$emit('blur', event, scope)
125
+ },
126
+ handleInput(val, scope) {
127
+ this.$emit('input', val, scope);
128
+ },
129
+ handleClear(scope) {
130
+ this.$emit('clear', scope);
131
+ }
132
+ }
133
+ }
@@ -0,0 +1,14 @@
1
+ export default {
2
+ props: {
3
+ onPreview: Function,
4
+ beforeRemove: Function,
5
+ onRemove: Function,
6
+ onSuccess: Function,
7
+ onError: Function,
8
+ onProgress: Function,
9
+ onChange: Function,
10
+ onExceed: Function,
11
+ beforeUpload: Function,
12
+ responseHandler: Function
13
+ }
14
+ }
@@ -0,0 +1,74 @@
1
+ import {assert, defaultIfBlank, isEmpty, isObject, isString} from "../util/util.js";
2
+ import Opt from "./opt.js";
3
+
4
+ /**
5
+ * @typedef {typeof Opt[keyof typeof Opt]} OptValue
6
+ */
7
+ class Cond {
8
+ /**
9
+ * 字段名
10
+ * @type {string}
11
+ */
12
+ col;
13
+ /**
14
+ * 操作符
15
+ * @type {OptValue}
16
+ */
17
+ opt;
18
+ /**
19
+ * 值
20
+ * @type {object}
21
+ */
22
+ val;
23
+
24
+ /**
25
+ * 构造函数
26
+ * @param col 字段
27
+ * @param opt {OptValue} 操作符,可以使用常量
28
+ * @param val 值
29
+ */
30
+ constructor(col, opt, val) {
31
+ assert(isString(col) && !isEmpty(col), 'col必须为有效字符串')
32
+ assert(Object.values(Opt).indexOf(opt) > -1, `opt无效:${opt}`)
33
+ this.col = col;
34
+ this.opt = opt;
35
+ this.val = val;
36
+ }
37
+
38
+ /**
39
+ * 设置操作符
40
+ * @param opt {string}
41
+ * @return {Cond}
42
+ */
43
+ setOpt(opt) {
44
+ this.opt = opt;
45
+ return this;
46
+ }
47
+
48
+ /**
49
+ * 设置值
50
+ * @param val {object}
51
+ * @return {Cond}
52
+ */
53
+ setVal(val) {
54
+ this.val = val;
55
+ return this;
56
+ }
57
+
58
+ /**
59
+ * 通过json构建一个Cond条件对象
60
+ * @param condJson {object} 条件的json
61
+ * @return {Cond}
62
+ */
63
+ static build(condJson) {
64
+ if (condJson instanceof Cond) {
65
+ return condJson;
66
+ }
67
+ assert(isObject(condJson), 'cond不是json格式!')
68
+ const {col, opt = Opt.EQ, val} = condJson
69
+ assert(!isEmpty(col), 'cond格式不正确: 无col属性或其值为空!')
70
+ return new Cond(col, defaultIfBlank(opt, Opt.EQ), val);
71
+ }
72
+ }
73
+
74
+ export default Cond
@@ -0,0 +1,72 @@
1
+ import {isEmpty, isFunction, isNull, isUndefined} from "../util/util.js";
2
+ import FastTableOption from "./fastTableOption.js";
3
+ import Opt from './opt.js'
4
+
5
+ /**
6
+ * 编辑组件配置
7
+ */
8
+ class EditComponentConfig {
9
+ component;
10
+ col;
11
+ label;
12
+ props;
13
+ val;
14
+ editable; // 是否可编辑, true 表示可编辑, false表示不可编辑, insert-表示新增时可编辑, update-表示更新时可编辑. 默认为true.
15
+ type; // inline, form
16
+ eventMethods; // 组件事件触发时调用其中的方法,例如参数验证
17
+
18
+ constructor({component, col, label, props, val, eventMethods, type, unique, tableOption}) {
19
+ this.component = component;
20
+ this.col = col;
21
+ this.label = label;
22
+ const {editable, ...validProps} = props; // 移除props中的editable属性,避免editable对组件影响
23
+ this.props = validProps;
24
+ this.val = val;
25
+ this.editable = editable;
26
+ this.eventMethods = eventMethods;
27
+ this.type = type;
28
+ // 将unique转换为 props.rules一部分
29
+ if (unique !== false && (tableOption instanceof FastTableOption)) {
30
+ const pkField = tableOption.idField
31
+ const uniqueValidator = async (rule, value, callback, source, options) => {
32
+ if (isNull(value) || isUndefined(value)) {
33
+ return Promise.resolve()
34
+ }
35
+
36
+ const {getRow} = rule
37
+ if (!isFunction(getRow)) {
38
+ // 无法获取当前行
39
+ console.error('无法进行唯一性校验:无法获取当前记录完整数据')
40
+ return Promise.resolve()
41
+ }
42
+ const currentRow = getRow()
43
+ const pkVal = currentRow[pkField]
44
+ if (type === 'inline') {
45
+ if (isEmpty(tableOption.ref?.editRows)) {
46
+ return Promise.resolve()
47
+ }
48
+ const editRows = tableOption.ref.editRows.map(fatRow => fatRow.editRow)
49
+ const duplicates = editRows.filter(row => row[rule.field] === value && row[pkField] !== pkVal)
50
+ if (duplicates.length > 0) {
51
+ return Promise.reject(`【${label}】${value}已存在于其它编辑行`)
52
+ }
53
+ }
54
+
55
+ // 后端唯一性校验
56
+ const result = await tableOption._exist([
57
+ {col: pkField, opt: Opt.NE, val: pkVal}, // 避免自身编辑时误报
58
+ {col: col, opt: Opt.EQ, val: value}
59
+ ])
60
+ if (result) { // 表示存在
61
+ return Promise.reject(`【${label}】${value}已存在`)
62
+ }
63
+ return Promise.resolve()
64
+ }
65
+ props?.rules.push({
66
+ validator: uniqueValidator, trigger: 'blur'
67
+ })
68
+ }
69
+ }
70
+ }
71
+
72
+ export default EditComponentConfig