@94ai/nf-search-form 3.1.13
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/.eslintrc.cjs +49 -0
- package/README.md +11 -0
- package/components.d.ts +8 -0
- package/lib/index.d.ts +2887 -0
- package/lib/nf-column-check-dialog.vue.d.ts +150 -0
- package/lib/nf-column-check-drawer.vue.d.ts +105 -0
- package/lib/nf-number-range.vue.d.ts +32 -0
- package/lib/nf-search-form-item.vue.d.ts +48 -0
- package/lib/nf-search-form.cjs.js +7882 -0
- package/lib/nf-search-form.esm-bundler.js +7882 -0
- package/lib/nf-search-form.vue.d.ts +637 -0
- package/lib/nf-time-range.vue.d.ts +42 -0
- package/lib/style/css.d.ts +1 -0
- package/lib/style/css.js +1 -0
- package/lib/style/index.d.ts +1 -0
- package/lib/style/index.js +1 -0
- package/lib/types.d.ts +50 -0
- package/package/index.ts +14 -0
- package/package/nf-column-check-dialog.vue +182 -0
- package/package/nf-column-check-drawer.vue +412 -0
- package/package/nf-number-range.vue +130 -0
- package/package/nf-search-form-item.vue +415 -0
- package/package/nf-search-form.vue +1153 -0
- package/package/nf-time-range.vue +128 -0
- package/package/style/css.ts +1 -0
- package/package/style/index.ts +1 -0
- package/package/types.ts +97 -0
- package/package.json +52 -0
- package/postcss.config.js +8 -0
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
export type NfSearchFormItemOption = {
|
|
2
|
+
key?: string;
|
|
3
|
+
_index?: number;
|
|
4
|
+
__index?: number;
|
|
5
|
+
initHidden?: boolean;
|
|
6
|
+
destory?: boolean;
|
|
7
|
+
label?: string;
|
|
8
|
+
addLabel?: string;
|
|
9
|
+
prop?: string;
|
|
10
|
+
width?: string;
|
|
11
|
+
isShowColon?: boolean;
|
|
12
|
+
hidden?: boolean;
|
|
13
|
+
required?: boolean;
|
|
14
|
+
rules?: Record<string, any>;
|
|
15
|
+
size?: 'medium' | 'small' | 'mini';
|
|
16
|
+
labelWidth?: string;
|
|
17
|
+
'is-range'?: boolean;
|
|
18
|
+
showMessage?: boolean;
|
|
19
|
+
inlineMessage?: boolean;
|
|
20
|
+
category?: string;
|
|
21
|
+
initValue?: any;
|
|
22
|
+
slot?: string;
|
|
23
|
+
labelSlot?: string;
|
|
24
|
+
class?: string;
|
|
25
|
+
tooltip?: {
|
|
26
|
+
slot: string;
|
|
27
|
+
};
|
|
28
|
+
type?: 'monthrange' | 'datetimerange' | 'daterange' | 'yearrange' | 'halfyearrange' | 'quarterrange' | 'date' | 'month' | 'week' | 'dates';
|
|
29
|
+
element?: 'el-input' | 'el-select' | 'custom-select' | 'ai-select' | 'ai-custom-select' | 'nf-lazy-select' | 'el-input-number' | 'el-date-picker' | 'el-cascader' | 'el-time-select' | 'el-time-picker' | 'number-range' | 'nf-date-picker' | 'nf-quarter-picker' | 'nf-half-year-picker' | 'nf-double-year' | 'nf-double-week' | 'nf-double-half-year' | 'nf-double-quarter' | 'nf-transfer-select';
|
|
30
|
+
events?: Record<string, Function>;
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
virtualList?: boolean;
|
|
33
|
+
'controls-position'?: 'right' | 'left';
|
|
34
|
+
clearable?: boolean;
|
|
35
|
+
startPlaceholder?: string;
|
|
36
|
+
rangeSeparator?: string;
|
|
37
|
+
endPlaceholder?: string;
|
|
38
|
+
defaultTime?: string[];
|
|
39
|
+
options?: {
|
|
40
|
+
label: string;
|
|
41
|
+
value: string | number;
|
|
42
|
+
}[];
|
|
43
|
+
'picker-options'?: {
|
|
44
|
+
start: string;
|
|
45
|
+
step: string;
|
|
46
|
+
end: string;
|
|
47
|
+
};
|
|
48
|
+
valueFormat?: string;
|
|
49
|
+
min?: 0;
|
|
50
|
+
};
|
package/package/index.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import NfSearchForm from './nf-search-form.vue'
|
|
2
|
+
import { Vue2, PluginObject } from 'vue-demi'
|
|
3
|
+
import NfMessage from '@94ai/nf-message'
|
|
4
|
+
|
|
5
|
+
NfSearchForm.install = (app: typeof Vue2) => {
|
|
6
|
+
// @ts-ignore
|
|
7
|
+
if (!app.$openMessage) {
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
app.use(NfMessage)
|
|
10
|
+
}
|
|
11
|
+
app!.component('nf-search-form', NfSearchForm)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default NfSearchForm as typeof NfSearchForm & PluginObject<undefined>
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<el-dialog
|
|
3
|
+
@open="$emit('open', $event)"
|
|
4
|
+
@opened="$emit('opened', $event)"
|
|
5
|
+
@close="$emit('close', $event)"
|
|
6
|
+
@closed="$emit('closed', $event)"
|
|
7
|
+
:visible.sync="visible"
|
|
8
|
+
:title="title"
|
|
9
|
+
:width="width"
|
|
10
|
+
:modal-append-to-body="modalAppendToBody"
|
|
11
|
+
:modal="modal"
|
|
12
|
+
:fullscreen="fullscreen"
|
|
13
|
+
:top="top"
|
|
14
|
+
:append-to-body="appendToBody"
|
|
15
|
+
:lock-scroll="lockScroll"
|
|
16
|
+
:custom-class="(customClass || '') + ' nf-search-form-nf-column-check-dialog'"
|
|
17
|
+
:close-on-click-modal="closeOnlickModal"
|
|
18
|
+
:close-on-press-escape="closeOnPressEscape"
|
|
19
|
+
:show-close="showClose"
|
|
20
|
+
:before-close="beforeClose"
|
|
21
|
+
:center="center"
|
|
22
|
+
:destroy-on-close="destroyOnClose"
|
|
23
|
+
>
|
|
24
|
+
<slot slot="title" name="title"></slot>
|
|
25
|
+
<div class="nf-search-form-nf-column-check-dialog-check-content">
|
|
26
|
+
<div v-for="(item,index) in fields" :key="index" class="nf-check-item">
|
|
27
|
+
<div class="nf-check-title">{{ item.name }}</div>
|
|
28
|
+
<el-checkbox v-for="obj in item.list" :key="obj.prop" v-model="tableData[obj.prop]" class="nf-check-box" :label="obj.prop">
|
|
29
|
+
{{ obj.addLabel || obj.label }}
|
|
30
|
+
</el-checkbox>
|
|
31
|
+
</div>
|
|
32
|
+
</div>
|
|
33
|
+
<slot slot="footer" name="footer">
|
|
34
|
+
<div class="nf-search-form-nf-column-check-dialog-button-container">
|
|
35
|
+
<nf-button size="mini" class="nf-search-form-nf-column-check-dialog-button-cancel" @click="visible=false">{{ cancelText }}</nf-button>
|
|
36
|
+
<nf-button type="primary" class="nf-search-form-nf-column-check-dialog-button-confirm" size="mini" @click="submit">{{ confirmText }}</nf-button>
|
|
37
|
+
</div>
|
|
38
|
+
</slot>
|
|
39
|
+
</el-dialog>
|
|
40
|
+
</template>
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
<script lang="ts">
|
|
44
|
+
import { defineComponent } from 'vue-demi'
|
|
45
|
+
|
|
46
|
+
export default defineComponent({
|
|
47
|
+
name: "NfColumnCheckDialog",
|
|
48
|
+
})
|
|
49
|
+
</script>
|
|
50
|
+
|
|
51
|
+
<script setup lang="ts">
|
|
52
|
+
import {
|
|
53
|
+
computed,
|
|
54
|
+
getCurrentInstance,
|
|
55
|
+
onMounted,
|
|
56
|
+
ref
|
|
57
|
+
} from 'vue-demi'
|
|
58
|
+
import { NfSearchFormItemOption } from './types'
|
|
59
|
+
import { CachedManager } from '@94ai/common-utils'
|
|
60
|
+
|
|
61
|
+
const props = withDefaults(defineProps<{
|
|
62
|
+
storageKey?: string
|
|
63
|
+
/**
|
|
64
|
+
* 列编辑,是否显示按钮配置表单项显示
|
|
65
|
+
*/
|
|
66
|
+
columnEdit?: boolean,
|
|
67
|
+
show?: boolean,
|
|
68
|
+
title?: string,
|
|
69
|
+
width?: string,
|
|
70
|
+
confirmText?: string
|
|
71
|
+
cancelText?: string
|
|
72
|
+
basicFieldDesc?: string
|
|
73
|
+
tableColumns?: NfSearchFormItemOption[],
|
|
74
|
+
modalAppendToBody?: boolean,
|
|
75
|
+
modal?: boolean,
|
|
76
|
+
fullscreen?: boolean,
|
|
77
|
+
top?: string,
|
|
78
|
+
appendToBody?: boolean,
|
|
79
|
+
lockScroll?: boolean,
|
|
80
|
+
customClass?: string,
|
|
81
|
+
closeOnlickModal?: boolean,
|
|
82
|
+
closeOnPressEscape?: boolean,
|
|
83
|
+
showClose?: boolean,
|
|
84
|
+
beforeClose?: Function,
|
|
85
|
+
center?: boolean,
|
|
86
|
+
destroyOnClose?: boolean,
|
|
87
|
+
}>(), {
|
|
88
|
+
columnEdit: false,
|
|
89
|
+
storageKey: 'nf-table-columns-cached-key',
|
|
90
|
+
show: false,
|
|
91
|
+
width: '600',
|
|
92
|
+
title: '设置显示查询框',
|
|
93
|
+
cancelText: '取 消',
|
|
94
|
+
confirmText: '保 存',
|
|
95
|
+
basicFieldDesc: '基础字段',
|
|
96
|
+
tableColumns: () => [],
|
|
97
|
+
modalAppendToBody: true,
|
|
98
|
+
modal: true,
|
|
99
|
+
fullscreen: false,
|
|
100
|
+
top: '15vh',
|
|
101
|
+
appendToBody: false,
|
|
102
|
+
lockScroll: true,
|
|
103
|
+
customClass: '',
|
|
104
|
+
closeOnlickModal: true,
|
|
105
|
+
closeOnPressEscape: true,
|
|
106
|
+
showClose: true,
|
|
107
|
+
beforeClose: undefined,
|
|
108
|
+
center: false,
|
|
109
|
+
destroyOnClose: false,
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
const tableData = ref<Record<string, boolean>>({})
|
|
113
|
+
|
|
114
|
+
const emit = defineEmits<{
|
|
115
|
+
(e: 'update:show', event: boolean): void
|
|
116
|
+
(e: 'save', event: Record<string, any>): void
|
|
117
|
+
}>()
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
const visible = computed({
|
|
121
|
+
get() {
|
|
122
|
+
return props.show
|
|
123
|
+
},
|
|
124
|
+
set(val) {
|
|
125
|
+
emit('update:show', val)
|
|
126
|
+
}
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* 按照category做分类
|
|
131
|
+
*/
|
|
132
|
+
const fields = computed(() => {
|
|
133
|
+
const obj: Record<string, any> = {}
|
|
134
|
+
props.tableColumns.filter(item => !item.destory).map(item => {
|
|
135
|
+
const key = item.category || props.basicFieldDesc
|
|
136
|
+
if (!obj[key]) {
|
|
137
|
+
obj[key] = []
|
|
138
|
+
}
|
|
139
|
+
obj[key].push(item)
|
|
140
|
+
})
|
|
141
|
+
const fields: {
|
|
142
|
+
name: string,
|
|
143
|
+
list: Record<string, any>[]
|
|
144
|
+
}[] = []
|
|
145
|
+
for (const key in obj) {
|
|
146
|
+
fields.push({
|
|
147
|
+
name: key,
|
|
148
|
+
list: obj[key]
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
return fields
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
onMounted(() => {
|
|
155
|
+
addInitValue()
|
|
156
|
+
})
|
|
157
|
+
const instance = getCurrentInstance()?.proxy
|
|
158
|
+
|
|
159
|
+
const submit = () => {
|
|
160
|
+
visible.value = false
|
|
161
|
+
const columnState = {}
|
|
162
|
+
props.tableColumns.map((i, index) => {
|
|
163
|
+
columnState[i.prop!] = {
|
|
164
|
+
initHidden: !tableData.value[i.prop!] || false,
|
|
165
|
+
prop: i.prop,
|
|
166
|
+
index
|
|
167
|
+
}
|
|
168
|
+
})
|
|
169
|
+
emit('save', tableData.value)
|
|
170
|
+
if (props.columnEdit) {
|
|
171
|
+
CachedManager.syncCachedSet(props.storageKey, columnState)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
const addInitValue = () => {
|
|
176
|
+
const obj: Record<string, any> = {}
|
|
177
|
+
props.tableColumns.forEach(v => {
|
|
178
|
+
obj[v.prop!] = !v.initHidden
|
|
179
|
+
})
|
|
180
|
+
tableData.value = obj
|
|
181
|
+
}
|
|
182
|
+
</script>
|
|
@@ -0,0 +1,412 @@
|
|
|
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.addLabel || 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.addLabel || 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.addLabel || 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
|
+
} from 'vue-demi'
|
|
142
|
+
import { deepClone } from '@94ai/common-utils'
|
|
143
|
+
import { CachedManager } from '@94ai/common-utils'
|
|
144
|
+
|
|
145
|
+
const instance = getCurrentInstance()?.proxy
|
|
146
|
+
|
|
147
|
+
const props = withDefaults(defineProps<{
|
|
148
|
+
selectEmptyWarningTips?: string,
|
|
149
|
+
// 源序列
|
|
150
|
+
tableColumns?: Record<string, any>[],
|
|
151
|
+
storageKey?: string
|
|
152
|
+
searchPlaceholder?: string
|
|
153
|
+
fixedLeftDesc?: string
|
|
154
|
+
clearDesc?: string
|
|
155
|
+
noFixedDesc?: string
|
|
156
|
+
basicFieldDesc?: string
|
|
157
|
+
getCheckedLengthDesc?: Function
|
|
158
|
+
getAllCheckDesc?: Function
|
|
159
|
+
/**
|
|
160
|
+
* 列编辑,是否显示按钮配置表单项显示
|
|
161
|
+
*/
|
|
162
|
+
columnEdit?: boolean,
|
|
163
|
+
}>(), {
|
|
164
|
+
columnEdit: false,
|
|
165
|
+
storageKey: 'nf-table-columns-cached-key',
|
|
166
|
+
tableColumns: () => [],
|
|
167
|
+
selectEmptyWarningTips: '请选择至少一个选项',
|
|
168
|
+
searchPlaceholder: '搜索',
|
|
169
|
+
fixedLeftDesc: '固定在左侧',
|
|
170
|
+
clearDesc: '清除',
|
|
171
|
+
noFixedDesc: '不固定',
|
|
172
|
+
basicFieldDesc: '基础字段',
|
|
173
|
+
getCheckedLengthDesc: (length) => '已选(' + length + ')',
|
|
174
|
+
getAllCheckDesc: (length) => '全选(' + length + ')',
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
// 获取当前缓存中的动态数据列
|
|
178
|
+
const currentTable = ref<Record<string, any>[]>([])
|
|
179
|
+
// 可选列表的绑定的已选值
|
|
180
|
+
const showColumn = ref<string[]>([])
|
|
181
|
+
// 不可操作列
|
|
182
|
+
const unChangedColumn = ref<string[]>([])
|
|
183
|
+
// 固定列
|
|
184
|
+
const fixedColumn = ref<Record<string, any>[]>([])
|
|
185
|
+
// 不固定列
|
|
186
|
+
const unFixedColumn = ref<Record<string, any>[]>([])
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
onBeforeMount(() => {
|
|
190
|
+
// 混合缓存后数据
|
|
191
|
+
currentTable.value = deepClone(props.tableColumns.filter(item => !item.destory)).sort((a,b) => a._index! - b._index! < 0 ? -1 : a._index! - b._index! > 0 ? 1 : 0) as Record<string, any>[]
|
|
192
|
+
// 兼容处理
|
|
193
|
+
currentTable.value.map(i => {
|
|
194
|
+
if (!i.attr) {
|
|
195
|
+
i.attr = {}
|
|
196
|
+
}
|
|
197
|
+
})
|
|
198
|
+
// 原始数据
|
|
199
|
+
const list = props.tableColumns.filter(item => !item.destory)
|
|
200
|
+
// 可选列表 → 字段区分
|
|
201
|
+
setFields(list)
|
|
202
|
+
// 已选列表
|
|
203
|
+
updateColumn()
|
|
204
|
+
if (currentTable.value.every(i => !i.initHidden)) {
|
|
205
|
+
showColumn.value = currentTable.value.map(i => i.prop)
|
|
206
|
+
checkedCount.value = list.length
|
|
207
|
+
checkAll.value = true
|
|
208
|
+
isIndeterminate.value = false
|
|
209
|
+
}
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* 可选列表 → 字段区分
|
|
214
|
+
* @description fields = [{ name: '基础字段', list: [{
|
|
215
|
+
* ...
|
|
216
|
+
* }] }, ...]
|
|
217
|
+
*/
|
|
218
|
+
const fields = ref<{
|
|
219
|
+
name: string,
|
|
220
|
+
list: Record<string, any>[]
|
|
221
|
+
}[]>([])
|
|
222
|
+
const setFields = (tableColumns) => {
|
|
223
|
+
const obj: Record<string, any> = {}
|
|
224
|
+
tableColumns.map(item => {
|
|
225
|
+
const key = item.category || props.basicFieldDesc
|
|
226
|
+
if (!obj[key]) {
|
|
227
|
+
obj[key] = []
|
|
228
|
+
}
|
|
229
|
+
obj[key].push(item)
|
|
230
|
+
})
|
|
231
|
+
const items: {
|
|
232
|
+
name: string
|
|
233
|
+
list: Record<string, any>[]
|
|
234
|
+
}[] = []
|
|
235
|
+
for (const key in obj) {
|
|
236
|
+
items.push({
|
|
237
|
+
name: key,
|
|
238
|
+
list: obj[key]
|
|
239
|
+
})
|
|
240
|
+
}
|
|
241
|
+
fields.value = items
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* 更新已选列表
|
|
246
|
+
*/
|
|
247
|
+
const checkedCount = ref(0) // 勾选的数量
|
|
248
|
+
const updateColumn = () => {
|
|
249
|
+
fixedColumn.value = []
|
|
250
|
+
unFixedColumn.value = []
|
|
251
|
+
currentTable.value.map(item => {
|
|
252
|
+
if (item.attr.fixed) {
|
|
253
|
+
fixedColumn.value.push(item)
|
|
254
|
+
} else {
|
|
255
|
+
unFixedColumn.value.push(item)
|
|
256
|
+
}
|
|
257
|
+
})
|
|
258
|
+
// 勾选状态
|
|
259
|
+
showColumn.value = currentTable.value.filter(i => !i.initHidden).map(item => item.prop)
|
|
260
|
+
// [全选 checkbox] 展示状态
|
|
261
|
+
if (columnName.value && fields.value.length) {
|
|
262
|
+
// 搜索时
|
|
263
|
+
checkedCount.value = searchValue.filter(i => !i.initHidden).length
|
|
264
|
+
checkAll.value = checkedCount.value === searchValue.length
|
|
265
|
+
isIndeterminate.value = checkedCount.value > 0 && checkedCount.value < searchValue.length
|
|
266
|
+
return
|
|
267
|
+
}
|
|
268
|
+
checkedCount.value = showColumn.value.length
|
|
269
|
+
checkAll.value = checkedCount.value === currentTable.value.length
|
|
270
|
+
isIndeterminate.value = checkedCount.value > 0 && checkedCount.value < currentTable.value.length
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
/**
|
|
274
|
+
* 搜索
|
|
275
|
+
*/
|
|
276
|
+
const columnName = ref('')
|
|
277
|
+
let searchValue: Record<string, any>[] = [] // 搜索结果
|
|
278
|
+
const handleSearch = (str) => {
|
|
279
|
+
searchValue = []
|
|
280
|
+
currentTable.value.map(i => {
|
|
281
|
+
if ((i.addLabel || i.label).includes(str)) {
|
|
282
|
+
searchValue.push(i)
|
|
283
|
+
}
|
|
284
|
+
})
|
|
285
|
+
setFields(searchValue)
|
|
286
|
+
updateColumn()
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* 全选
|
|
291
|
+
* @param {Boolean} v 回调参数 - 是否全选
|
|
292
|
+
*/
|
|
293
|
+
const checkAll = ref(false)
|
|
294
|
+
const isIndeterminate = ref(false) // 来自官方解释:indeterminate 属性用以表示 checkbox 的不确定状态,一般用于实现全选的效果
|
|
295
|
+
const handleCheckAllChange = (v) => {
|
|
296
|
+
// 搜索时,全选
|
|
297
|
+
if (columnName.value && fields.value.length) {
|
|
298
|
+
searchValue.map(item => {
|
|
299
|
+
if (!unChangedColumn.value.includes(item.prop)) {
|
|
300
|
+
item.initHidden = !v
|
|
301
|
+
// 清除列目时,清除固定属性
|
|
302
|
+
v ? '' : item.attr.fixed = false
|
|
303
|
+
}
|
|
304
|
+
})
|
|
305
|
+
updateColumn()
|
|
306
|
+
} else {
|
|
307
|
+
currentTable.value.map(item => {
|
|
308
|
+
if (!unChangedColumn.value.includes(item.prop)) {
|
|
309
|
+
item.initHidden = !v
|
|
310
|
+
// 清除列目时,清除固定属性
|
|
311
|
+
v ? '' : item.attr.fixed = false
|
|
312
|
+
}
|
|
313
|
+
})
|
|
314
|
+
updateColumn()
|
|
315
|
+
}
|
|
316
|
+
isIndeterminate.value = false
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 单选/取消
|
|
321
|
+
* @param {Boolean} v 是否取消 true:选中; false: 取消
|
|
322
|
+
* @param {String} prop 当前选中列目的 prop
|
|
323
|
+
*/
|
|
324
|
+
const handleCheckedChange = (v, prop) => {
|
|
325
|
+
currentTable.value.map(item => {
|
|
326
|
+
if (item.prop === prop) {
|
|
327
|
+
item.initHidden = !v
|
|
328
|
+
// 清除列目时,清除固定属性
|
|
329
|
+
v ? '' : item.attr.fixed = false
|
|
330
|
+
}
|
|
331
|
+
})
|
|
332
|
+
updateColumn()
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* 固定/取消固定
|
|
337
|
+
* @param {Boolean} v 是否取消 true:固定; false: 取消固定
|
|
338
|
+
* @param {String} prop 当前选中列目的 prop
|
|
339
|
+
*/
|
|
340
|
+
const handleFixed = (v, prop) => {
|
|
341
|
+
const columnInfo = currentTable.value.find(item => item.prop === prop)
|
|
342
|
+
if (columnInfo) {
|
|
343
|
+
columnInfo.attr.fixed = v ? 'left' : false
|
|
344
|
+
}
|
|
345
|
+
updateColumn()
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* 确定
|
|
350
|
+
*/
|
|
351
|
+
const syncTableColumnsToCookies = () => {
|
|
352
|
+
const newTableColumns = [...fixedColumn.value, ...unFixedColumn.value]
|
|
353
|
+
if (newTableColumns.filter(item => !item.initHidden).length === 0) {
|
|
354
|
+
// @ts-ignore
|
|
355
|
+
instance?.$openMessage?.warning({
|
|
356
|
+
message: props.selectEmptyWarningTips,
|
|
357
|
+
duration: 2000,
|
|
358
|
+
})
|
|
359
|
+
throw new Error(props.selectEmptyWarningTips)
|
|
360
|
+
}
|
|
361
|
+
const columnState = {}
|
|
362
|
+
const obj: Record<string, any> = {}
|
|
363
|
+
newTableColumns.map((i, index) => {
|
|
364
|
+
columnState[i.prop] = {
|
|
365
|
+
initHidden: i.initHidden || false,
|
|
366
|
+
fixed: i.attr?.fixed || false,
|
|
367
|
+
prop: i.prop,
|
|
368
|
+
index
|
|
369
|
+
}
|
|
370
|
+
obj[i.prop] = !columnState[i.prop].initHidden
|
|
371
|
+
})
|
|
372
|
+
if (props.columnEdit) {
|
|
373
|
+
CachedManager.syncCachedSet(props.storageKey, columnState)
|
|
374
|
+
}
|
|
375
|
+
return obj
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* 拖拽
|
|
380
|
+
* @description vueDraggable
|
|
381
|
+
*/
|
|
382
|
+
const drag = ref(false)
|
|
383
|
+
const dragOptions = computed(() => {
|
|
384
|
+
return {
|
|
385
|
+
animation: 200,
|
|
386
|
+
group: 'description',
|
|
387
|
+
disabled: false,
|
|
388
|
+
ghostClass: 'ghost'
|
|
389
|
+
}
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
defineExpose({
|
|
393
|
+
syncTableColumnsToCookies,
|
|
394
|
+
setFields,
|
|
395
|
+
updateColumn,
|
|
396
|
+
handleSearch,
|
|
397
|
+
currentTable,
|
|
398
|
+
showColumn,
|
|
399
|
+
unChangedColumn,
|
|
400
|
+
fixedColumn,
|
|
401
|
+
unFixedColumn,
|
|
402
|
+
checkAll,
|
|
403
|
+
isIndeterminate,
|
|
404
|
+
columnName,
|
|
405
|
+
searchValue,
|
|
406
|
+
checkedCount,
|
|
407
|
+
fields,
|
|
408
|
+
dragOptions,
|
|
409
|
+
drag,
|
|
410
|
+
})
|
|
411
|
+
</script>
|
|
412
|
+
|