@94ai/nf-table 3.2.4 → 3.2.21

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.
@@ -1,10 +1,14 @@
1
1
  <template>
2
2
  <div class="nf-table" ref="nfTableRef">
3
- <slot name="searchBox" ref="searchBox" >
3
+ <slot name="searchBox" ref="searchBox">
4
4
  <nf-search-form
5
5
  ref="nfSearchFormRef"
6
6
  v-bind="searchFormAttrs"
7
7
  v-on="searchFormEvents"
8
+ :operation-prop-key="operationPropKey"
9
+ :storage-key="searchFormStorageKey"
10
+ :property="priority"
11
+ :select-empty-warning-tips="selectEmptyWarningTips"
8
12
  >
9
13
  <template v-for="item in (nfSearchFormRef?.renderSearchFormItemOptions || [])">
10
14
  <!-- 定制化SearchItem?提示-->
@@ -21,432 +25,521 @@
21
25
  <slot name="searchFormColumnEditDialogFooter" slot="dialogFooter" />
22
26
  </nf-search-form>
23
27
  </slot>
24
- <div class="nf-table-content" ref="nfTableContent">
25
- <slot name="columnEdit">
26
- <el-button v-if="columnEdit"
27
- @click="nfColumCheckDialogVisible = true"
28
- :class="(columnDisplayBtnClass || '') + ' nf-column-display'"
29
- :type="columnDisplayBtnType"
30
- :plain="columnDisplayBtnPlain"
31
- :icon="columnDisplayBtnIcon"
32
- :size="columnDisplayBtnSize"
33
- :round="columnDisplayBtnRound"
34
- :circle="columnDisplayBtnCircle"
35
- :loading="columnDisplayBtnLoading"
36
- :disabled="columnDisplayBtnDisabled"
37
- >
38
- {{ columnDisplayBtnText }}
39
- </el-button>
40
- </slot>
41
- <el-table
42
- ref="elTableRef"
43
- :class="{'nf-table-container': true, 'nf-default-table-border': !tableAttrs?.border }"
44
- :data="showData"
45
- :fit="tableAttrer?.fit ?? true"
46
- :height="elTableHeight"
47
- v-bind="tableAttrer"
48
- v-on="tableEventer"
49
- >
50
- <template v-for="column in tableColumns">
51
- <template v-if="isShow(column)">
52
- <template v-if="column.type">
53
- <el-table-column :key="column.label" :type="column.type" :label="column.label" v-bind="column.attr" v-if="column.render || column.prop || column.slot">
54
- <template slot-scope="scope" >
55
- <render-component v-if="column.render" :render="column.render" :row="scope.row" />
56
- <template v-else>
57
- <slot v-if="column.slot" :name="column.slot" :row="scope.row" :index="scope.$index" />
58
- <span v-else>{{ scope.row[column.prop] }}</span>
59
- </template>
60
- </template>
61
- </el-table-column>
62
- <el-table-column :key="column.label" :type="column.type" :label="column.label" v-bind="column.attr" v-else />
28
+ <div class="nf-table-content" ref="nfTableContent">
29
+ <slot name="columnEdit" v-if="columnEdit && columnPosition === 'free'">
30
+ <el-button @click="nfColumCheckDialogVisible = true"
31
+ :class="(columnDisplayBtnClass || '') + ' nf-column-display'"
32
+ :type="columnDisplayBtnType"
33
+ :plain="columnDisplayBtnPlain"
34
+ :icon="columnDisplayBtnIcon"
35
+ :size="columnDisplayBtnSize"
36
+ :round="columnDisplayBtnRound"
37
+ :circle="columnDisplayBtnCircle"
38
+ :loading="columnDisplayBtnLoading"
39
+ :disabled="columnDisplayBtnDisabled"
40
+ >
41
+ {{ columnDisplayBtnText }}
42
+ </el-button>
43
+ </slot>
44
+ <el-table
45
+ ref="elTableRef"
46
+ :class="{'nf-table-container': true, 'nf-default-table-border': !tableAttrs?.border }"
47
+ :data="showData"
48
+ :fit="tableAttrer?.fit ?? true"
49
+ :height="elTableHeight"
50
+ v-bind="tableAttrer"
51
+ v-on="tableEventer"
52
+ :key="elTableRefKey"
53
+ >
54
+ <template v-for="column in tableColumns">
55
+ <template v-if="isShow(column)">
56
+ <template v-if="column.type">
57
+ <el-table-column :key="column.label" :type="column.type" :label="column.label" v-bind="column.attr"
58
+ v-if="column.render || column.prop || column.slot">
59
+ <template slot-scope="scope">
60
+ <render-component v-if="column.render" :render="column.render" :row="scope.row" />
61
+ <template v-else>
62
+ <slot v-if="column.slot" :name="column.slot" :row="scope.row" :index="scope.$index" />
63
+ <span v-else>{{ scope.row[column.prop] }}</span>
64
+ </template>
63
65
  </template>
64
- <template v-else>
65
- <el-table-column
66
- v-if="column.attr&&column.attr.formatter"
67
- :key="column.label"
68
- :prop="column.prop"
69
- :label="column.label"
70
- v-bind="column.attr"
71
- >
72
- <slot v-if="column.singleHeadMutiColSlot" :name="column.singleHeadMutiColSlot" />
73
- <template slot="header" slot-scope="scope">
74
- <template v-if="column.headerSlot">
75
- <slot :name="column.headerSlot" :$index="scope.$index" :column="scope.column" />
76
- </template>
77
- <span v-else>
78
- {{ column.label }}
79
- </span>
80
- </template>
81
- </el-table-column>
82
- <el-table-column v-else :key="column.label" :prop="column.prop" :label="column.label" v-bind="column.attr">
83
- <slot v-if="column.singleHeadMutiColSlot" :name="column.singleHeadMutiColSlot" />
84
- <template slot="header" slot-scope="scope">
85
- <template v-if="column.headerSlot">
86
- <slot :name="column.headerSlot" :$index="scope.$index" :column="scope.column" />
87
- </template>
88
- <span v-else>
66
+ </el-table-column>
67
+ <el-table-column :key="column.label" :type="column.type" :label="column.label" v-bind="column.attr"
68
+ v-else />
69
+ </template>
70
+ <template v-else>
71
+ <el-table-column
72
+ v-if="column.attr&&column.attr.formatter"
73
+ :key="column.label"
74
+ :prop="column.prop"
75
+ :label="column.label"
76
+ v-bind="column.attr"
77
+ >
78
+ <slot v-if="column.singleHeadMutiColSlot" :name="column.singleHeadMutiColSlot" />
79
+ <template slot="header" slot-scope="scope">
80
+ <template v-if="column.headerSlot">
81
+ <slot :name="column.headerSlot" :$index="scope.$index" :column="scope.column" />
82
+ </template>
83
+ <span v-else>
84
+ {{ column.label }}
85
+ </span>
86
+ </template>
87
+ </el-table-column>
88
+ <el-table-column v-else :key="column.label" :prop="column.prop" :label="column.label"
89
+ v-bind="column.attr">
90
+ <slot v-if="column.singleHeadMutiColSlot" :name="column.singleHeadMutiColSlot" />
91
+ <template slot="header" slot-scope="scope">
92
+ <template v-if="column.headerSlot">
93
+ <slot :name="column.headerSlot" :$index="scope.$index" :column="scope.column" />
94
+ </template>
95
+ <span v-else>
89
96
  {{ column.label }}
90
97
  </span>
