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,496 @@
1
+ import {buildFinalQueryComponentConfig, buildFinalEditComponentConfig} from '../../mapping'
2
+ import Schema from 'async-validator'
3
+ import Opt from '../../../model/opt.js'
4
+ import * as util from '../../../util/util.js'
5
+ import * as cache from '../../../util/cache.js'
6
+
7
+ /**
8
+ * 单个col值校验, 校验失败会添加class: valid-error并reject(errors), 成功则会移除可能存在的valid-error,并resolve
9
+ * @param editRow 当前单元格所在行数据
10
+ * @param config col完整的config配置
11
+ * @returns {Promise<unknown>} 若校验通过resolve, 否则reject(errors)
12
+ */
13
+ export function colValid(editRow, config) {
14
+ const {col, props} = config;
15
+ const val = editRow[col]
16
+ return new Promise((resolve, reject) => {
17
+ if (util.isEmpty(props?.rules)) {
18
+ resolve()
19
+ return
20
+ }
21
+ props.rules.forEach(rule => rule.getRow = (() => editRow)) // 为了自定义验证器里能获取到当前行 煞费苦心
22
+ const validator = new Schema({
23
+ [col]: util.defaultIfEmpty(props.rules, [])
24
+ });
25
+ validator.validate({[col]: val}, async (errors, fields) => {
26
+ if (util.isEmpty(errors)) {
27
+ props.class = util.defaultIfBlank(props.class, '').replaceAll('fc-valid-error', '');
28
+ resolve();
29
+ } else {
30
+ props.class = util.defaultIfBlank(props.class, '') + ' fc-valid-error';
31
+ reject(errors);
32
+ }
33
+ })
34
+ })
35
+ }
36
+
37
+ /**
38
+ * 多行(整行)校验, 校验失败会为每个col配置添加class: valid-error并reject(errors), 成功则会移除每个col可能存在的valid-error,并resolve。
39
+ * @param fatRows 完整的行记录
40
+ * @param tableOption tableOption
41
+ * @return 返回Promise, 校验通过走then; 校验失败走catch(errors)
42
+ */
43
+ export function rowValid(fatRows, tableOption) {
44
+ const validPromises = []
45
+ const context = tableOption.context
46
+ for (let i = 0; i < fatRows.length; i++) {
47
+ const fatRow = fatRows[i]
48
+ const {editRow, config} = fatRow
49
+ Object.keys(config).map(col => {
50
+ const canEdit = colEditable.call(context == null ? this : context, fatRow, col)
51
+ if (canEdit) {
52
+ validPromises.push(colValid(editRow, config[col]))
53
+ }
54
+ });
55
+ }
56
+ return Promise.all(validPromises)
57
+ }
58
+
59
+ /**
60
+ * 获取编辑配置
61
+ * @param columnConfig 列配置
62
+ * @param editType 编辑类型(inline, form)
63
+ * @returns {{}}
64
+ */
65
+ export const getEditConfig = function (columnConfig, editType) {
66
+ const config = {}
67
+ try {
68
+ const keys = Object.keys(columnConfig);
69
+ for (let i = 0; i < keys.length; i++) {
70
+ const col = keys[i];
71
+ const {tableColumnComponentName, inlineItemConfig, formItemConfig} = columnConfig[col];
72
+ // FIX: 此处深拷贝针对FastTableColumnObject可能存在问题(TypeError: Cannot convert a Symbol value to a string)
73
+ // 权衡下,这里无需深拷贝, config内容其实不会更改
74
+ // config[col] = (editType === 'form' ? util.deepClone(formItemConfig) : util.deepClone(inlineItemConfig));
75
+ config[col] = (editType === 'form' ? formItemConfig : inlineItemConfig);
76
+ if (tableColumnComponentName === 'fast-table-column') {
77
+ config[col].props.disabled = true;
78
+ }
79
+ }
80
+ } catch (err) {
81
+ console.error(err);
82
+ }
83
+ return config;
84
+ }
85
+
86
+ /**
87
+ * 将行数据转换为table-row格式
88
+ * @param row
89
+ * @param columnConfig
90
+ * @param status 表格状态
91
+ * @prop editType
92
+ * @returns {{editRow: *, row: *, status: string}}
93
+ */
94
+ export function toTableRow(row, columnConfig, status = 'normal', editType) {
95
+ const config = getEditConfig(columnConfig, editType);
96
+ if (status === 'insert') {
97
+ // fill row
98
+ const cols = Object.keys(config);
99
+ const newRow = {};
100
+ cols.forEach(col => {
101
+ const {val} = config[col];
102
+ newRow[col] = util.deepClone(val);
103
+ })
104
+ util.merge(row, newRow, true, false)
105
+ }
106
+ return {
107
+ row: row,
108
+ editRow: {...row},
109
+ status: status,
110
+ config: util.deepClone(config)
111
+ }
112
+ }
113
+
114
+ export function isFatRow(row) {
115
+ return row.hasOwnProperty('row')
116
+ && row.hasOwnProperty('editRow')
117
+ && row.hasOwnProperty('status')
118
+ && row.hasOwnProperty('config')
119
+ }
120
+
121
+ function parseStaticProps(staticProps) {
122
+ const props = {}
123
+ if (!util.isEmpty(staticProps)) {
124
+ for (const key in staticProps) {
125
+ if (staticProps[key].hasOwnProperty('default')) {
126
+ const defaultV = staticProps[key]['default']
127
+ props[key] = util.isFunction(defaultV) ? defaultV() : defaultV
128
+ }
129
+ }
130
+ }
131
+ return props
132
+ }
133
+
134
+ /**
135
+ * 构建组件配置
136
+ * @param tableColumnVNodes fast-table-column-* 组成的节点数组,蕴含fast-table-column-*组件节点上的信息(也可能是ElTableColumn)
137
+ * @param tableOption 表格配置
138
+ * @param callback 针对每个table-column解析的回调函数
139
+ */
140
+ export function iterBuildComponentConfig(tableColumnVNodes, tableOption, callback) {
141
+ const fromTableProps = { // 通过option传入配置项, 需要作用到搜索或编辑等组件内部
142
+ size: tableOption.style.size
143
+ }
144
+
145
+ for (let i = 0; i < tableColumnVNodes.length; i++) {
146
+ const columnVNode = tableColumnVNodes[i]
147
+ const {
148
+ props: _props,
149
+ type: {
150
+ name: tableColumnComponentName,
151
+ props: _typeProps,
152
+ mixins = []
153
+ }
154
+ } = columnVNode
155
+ const propsInMixin = mixins.reduce((acc, item) => {
156
+ let mixinProps = parseStaticProps(item.props)
157
+ return {...acc, ...mixinProps}
158
+ }, {})
159
+
160
+ const customProps = util.convertKeyFromCaseToCamel(_props, '-')
161
+ const defaultProps = {
162
+ ...fromTableProps,
163
+ ...parseStaticProps(_typeProps),
164
+ ...propsInMixin
165
+ }
166
+ const props = {...defaultProps, ...customProps}
167
+
168
+ const param = {}
169
+ const {showOverflowTooltip, minWidth, ...leftProp} = props
170
+ const {label, prop: col, filter, quickFilter, dynamicFilter, unique, firstFilter, hidden, showLength} = leftProp
171
+ if (util.isEmpty(col)) { // 操作列
172
+ continue
173
+ }
174
+ const customConfig = {
175
+ label: label,
176
+ col: col,
177
+ filter: filter, // 当前列是否支持过滤(快筛、简筛、动筛)
178
+ quickFilter: quickFilter, // 当前列是否支持快筛
179
+ dynamicFilter: dynamicFilter, // 当前列是否支持动筛
180
+ unique: unique,
181
+ firstFilter: firstFilter, // deprecated: 1.6.0
182
+ hidden: hidden,
183
+ showLength: showLength,
184
+ // 对于FastTableColumn*中定义了的prop, 从leftProp中移除 TODO 1.5.19 针对FastTableColumn* props中定义的属性,而又不希望透传给内置控件的, 应当在FastTableColumn*中声明, 而不是在这里设置"黑名单"
185
+ props: filterConflictKey(leftProp, columnVNode, ['quickFilterCheckbox', 'quickFilterBlock', 'tableOption', 'quickFilterConfig'])
186
+ // props: leftProp
187
+ }
188
+ try {
189
+ if (filter !== false) {
190
+ buildFilterComponentConfig(param, tableColumnComponentName, customConfig, tableOption);
191
+ }
192
+ buildEditComponentConfig(param, tableColumnComponentName, customConfig, tableOption);
193
+ } catch (err) {
194
+ console.error(err)
195
+ } finally {
196
+ callback({tableColumnComponentName, col, customConfig: customConfig, ...param})
197
+ }
198
+ }
199
+
200
+ }
201
+
202
+
203
+ /**
204
+ * 排除掉props中那些已经在vnode里静态定义过的属性(包括事件), 视为columnVNode的,无需透传给底层控件
205
+ *
206
+ * 例如:
207
+ * props中有属性onChange, vnode里在emits中定义了change(columnVNode.type.emits或vnode.type.mixins[*].emits), 则返回的对象中不会包含onChange。
208
+ * 针对事件的过滤,主要目的是预防vnode对应的组件中定义了透传给底层控件的事件,却被传入的覆盖,导致内部的不触发。
209
+ * @param props 属性键值对象
210
+ * @param columnVNode vnode节点
211
+ * @param ignoreKeys 忽略的属性
212
+ * @return 返回过滤后新的props属性
213
+ */
214
+ function filterConflictKey(props, columnVNode, ignoreKeys) {
215
+ const {type: {emits = [], props: _props, mixins = []} = {}} = columnVNode
216
+ // 定义的属性
217
+ const allProps = {
218
+ ...(_props || {}),
219
+ ...((mixins || []).reduce((acc, m) => {
220
+ return {...acc, ...m.props}
221
+ }, {}))
222
+ }
223
+ const allPropKeys = Object.keys(allProps)
224
+
225
+ // 定义的emits
226
+ const allEmits = new Set([
227
+ ...(emits || []),
228
+ ...((mixins || []).flatMap(m => {
229
+ const {emits: emitsInMixin} = m
230
+ return emitsInMixin || []
231
+ }))
232
+ ])
233
+
234
+ const newProps = {}
235
+ for (const [key, value] of Object.entries(props)) {
236
+ if (ignoreKeys.indexOf(key) > -1) {
237
+ newProps[key] = value
238
+ continue
239
+ }
240
+
241
+ // 通过在FastTableColumn*中定义的prop中声明一个自定义属性skip为true,表示此属性需要透传到控件上,此法可替代目前的冲突策略。不过还没考虑清楚,先不启用
242
+ // if (_props[key]?.skip === true) {
243
+ // newProps[key] = value
244
+ // continue
245
+ // }
246
+
247
+ if (allPropKeys.indexOf(key) > -1) {
248
+ continue
249
+ }
250
+ const evtName = util.extractEventName(key)
251
+ if (evtName && allEmits.has(evtName)) {
252
+ continue
253
+ }
254
+ newProps[key] = value
255
+ }
256
+ return newProps
257
+ }
258
+
259
+ /**
260
+ * 构建过滤器组件配置
261
+ * @param param
262
+ * @param tableColumnComponentName
263
+ * @param customConfig
264
+ * @param tableOption
265
+ */
266
+ function buildFilterComponentConfig(param, tableColumnComponentName, customConfig, tableOption) {
267
+ const {filter, quickFilter, firstFilter, hidden, props} = customConfig
268
+ customConfig.props = props
269
+ if (filter === false) {
270
+ return
271
+ }
272
+
273
+ // build quick filters
274
+ if (quickFilter !== false) {
275
+ try {
276
+ param.quickFilter = buildFinalQueryComponentConfig(customConfig, tableColumnComponentName, 'quick', tableOption);
277
+ if (firstFilter !== false) { // deprecated: 1.6.0
278
+ param.quickFilter.index = 99
279
+ }
280
+ if (util.isNumber(quickFilter)) {
281
+ param.quickFilter.index = quickFilter
282
+ }
283
+ } catch (e) {
284
+ console.error(e)
285
+ }
286
+ }
287
+ // build easy filters
288
+ if (!hidden) {
289
+ try {
290
+ param.easyFilter = buildFinalQueryComponentConfig(customConfig, tableColumnComponentName, 'easy', tableOption);
291
+ param.easyFilter.disabled = true
292
+ if (firstFilter !== false) { // deprecated: 1.6.0
293
+ param.easyFilter.index = 99
294
+ }
295
+ if (util.isNumber(filter)) {
296
+ param.easyFilter.index = filter
297
+ }
298
+ } catch (e) {
299
+ console.error(e)
300
+ }
301
+ }
302
+ }
303
+
304
+ /**
305
+ * 构建编辑组件配置
306
+ * @param param
307
+ * @param tableColumnComponentName
308
+ * @param customConfig
309
+ * @param tableOption
310
+ */
311
+ function buildEditComponentConfig(param, tableColumnComponentName, customConfig, tableOption) {
312
+ // form表单组件配置
313
+ try {
314
+ param.formItemConfig = buildFinalEditComponentConfig(customConfig, tableColumnComponentName, 'form', tableOption);
315
+ } catch (e) {
316
+ console.error(e)
317
+ }
318
+ // 行内表单组件配置
319
+ try {
320
+ param.inlineItemConfig = buildFinalEditComponentConfig(customConfig, tableColumnComponentName, 'inline', tableOption);
321
+ param.inlineItemConfig.eventMethods = {
322
+ // 绑定一个valid事件, 完成校验逻辑,如果校验不通过,则追加class: valid-error以便显示出来
323
+ valid: (val, row, ref, props) => {
324
+ colValid(row, param.inlineItemConfig).then(() => {
325
+ // ref.$el.classList.remove('fc-valid-error') // !!! 这里不用ref是因为当el-table中存在fixed的列时,会渲染两个表格, 然后这个ref拿到的是另一个fixed的那个,导致无法正确显示/移除valid-error
326
+ props.class = util.defaultIfBlank(props.class, '').replaceAll('fc-valid-error', '');
327
+ }).catch(errors => {
328
+ // ref.$el.classList.add('fc-valid-error');
329
+ props.class = util.defaultIfBlank(props.class, '') + ' fc-valid-error';
330
+ });
331
+ return val
332
+ }
333
+ }
334
+ } catch (e) {
335
+ console.error(e)
336
+ }
337
+ }
338
+
339
+ // 需要转义值的组件
340
+ /**
341
+ * 判断单元格是否可编辑
342
+ * @param editRow 当前编辑行
343
+ * @param status 当前编辑状态(normal、insert、update)
344
+ * @param config 当前列的配置
345
+ * @param col 当前列属性
346
+ */
347
+ export function colEditable(fatRow, col) {
348
+ const {status, config} = fatRow;
349
+ if (status === 'normal') {
350
+ return false;
351
+ }
352
+
353
+ const {editable} = config[col];
354
+ if (util.isBoolean(editable)) {
355
+ return editable;
356
+ } else if (util.isFunction(editable)) {
357
+ return editable.call(this, {...fatRow, status, config, col})
358
+ }
359
+ if (status === 'insert') {
360
+ return editable === 'insert';
361
+ }
362
+ if (status === 'update') {
363
+ return editable === 'update';
364
+ }
365
+ return false;
366
+ }
367
+
368
+ /**
369
+ * 构建导出请求参数
370
+ * @param columnConfigs
371
+ * @returns {*}
372
+ */
373
+ export function buildParamForExport(columnConfigs) {
374
+ return Object.values(columnConfigs).map(config => {
375
+ return {
376
+ ...config.customConfig,
377
+ tableColumnComponentName: config.tableColumnComponentName,
378
+ // 图片和文件默认不导出,不然往往文件太大
379
+ exportable: config.tableColumnComponentName !== 'FastTableColumnImg' && config.tableColumnComponentName !== 'FastTableColumnFile'
380
+ }
381
+ })
382
+ }
383
+
384
+ /**
385
+ * 设置自定义存筛,保存到localStorage, 只存条件
386
+ */
387
+ export function setCustomFilterGroups(tableOption, filterGroups) {
388
+ const storedConds = filterGroups.map(g => {
389
+ return {
390
+ label: g.label,
391
+ conds: g.filters.map(f => {
392
+ return {
393
+ col: f.col,
394
+ opt: util.defaultIfBlank(f.opt, Opt.EQ),
395
+ val: f.val
396
+ }
397
+ })
398
+ }
399
+ })
400
+ cache.setToLocalStorage(`STORED_CONDS:${tableOption.id}`, storedConds)
401
+ }
402
+
403
+ /**
404
+ * 从localStorage中获取自定义存筛
405
+ * @param tableOption tableOption
406
+ * @param columnConfig localStorage中只存条件, 需要借助columnConfig进行重建
407
+ */
408
+ export function getCustomFilterGroups(tableOption, columnConfig) {
409
+ try {
410
+ const condGroups = cache.getFromLocalStorage(`STORED_CONDS:${tableOption.id}`)
411
+ if (util.isEmpty(condGroups) || !util.isArray(condGroups)) {
412
+ return []
413
+ }
414
+ return buildFilterGroups(tableOption, columnConfig, condGroups, false)
415
+ } catch (err) {
416
+ console.error(err)
417
+ return []
418
+ }
419
+ }
420
+
421
+ /**
422
+ * 根据条件组创建筛选组
423
+ * @param tableOption tableOption
424
+ * @param columnConfig 列配置
425
+ * @param condGroups 条件组
426
+ * @param buildIn 是否为内建筛选组
427
+ * @return {*[]}
428
+ */
429
+ export function buildFilterGroups(tableOption, columnConfig, condGroups, buildIn) {
430
+ const filterGroups = []
431
+ if (util.isEmpty(condGroups)) {
432
+ return filterGroups
433
+ }
434
+ for (let i = 0; i < condGroups.length; i++) {
435
+ const {label, conds = []} = condGroups[i]
436
+ if (util.isEmpty(label)) {
437
+ console.error('label can not be empty in storeFilters of tableOption')
438
+ continue
439
+ }
440
+ if (util.isEmpty(conds)) {
441
+ console.error('conds can not be empty in storeFilters of tableOption')
442
+ continue
443
+ }
444
+ if (!util.isArray(conds)) {
445
+ console.error('conds must be a array in storeFilters of tableOption')
446
+ continue
447
+ }
448
+ const filterGroup = {
449
+ label: label,
450
+ filters: [],
451
+ buildIn: buildIn,
452
+ compatible: true
453
+ }
454
+ try {
455
+ for (let j = 0; j < conds.length; j++) {
456
+ const {col, opt = Opt.EQ, val} = conds[j]
457
+ const filter = buildStoredFilterComponent(col, columnConfig, tableOption)
458
+ if (!util.isNull(filter)) {
459
+ filter.opt = opt
460
+ filter.val = val
461
+ filterGroup.filters.push(filter)
462
+ } else {
463
+ filterGroup.compatible = false
464
+ }
465
+ }
466
+ } catch (err) {
467
+ console.error(err)
468
+ filterGroup.filters = []
469
+ filterGroup.compatible = false
470
+ } finally {
471
+ filterGroups.push(filterGroup)
472
+ }
473
+ }
474
+ return filterGroups
475
+ }
476
+
477
+ /**
478
+ * 从columnConfig中针对指定col构造一个Filter, 返回null表示
479
+ * @param col
480
+ * @param columnConfig
481
+ * @param tableOption
482
+ * @return FilterComponentConfig
483
+ */
484
+ export function buildStoredFilterComponent(col, columnConfig, tableOption) {
485
+ if (util.isObject(columnConfig) && util.isObject(columnConfig[col]) && util.isObject(columnConfig[col]['customConfig'])) {
486
+ const {customConfig, tableColumnComponentName} = columnConfig[col]
487
+ try {
488
+ return buildFinalQueryComponentConfig(customConfig, tableColumnComponentName, 'stored', tableOption)
489
+ } catch (err) {
490
+ console.error(err)
491
+ return null;
492
+ }
493
+ }
494
+ console.warn(`The column is invalid or filtering is not enabled: ${col}`)
495
+ return null
496
+ }
@@ -0,0 +1,64 @@
1
+ import {easyOptParse, isUndefined, merge, ternary} from "../../util/util";
2
+ import Opt from "../../model/opt.js";
3
+
4
+ const defaultQueryConfig = {
5
+ component: 'el-input',
6
+ opt: Opt.LIKE,
7
+ val: null, // 默认值
8
+ props: {
9
+ clearable: true,
10
+ placeholder: '请输入..'
11
+ },
12
+ condMapFn: (cond) => {
13
+ const operators = {
14
+ '^!=': {
15
+ opt: Opt.NE,
16
+ valExtract: (cond) => cond.val.substring(2)
17
+ },
18
+ '^=': {
19
+ opt: Opt.EQ,
20
+ valExtract: (cond) => cond.val.substring(1)
21
+ },
22
+ '^~': {
23
+ opt: Opt.NLIKE,
24
+ valExtract: (cond) => cond.val.substring(1)
25
+ },
26
+ '^\\*': {
27
+ opt: Opt.LLIKE,
28
+ valExtract: (cond) => cond.val.substring(1)
29
+ },
30
+ '\\*$': {
31
+ opt: Opt.RLIKE,
32
+ valExtract: (cond) => cond.val.substring(0, cond.val.length - 1)
33
+ }
34
+ }
35
+ easyOptParse(cond, operators)
36
+ return [cond]
37
+ }
38
+ }
39
+ const defaultEditConfig = {
40
+ component: 'el-input',
41
+ val: null,
42
+ props: {
43
+ class: 'fc-table-inline-edit-component',
44
+ editable: false // fast-table-column不允许编辑
45
+ }
46
+ }
47
+ export default {
48
+ query: (config, type) => {
49
+ let val = defaultQueryConfig.val;
50
+ const {props: {defaultVal, ...validProps} = {}} = config
51
+ if (type === 'quick') {
52
+ val = ternary(isUndefined(defaultVal), val, defaultVal);
53
+ }
54
+ config.val = val;
55
+ config.props = validProps;
56
+ return merge(config, defaultQueryConfig, true, false)
57
+ },
58
+ edit: (config, type) => {
59
+ const {props: {defaultVal, ...validProps} = {}} = config
60
+ config.val = ternary(isUndefined(defaultVal), defaultEditConfig.val, defaultVal);
61
+ config.props = validProps;
62
+ return merge(config, defaultEditConfig, true, false)
63
+ }
64
+ }
@@ -0,0 +1,7 @@
1
+ import FastTableColumn from './src/table-column.vue'
2
+
3
+ FastTableColumn.install = (app) => {
4
+ app.component(FastTableColumn.name, FastTableColumn)
5
+ }
6
+
7
+ export default FastTableColumn
@@ -0,0 +1,44 @@
1
+ <template>
2
+ <el-table-column class-name="fc-table-column"
3
+ :prop="prop"
4
+ :label="label"
5
+ :min-width="minWidth"
6
+ :show-overflow-tooltip="showOverflowTooltip"
7
+ v-bind="$attrs"
8
+ v-if="!hidden">
9
+ <template #header="{column, $index}">
10
+ <fast-table-head-cell :column="columnProp" @click="headCellClick(column)">
11
+ <slot name="header" v-bind:column="column" v-bind:$index="$index">
12
+ <span>{{ label }}</span>
13
+ </slot>
14
+ </fast-table-head-cell>
15
+ </template>
16
+
17
+ <template #default="{row, column, $index}">
18
+ <slot v-bind:row="row" v-bind:column="column" v-bind:$index="$index">
19
+ <fast-cell-content :value="showLabel(row)" :fat-row="row" :show-length="showLength" :linkTo="link"/>
20
+ </slot>
21
+ </template>
22
+ </el-table-column>
23
+ </template>
24
+
25
+ <script>
26
+ import tableColumn from "../../../mixins/table-column"
27
+ import FastCellContent from "../../content-dialog/src/fast-cell-content.vue";
28
+
29
+ export default {
30
+ name: "FastTableColumn",
31
+ components: {FastCellContent},
32
+ mixins: [tableColumn],
33
+ props: {
34
+ minWidth: {
35
+ type: String,
36
+ default: () => '150px'
37
+ }
38
+ }
39
+ }
40
+ </script>
41
+
42
+ <style scoped lang="scss">
43
+
44
+ </style>