@94ai/nf-search-form 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.
package/lib/tools.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- export declare function createUniqueString(): string;
1
+ export declare function createUniqueString(randomLength?: number): string;
2
2
  export declare function debounce(func: any, wait: any, immediate: any): (...args: any[]) => any;
3
3
  export declare const on: (event: any, handler: any, element?: Window & typeof globalThis) => void;
4
+ export declare function deepClone(source: any): Record<string, any> | Record<string, any>[];
4
5
  export declare const off: (event: any, handler: any, element?: Window & typeof globalThis) => void;
5
6
  export declare const pickerOptionsRange: {
6
7
  shortcuts: {
package/lib/types.d.ts CHANGED
@@ -1,4 +1,8 @@
1
1
  export type NfSearchFormItemOption = {
2
+ key?: string;
3
+ _index?: number;
4
+ __index?: number;
5
+ initHidden?: boolean;
2
6
  label?: string;
3
7
  addLabel?: string;
4
8
  prop?: string;
package/package/index.ts CHANGED
@@ -1,8 +1,20 @@
1
1
  import NfSearchForm from './nf-search-form.vue'
2
2
  import { Vue2, PluginObject } from 'vue-demi'
3
+ import NfMessage from '@94ai/nf-message'
4
+ import VueCookies from 'vue-cookies'
3
5
 
4
6
  NfSearchForm.install = (app: typeof Vue2) => {
7
+ // @ts-ignore
8
+ if (!app.$cookies) {
9
+ // @ts-ignore
10
+ app.use(VueCookies)
11
+ }
12
+ // @ts-ignore
13
+ if (!app.$openMessage) {
14
+ // @ts-ignore
15
+ app.use(NfMessage)
16
+ }
5
17
  app!.component('nf-search-form', NfSearchForm)
6
18
  }
7
19
 
8
- export default NfSearchForm as typeof NfSearchForm & PluginObject<undefined>
20
+ export default NfSearchForm as typeof NfSearchForm & PluginObject<undefined>
@@ -51,12 +51,14 @@ export default defineComponent({
51
51
  <script setup lang="ts">
52
52
  import {
53
53
  computed,
54
+ getCurrentInstance,
54
55
  onMounted,
55
56
  ref
56
57
  } from 'vue-demi'
57
58
  import { NfSearchFormItemOption } from 'packages/nf-search-form/lib/types'
58
59
 
59
60
  const props = withDefaults(defineProps<{
61
+ storageKey?: string
60
62
  show?: boolean,
61
63
  title?: string,
62
64
  width?: string,
@@ -78,6 +80,7 @@ const props = withDefaults(defineProps<{
78
80
  center?: boolean,
79
81
  destroyOnClose?: boolean,
80
82
  }>(), {
83
+ storageKey: 'nf-table-columns-cached-key',
81
84
  show: false,
82
85
  width: '600',
83
86
  title: '设置显示查询框',
@@ -145,9 +148,20 @@ const fields = computed(() => {
145
148
  onMounted(() => {
146
149
  addInitValue()
147
150
  })
151
+ const instance = getCurrentInstance()?.proxy
148
152
 
149
153
  const submit = () => {
150
154
  visible.value = false
155
+ const columnState = {}
156
+ props.tableColumns.map((i, index) => {
157
+ columnState[i.prop!] = {
158
+ initHidden: !tableData.value[i.prop!] || false,
159
+ prop: i.prop,
160
+ index
161
+ }
162
+ })
163
+ // @ts-ignore
164
+ instance?.$cookies?.set(props.storageKey, JSON.stringify(columnState), -1)
151
165
  emit('save', tableData.value)
152
166
  }
153
167
 
@@ -0,0 +1,404 @@
1
+ <template>
2
+ <div class="nf-table-nf-column-check-drawer">
3
+ <!-- 左侧-可操作类目 START -->
4
+ <div class="nf-not-chosen">
5
+ <div class="nf-search-column">
6
+ <el-input
7
+ v-model="columnName"
8
+ size="small"
9
+ :placeholder="searchPlaceholder"
10
+ clearable
11
+ style="width: 308px;margin-bottom: 16px;"
12
+ prefix-icon="iconfont icon-sousuo"
13
+ @input="handleSearch"
14
+ />
15
+ <el-checkbox
16
+ v-if="fields.length"
17
+ v-model="checkAll"
18
+ :indeterminate="isIndeterminate"
19
+ @change="handleCheckAllChange"
20
+ >{{ getAllCheckDesc(checkedCount) }}</el-checkbox>
21
+ </div>
22
+ <div class="nf-select-column">
23
+ <div v-for="(item,index) in fields" :key="index + item.name" class="nf-column-category">
24
+ <el-checkbox-group v-model="showColumn">
25
+ <div class="nf-check-title">{{ item.name }}</div>
26
+ <el-checkbox
27
+ v-for="obj in item.list"
28
+ :key="obj.prop"
29
+ :label="obj.prop"
30
+ :disabled="unChangedColumn.includes(obj.prop)"
31
+ @change="(v) => handleCheckedChange(v, obj.prop)"
32
+ >{{ obj.label }}</el-checkbox>
33
+ </el-checkbox-group>
34
+ </div>
35
+ </div>
36
+ </div>
37
+ <!-- 左侧-可操作类目 END -->
38
+ <!-- 右侧-已选择类目 START -->
39
+ <div class="nf-already-chosen">
40
+ <div class="nf-selected-column">
41
+ <p>{{ getCheckedLengthDesc((showColumn.length - unChangedColumn.length)) }}</p>
42
+ <span v-if="showColumn.length - unChangedColumn.length" @click="handleCheckAllChange(false)">{{ clearDesc }}</span>
43
+ </div>
44
+ <div class="nf-drag-container">
45
+ <div
46
+ class="nf-fixed"
47
+ :style="{'margin-bottom': fixedColumn.length - unChangedColumn.length ? '8px' : '16px'}"
48
+ >
49
+ <!-- <p> {{ fixedLeftDesc }} </p>-->
50
+ <draggable
51
+ v-model="fixedColumn"
52
+ v-bind="dragOptions"
53
+ class="nf-drag-column"
54
+ handle=".nf-handle"
55
+ :group="{ put: false }"
56
+ tag="ul"
57
+ @start="drag = true"
58
+ @end="drag = false"
59
+ >
60
+ <transition-group name="nf-slide-fade" tag="ul">
61
+ <template v-for="(dragElement, index) in fixedColumn" >
62
+ <li
63
+ v-if="!dragElement.initHidden && !unChangedColumn.includes(dragElement.prop)"
64
+ :key="dragElement.prop || index"
65
+ class="nf-drag-element"
66
+ >
67
+ <span class="nf-handle">
68
+ <i class="iconfont icon-ketuozhuai" />
69
+ <span>{{ dragElement.label }}</span>
70
+ </span>
71
+ <span>
72
+ <!-- <el-tooltip placement="top" :content="noFixedDesc">-->
73
+ <!-- <i-->
74
+ <!-- class="iconfont icon-buguding"-->
75
+ <!-- @click="handleFixed(false, dragElement.prop)"-->
76
+ <!-- />-->
77
+ <!-- </el-tooltip>-->
78
+ <i
79
+ class="iconfont icon-guanbi1"
80
+ @click="handleCheckedChange(false, dragElement.prop)"
81
+ />
82
+ </span>
83
+ </li>
84
+ </template>
85
+ </transition-group>
86
+ </draggable>
87
+ </div>
88
+ <div class="nf-not-fixed">
89
+ <!-- <p>{{ noFixedDesc }}</p>-->
90
+ <draggable
91
+ v-model="unFixedColumn"
92
+ v-bind="dragOptions"
93
+ class="nf-drag-column"
94
+ handle=".nf-handle"
95
+ tag="ul"
96
+ :group="{ put: false }"
97
+ :pull="false"
98
+ @start="drag = true"
99
+ @end="drag = false"
100
+ >
101
+ <transition-group name="nf-slide-fade" tag="ul">
102
+ <template v-for="(dragElement, index) in unFixedColumn">
103
+ <li v-if="!dragElement.initHidden" :key="dragElement.prop || index" class="nf-drag-element">
104
+ <span class="nf-handle">
105
+ <i class="iconfont icon-ketuozhuai nf-handle" />
106
+ <span>{{ dragElement.label }}</span>
107
+ </span>
108
+ <span>
109
+ <!-- <el-tooltip style="margin-left:20px" placement="top" :content="fixedLeftDesc">-->
110
+ <!-- <i class="iconfont icon-gudingzailieshou" @click="handleFixed(true, dragElement.prop)" />-->
111
+ <!-- </el-tooltip>-->
112
+ <i v-if="!unChangedColumn.includes(dragElement.prop)" class="iconfont icon-guanbi1" @click="handleCheckedChange(false, dragElement.prop)" />
113
+ </span>
114
+ </li>
115
+ </template>
116
+ </transition-group>
117
+ </draggable>
118
+ </div>
119
+ </div>
120
+ </div>
121
+ <!-- 右侧-已选择类目 END -->
122
+ </div>
123
+ </template>
124
+
125
+
126
+ <script lang="ts">
127
+ import { defineComponent } from 'vue-demi'
128
+
129
+ export default defineComponent({
130
+ name: "NfColumnCheckDrawer",
131
+ })
132
+ </script>
133
+
134
+ <script setup lang="ts">
135
+ import draggable from 'vuedraggable'
136
+ import {
137
+ ref,
138
+ computed,
139
+ onBeforeMount,
140
+ getCurrentInstance,
141
+ PropType,
142
+ onMounted
143
+ } from 'vue-demi'
144
+ import { deepClone } from './tools'
145
+
146
+ const instance = getCurrentInstance()?.proxy
147
+
148
+
149
+ const props = withDefaults(defineProps<{
150
+ selectEmptyWarningTips?: string,
151
+ // 源序列
152
+ tableColumns?: Record<string, any>[],
153
+ storageKey?: string
154
+ searchPlaceholder?: string
155
+ fixedLeftDesc?: string
156
+ clearDesc?: string
157
+ noFixedDesc?: string
158
+ getCheckedLengthDesc?: Function
159
+ getAllCheckDesc?: Function
160
+ }>(), {
161
+ selectEmptyWarningTips: '请选择至少一个选项',
162
+ tableColumns: () => [],
163
+ storageKey: 'nf-table-columns-cached-key',
164
+ searchPlaceholder: '搜索',
165
+ fixedLeftDesc: '固定在左侧',
166
+ clearDesc: '清除',
167
+ noFixedDesc: '不固定',
168
+ getCheckedLengthDesc: (length) => '已选(' + length + ')',
169
+ getAllCheckDesc: (length) => '全选(' + length + ')'
170
+ })
171
+
172
+ // 获取当前缓存中的动态数据列
173
+ const currentTable = ref<Record<string, any>[]>([])
174
+ // 可选列表的绑定的已选值
175
+ const showColumn = ref<string[]>([])
176
+ // 不可操作列
177
+ const unChangedColumn = ref<string[]>([])
178
+ // 固定列
179
+ const fixedColumn = ref<Record<string, any>[]>([])
180
+ // 不固定列
181
+ const unFixedColumn = ref<Record<string, any>[]>([])
182
+
183
+
184
+ onBeforeMount(() => {
185
+ currentTable.value = deepClone(props.tableColumns).sort((a,b) => a._index! - b._index! < 0 ? -1 : a._index! - b._index! > 0 ? 1 : 0) as Record<string, any>[]
186
+ // 兼容处理
187
+ currentTable.value.map(i => {
188
+ if (!i.attr) {
189
+ i.attr = {}
190
+ }
191
+ })
192
+
193
+ // 可选列表 → 字段区分
194
+ setFields(props.tableColumns)
195
+ // 已选列表
196
+ updateColumn()
197
+ if (currentTable.value.every(i => !i.initHidden)) {
198
+ showColumn.value = currentTable.value.map(i => i.prop)
199
+ checkedCount.value = currentTable.value.length
200
+ checkAll.value = true
201
+ isIndeterminate.value = false
202
+ }
203
+ })
204
+
205
+ /**
206
+ * 可选列表 → 字段区分
207
+ * @description fields = [{ name: '基础字段', list: [{
208
+ * ...
209
+ * }] }, ...]
210
+ */
211
+ const fields = ref<{
212
+ name: string,
213
+ list: Record<string, any>[]
214
+ }[]>([])
215
+ const setFields = (tableColumns) => {
216
+ const obj: Record<string, any> = {}
217
+ tableColumns.map(item => {
218
+ const key = item.category || '基础字段'
219
+ if (!obj[key]) {
220
+ obj[key] = []
221
+ }
222
+ obj[key].push(item)
223
+ })
224
+ const items: {
225
+ name: string
226
+ list: Record<string, any>[]
227
+ }[] = []
228
+ for (const key in obj) {
229
+ items.push({
230
+ name: key,
231
+ list: obj[key]
232
+ })
233
+ }
234
+ fields.value = items
235
+ }
236
+
237
+ /**
238
+ * 更新已选列表
239
+ */
240
+ const checkedCount = ref(0) // 勾选的数量
241
+ const updateColumn = () => {
242
+ fixedColumn.value = []
243
+ unFixedColumn.value = []
244
+ currentTable.value.map(item => {
245
+ if (item.attr.fixed) {
246
+ fixedColumn.value.push(item)
247
+ } else {
248
+ unFixedColumn.value.push(item)
249
+ }
250
+ })
251
+ // 勾选状态
252
+ showColumn.value = currentTable.value.filter(i => !i.initHidden).map(item => item.prop)
253
+ // [全选 checkbox] 展示状态
254
+ if (columnName.value && fields.value.length) {
255
+ // 搜索时
256
+ checkedCount.value = searchValue.filter(i => !i.initHidden).length
257
+ checkAll.value = checkedCount.value === searchValue.length
258
+ isIndeterminate.value = checkedCount.value > 0 && checkedCount.value < searchValue.length
259
+ return
260
+ }
261
+ checkedCount.value = showColumn.value.length
262
+ checkAll.value = checkedCount.value === currentTable.value.length
263
+ isIndeterminate.value = checkedCount.value > 0 && checkedCount.value < currentTable.value.length
264
+ }
265
+
266
+ /**
267
+ * 搜索
268
+ */
269
+ const columnName = ref('')
270
+ let searchValue: Record<string, any>[] = [] // 搜索结果
271
+ const handleSearch = (str) => {
272
+ searchValue = []
273
+ currentTable.value.map(i => {
274
+ if (i.label.includes(str)) {
275
+ searchValue.push(i)
276
+ }
277
+ })
278
+ setFields(searchValue)
279
+ updateColumn()
280
+ }
281
+
282
+ /**
283
+ * 全选
284
+ * @param {Boolean} v 回调参数 - 是否全选
285
+ */
286
+ const checkAll = ref(false)
287
+ const isIndeterminate = ref(false) // 来自官方解释:indeterminate 属性用以表示 checkbox 的不确定状态,一般用于实现全选的效果
288
+ const handleCheckAllChange = (v) => {
289
+ // 搜索时,全选
290
+ if (columnName.value && fields.value.length) {
291
+ searchValue.map(item => {
292
+ if (!unChangedColumn.value.includes(item.prop)) {
293
+ item.initHidden = !v
294
+ // 清除列目时,清除固定属性
295
+ v ? '' : item.attr.fixed = false
296
+ }
297
+ })
298
+ updateColumn()
299
+ } else {
300
+ currentTable.value.map(item => {
301
+ if (!unChangedColumn.value.includes(item.prop)) {
302
+ item.initHidden = !v
303
+ // 清除列目时,清除固定属性
304
+ v ? '' : item.attr.fixed = false
305
+ }
306
+ })
307
+ updateColumn()
308
+ }
309
+ isIndeterminate.value = false
310
+ }
311
+
312
+ /**
313
+ * 单选/取消
314
+ * @param {Boolean} v 是否取消 true:选中; false: 取消
315
+ * @param {String} prop 当前选中列目的 prop
316
+ */
317
+ const handleCheckedChange = (v, prop) => {
318
+ currentTable.value.map(item => {
319
+ if (item.prop === prop) {
320
+ item.initHidden = !v
321
+ // 清除列目时,清除固定属性
322
+ v ? '' : item.attr.fixed = false
323
+ }
324
+ })
325
+ updateColumn()
326
+ }
327
+
328
+ /**
329
+ * 固定/取消固定
330
+ * @param {Boolean} v 是否取消 true:固定; false: 取消固定
331
+ * @param {String} prop 当前选中列目的 prop
332
+ */
333
+ const handleFixed = (v, prop) => {
334
+ const columnInfo = currentTable.value.find(item => item.prop === prop)
335
+ if (columnInfo) {
336
+ columnInfo.attr.fixed = v ? 'left' : false
337
+ }
338
+ updateColumn()
339
+ }
340
+
341
+ /**
342
+ * 确定
343
+ */
344
+ const syncTableColumnsToCookies = () => {
345
+ const newTableColumns = [...fixedColumn.value, ...unFixedColumn.value]
346
+ if (newTableColumns.filter(item => !item.initHidden).length === 0) {
347
+ // @ts-ignore
348
+ instance?.$openMessage.warning({
349
+ message: props.selectEmptyWarningTips,
350
+ duration: 2000,
351
+ })
352
+ throw new Error(props.selectEmptyWarningTips)
353
+ }
354
+ const columnState = {}
355
+ const obj: Record<string, any> = {}
356
+ newTableColumns.map((i, index) => {
357
+ columnState[i.prop] = {
358
+ initHidden: i.initHidden || false,
359
+ fixed: i.attr?.fixed || false,
360
+ prop: i.prop,
361
+ index
362
+ }
363
+ obj[i.prop] = !columnState[i.prop].initHidden
364
+ })
365
+ // @ts-ignore
366
+ instance?.$cookies?.set(props.storageKey, JSON.stringify(columnState), -1)
367
+ return obj
368
+ }
369
+
370
+ /**
371
+ * 拖拽
372
+ * @description vueDraggable
373
+ */
374
+ const drag = ref(false)
375
+ const dragOptions = computed(() => {
376
+ return {
377
+ animation: 200,
378
+ group: 'description',
379
+ disabled: false,
380
+ ghostClass: 'ghost'
381
+ }
382
+ })
383
+
384
+ defineExpose({
385
+ syncTableColumnsToCookies,
386
+ setFields,
387
+ updateColumn,
388
+ handleSearch,
389
+ currentTable,
390
+ showColumn,
391
+ unChangedColumn,
392
+ fixedColumn,
393
+ unFixedColumn,
394
+ checkAll,
395
+ isIndeterminate,
396
+ columnName,
397
+ searchValue,
398
+ checkedCount,
399
+ fields,
400
+ dragOptions,
401
+ drag,
402
+ })
403
+ </script>
404
+
@@ -5,7 +5,6 @@
5
5
  </template>
6
6
  <template v-else>
7
7
  <el-input
8
- size="mini"
9
8
  v-if="isInput"
10
9
  v-model="currentVal"
11
10
  v-bind="bindProps"
@@ -23,6 +22,7 @@
23
22
  />
24
23
  <nf-virtual-select
25
24
  v-if="isSelect"
25
+ :width="width"
26
26
  v-model="currentVal"
27
27
  v-bind="bindProps"
28
28
  v-on="bindEvents"
@@ -197,13 +197,14 @@ const props = withDefaults(defineProps<{
197
197
  * 单个表单项渲染数据
198
198
  */
199
199
  itemOptions?: NfSearchFormItemOption,
200
+ /**
201
+ * content宽度
202
+ */
200
203
  itemWidth?: number,
201
- labelWidth?: number
202
204
  }>(), {
203
205
  value: undefined,
204
206
  itemOptions: () => ({}),
205
207
  itemWidth: 170,
206
- labelWidth: 70
207
208
  })
208
209
 
209
210
  const slotName = computed(() => {
@@ -228,7 +229,6 @@ const currentVal = computed({
228
229
  // 绑定属性
229
230
  const bindProps = computed(() => {
230
231
  let obj:Record<string, any> = {
231
- size: 'mini',
232
232
  clearable: true,
233
233
  ...props.itemOptions
234
234
  }