91
- </template>
92
- <template slot-scope="scope">
93
- <render-component v-if="column.render" :render="column.render" :row="scope.row" />
94
- <template v-else>
95
- <slot v-if="column.slot" :name="column.slot" :row="scope.row" :index="scope.$index" />
96
- <template v-else>
97
- <template v-if="column.prop === operationPropKey && !hasOperationSlot">
98
- <el-button
99
- :size="item.size || 'mini'"
100
- :type="item.type || 'text'"
101
- :disabled="item.disabled"
102
- :loading="item.loading"
103
- :class="item.class"
104
- :plain="item.plain"
105
- :icon="item.icon"
106
- :round="item.round"
107
- :circle="item.circle"
108
- :style="item.style"
109
- v-for="(item, index) in column.operationList"
110
- v-on="item.events"
111
- :key="item.key || index"
112
- >{{ item.text }}</el-button>
113
- </template>
114
- <span v-else>{{ scope.row[column.prop] }}</span>
115
- </template>
98
+
99
+ <slot name="operationIconColumnCheck" :column="column"
100
+ v-if="column.prop === operationPropKey && columnEdit && columnPosition === 'embed'">
101
+ <el-tooltip
102
+ popper-class="actionTooltipRef"
103
+ placement="top"
104
+ effect="dark"
105
+ :content="columnDisplayBtnText">
106
+ <i class="iconfont icon-liebiao_xianshiliemu operation-icon-column-check"
107
+ @click="nfColumCheckDialogVisible = true"
108
+ />
109
+ </el-tooltip>
110
+ </slot>
111
+
112
+ </template>
113
+ <template slot-scope="scope">
114
+ <render-component v-if="column.render" :render="column.render" :row="scope.row" />
115
+ <template v-else>
116
+ <slot v-if="column.slot" :name="column.slot" :row="scope.row" :index="scope.$index" />
117
+ <template v-else>
118
+ <template v-if="column.prop === operationPropKey && !hasOperationSlot">
119
+ <el-button
120
+ :size="item.size || 'mini'"
121
+ :type="item.type || 'text'"
122
+ :disabled="item.disabled"
123
+ :loading="item.loading"
124
+ :class="item.class"
125
+ :plain="item.plain"
126
+ :icon="item.icon"
127
+ :round="item.round"
128
+ :circle="item.circle"
129
+ :style="item.style"
130
+ v-for="(item, index) in column.operationList"
131
+ v-on="item.events"
132
+ :key="item.key || index"
133
+ >{{ item.text }}
134
+ </el-button>
116
135
  </template>
136
+ <span v-else>{{ scope.row[column.prop] }}</span>
117
137
  </template>
118
- </el-table-column>
138
+ </template>
119
139
  </template>
120
- </template>
140
+ </el-table-column>
121
141
  </template>
122
- <slot name="append" slot="append"></slot>
123
- <slot name="empty" slot="empty"></slot>
124
- </el-table>
125
- <div ref="nfTableActionContainerRef" class="nf-action-box nf-clearfix">
126
- <slot name="actionBar" ref="nfTableActionBarRef" >
127
- <template v-if="actionBarOptList?.length && !hasActionBarSlot">
128
- <template v-for="(item, index) in actionBarOptList" >
129
- <el-button
130
- :key="item.key || index"
131
- v-if="item.element === 'el-button'"
132
- :size="item.size || 'mini'"
133
- :type="item.type || 'text'"
134
- :disabled="item.disabled"
135
- :loading="item.loading"
136
- :class="item.class"
137
- :plain="item.plain"
138
- :icon="item.icon"
139
- :round="item.round"
140
- :circle="item.circle"
141
- :style="{...(item.style || {}), marginRight: '10px'}"
142
- v-on="item.events"
143
- >{{ item.value }}</el-button>
144
- <el-checkbox
145
- :key="item.key || index"
146
- v-model="item.value"
147
- :class="item.class"
148
- :label="item.label"
149
- :true-label="item['true-label']"
150
- :false-label="item['false-label']"
151
- :disabled="item.disabled"
152
- :border="item.border"
153
- :size="item.size"
154
- :name="item.name"
155
- :checked="item.checked"
156
- :indeterminate="item.indeterminate"
157
- :style="{...(item.style || {}), marginRight: '10px'}"
158
- v-if="item.element === 'el-checkbox'"
159
- v-on="item.events"
160
- >{{ item.text }}</el-checkbox>
161
- <el-checkbox-group
162
- :key="item.key || index"
163
- v-model="item.value"
164
- :class="item.class"
165
- :label="item.label"
166
- :true-label="item['true-label']"
167
- :false-label="item['false-label']"
168
- :disabled="item.disabled"
169
- :border="item.border"
170
- :size="item.size"
171
- :name="item.name"
172
- :checked="item.checked"
173
- :indeterminate="item.indeterminate"
174
- :style="{...(item.style || {}), marginRight: '10px'}"
175
- v-if="item.element === 'el-checkbox-group'"
176
- v-on="item.events"
177
- >
178
- <template v-if="item.children?.length">
179
- <template
180
- v-for="(itemChildren, j) in item.children"
181
- >
182
- <el-checkbox
183
- :key="itemChildren.key || j"
184
- v-model="itemChildren.value"
185
- :class="itemChildren.class"
186
- :label="itemChildren.label"
187
- :true-label="itemChildren['true-label']"
188
- :false-label="itemChildren['false-label']"
189
- :disabled="itemChildren.disabled"
190
- :border="itemChildren.border"
191
- :size="itemChildren.size"
192
- :name="itemChildren.name"
193
- :checked="itemChildren.checked"
194
- :indeterminate="itemChildren.indeterminate"
195
- :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
196
- v-if="itemChildren.element === 'el-checkbox'"
197
- v-on="itemChildren.events"
198
- >{{ item.text }}</el-checkbox>
199
- <el-checkbox-button
200
- :key="itemChildren.key || j"
201
- v-model="itemChildren.value"
202
- :class="itemChildren.class"
203
- :label="itemChildren.label"
204
- :true-label="itemChildren['true-label']"
205
- :false-label="itemChildren['false-label']"
206
- :disabled="itemChildren.disabled"
207
- :border="itemChildren.border"
208
- :size="itemChildren.size"
209
- :name="itemChildren.name"
210
- :checked="itemChildren.checked"
211
- :indeterminate="itemChildren.indeterminate"
212
- :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
213
- v-if="itemChildren.element === 'el-checkbox-button'"
214
- v-on="itemChildren.events"
215
- >{{ item.text }}</el-checkbox-button>
216
- </template>
142
+ </template>
143
+ </template>
144
+ <slot name="append" slot="append"></slot>
145
+ <slot name="empty" slot="empty">
146
+ <nf-empty style="margin-top: 20px;" slot="empty" :image-size="145"></nf-empty>
147
+ </slot>
148
+ </el-table>
149
+ <div ref="nfTableActionContainerRef" class="nf-action-box nf-clearfix">
150
+ <slot name="actionBar" ref="nfTableActionBarRef">
151
+ <template v-if="actionBarOptList?.length && !hasActionBarSlot">
152
+ <template v-for="(item, index) in actionBarOptList">
153
+ <el-button
154
+ :key="item.key || index"
155
+ v-if="item.element === 'el-button'"
156
+ :size="item.size || 'mini'"
157
+ :type="item.type || 'text'"
158
+ :disabled="item.disabled"
159
+ :loading="item.loading"
160
+ :class="item.class"
161
+ :plain="item.plain"
162
+ :icon="item.icon"
163
+ :round="item.round"
164
+ :circle="item.circle"
165
+ :style="{...(item.style || {}), marginRight: '10px'}"
166
+ v-on="item.events"
167
+ >{{ item.value }}
168
+ </el-button>
169
+ <el-checkbox
170
+ :key="item.key || index"
171
+ v-model="item.value"
172
+ :class="item.class"
173
+ :label="item.label"
174
+ :true-label="item['true-label']"
175
+ :false-label="item['false-label']"
176
+ :disabled="item.disabled"
177
+ :border="item.border"
178
+ :size="item.size"
179
+ :name="item.name"
180
+ :checked="item.checked"
181
+ :indeterminate="item.indeterminate"
182
+ :style="{...(item.style || {}), marginRight: '10px'}"
183
+ v-if="item.element === 'el-checkbox'"
184
+ v-on="item.events"
185
+ >{{ item.text }}
186
+ </el-checkbox>
187
+ <el-checkbox-group
188
+ :key="item.key || index"
189
+ v-model="item.value"
190
+ :class="item.class"
191
+ :label="item.label"
192
+ :true-label="item['true-label']"
193
+ :false-label="item['false-label']"
194
+ :disabled="item.disabled"
195
+ :border="item.border"
196
+ :size="item.size"
197
+ :name="item.name"
198
+ :checked="item.checked"
199
+ :indeterminate="item.indeterminate"
200
+ :style="{...(item.style || {}), marginRight: '10px'}"
201
+ v-if="item.element === 'el-checkbox-group'"
202
+ v-on="item.events"
203
+ >
204
+ <template v-if="item.children?.length">
205
+ <template
206
+ v-for="(itemChildren, j) in item.children"
207
+ >
208
+ <el-checkbox
209
+ :key="itemChildren.key || j"
210
+ v-model="itemChildren.value"
211
+ :class="itemChildren.class"
212
+ :label="itemChildren.label"
213
+ :true-label="itemChildren['true-label']"
214
+ :false-label="itemChildren['false-label']"
215
+ :disabled="itemChildren.disabled"
216
+ :border="itemChildren.border"
217
+ :size="itemChildren.size"
218
+ :name="itemChildren.name"
219
+ :checked="itemChildren.checked"
220
+ :indeterminate="itemChildren.indeterminate"
221
+ :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
222
+ v-if="itemChildren.element === 'el-checkbox'"
223
+ v-on="itemChildren.events"
224
+ >{{ item.text }}
225
+ </el-checkbox>
226
+ <el-checkbox-button
227
+ :key="itemChildren.key || j"
228
+ v-model="itemChildren.value"
229
+ :class="itemChildren.class"
230
+ :label="itemChildren.label"
231
+ :true-label="itemChildren['true-label']"
232
+ :false-label="itemChildren['false-label']"
233
+ :disabled="itemChildren.disabled"
234
+ :border="itemChildren.border"
235
+ :size="itemChildren.size"
236
+ :name="itemChildren.name"
237
+ :checked="itemChildren.checked"
238
+ :indeterminate="itemChildren.indeterminate"
239
+ :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
240
+ v-if="itemChildren.element === 'el-checkbox-button'"
241
+ v-on="itemChildren.events"
242
+ >{{ item.text }}
243
+ </el-checkbox-button>
217
244
  </template>
