@xmszm/core 0.0.1 → 0.0.3
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/README.md +187 -0
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +1431 -1170
- package/dist/plugin/vite/initRouteMeta.cjs +1 -0
- package/dist/plugin/vite/initRouteMeta.mjs +13 -0
- package/dist/style.css +1 -1
- package/docs/.vitepress/config.mjs +91 -0
- package/docs/components/config-options.md +125 -0
- package/docs/components/dataform.md +176 -23
- package/docs/components/datatable.md +58 -39
- package/docs/components/dialog.md +158 -19
- package/docs/components/options.md +44 -15
- package/docs/components/query.md +68 -14
- package/docs/components/utils.md +124 -16
- package/docs/guide/changelog.md +81 -0
- package/docs/guide/config.md +415 -0
- package/docs/guide/demo.md +2 -2
- package/docs/guide/local-development.md +109 -0
- package/docs/guide/quickstart.md +40 -11
- package/docs/index.md +3 -3
- package/docs/usage.md +30 -6
- package/examples/README.md +46 -0
- package/examples/index.html +14 -0
- package/examples/package.json +25 -0
- package/examples/pnpm-lock.yaml +1569 -0
- package/examples/pnpm-workspace.yaml +3 -0
- package/examples/src/AdminSystem.vue +870 -0
- package/examples/src/App.vue +330 -0
- package/examples/src/Introduction.vue +307 -0
- package/examples/src/main.js +22 -0
- package/examples/src/utils/permission.js +16 -0
- package/examples/src/utils/request.js +10 -0
- package/examples/vite.config.js +41 -0
- package/package.json +13 -4
- package/src/dialog/commonDialog.tsx +285 -0
- package/src/dialog/useCommonDialog.ts +41 -0
- package/src/dialog/utils/{dialog.js → dialog.ts} +2 -0
- package/src/directives/auto-register.ts +57 -0
- package/src/directives/permission.ts +67 -0
- package/src/enum/sort.tsx +45 -0
- package/src/form/DataForm.vue +34 -52
- package/src/index.ts +58 -0
- package/src/list/{useList.jsx → useList.tsx} +49 -14
- package/src/options/{Options.jsx → Options.tsx} +86 -72
- package/src/options/defaultOptions.tsx +656 -0
- package/src/plugin/index.ts +20 -0
- package/src/query/CommonQuery.vue +65 -90
- package/src/table/DataTable.vue +82 -95
- package/src/table/opr/{DataColumnCollet.jsx → DataColumnCollet.tsx} +18 -8
- package/src/table/opr/useDataColumn.tsx +226 -0
- package/src/table/opr/{useDataColumnButton.jsx → useDataColumnButton.tsx} +13 -6
- package/src/table/opr/{useDataColumnPop.jsx → useDataColumnPop.tsx} +13 -5
- package/src/table/opr/useQRCode.ts +40 -0
- package/src/utils/{array.js → array.ts} +4 -6
- package/src/utils/config.ts +192 -0
- package/src/utils/dialog.ts +110 -0
- package/src/utils/{object.js → object.ts} +1 -0
- package/src/utils/upload.ts +53 -0
- package/types/auto-imports.d.ts +78 -0
- package/types/components.d.ts +402 -0
- package/types/index.d.ts +145 -7
- package/types/plugin/vite/initRouteMeta.d.ts +23 -0
- package/types/src.d.ts +55 -0
- package/types/vue-shim.d.ts +9 -0
- package/examples/demo.vue +0 -224
- package/src/dialog/commonDialog.jsx +0 -230
- package/src/enum/sort.jsx +0 -31
- package/src/index.js +0 -46
- package/src/options/defaultOptions.jsx +0 -580
- package/src/table/opr/useDataColumn.jsx +0 -196
- package/src/utils/upload.js +0 -46
- /package/src/enum/{options.js → options.ts} +0 -0
- /package/src/plugin/vite/{initRouteMeta.js → initRouteMeta.ts} +0 -0
- /package/src/store/utils/{index.js → index.ts} +0 -0
- /package/src/table/utils/{ellipsis.js → ellipsis.ts} +0 -0
- /package/src/utils/{auth.js → auth.ts} +0 -0
- /package/src/utils/{time.js → time.ts} +0 -0
|
@@ -1,81 +1,61 @@
|
|
|
1
|
-
<script setup lang="
|
|
1
|
+
<script setup lang="tsx">
|
|
2
2
|
import { RefreshOutline, SearchOutline } from '@vicons/ionicons5'
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
3
|
+
import type { CommonQueryProps, CommonQueryEmits, FormOption } from '../../types/components'
|
|
4
|
+
import DataForm from '../form/DataForm.vue'
|
|
5
|
+
import { getOptions } from '../options/defaultOptions'
|
|
6
|
+
import { ObjectToArray } from '../utils/object'
|
|
7
|
+
import { computed, onMounted, onUnmounted, ref, getCurrentInstance } from 'vue'
|
|
8
|
+
import { NButton, NSpace } from 'naive-ui'
|
|
9
|
+
import { registerDirectives } from '../directives/auto-register'
|
|
10
|
+
|
|
11
|
+
// 自动注册指令
|
|
12
|
+
const instance = getCurrentInstance()
|
|
13
|
+
if (instance?.appContext?.app) {
|
|
14
|
+
registerDirectives(instance.appContext.app)
|
|
15
|
+
}
|
|
7
16
|
|
|
8
17
|
// 防抖函数
|
|
9
|
-
function debounce(func, delay) {
|
|
10
|
-
let timeoutId
|
|
11
|
-
return function (...args) {
|
|
18
|
+
function debounce<T extends (...args: any[]) => any>(func: T, delay: number): (...args: Parameters<T>) => void {
|
|
19
|
+
let timeoutId: ReturnType<typeof setTimeout> | undefined
|
|
20
|
+
return function (...args: Parameters<T>) {
|
|
12
21
|
clearTimeout(timeoutId)
|
|
13
22
|
timeoutId = setTimeout(() => {
|
|
14
23
|
func.apply(this, args)
|
|
15
24
|
}, delay)
|
|
16
25
|
}
|
|
17
26
|
}
|
|
18
|
-
const emit = defineEmits(
|
|
19
|
-
|
|
20
|
-
const props = defineProps({
|
|
21
|
-
inlineText:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
type: Object,
|
|
31
|
-
default: () => ({}),
|
|
32
|
-
},
|
|
33
|
-
selectCount: {
|
|
34
|
-
type: Number,
|
|
35
|
-
default: () => 1,
|
|
36
|
-
},
|
|
37
|
-
type: {
|
|
38
|
-
type: String,
|
|
39
|
-
default: () => 'primary',
|
|
40
|
-
},
|
|
41
|
-
noButton: {
|
|
42
|
-
type: Boolean,
|
|
43
|
-
default: () => false,
|
|
44
|
-
},
|
|
45
|
-
isRead: {
|
|
46
|
-
type: Boolean,
|
|
47
|
-
default: () => false,
|
|
48
|
-
},
|
|
49
|
-
btn: {
|
|
50
|
-
type: Array,
|
|
51
|
-
default: () => ['reset', 'search'],
|
|
52
|
-
},
|
|
53
|
-
size: {
|
|
54
|
-
type: String,
|
|
55
|
-
default: () => 'medium',
|
|
56
|
-
},
|
|
57
|
-
|
|
27
|
+
const emit = defineEmits<CommonQueryEmits>()
|
|
28
|
+
|
|
29
|
+
const props = withDefaults(defineProps<CommonQueryProps>(), {
|
|
30
|
+
inlineText: true,
|
|
31
|
+
options: () => [],
|
|
32
|
+
query: () => ({}),
|
|
33
|
+
selectCount: 1,
|
|
34
|
+
type: 'primary',
|
|
35
|
+
noButton: false,
|
|
36
|
+
isRead: false,
|
|
37
|
+
btn: () => ['reset', 'search'],
|
|
38
|
+
size: 'medium',
|
|
58
39
|
})
|
|
59
40
|
|
|
60
|
-
function onBeforeOptions(arr){
|
|
61
|
-
return arr.map(v=>({
|
|
41
|
+
function onBeforeOptions(arr: FormOption[]): FormOption[] {
|
|
42
|
+
return arr.map((v: FormOption) => ({
|
|
62
43
|
...v,
|
|
63
|
-
props:{
|
|
44
|
+
props: {
|
|
64
45
|
...v.props,
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
46
|
+
...((!v.way || v.way === 'input') ? {
|
|
47
|
+
onUpdateValue: (...args: any[]) => {
|
|
48
|
+
;(v.props as any)?.onUpdateValue?.(...args)
|
|
68
49
|
debouncedSubmit()
|
|
69
50
|
}
|
|
70
|
-
|
|
51
|
+
} : {}),
|
|
71
52
|
...(v?.way === 'select' ? {
|
|
72
|
-
|
|
73
|
-
|
|
53
|
+
onUpdateValue: (...args: any[]) => {
|
|
54
|
+
;(v.props as any)?.onUpdateValue?.(...args)
|
|
74
55
|
debouncedSubmit()
|
|
75
56
|
}
|
|
76
|
-
|
|
57
|
+
} : {})
|
|
77
58
|
}
|
|
78
|
-
|
|
79
59
|
}))
|
|
80
60
|
}
|
|
81
61
|
|
|
@@ -108,9 +88,9 @@ const defaultOptions = getOptions(_queryOptionsKey.value)
|
|
|
108
88
|
|
|
109
89
|
const _queryOptions = computed(() => {
|
|
110
90
|
try {
|
|
111
|
-
const arr = []
|
|
112
|
-
for (let i = 0; i < props.options
|
|
113
|
-
const v = props.options[i]
|
|
91
|
+
const arr: FormOption[] = []
|
|
92
|
+
for (let i = 0; i < (props.options?.length || 0); i++) {
|
|
93
|
+
const v = props.options![i]
|
|
114
94
|
if (v?.enum && !v?.options)
|
|
115
95
|
v.options = ObjectToArray(v.enum)
|
|
116
96
|
if (!v?.props) {
|
|
@@ -123,19 +103,21 @@ const _queryOptions = computed(() => {
|
|
|
123
103
|
v.formItemProps = { ...defaultFormItemProps }
|
|
124
104
|
}
|
|
125
105
|
else {
|
|
106
|
+
const formItemProps = typeof v.formItemProps === 'function'
|
|
107
|
+
? v.formItemProps({}, {})
|
|
108
|
+
: v.formItemProps
|
|
126
109
|
v.formItemProps = {
|
|
127
110
|
...defaultFormItemProps,
|
|
128
|
-
...
|
|
129
|
-
style: { ...defaultFormItemProps.style, ...
|
|
111
|
+
...formItemProps,
|
|
112
|
+
style: { ...defaultFormItemProps.style, ...(formItemProps as any)?.style },
|
|
130
113
|
}
|
|
131
114
|
}
|
|
132
115
|
|
|
133
|
-
const key = v?.key || v?.value
|
|
116
|
+
const key = v?.key || (v as any)?.value
|
|
134
117
|
if (!key)
|
|
135
118
|
throw new Error('key no set')
|
|
136
119
|
arr.push({
|
|
137
120
|
...v,
|
|
138
|
-
|
|
139
121
|
key,
|
|
140
122
|
})
|
|
141
123
|
}
|
|
@@ -189,35 +171,28 @@ const defaultBtn = {
|
|
|
189
171
|
),
|
|
190
172
|
}
|
|
191
173
|
|
|
192
|
-
function clearQuery() {
|
|
193
|
-
props.options
|
|
194
|
-
const key = v?.key || v?.value
|
|
174
|
+
function clearQuery(): void {
|
|
175
|
+
props.options?.forEach((v: FormOption) => {
|
|
176
|
+
const key = (v?.key as string) || (v as any)?.value
|
|
195
177
|
if (key) {
|
|
196
|
-
if (v?.queryType)
|
|
197
|
-
_query.value[v.queryType]
|
|
198
|
-
|
|
178
|
+
if (v?.queryType) {
|
|
179
|
+
if (!(_query.value as any)[v.queryType]) {
|
|
180
|
+
(_query.value as any)[v.queryType] = {}
|
|
181
|
+
}
|
|
182
|
+
(_query.value as any)[v.queryType][key] = null
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
(_query.value as any)[key] = null
|
|
186
|
+
}
|
|
199
187
|
}
|
|
200
188
|
})
|
|
201
189
|
emit('reset')
|
|
202
190
|
}
|
|
203
191
|
|
|
204
192
|
// 全局监听 Enter 键的方法
|
|
205
|
-
function handleGlobalEnter(event) {
|
|
193
|
+
function handleGlobalEnter(event: KeyboardEvent): void {
|
|
206
194
|
// 检查是否按下了 Enter 键
|
|
207
195
|
if (event.key === 'Enter') {
|
|
208
|
-
// 检查是否在输入框、选择框等表单元素中
|
|
209
|
-
// const target = event.target
|
|
210
|
-
// const isFormElement = target.tagName === 'INPUT' ||
|
|
211
|
-
// target.tagName === 'SELECT' ||
|
|
212
|
-
// target.tagName === 'TEXTAREA' ||
|
|
213
|
-
// target.contentEditable === 'true'
|
|
214
|
-
|
|
215
|
-
// if (isFormElement) {
|
|
216
|
-
// // 阻止默认行为(如换行)
|
|
217
|
-
// event.preventDefault()
|
|
218
|
-
// // 触发搜索
|
|
219
|
-
|
|
220
|
-
// }
|
|
221
196
|
onSubmit()
|
|
222
197
|
}
|
|
223
198
|
}
|
|
@@ -234,7 +209,7 @@ onUnmounted(() => {
|
|
|
234
209
|
</script>
|
|
235
210
|
|
|
236
211
|
<template>
|
|
237
|
-
<
|
|
212
|
+
<NSpace
|
|
238
213
|
:wrap-item="false"
|
|
239
214
|
justify="space-between"
|
|
240
215
|
align="center"
|
|
@@ -247,14 +222,14 @@ onUnmounted(() => {
|
|
|
247
222
|
:form-props="{ showFeedback: false }"
|
|
248
223
|
/>
|
|
249
224
|
</div>
|
|
250
|
-
<
|
|
225
|
+
<NSpace v-if="!props.noButton" align="center" :wrap="false">
|
|
251
226
|
<slot name="left-btn" />
|
|
252
227
|
<template v-for="(itm, idx) in props.btn" :key="idx">
|
|
253
228
|
<component :is="defaultBtn?.[itm]?.()" />
|
|
254
229
|
</template>
|
|
255
230
|
<slot name="right-btn" />
|
|
256
|
-
</
|
|
257
|
-
</
|
|
231
|
+
</NSpace>
|
|
232
|
+
</NSpace>
|
|
258
233
|
</template>
|
|
259
234
|
|
|
260
235
|
<style scoped lang="less">
|
package/src/table/DataTable.vue
CHANGED
|
@@ -1,87 +1,68 @@
|
|
|
1
|
-
<script setup lang="
|
|
1
|
+
<script setup lang="tsx">
|
|
2
|
+
import type { DataTableProps, DataTableExpose } from '../../types/components'
|
|
2
3
|
import { ChevronDown, ChevronUp, Code, Funnel } from '@vicons/ionicons5'
|
|
3
4
|
import { commonDialogMethod, toArray } from 'core'
|
|
4
5
|
import { ellipsis } from 'core/table/utils/ellipsis'
|
|
5
6
|
import dayjs from 'dayjs'
|
|
6
7
|
import { uniqueId } from 'lodash-es'
|
|
7
8
|
import { NButton, NTooltip } from 'naive-ui'
|
|
8
|
-
import { computed, onMounted, ref, unref, watch ,isProxy} from 'vue'
|
|
9
|
+
import { computed, onMounted, ref, unref, watch ,isProxy, getCurrentInstance} from 'vue'
|
|
9
10
|
import { useRoute } from 'vue-router'
|
|
10
11
|
import FilterDialog from './FilterDialog.vue'
|
|
11
12
|
import { orderEnum } from 'core'
|
|
13
|
+
import { registerDirectives } from '../directives/auto-register'
|
|
14
|
+
import {NDataTable} from 'naive-ui'
|
|
15
|
+
// 自动注册指令
|
|
16
|
+
const instance = getCurrentInstance()
|
|
17
|
+
if (instance?.appContext?.app) {
|
|
18
|
+
registerDirectives(instance.appContext.app)
|
|
19
|
+
}
|
|
12
20
|
|
|
13
|
-
const props = defineProps({
|
|
14
|
-
data:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
},
|
|
18
|
-
pagination: {
|
|
19
|
-
type: [Object, null],
|
|
20
|
-
default: () => undefined,
|
|
21
|
-
},
|
|
22
|
-
columns: {
|
|
23
|
-
type: Array,
|
|
24
|
-
default: () => [
|
|
21
|
+
const props = withDefaults(defineProps<DataTableProps>(), {
|
|
22
|
+
data: () => [],
|
|
23
|
+
pagination: undefined,
|
|
24
|
+
columns: () => [
|
|
25
25
|
{
|
|
26
26
|
title: '测试案例',
|
|
27
27
|
},
|
|
28
28
|
],
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
},
|
|
38
|
-
|
|
39
|
-
type: Array,
|
|
40
|
-
default: () => [],
|
|
41
|
-
},
|
|
42
|
-
summaryColumns: {
|
|
43
|
-
type: null,
|
|
44
|
-
default: () => null,
|
|
45
|
-
},
|
|
46
|
-
emptyText: {
|
|
47
|
-
type: String,
|
|
48
|
-
default: () => '没有数据',
|
|
49
|
-
},
|
|
50
|
-
emptyIcon: {
|
|
51
|
-
type: String,
|
|
52
|
-
default: () => '',
|
|
53
|
-
},
|
|
54
|
-
isFilter: {
|
|
55
|
-
type: Boolean,
|
|
56
|
-
default: () => false,
|
|
57
|
-
},
|
|
58
|
-
isEllipsis: {
|
|
59
|
-
type: Boolean,
|
|
60
|
-
default: () => true,
|
|
61
|
-
},
|
|
62
|
-
virtual: {
|
|
63
|
-
type: null,
|
|
64
|
-
default: () => {},
|
|
65
|
-
},
|
|
66
|
-
singleColumn: {
|
|
67
|
-
type: Boolean,
|
|
68
|
-
default: () => false,
|
|
69
|
-
},
|
|
29
|
+
oprColumns: null,
|
|
30
|
+
selectColumns: null,
|
|
31
|
+
defaultColumns: () => [],
|
|
32
|
+
summaryColumns: null,
|
|
33
|
+
emptyText: '没有数据',
|
|
34
|
+
emptyIcon: '',
|
|
35
|
+
isFilter: false,
|
|
36
|
+
isEllipsis: true,
|
|
37
|
+
virtual: () => ({}),
|
|
38
|
+
singleColumn: false,
|
|
70
39
|
})
|
|
71
40
|
const route = useRoute()
|
|
72
41
|
const FilterKey = 'filter_key'
|
|
73
|
-
const emit = defineEmits
|
|
42
|
+
const emit = defineEmits<{
|
|
43
|
+
sorted: []
|
|
44
|
+
}>()
|
|
45
|
+
|
|
46
|
+
// 安全获取路由路径,如果没有路由上下文则使用默认值
|
|
47
|
+
const getRoutePath = (): string => {
|
|
48
|
+
try {
|
|
49
|
+
return route?.fullPath || route?.path || ''
|
|
50
|
+
} catch {
|
|
51
|
+
return ''
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
74
55
|
const _data = computed(() => {
|
|
75
56
|
console.log('table -data', props.data)
|
|
76
57
|
|
|
77
58
|
return props.data
|
|
78
59
|
})
|
|
79
|
-
function setHeadFilter(val) {
|
|
60
|
+
function setHeadFilter(val: Record<string, any>): void {
|
|
80
61
|
window.localStorage.setItem(FilterKey, JSON.stringify(val))
|
|
81
62
|
}
|
|
82
63
|
|
|
83
|
-
function getHeadFilter() {
|
|
84
|
-
return JSON.parse(window.localStorage.getItem(FilterKey)) || {}
|
|
64
|
+
function getHeadFilter(): Record<string, any> {
|
|
65
|
+
return JSON.parse(window.localStorage.getItem(FilterKey) || '{}') || {}
|
|
85
66
|
}
|
|
86
67
|
|
|
87
68
|
const getFilterAll = ref(getHeadFilter())
|
|
@@ -89,14 +70,14 @@ const headDefault = ref([])
|
|
|
89
70
|
|
|
90
71
|
const scrollX = ref(0)
|
|
91
72
|
|
|
92
|
-
function _summary(pageData) {
|
|
73
|
+
function _summary(pageData: any[]): Record<string, { value: any }> | undefined {
|
|
93
74
|
if (!props.summaryColumns)
|
|
94
75
|
return
|
|
95
76
|
return [
|
|
96
77
|
props.selectColumns,
|
|
97
|
-
...unref(props.columns),
|
|
78
|
+
...unref(props.columns || []),
|
|
98
79
|
props.oprColumns,
|
|
99
|
-
]?.reduce((o, n) => {
|
|
80
|
+
]?.reduce((o: Record<string, { value: any }>, n: any) => {
|
|
100
81
|
if (n?.key)
|
|
101
82
|
o[n.key] = props.summaryColumns?.(pageData)?.[n.key] || { value: null }
|
|
102
83
|
else o[uniqueId('table')] = { value: null }
|
|
@@ -123,26 +104,27 @@ watch(
|
|
|
123
104
|
},
|
|
124
105
|
)
|
|
125
106
|
|
|
126
|
-
function init() {
|
|
127
|
-
const columns = unref(props.columns)
|
|
107
|
+
function init(): void {
|
|
108
|
+
const columns = unref(props.columns || [])
|
|
109
|
+
const routePath = getRoutePath()
|
|
128
110
|
headDefault.value
|
|
129
|
-
= getFilterAll.value?.[
|
|
130
|
-
|| columns?.map((v, i) => v?.key || dayjs().valueOf() + i)
|
|
111
|
+
= (routePath && getFilterAll.value?.[routePath])
|
|
112
|
+
|| columns?.map((v: any, i: number) => v?.key || String(dayjs().valueOf() + i))
|
|
131
113
|
|
|
132
|
-
const arr = props.isFilter
|
|
133
|
-
? columns.filter(item => headDefault.value?.includes(item.key))
|
|
114
|
+
const arr: any[] = props.isFilter
|
|
115
|
+
? columns.filter((item: any) => headDefault.value?.includes(item.key))
|
|
134
116
|
: [...columns]
|
|
135
117
|
if (props.selectColumns)
|
|
136
118
|
arr.unshift({ key: 'selectKey', ...props.selectColumns })
|
|
137
119
|
if (props.oprColumns)
|
|
138
120
|
arr.push(props.oprColumns)
|
|
139
121
|
let scrollNum = 0
|
|
140
|
-
_columns.value = arr.reduce((o, obj) => {
|
|
122
|
+
_columns.value = arr.reduce((o: any[], obj: any) => {
|
|
141
123
|
if (obj?.display)
|
|
142
124
|
console.log('display', obj?.display)
|
|
143
125
|
if (!(obj?.display ?? true))
|
|
144
126
|
return o
|
|
145
|
-
const v = {
|
|
127
|
+
const v: any = {
|
|
146
128
|
'align': 'center',
|
|
147
129
|
'width': 120,
|
|
148
130
|
...obj,
|
|
@@ -153,7 +135,7 @@ function init() {
|
|
|
153
135
|
? obj?.ellipsisProp(ellipsis)
|
|
154
136
|
: ellipsis
|
|
155
137
|
: false,
|
|
156
|
-
'ellipsis-component': 'ellipsis'
|
|
138
|
+
'ellipsis-component': 'ellipsis',
|
|
157
139
|
'title': () => {
|
|
158
140
|
const title = obj?.label || obj?.title || ''
|
|
159
141
|
return (
|
|
@@ -165,8 +147,8 @@ function init() {
|
|
|
165
147
|
}
|
|
166
148
|
|
|
167
149
|
if (obj?.sorter) {
|
|
168
|
-
v.renderSorterIcon = ({ order }) => {
|
|
169
|
-
const { Icon, title } = orderEnum[order]
|
|
150
|
+
v.renderSorterIcon = ({ order }: { order: string }) => {
|
|
151
|
+
const { Icon, title } = orderEnum[order as keyof typeof orderEnum]
|
|
170
152
|
return (
|
|
171
153
|
<NTooltip>
|
|
172
154
|
{{
|
|
@@ -178,14 +160,13 @@ function init() {
|
|
|
178
160
|
}
|
|
179
161
|
v.sorter = {
|
|
180
162
|
multiple: 1,
|
|
181
|
-
fn:obj.sorter
|
|
163
|
+
fn: obj.sorter
|
|
182
164
|
}
|
|
183
165
|
}
|
|
184
166
|
|
|
185
|
-
|
|
186
167
|
scrollNum += v?.width
|
|
187
|
-
? Number.parseInt(v?.width)
|
|
188
|
-
:
|
|
168
|
+
? Number.parseInt(String(v?.width))
|
|
169
|
+
: (typeof v?.title === 'string' ? v?.title?.length * 30 : 0) || 0
|
|
189
170
|
|
|
190
171
|
o.push(v)
|
|
191
172
|
return o
|
|
@@ -194,7 +175,7 @@ function init() {
|
|
|
194
175
|
console.log('计算')
|
|
195
176
|
}
|
|
196
177
|
|
|
197
|
-
function filterButton() {
|
|
178
|
+
function filterButton(): any {
|
|
198
179
|
return (
|
|
199
180
|
<NButton type="info" onClick={() => filterHandle()}>
|
|
200
181
|
{{
|
|
@@ -205,13 +186,14 @@ function filterButton() {
|
|
|
205
186
|
)
|
|
206
187
|
}
|
|
207
188
|
|
|
208
|
-
function filterHandle() {
|
|
189
|
+
function filterHandle(): void {
|
|
209
190
|
const { cancel } = commonDialogMethod(
|
|
210
191
|
{
|
|
211
192
|
title: '筛选字段',
|
|
212
193
|
read: true,
|
|
213
194
|
options: [
|
|
214
195
|
{
|
|
196
|
+
key: 'filter-dialog',
|
|
215
197
|
render: () => (
|
|
216
198
|
<FilterDialog
|
|
217
199
|
style={{
|
|
@@ -219,12 +201,15 @@ function filterHandle() {
|
|
|
219
201
|
margin: '0',
|
|
220
202
|
padding: 0,
|
|
221
203
|
}}
|
|
222
|
-
filterItem={unref(props.columns)}
|
|
204
|
+
filterItem={unref(props.columns || [])}
|
|
223
205
|
selectItem={headDefault.value}
|
|
224
206
|
defaultItem={props.defaultColumns}
|
|
225
|
-
onSubmit={(v) => {
|
|
226
|
-
|
|
207
|
+
onSubmit={(v: string[]) => {
|
|
208
|
+
const routePath = getRoutePath()
|
|
209
|
+
if (routePath) {
|
|
210
|
+
getFilterAll.value[routePath] = v
|
|
227
211
|
setHeadFilter(getFilterAll.value)
|
|
212
|
+
}
|
|
228
213
|
init()
|
|
229
214
|
cancel()
|
|
230
215
|
}}
|
|
@@ -242,32 +227,34 @@ function filterHandle() {
|
|
|
242
227
|
)
|
|
243
228
|
}
|
|
244
229
|
|
|
245
|
-
function onSorter(e) {
|
|
230
|
+
function onSorter(e: any): void {
|
|
246
231
|
console.log('onSorter', e)
|
|
247
232
|
if (!e)
|
|
248
233
|
return
|
|
249
234
|
const sortArr = toArray(e)
|
|
250
235
|
|
|
251
|
-
sortArr.forEach(v => {
|
|
236
|
+
sortArr.forEach((v: any) => {
|
|
252
237
|
console.log('v', v)
|
|
253
238
|
|
|
254
239
|
if (v?.sorter) {
|
|
255
|
-
v?.sorter?.fn
|
|
256
|
-
|
|
257
|
-
|
|
240
|
+
v?.sorter?.fn?.(
|
|
241
|
+
(listQuery: any, pageState: any, key: string) => {
|
|
242
|
+
orderEnum[v.order as keyof typeof orderEnum]?.fn(listQuery, key)
|
|
258
243
|
pageState.fetchData()
|
|
259
|
-
|
|
244
|
+
},
|
|
245
|
+
{
|
|
260
246
|
field: v?.columnKey,
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
247
|
+
value: orderEnum[v?.order as keyof typeof orderEnum]?.value,
|
|
248
|
+
isClick: !isProxy(v)
|
|
249
|
+
}
|
|
250
|
+
)
|
|
264
251
|
}
|
|
265
252
|
})
|
|
266
253
|
|
|
267
254
|
emit('sorted')
|
|
268
255
|
}
|
|
269
256
|
|
|
270
|
-
defineExpose({
|
|
257
|
+
defineExpose<DataTableExpose>({
|
|
271
258
|
filterHandle,
|
|
272
259
|
filterButton,
|
|
273
260
|
initColumns: init,
|
|
@@ -277,7 +264,7 @@ onMounted(() => {})
|
|
|
277
264
|
</script>
|
|
278
265
|
|
|
279
266
|
<template>
|
|
280
|
-
<
|
|
267
|
+
<NDataTable
|
|
281
268
|
:data="_data"
|
|
282
269
|
:columns="_columns"
|
|
283
270
|
:scroll-x="scrollX"
|
|
@@ -288,7 +275,7 @@ onMounted(() => {})
|
|
|
288
275
|
:row-props="() => ({ style: { height: '60px' } })"
|
|
289
276
|
flex-height
|
|
290
277
|
remote
|
|
291
|
-
:virtual-scroll="props.virtual ?? props.data.length > 1000"
|
|
278
|
+
:virtual-scroll="!!(props.virtual ?? props.data.length > 1000)"
|
|
292
279
|
style="flex: 1"
|
|
293
280
|
@update:sorter="onSorter"
|
|
294
281
|
>
|
|
@@ -298,7 +285,7 @@ onMounted(() => {})
|
|
|
298
285
|
<n-empty>{{ emptyText }}</n-empty>
|
|
299
286
|
</slot>
|
|
300
287
|
</template>
|
|
301
|
-
</
|
|
288
|
+
</NDataTable>
|
|
302
289
|
</template>
|
|
303
290
|
|
|
304
291
|
<style scoped lang="less">
|
|
@@ -1,12 +1,20 @@
|
|
|
1
1
|
import { NButton, NPopover, NSpace } from 'naive-ui'
|
|
2
|
-
import { computed, defineComponent, ref } from 'vue'
|
|
2
|
+
import { computed, defineComponent, ref, type VNode } from 'vue'
|
|
3
|
+
import type { ActionOption } from '../../../types/components'
|
|
3
4
|
|
|
4
5
|
import { rowIndexKey } from './useDataColumn'
|
|
5
6
|
import OprButton from './useDataColumnButton'
|
|
6
7
|
import Pop from './useDataColumnPop'
|
|
7
8
|
|
|
9
|
+
interface Props {
|
|
10
|
+
options: ActionOption[]
|
|
11
|
+
max: number
|
|
12
|
+
data: any
|
|
13
|
+
index: number
|
|
14
|
+
}
|
|
15
|
+
|
|
8
16
|
export default defineComponent(
|
|
9
|
-
(props) => {
|
|
17
|
+
(props: Props) => {
|
|
10
18
|
const leng = props.options.length
|
|
11
19
|
|
|
12
20
|
const toggle = ref(false)
|
|
@@ -16,7 +24,7 @@ export default defineComponent(
|
|
|
16
24
|
|
|
17
25
|
const ellipOptions = computed(() => props.options.slice(props.max))
|
|
18
26
|
|
|
19
|
-
function renderOptions(op) {
|
|
27
|
+
function renderOptions(op: ActionOption[]): (VNode | undefined)[] {
|
|
20
28
|
return op
|
|
21
29
|
?.map(
|
|
22
30
|
(
|
|
@@ -30,20 +38,21 @@ export default defineComponent(
|
|
|
30
38
|
},
|
|
31
39
|
i,
|
|
32
40
|
) => {
|
|
33
|
-
return isRender
|
|
41
|
+
return (typeof isRender === 'function' ? isRender(props.data) : isRender)
|
|
34
42
|
? (
|
|
35
43
|
mode === 'pop'
|
|
36
44
|
? (
|
|
37
45
|
<Pop
|
|
38
46
|
onClick={onClick}
|
|
39
47
|
row={props.data}
|
|
48
|
+
index={props.index}
|
|
40
49
|
action={action}
|
|
41
50
|
key={rowIndexKey(props.data, props.index) + i}
|
|
42
51
|
>
|
|
43
52
|
<NButton
|
|
44
53
|
text
|
|
45
|
-
disabled={disabled
|
|
46
|
-
type={disabled && disabled(props.data) ? 'default' : type}
|
|
54
|
+
disabled={typeof disabled === 'function' ? disabled(props.data) : disabled}
|
|
55
|
+
type={typeof disabled === 'function' && disabled(props.data) ? 'default' : type}
|
|
47
56
|
{...action}
|
|
48
57
|
>
|
|
49
58
|
{typeof action?.label === 'function'
|
|
@@ -61,6 +70,7 @@ export default defineComponent(
|
|
|
61
70
|
onClick,
|
|
62
71
|
type,
|
|
63
72
|
}}
|
|
73
|
+
index={props.index}
|
|
64
74
|
key={rowIndexKey(props.data, props.index) + i}
|
|
65
75
|
/>
|
|
66
76
|
)
|
|
@@ -68,7 +78,7 @@ export default defineComponent(
|
|
|
68
78
|
: undefined
|
|
69
79
|
},
|
|
70
80
|
)
|
|
71
|
-
.filter(v => v)
|
|
81
|
+
.filter((v): v is VNode => v !== undefined)
|
|
72
82
|
}
|
|
73
83
|
|
|
74
84
|
return () => (
|
|
@@ -116,7 +126,7 @@ export default defineComponent(
|
|
|
116
126
|
},
|
|
117
127
|
data: {
|
|
118
128
|
type: Object,
|
|
119
|
-
default: () => {},
|
|
129
|
+
default: () => ({}),
|
|
120
130
|
},
|
|
121
131
|
index: {
|
|
122
132
|
type: Number,
|