218
- </el-checkbox-group>
219
- <el-checkbox-button
220
- :key="item.key || index"
221
- v-model="item.value"
222
- :class="item.class"
223
- :label="item.label"
224
- :true-label="item['true-label']"
225
- :false-label="item['false-label']"
226
- :disabled="item.disabled"
227
- :border="item.border"
228
- :size="item.size"
229
- :name="item.name"
230
- :checked="item.checked"
231
- :indeterminate="item.indeterminate"
232
- :style="{...(item.style || {}), marginRight: '10px'}"
233
- v-if="item.element === 'el-checkbox-button'"
234
- v-on="item.events"
235
- >{{ item.text }}</el-checkbox-button>
236
- <el-radio
237
- :key="item.key || index"
238
- v-model="item.value"
239
- :label="item.label"
240
- :disabled="item.disabled"
241
- :border="item.border"
242
- :name="item.name"
243
- :size="item.size"
244
- :class="item.class"
245
- :style="{...(item.style || {}), marginRight: '10px'}"
246
- v-if="item.element === 'el-radio'"
247
- v-on="item.events"
248
- >{{ item.text }}</el-radio>
249
- <el-radio-group
250
- :key="item.key || index"
251
- v-model="item.value"
252
- :disabled="item.disabled"
253
- :size="item.size"
254
- :class="item.class"
255
- :text-color="item['text-color']"
256
- :fill="item['fill']"
257
- :style="{...(item.style || {}), marginRight: '10px'}"
258
- v-if="item.element === 'el-radio-group'"
259
- v-on="item.events"
260
- >
261
- <template v-if="item.children?.length">
262
- <template
263
- v-for="(itemChildren, j) in item.children"
264
- >
265
- <el-radio
266
- :key="itemChildren.key || j"
267
- v-model="itemChildren.value"
268
- :label="itemChildren.label"
269
- :disabled="itemChildren.disabled"
270
- :border="itemChildren.border"
271
- :name="itemChildren.name"
272
- :size="itemChildren.size"
273
- :class="itemChildren.class"
274
- :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
275
- v-if="itemChildren.element === 'el-radio'"
276
- v-on="itemChildren.events"
277
- >{{ item.text }}</el-radio>
278
- <el-radio-button
279
- :key="itemChildren.key || j"
280
- v-model="itemChildren.value"
281
- :label="itemChildren.label"
282
- :disabled="itemChildren.disabled"
283
- :border="itemChildren.border"
284
- :name="itemChildren.name"
285
- :size="itemChildren.size"
286
- :class="itemChildren.class"
287
- :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
288
- v-if="itemChildren.element === 'el-radio-button'"
289
- v-on="itemChildren.events"
290
- >{{ item.text }}</el-radio-button>
291
- </template>
245
+ </template>
246
+ </el-checkbox-group>
247
+ <el-checkbox-button
248
+ :key="item.key || index"
249
+ v-model="item.value"
250
+ :class="item.class"
251
+ :label="item.label"
252
+ :true-label="item['true-label']"
253
+ :false-label="item['false-label']"
254
+ :disabled="item.disabled"
255
+ :border="item.border"
256
+ :size="item.size"
257
+ :name="item.name"
258
+ :checked="item.checked"
259
+ :indeterminate="item.indeterminate"
260
+ :style="{...(item.style || {}), marginRight: '10px'}"
261
+ v-if="item.element === 'el-checkbox-button'"
262
+ v-on="item.events"
263
+ >{{ item.text }}
264
+ </el-checkbox-button>
265
+ <el-radio
266
+ :key="item.key || index"
267
+ v-model="item.value"
268
+ :label="item.label"
269
+ :disabled="item.disabled"
270
+ :border="item.border"
271
+ :name="item.name"
272
+ :size="item.size"
273
+ :class="item.class"
274
+ :style="{...(item.style || {}), marginRight: '10px'}"
275
+ v-if="item.element === 'el-radio'"
276
+ v-on="item.events"
277
+ >{{ item.text }}
278
+ </el-radio>
279
+ <el-radio-group
280
+ :key="item.key || index"
281
+ v-model="item.value"
282
+ :disabled="item.disabled"
283
+ :size="item.size"
284
+ :class="item.class"
285
+ :text-color="item['text-color']"
286
+ :fill="item['fill']"
287
+ :style="{...(item.style || {}), marginRight: '10px'}"
288
+ v-if="item.element === 'el-radio-group'"
289
+ v-on="item.events"
290
+ >
291
+ <template v-if="item.children?.length">
292
+ <template
293
+ v-for="(itemChildren, j) in item.children"
294
+ >
295
+ <el-radio
296
+ :key="itemChildren.key || j"
297
+ v-model="itemChildren.value"
298
+ :label="itemChildren.label"
299
+ :disabled="itemChildren.disabled"
300
+ :border="itemChildren.border"
301
+ :name="itemChildren.name"
302
+ :size="itemChildren.size"
303
+ :class="itemChildren.class"
304
+ :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
305
+ v-if="itemChildren.element === 'el-radio'"
306
+ v-on="itemChildren.events"
307
+ >{{ item.text }}
308
+ </el-radio>
309
+ <el-radio-button
310
+ :key="itemChildren.key || j"
311
+ v-model="itemChildren.value"
312
+ :label="itemChildren.label"
313
+ :disabled="itemChildren.disabled"
314
+ :border="itemChildren.border"
315
+ :name="itemChildren.name"
316
+ :size="itemChildren.size"
317
+ :class="itemChildren.class"
318
+ :style="{...(itemChildren.style || {}), marginRight: j === 0 ? 0 : '10px'}"
319
+ v-if="itemChildren.element === 'el-radio-button'"
320
+ v-on="itemChildren.events"
321
+ >{{ item.text }}
322
+ </el-radio-button>
292
323
  </template>
293
- </el-radio-group>
294
- <el-radio-button
295
- :key="item.key || index"
296
- v-model="item.value"
297
- :label="item.label"
298
- :disabled="item.disabled"
299
- :border="item.border"
300
- :name="item.name"
301
- :size="item.size"
302
- :class="item.class"
303
- :style="{...(item.style || {}), marginRight: '10px'}"
304
- v-if="item.element === 'el-radio-button'"
305
- v-on="item.events"
306
- >{{ item.text }}</el-radio-button>
307
- <el-input
308
- :key="item.key || index"
309
- v-model="item.value"
310
- :class="item.class"
311
- :show-word-limit="item['show-word-limit']"
312
- :show-password="item['show-password']"
313
- :prefix-icon="item['prefix-icon']"
314
- :suffix-icon="item['suffix-icon']"
315
- :validate-event="item['validate-event']"
316
- :type="item.type"
317
- :placeholder="item.placeholder"
318
- :disabled="item.disabled"
319
- :size="item.size"
320
- :name="item.name"
321
- :max="item.max"
322
- :min="item.min"
323
- :step="item.step"
324
- :label="item.label"
325
- :maxlength="item.maxlength"
326
- :minlength="item.minlength"
327
- :clearable="item.clearable"
328
- :rows="item.rows"
329
- :autosize="item.autosize"
330
- :autocomplete="item.autocomplete"
331
- :readonly="item.readonly"
332
- :resize="item.resize"
333
- :autofocus="item.autofocus"
334
- :form="item.form"
335
- :tabindex="item.tabindex"
336
- :style="{...(item.style || {}), marginRight: '10px'}"
337
- v-if="item.element === 'el-input'"
338
- v-on="item.events"
339
- >
340
- <slot v-if='item.slot?.prefix' :name='item.slot.prefix' slot="prefix" />
341
- <slot v-if='item.slot?.suffix' :name='item.slot.suffix' slot="suffix" />
342
- <slot v-if='item.slot?.prepend' :name='item.slot.prepend' slot="prepend" />
343
- <slot v-if='item.slot?.append' :name='item.slot.append' slot="append" />
344
- </el-input>
345
- <el-autocomplete
346
- :key="item.key || index"
347
- v-model="item.value"
348
- :class="item.class"
349
- :style="{...(item.style || {}), marginRight: '10px'}"
350
- :value-key="item['value-key']"
351
- :fetch-suggestions="item['fetch-suggestions']"
352
- :popper-class="item['popper-class']"
353
- :trigger-on-focus="item['trigger-on-focus']"
354
- :select-when-unmatched="item['select-when-unmatched']"
355
- :hide-loading="item['hide-loading']"
356
- :popper-append-to-body="item['popper-append-to-body']"
357
- :highlight-first-item="item['highlight-first-item']"
358
- :prefix-icon="item['prefix-icon']"
359
- :suffix-icon="item['suffix-icon']"
360
- :placeholder="item.placeholder"
361
- :disabled="item.disabled"
362
- :debounce="item.debounce"
363
- :placement="item.placement"
364
- :label="item.label"
365
- :name="item.name"
366
- v-if="item.element === 'el-autocomplete'"
367
- v-on="item.events"
368
- >
369
- <slot v-if='item.slot?.prefix' :name='item.slot.prefix' slot="prefix" />
370
- <slot v-if='item.slot?.suffix' :name='item.slot.suffix' slot="suffix" />
371
- <slot v-if='item.slot?.prepend' :name='item.slot.prepend' slot="prepend" />
372
- <slot v-if='item.slot?.append' :name='item.slot.append' slot="append" />
373
- </el-autocomplete>
374
- <el-switch
375
- :key="item.key || index"
376
- v-model="item.value"
377
- :disabled="item.disabled"
378
- :width="item.width"
379
- :name="item.name"
380
- :active-icon-class="item['active-icon-class']"
381
- :inactive-icon-class="item['inactive-icon-class']"
382
- :active-text="item['active-text']"
383
- :inactive-text="item['inactive-text']"
384
- :active-value="item['active-value']"
385
- :inactive-value="item['inactive-value']"
386
- :active-color="item['active-color']"
387
- :inactive-color="item['inactive-color']"
388
- :validate-event="item['validate-event']"
389
- :class="item.class"
390
- :style="{...(item.style || {}), marginRight: '10px'}"
391
- v-if="item.element === 'el-switch'"
392
- v-on="item.events"
393
- >{{ item.text }}</el-switch>
394
- <el-input-number
395
- :key="item.key || index"
396
- v-model="item.value"
397
- :class="item.class"
398
- :min="item.min"
399
- :max="item.max"
400
- :step="item.step"
401
- :step-strictly="item['step-strictly']"
402
- :precision="item.precision"
403
- :size="item.size"
404
- :disabled="item.disabled"
405
- :controls="item.controls"
406
- :controls-position="item['controls-position']"
407
- :name="item.name"
408
- :label="item.label"
409
- :placeholder="item.placeholder"
410
- :style="{...(item.style || {}), marginRight: '10px'}"
411
- v-if="item.element === 'el-input-number'"
412
- v-on="item.events"
413
- ></el-input-number>
414
- <span
415
- :key="item.key || index"
416
- :class="item.class"
417
- v-if="item.element === 'text'"
418
- :style="{...(item.style || {}), marginRight: '10px'}"
419
- v-on="item.events"
420
- v-bind="item.attr"
421
- >
324
+ </template>
325
+ </el-radio-group>
326
+ <el-radio-button
327
+ :key="item.key || index"
328
+ v-model="item.value"
329
+ :label="item.label"
330
+ :disabled="item.disabled"
331
+ :border="item.border"
332
+ :name="item.name"
333
+ :size="item.size"
334
+ :class="item.class"
335
+ :style="{...(item.style || {}), marginRight: '10px'}"
336
+ v-if="item.element === 'el-radio-button'"
337
+ v-on="item.events"
338
+ >{{ item.text }}
339
+ </el-radio-button>
340
+ <el-input
341
+ :key="item.key || index"
342
+ v-model="item.value"
343
+ :class="item.class"
344
+ :show-word-limit="item['show-word-limit']"
345
+ :show-password="item['show-password']"
346
+ :prefix-icon="item['prefix-icon']"
347
+ :suffix-icon="item['suffix-icon']"
348
+ :validate-event="item['validate-event']"
349
+ :type="item.type"
350
+ :placeholder="item.placeholder"
351
+ :disabled="item.disabled"
352
+ :size="item.size"
353
+ :name="item.name"
354
+ :max="item.max"
355
+ :min="item.min"
356
+ :step="item.step"
357
+ :label="item.label"
358
+ :maxlength="item.maxlength"
359
+ :minlength="item.minlength"
360
+ :clearable="item.clearable"
361
+ :rows="item.rows"
362
+ :autosize="item.autosize"
363
+ :autocomplete="item.autocomplete"
364
+ :readonly="item.readonly"
365
+ :resize="item.resize"
366
+ :autofocus="item.autofocus"
367
+ :form="item.form"
368
+ :tabindex="item.tabindex"
369
+ :style="{...(item.style || {}), marginRight: '10px'}"
370
+ v-if="item.element === 'el-input'"
371
+ v-on="item.events"
372
+ >
373
+ <slot v-if="item.slot?.prefix" :name="item.slot.prefix" slot="prefix" />
374
+ <slot v-if="item.slot?.suffix" :name="item.slot.suffix" slot="suffix" />
375
+ <slot v-if="item.slot?.prepend" :name="item.slot.prepend" slot="prepend" />
376
+ <slot v-if="item.slot?.append" :name="item.slot.append" slot="append" />
377
+ </el-input>
378
+ <el-autocomplete
379
+ :key="item.key || index"
380
+ v-model="item.value"
381
+ :class="item.class"
382
+ :style="{...(item.style || {}), marginRight: '10px'}"
383
+ :value-key="item['value-key']"
384
+ :fetch-suggestions="item['fetch-suggestions']"
385
+ :popper-class="item['popper-class']"
386
+ :trigger-on-focus="item['trigger-on-focus']"
387
+ :select-when-unmatched="item['select-when-unmatched']"
388
+ :hide-loading="item['hide-loading']"
389
+ :popper-append-to-body="item['popper-append-to-body']"
390
+ :highlight-first-item="item['highlight-first-item']"
391
+ :prefix-icon="item['prefix-icon']"
392
+ :suffix-icon="item['suffix-icon']"
393
+ :placeholder="item.placeholder"
394
+ :disabled="item.disabled"
395
+ :debounce="item.debounce"
396
+ :placement="item.placement"
397
+ :label="item.label"
398
+ :name="item.name"
399
+ v-if="item.element === 'el-autocomplete'"
400
+ v-on="item.events"
401
+ >
402
+ <slot v-if="item.slot?.prefix" :name="item.slot.prefix" slot="prefix" />
403
+ <slot v-if="item.slot?.suffix" :name="item.slot.suffix" slot="suffix" />
404
+ <slot v-if="item.slot?.prepend" :name="item.slot.prepend" slot="prepend" />
405
+ <slot v-if="item.slot?.append" :name="item.slot.append" slot="append" />
406
+ </el-autocomplete>
407
+ <el-switch
408
+ :key="item.key || index"
409
+ v-model="item.value"
410
+ :disabled="item.disabled"
411
+ :width="item.width"
412
+ :name="item.name"
413
+ :active-icon-class="item['active-icon-class']"
414
+ :inactive-icon-class="item['inactive-icon-class']"
415
+ :active-text="item['active-text']"
416
+ :inactive-text="item['inactive-text']"
417
+ :active-value="item['active-value']"
418
+ :inactive-value="item['inactive-value']"
419
+ :active-color="item['active-color']"
420
+ :inactive-color="item['inactive-color']"
421
+ :validate-event="item['validate-event']"
422
+ :class="item.class"
423
+ :style="{...(item.style || {}), marginRight: '10px'}"
424
+ v-if="item.element === 'el-switch'"
425
+ v-on="item.events"
426
+ >{{ item.text }}
427
+ </el-switch>
428
+ <el-input-number
429
+ :key="item.key || index"
430
+ v-model="item.value"
431
+ :class="item.class"
432
+ :min="item.min"
433
+ :max="item.max"
434
+ :step="item.step"
435
+ :step-strictly="item['step-strictly']"
436
+ :precision="item.precision"
437
+ :size="item.size"
438
+ :disabled="item.disabled"
439
+ :controls="item.controls"
440
+ :controls-position="item['controls-position']"
441
+ :name="item.name"
442
+ :label="item.label"
443
+ :placeholder="item.placeholder"
444
+ :style="{...(item.style || {}), marginRight: '10px'}"
445
+ v-if="item.element === 'el-input-number'"
446
+ v-on="item.events"
447
+ ></el-input-number>
448
+ <span
449
+ :key="item.key || index"
450
+ :class="item.class"
451
+ v-if="item.element === 'text'"
452
+ :style="{...(item.style || {}), marginRight: '10px'}"
453
+ v-on="item.events"
454
+ v-bind="item.attr"
455
+ >
422
456
  {{ item.value }}
423
457
  </span>
424
- </template>
425
458
  </template>
426
- </slot>
427
- <slot name="pagination">
428
- <el-pagination ref="nfTablePaginationRef" v-if="renderPage" v-bind="pageAttrer" v-on="pageEvents" class="nf-pagination-box nf-fr" />
429
- </slot>
430
- </div>
459
+ </template>
460
+ </slot>
461
+ <slot name="pagination">
462
+ <el-pagination ref="nfTablePaginationRef" v-if="renderPage" v-bind="pageAttrer" v-on="pageEvents"
463
+ class="nf-pagination-box nf-fr" />
464
+ </slot>
431
465
  </div>
432
- <column-check-dialog v-if="nfColumCheckDialogVisible" :show.sync="nfColumCheckDialogVisible" :table-columns="tableColumns" :show-column="items" @save="fieldsSave" >
433
- <slot slot="tableColumnEditDialogTitle" name="dialogTitle"></slot>
434
- <slot slot="tableColumnEditDialogFooter" name="dialogFooter"></slot>
466
+ </div>
467
+ <column-check-dialog
468
+ v-if="nfColumCheckDialogVisible && checkMode === 'dialog'"
469
+ :show.sync="nfColumCheckDialogVisible"
470
+ :table-columns="props.columns"
471
+ :show-column="localShowColumn"
472
+ :storage-key="storageKey"
473
+ @save="fieldsConfirm"
474
+ :title="columnCheckTitle"
475
+ :width="columnCheckWidth"
476
+ :confirm-text="columnCheckConfirmText"
477
+ :cancel-text="columnCheckCancelText"
478
+ :modal-append-to-body="columnCheckModalAppendToBody"
479
+ :modal="columnCheckModal"
480
+ :fullscreen="columnCheckFullscreen"
481
+ :top="columnCheckTop"
482
+ :append-to-body="columnCheckAppendToBody"
483
+ :lock-scroll="columnCheckLockScroll"
484
+ :custom-class="columnCheckCustomClass"
485
+ :close-onlick-modal="columnCheckCloseOnlickModal"
486
+ :close-on-press-escape="columnCheckCloseOnPressEscape"
487
+ :show-close="columnCheckShowClose"
488
+ :before-close="columnCheckBeforeClose"
489
+ :center="columnCheckCenter"
490
+ :destroy-on-close="columnCheckDestroyOnClose"
491
+ ref="columnCheckDialog"
492
+ >
493
+ <slot slot="tableColumnEditDialogTitle" name="title"></slot>
494
+ <slot slot="tableColumnEditDialogFooter" name="footer"></slot>
435
495
  </column-check-dialog>
496
+ <nf-drawer
497
+ ref="columnCheckNfDrawer"
498
+ size="680px"
499
+ v-if="checkMode === 'drawer'"
500
+ :title="columnCheckTitle"
501
+ :cancel-button-text="columnCheckCancelButtonText"
502
+ :confirm-button-text="columnCheckConfirmButtonText"
503
+ :visible.sync="nfColumCheckDialogVisible"
504
+ :tabs="columnCheckTabs"
505
+ :destroy-on-close="true"
506
+ :currentTab="columnCheckCurrentTab"
507
+ @confirm="columnCheckConfirm"
508
+ @changeTab="(done) => $emit('changeTab', done)"
509
+ @cancel="(name) => $emit('cancel', name)"
510
+ >
511
+ <slot slot="tableColumnEditDialogTitle" name="title" />
512
+ <slot slot="tableColumnEditDialogFooter" name="footer" />
513
+ <column-check-drawer
514
+ :search-placeholder="columnCheckSearchPlaceholder"
515
+ :fixed-left-desc="columnCheckFixedLeftDesc"
516
+ :clear-desc="columnCheckClearDesc"
517
+ :no-fixed-desc="columnCheckNoFixedDesc"
518
+ :get-checked-length-desc="columnCheckGetCheckedLengthDesc"
519
+ :get-all-check-desc="columnCheckGetAllCheckDesc"
520
+ :operation-prop-key="operationPropKey"
521
+ ref="columnCheckDrawer"
522
+ :storage-key="storageKey"
523
+ :table-columns="props.columns"
524
+ :select-empty-warning-tips="selectEmptyWarningTips"
525
+ />
526
+ </nf-drawer>
436
527
  </div>
437
528
  </template>
438
529
 
439
530
  <script lang="ts">
440
531
  import { defineComponent } from 'vue-demi'
532
+
441
533
  export default defineComponent({
442
- name: "nf-table",
534
+ name: 'nf-table'
443
535
  })
444
536
  </script>
445
537
 
446
538
  <script lang="ts" setup>
447
539
  import ColumnCheckDialog from './nf-column-check-dialog.vue'
540
+ import ColumnCheckDrawer from './nf-column-check-drawer.vue'
448
541
  import RenderComponent from './nf-render-component.vue'
449
- import { Loading } from 'element-ui';
542
+ import { Loading } from 'element-ui'
450
543
  import {
451
544
  computed,
452
545
  getCurrentInstance,
@@ -466,6 +559,7 @@ import {
466
559
  NfSearchFormEventKey,
467
560
  NfTableActionBtnAttributes
468
561
  } from './types'
562
+ import { ITabItem } from '@94ai/nf-drawer/lib/types'
469
563
 
470
564
  const props = withDefaults(defineProps<{
471
565
  data?: Record<string, any>[],
@@ -482,26 +576,22 @@ const props = withDefaults(defineProps<{
482
576
  */
483
577
  calHeight?: boolean,
484
578
  /**
485
- * 列目显示开关
579
+ * 列编辑显示开关
486
580
  */
487
581
  columnEdit?: boolean,
582
+ columnPosition?: 'free' | 'embed',
583
+ checkMode?: 'dialog' | 'drawer',
584
+ priority?: 'cached' | 'value',
585
+ storageKey?: string
586
+ searchFormStorageKey?: string
488
587
  /**
489
- * 要显示的表格项字段
588
+ * 列编辑要显示的表格项字段
490
589
  */
491
590
  showColumn?: string[],
591
+ selectEmptyWarningTips?: string,
492
592
  /**
493
- * 表格loading
593
+ * 列编辑按钮修饰
494
594
  */
495
- loading?: boolean,
496
- target?: HTMLElement,
497
- body?: boolean,
498
- fullscreen?: boolean,
499
- lock?: boolean,
500
- text?: string,
501
- spinner?: string,
502
- background?: string,
503
- customClass?: string,
504
-
505
595
  columnDisplayBtnClass?: string,
506
596
  columnDisplayBtnIcon?: string,
507
597
  columnDisplayBtnType?: string,
@@ -512,11 +602,70 @@ const props = withDefaults(defineProps<{
512
602
  columnDisplayBtnLoading?: boolean,
513
603
  columnDisplayBtnDisabled?: boolean,
514
604
  columnDisplayBtnText?: string,
605
+ /**
606
+ * 列编辑dialog/drawer模式
607
+ */
608
+ columnCheckTitle?: string,
609
+ columnCheckCancelButtonText?: string,
610
+ columnCheckConfirmButtonText?: string,
611
+ /**
612
+ * 列编辑dialog模式
613
+ */
614
+ columnCheckWidth?: string,
615
+ columnCheckConfirmText?: string
616
+ columnCheckCancelText?: string
617
+ columnCheckModalAppendToBody?: boolean,
618
+ columnCheckModal?: boolean,
619
+ columnCheckFullscreen?: boolean,
620
+ columnCheckTop?: string,
621
+ columnCheckAppendToBody?: boolean,
622
+ columnCheckLockScroll?: boolean,
623
+ columnCheckCustomClass?: string,
624
+ columnCheckCloseOnlickModal?: boolean,
625
+ columnCheckCloseOnPressEscape?: boolean,
626
+ columnCheckShowClose?: boolean,
627
+ columnCheckBeforeClose?: Function,
628
+ columnCheckCenter?: boolean,
629
+ columnCheckDestroyOnClose?: boolean,
630
+ /**
631
+ * 列编辑drawer模式
632
+ */
633
+ columnCheckSearchPlaceholder?: string
634
+ columnCheckFixedLeftDesc?: string
635
+ columnCheckClearDesc?: string
636
+ columnCheckNoFixedDesc?: string
637
+ columnCheckGetCheckedLengthDesc?: Function
638
+ columnCheckGetAllCheckDesc?: Function
639
+ columnCheckTabs?: ITabItem[],
640
+ columnCheckCurrentTab?: string,
641
+
642
+ /**
643
+ * 表格loading
644
+ */
645
+ loading?: boolean,
646
+ target?: HTMLElement,
647
+ body?: boolean,
648
+ fullscreen?: boolean,
649
+ lock?: boolean,
650
+ text?: string,
651
+ spinner?: string,
652
+ background?: string,
653
+ customClass?: string,
515
654
 
655
+ /**
656
+ * 分页
657
+ */
516
658
  alwaysShowPage?: boolean,
659
+ /**
660
+ * 操作列属性key
661
+ */
517
662
  operationPropKey?: string
518
-
519
663
  }>(), {
664
+ selectEmptyWarningTips: '请选择至少一个选项',
665
+ priority: 'cached',
666
+ storageKey: 'nf-table-columns-cached-key',
667
+ searchFormStorageKey: 'nf-search-form-columns-cached-key',
668
+ checkMode: 'drawer',
520
669
  data: () => [],
521
670
  columns: () => [],
522
671
  searchFormAttrs: () => ({}),
@@ -527,7 +676,8 @@ const props = withDefaults(defineProps<{
527
676
  pageEvents: () => ({}),
528
677
  actionBarOptList: () => [],
529
678
  calHeight: false,
530
- columnEdit: true,
679
+ columnEdit: false,
680
+ columnPosition: 'embed',
531
681
  showColumn: undefined,
532
682
  loading: false,
533
683
  target: undefined,
@@ -549,24 +699,77 @@ const props = withDefaults(defineProps<{
549
699
  columnDisplayBtnText: '定制表格列目显示隐藏',
550
700
  columnDisplayBtnClass: '',
551
701
  alwaysShowPage: true,
552
- operationPropKey: 'operation'
702
+ operationPropKey: 'operation',
703
+ columnCheckTitle: '设置显示字段',
704
+ columnCheckWidth: '600px',
705
+ columnCheckConfirmText: '保 存',
706
+ columnCheckCancelText: '取 消',
707
+ columnCheckModalAppendToBody: true,
708
+ columnCheckModal: true,
709
+ columnCheckFullscreen: false,
710
+ columnCheckTop: '15vh',
711
+ columnCheckAppendToBody: false,
712
+ columnCheckLockScroll: true,
713
+ columnCheckCustomClass: '',
714
+ columnCheckCloseOnlickModal: true,
715
+ columnCheckCloseOnPressEscape: true,
716
+ columnCheckShowClose: true,
717
+ columnCheckBeforeClose: undefined,
718
+ columnCheckCenter: false,
719
+ columnCheckDestroyOnClose: false,
720
+ columnCheckCancelButtonText: '取消',
721
+ columnCheckConfirmButtonText: '确定',
722
+ columnCheckSearchPlaceholder: '搜索',
723
+ columnCheckFixedLeftDesc: '固定在左侧',
724
+ columnCheckClearDesc: '清除',
725
+ columnCheckNoFixedDesc: '不固定',
726
+ columnCheckGetCheckedLengthDesc: (length) => '已选(' + length + ')',
727
+ columnCheckGetAllCheckDesc: (length) => '全选(' + length + ')'
553
728
  })
554
729
 
730
+ const emit = defineEmits<{
731
+ (e: 'fieldsChange', event: string[]): void
732
+ (e: 'update:showColumn', event: string[] | undefined): void
733
+ }>()
734
+
735
+ const instance = getCurrentInstance()?.proxy
736
+ const elTableRef = ref()
737
+ const nfTableActionContainerRef = ref()
738
+ const nfTablePaginationRef = ref()
739
+ const nfTableActionBarRef = ref()
740
+ const nfTableRef = ref()
741
+ const nfTableContent = ref()
742
+ const nfSearchFormRef = ref()
743
+ const columnCheckDrawer = ref()
744
+ const columnCheckDialog = ref()
745
+ const columnCheckNfDrawer = ref()
746
+ const elTableHeight = ref()
747
+ const nfColumCheckDialogVisible = ref(false)
748
+
749
+ /**
750
+ * 处理前端分页和后端分页
751
+ */
555
752
  const showData = computed(() => {
556
753
  const pageSize = props.pageAttrs['page-size']
557
754
  const currentPage = props.pageAttrs['current-page'] || 1
558
755
  const noTotal = typeof props.pageAttrs.total === 'undefined'
559
756
  if (!pageSize || !noTotal) return props.data
560
- if(props.data.length > pageSize) {
561
- return JSON.parse(JSON.stringify(props.data.slice((currentPage - 1) * pageSize, currentPage * pageSize)))
757
+ if (props.data.length > pageSize) {
758
+ return props.data.slice((currentPage - 1) * pageSize, currentPage * pageSize)
562
759
  } else {
563
- return JSON.parse(JSON.stringify(props.data))
760
+ return props.data
564
761
  }
565
762
  })
763
+ /**
764
+ * 定制按钮
765
+ */
766
+ const hasOperationSlot = computed(() => {
767
+ return instance?.$slots.operation
768
+ })
769
+ const hasActionBarSlot = computed(() => {
770
+ return instance?.$slots.actionBar
771
+ })
566
772
 
567
- const emit = defineEmits<{
568
- (e: 'fieldsChange', event: string[]): void
569
- }>()
570
773
 
571
774
  const loadingInstance = ref()
572
775
  watch(() => {
@@ -581,7 +784,7 @@ watch(() => {
581
784
  text,
582
785
  spinner,
583
786
  background,
584
- customClass,
787
+ customClass
585
788
  } = props
586
789
  loadingInstance.value = Loading.service({
587
790
  target: target || elTableRef.value?.$el || document.body,
@@ -590,51 +793,105 @@ watch(() => {
590
793
  text,
591
794
  spinner,
592
795
  background,
593
- customClass,
796
+ customClass
594
797
  })
595
798
  } else {
596
- loadingInstance.value?.close();
799
+ loadingInstance.value?.close()
597
800
  }
598
801
  }, {
599
802
  immediate: true
600
803
  })
804
+ // 同步用户参数
805
+ const initLocalShow = () => {
806
+ return props.columns.filter(item => {
807
+ const prop = item.prop || item.attr?.prop
808
+ if (props.showColumn?.includes(prop!)) {
809
+ item.initHidden = true
810
+ }
811
+ return item.initHidden
812
+ }).map(item => item.prop! || item.attr?.prop!)
813
+ }
814
+ const localShowColumn = ref<string[]>(initLocalShow())
815
+ watch(() => localShowColumn.value?.length, () => {
816
+ emit('update:showColumn', localShowColumn.value)
817
+ }, {
818
+ immediate: true
819
+ })
601
820
 
821
+ const syncLocalShowColumnToCookies = () => {
822
+ if (props.columnEdit) {
823
+ const columnState = {}
824
+ props.columns.map((i, index) => {
825
+ const prop = i.prop || i.attr?.prop
826
+ columnState[prop!] = {
827
+ initHidden: i.initHidden || false,
828
+ fixed: i.attr?.fixed || false,
829
+ prop,
830
+ index
831
+ }
832
+ })
833
+ // @ts-ignore
834
+ instance?.$cookies?.set(props.storageKey, JSON.stringify(columnState), -1)
835
+ }
836
+ }
837
+ const syncCookiesToLocalShowColumn = () => {
838
+ if (props.columnEdit) {
839
+ let columnState: string | NfTableColumnAttributes | null = instance?.$cookies?.get(props.storageKey)
840
+ if (columnState) {
841
+ if (typeof columnState === 'string') {
842
+ columnState = JSON.parse(columnState)
843
+ }
844
+ const showColumnItems: string[] = []
845
+ for (const key in columnState as NfTableColumnAttributes) {
846
+ if (!columnState![key].initHidden) {
847
+ showColumnItems.push(columnState![key].prop)
848
+ }
849
+ }
850
+ localShowColumn.value = showColumnItems
602
851
 
603
- const elTableHeight = ref()
604
- const nfColumCheckDialogVisible = ref(false)
605
-
606
- const items = ref<string[]>(props.showColumn)
607
-
608
- const instance = getCurrentInstance()?.proxy
609
-
610
-
611
- const elTableRef = ref()
612
- const nfTableActionContainerRef = ref()
613
- const nfTablePaginationRef = ref()
614
- const nfTableActionBarRef = ref()
615
- const nfTableRef = ref()
616
- const nfTableContent = ref()
617
- const searchBoxRef = ref()
618
- const nfSearchFormRef = ref()
619
-
620
- /**
621
- * 定制按钮
622
- */
623
- const hasOperationSlot = computed(() => {
624
- return instance?.$slots.operation
625
- })
626
- const hasActionBarSlot = computed(() => {
627
- return instance?.$slots.actionBar
628
- })
852
+ props.columns.forEach(item => {
853
+ const prop = item.prop || item.attr?.prop
854
+ if (localShowColumn.value?.includes(prop!)) {
855
+ item.initHidden = true
856
+ } else {
857
+ item.initHidden = false
858
+ }
859
+ })
860
+ }
861
+ }
862
+ }
863
+ if (props.columnEdit) {
864
+ // 同步缓存参数
865
+ const cached = instance?.$cookies?.get(props.storageKey)
866
+ const cachedPriority = props.priority === 'cached'
867
+ if (cachedPriority ? cached : localShowColumn.value?.length) {
868
+ cachedPriority ? syncCookiesToLocalShowColumn() : syncLocalShowColumnToCookies()
869
+ } else if (cachedPriority ? localShowColumn.value?.length : cached) {
870
+ cachedPriority ? syncLocalShowColumnToCookies() : syncCookiesToLocalShowColumn()
871
+ }
872
+ }
629
873
 
630
- const tableColumns = computed(() => {
631
- const columns = JSON.parse(JSON.stringify(props.columns))!.map(item => {
874
+ const tableColumns = ref<NfTableColumnAttributes[]>([])
875
+ const elTableRefKey = ref(Date.now())
876
+ const syncCookiesToTableColumn = () => {
877
+ const columns = props.columns!.map((item, index) => {
632
878
  const len = item.label?.length || 0
633
879
  const fz = 15 // 每个字大小,其实是每个字的比例值,大概会比字体大小差不多大一点,
634
880
  const attr = (item.attr || {}) as ElTableColumnAttributes
635
- const minWidth = fz * len + 20 + (attr.sortable ? 24 : 0)
636
- if (!attr['min-width'] || minWidth > parseFloat(attr['min-width'])) {
637
- attr['min-width'] = String(minWidth) + 'px' // 字大小乘个数即长度 ,注意不要加px像素,这里minWidth只是一个比例值,不是真正的长度,+20表示th左右两边的内边距
881
+ // const minWidth = fz * len + 32 + (attr.sortable ? 24 : 0)
882
+ // if (!attr['min-width'] || minWidth > parseFloat(attr['min-width'])) {
883
+ // attr['min-width'] = String(minWidth) + 'px' // 字大小乘个数即长度 ,注意不要加px像素,这里minWidth只是一个比例值,不是真正的长度,+32表示th左右两边的内边距
884
+ // }
885
+ // 区分中文、数字、其他字符
886
+ if (!attr['min-width'] && item.label) {
887
+ const fs = 14
888
+ const char = item.label.match(/[\u2E80-\u9FFF]/g)
889
+ const charLen = char ? char.length : 0
890
+ const num = item.label.match(/\d|\./g)
891
+ const numLen = num ? num.length : 0
892
+ const otherLen = item.label.length - charLen - numLen
893
+ const minWidth = fs * (charLen * 1.1 + numLen * 0.65 + otherLen * 0.5) + 32 + (attr.sortable ? 24 : 0)
894
+ attr['min-width'] = String(minWidth) + 'px'
638
895
  }
639
896
  item.attr = {
640
897
  ...item.attr,
@@ -642,15 +899,47 @@ const tableColumns = computed(() => {
642
899
  } as ElTableColumnAttributes
643
900
  delete item.attr.prop
644
901
  delete item.attr.label
645
- return item || {}
902
+ item._index = index
903
+ item.__index = index
904
+ return item
646
905
  })
647
- return columns
648
- })
906
+ if (props.columnEdit) {
907
+ // 读取缓存 Column 配置
908
+ let columnState: string | NfTableColumnAttributes | null = instance?.$cookies?.get(props.storageKey)
909
+ if (columnState) {
910
+ if (typeof columnState === 'string') {
911
+ columnState = JSON.parse(columnState)
912
+ }
913
+ for (const key in columnState as NfTableColumnAttributes) {
914
+ const state = columnState![key]
915
+ columns.every(i => {
916
+ if (i.prop === key) {
917
+ i.initHidden = state.initHidden
918
+ i.attr ? i.attr['fixed'] = state.fixed : i.attr = { fixed: state.fixed }
919
+ i._index = state.index
920
+ return false
921
+ }
922
+ return true
923
+ })
924
+ }
925
+ }
926
+ }
927
+ tableColumns.value = columns.sort((a, b) => a._index! - b._index! < 0 ? -1 : a._index! - b._index! > 0 ? 1 : 0)
928
+ elTableRefKey.value = Date.now()
929
+ }
930
+
931
+ syncCookiesToTableColumn()
649
932
 
650
933
  const tableAttrer = computed(() => {
651
- const obj:Record<string, any> = {
652
- 'header-cell-style':{'text-align':'center','background': '#F5F7FA','height':'48px', 'color': '#303133', 'font-size': '14px'},
653
- 'cell-style':{'text-align':'center'},
934
+ const obj: Record<string, any> = {
935
+ 'header-cell-style': {
936
+ 'text-align': 'left',
937
+ 'background': '#F5F7FA',
938
+ 'height': '48px',
939
+ 'color': '#303133',
940
+ 'font-size': '14px'
941
+ },
942
+ 'cell-style': { 'text-align': 'left' },
654
943
  resizable: true,
655
944
  border: true,
656
945
  ...props.tableAttrs
@@ -659,18 +948,10 @@ const tableAttrer = computed(() => {
659
948
  return obj
660
949
  })
661
950
 
662
- const headerDragend = async (newWidth, oldWidth, column, event) => {
663
- await nextTick()
664
- if (newWidth < column.minWidth) {
665
- column.width = column.minWidth
666
- }
667
- await props.tableEvents['header-dragend']?.(newWidth, oldWidth, column, event)
668
- }
669
-
670
951
  const tableEventer = computed(() => {
671
- const obj:Record<string, any> = {
952
+ const obj: Record<string, any> = {
672
953
  ...props.tableEvents,
673
- 'header-dragend': headerDragend,
954
+ 'header-dragend': headerDragend
674
955
  }
675
956
  return obj
676
957
  })
@@ -704,27 +985,26 @@ const pageAttrer = computed(() => {
704
985
  })
705
986
 
706
987
  const isShow = (row: Record<string, any>) => {
707
- if (!items.value || row.type) {
988
+ if (!localShowColumn.value?.length || row.type) {
708
989
  return true
709
990
  }
710
- return items.value.includes(row.prop)
991
+ return localShowColumn.value.includes(row.prop) && !row.initHidden
711
992
  }
712
993
 
713
-
714
- const resetNfSearchFormModel = () =>{
994
+ const resetNfSearchFormModel = () => {
715
995
  nfSearchFormRef.value?.resetNfSearchFormModel()
716
996
  }
717
- const onNfSearchFormValidate = (callback) =>{
997
+ const onNfSearchFormValidate = (callback) => {
718
998
  nfSearchFormRef.value?.onNfSearchFormValidate(callback)
719
999
  }
720
- const onNfSearchFormSearch = () =>{
1000
+ const onNfSearchFormSearch = () => {
721
1001
  nfSearchFormRef.value?.onNfSearchFormSearch()
722
1002
  }
723
- const onNfSearchFormExport = () =>{
1003
+ const onNfSearchFormExport = () => {
724
1004
  nfSearchFormRef.value?.onNfSearchFormExport()
725
1005
  }
726
1006
 
727
- const clearSelection = () =>{
1007
+ const clearSelection = () => {
728
1008
  elTableRef.value?.clearSelection()
729
1009
  }
730
1010
  const toggleRowSelection = (row: Record<string, any>, selected: boolean) => {
@@ -751,15 +1031,66 @@ const doLayout = () => {
751
1031
  const sort = (prop, order) => {
752
1032
  elTableRef.value?.sort(prop, order)
753
1033
  }
754
- const fieldsSave = (value) => {
755
- const itemResult: string[] = []
756
- for (const key in value) {
757
- if (value[key]) {
758
- itemResult.push(key)
1034
+
1035
+ const headerDragend = async (newWidth, oldWidth, column, event) => {
1036
+ await nextTick()
1037
+ if (newWidth < column.minWidth) {
1038
+ column.width = column.minWidth
1039
+ }
1040
+ await props.tableEvents['header-dragend']?.(newWidth, oldWidth, column, event)
1041
+ }
1042
+
1043
+ const syncShowItemToInitHidden = () => {
1044
+ props.columns.forEach(item => {
1045
+ if (localShowColumn.value?.includes(item.prop!)) {
1046
+ item.initHidden = false
1047
+ } else {
1048
+ item.initHidden = true
1049
+ }
1050
+ })
1051
+ }
1052
+
1053
+ const columnCheckConfirmFeedback = (value: Record<string, any>) => {
1054
+ if (!props.columnEdit) {
1055
+ const itemsList: string[] = []
1056
+ for (const key in value) {
1057
+ if (value[key]) {
1058
+ itemsList.push(key)
1059
+ }
759
1060
  }
1061
+ localShowColumn.value = itemsList
1062
+ syncShowItemToInitHidden()
1063
+ }
1064
+ }
1065
+
1066
+ /**
1067
+ * 弹框确定
1068
+ * @param { Object } value
1069
+ */
1070
+ const fieldsConfirm = (value) => {
1071
+ columnCheckConfirmFeedback(value)
1072
+ syncCookiesToLocalShowColumn()
1073
+ syncCookiesToTableColumn()
1074
+ emit('fieldsChange', localShowColumn.value)
1075
+
1076
+ }
1077
+ /**
1078
+ * 抽屉确定
1079
+ * @param { Function } cb
1080
+ * @param { Function } error
1081
+ */
1082
+ const columnCheckConfirm = (cb, error) => {
1083
+ try {
1084
+ const value = columnCheckDrawer.value.syncTableColumnsToCookies()
1085
+ columnCheckConfirmFeedback(value)
1086
+ syncCookiesToLocalShowColumn()
1087
+ syncCookiesToTableColumn()
1088
+ emit('fieldsChange', localShowColumn.value)
1089
+ cb()
1090
+ } catch (e) {
1091
+ error()
1092
+ console.log(e)
760
1093
  }
761
- items.value = itemResult
762
- emit('fieldsChange', itemResult)
763
1094
  }
764
1095
 
765
1096
  onMounted(() => {
@@ -779,28 +1110,130 @@ onMounted(() => {
779
1110
 
780
1111
 
781
1112
  defineExpose({
1113
+ /**
1114
+ * 表格clearFilter
1115
+ */
782
1116
  clearFilter,
1117
+ /**
1118
+ * 表格sort
1119
+ */
783
1120
  sort,
1121
+ /**
1122
+ * 表格doLayout
1123
+ */
784
1124
  doLayout,
1125
+ /**
1126
+ * 表格clearSort
1127
+ */
785
1128
  clearSort,
1129
+ /**
1130
+ * 表格setCurrentRow
1131
+ */
786
1132
  setCurrentRow,
1133
+ /**
1134
+ * 表格toggleRowExpansion
1135
+ */
787
1136
  toggleRowExpansion,
1137
+ /**
1138
+ * 表格toggleAllSelection
1139
+ */
788
1140
  toggleAllSelection,
1141
+ /**
1142
+ * 表格toggleRowSelection
1143
+ */
789
1144
  toggleRowSelection,
1145
+ /**
1146
+ * 表格clearSelection
1147
+ */
790
1148
  clearSelection,
1149
+ /**
1150
+ * 表单重置
1151
+ */
1152
+ resetNfSearchFormModel,
1153
+ /**
1154
+ * 表单验证
1155
+ */
1156
+ onNfSearchFormValidate,
1157
+ /**
1158
+ * 表单搜索
1159
+ */
1160
+ onNfSearchFormSearch,
1161
+ /**
1162
+ * 表单导出
1163
+ */
1164
+ onNfSearchFormExport,
1165
+ /**
1166
+ * 表格nf-table ref(div)
1167
+ */
1168
+ nfTableRef,
1169
+ /**
1170
+ * 表格el-table ref
1171
+ */
791
1172
  elTableRef,
1173
+ /**
1174
+ * 表格actionBar ref(div)
1175
+ */
792
1176
  nfTableActionContainerRef,
793
- nfTablePaginationRef,
1177
+ /**
1178
+ * 表格actionBar ref(slot)
1179
+ */
794
1180
  nfTableActionBarRef,
795
- nfTableRef,
1181
+ /**
1182
+ * 表格pagination ref
1183
+ */
1184
+ nfTablePaginationRef,
1185
+ /**
1186
+ * 表单nf-search-form ref
1187
+ */
796
1188
  nfSearchFormRef,
797
- searchBoxRef,
1189
+ /**
1190
+ * loadingInstance
1191
+ */
798
1192
  loadingInstance,
799
- resetNfSearchFormModel,
800
- onNfSearchFormValidate,
801
- onNfSearchFormSearch,
802
- onNfSearchFormExport,
1193
+ /**
1194
+ * 列编辑dialog/drawer显示/隐藏
1195
+ */
803
1196
  nfColumCheckDialogVisible,
1197
+ /**
1198
+ * 列编辑nf-drawer ref
1199
+ */
1200
+ columnCheckNfDrawer,
1201
+ /**
1202
+ * 列编辑column-check-dialog ref
1203
+ */
1204
+ columnCheckDialog,
1205
+ /**
1206
+ * 列编辑column-check-drawer ref
1207
+ */
1208
+ columnCheckDrawer,
1209
+ /**
1210
+ * showItems同步props.formOptions[i].initHidden
1211
+ */
1212
+ syncShowItemToInitHidden,
1213
+ /**
1214
+ * 分页数据(处理前端分页和后端分页)
1215
+ */
1216
+ showData,
1217
+ /**
1218
+ * 列编辑显示的列prop
1219
+ */
1220
+ localShowColumn,
1221
+ /**
1222
+ * 渲染表格项数据
1223
+ */
1224
+ tableColumns,
1225
+ /**
1226
+ * 列编辑同步组件到cookies
1227
+ */
1228
+ syncLocalShowColumnToCookies,
1229
+ /**
1230
+ * 列编辑同步cookies到组件localShowItems
1231
+ */
1232
+ syncCookiesToLocalShowColumn,
1233
+ /**
1234
+ * 列编辑同步cookies到组件渲染数据
1235
+ */
1236
+ syncCookiesToTableColumn
804
1237
  })
805
1238
 
806
1239
  </script>