@xmszm/core 0.0.2 → 0.0.4
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 +10 -1
- package/dist/index.cjs +2 -2
- package/dist/index.mjs +1296 -1285
- 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 +10 -1
- package/docs/components/config-options.md +125 -0
- package/docs/components/dataform.md +175 -22
- package/docs/components/datatable.md +21 -39
- package/docs/components/dialog.md +155 -16
- package/docs/components/options.md +43 -14
- package/docs/components/query.md +20 -12
- package/docs/components/utils.md +118 -10
- package/docs/guide/changelog.md +81 -0
- package/docs/guide/config.md +241 -4
- package/docs/guide/quickstart.md +27 -2
- package/docs/index.md +1 -1
- package/docs/usage.md +16 -3
- package/examples/README.md +46 -0
- package/examples/index.html +14 -0
- package/examples/package.json +25 -0
- package/examples/pnpm-lock.yaml +1568 -0
- package/examples/pnpm-workspace.yaml +2 -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 +10 -4
- package/src/dialog/commonDialog.tsx +286 -0
- package/src/dialog/utils/{dialog.js → dialog.ts} +2 -0
- package/src/enum/sort.tsx +45 -0
- package/src/form/DataForm.vue +26 -52
- package/src/{index.js → index.ts} +7 -6
- package/src/list/{useList.jsx → useList.tsx} +49 -14
- package/src/options/{Options.jsx → Options.tsx} +37 -36
- package/src/options/defaultOptions.tsx +656 -0
- package/src/query/CommonQuery.vue +57 -89
- package/src/table/DataTable.vue +60 -94
- package/src/table/opr/{DataColumnCollet.jsx → DataColumnCollet.tsx} +18 -8
- package/src/table/opr/{useDataColumn.jsx → useDataColumn.tsx} +43 -48
- package/src/table/opr/{useDataColumnButton.jsx → useDataColumnButton.tsx} +13 -6
- package/src/table/opr/{useDataColumnPop.jsx → useDataColumnPop.tsx} +13 -5
- package/src/utils/{array.js → array.ts} +4 -6
- package/src/utils/{config.js → config.ts} +16 -2
- package/src/utils/{dialog.js → dialog.ts} +2 -2
- package/src/utils/{object.js → object.ts} +1 -0
- package/src/utils/{upload.js → upload.ts} +3 -3
- 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 -262
- package/src/enum/sort.jsx +0 -31
- package/src/options/defaultOptions.jsx +0 -580
- /package/src/dialog/{useCommonDialog.js → useCommonDialog.ts} +0 -0
- /package/src/directives/{auto-register.js → auto-register.ts} +0 -0
- /package/src/directives/{permission.js → permission.ts} +0 -0
- /package/src/enum/{options.js → options.ts} +0 -0
- /package/src/plugin/{index.js → index.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/opr/{useQRCode.js → useQRCode.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,25 +1,32 @@
|
|
|
1
1
|
import { checkPermission } from '../../utils/config'
|
|
2
2
|
import { NButton, NImage, NSpace, NSpin } from 'naive-ui'
|
|
3
|
-
import { ref } from 'vue'
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
3
|
+
import { ref, type VNode } from 'vue'
|
|
4
|
+
import type { ActionOption, TableColumn } from '../../../types/components'
|
|
5
|
+
import DataColumnCollet from './DataColumnCollet'
|
|
6
|
+
import OprButton from './useDataColumnButton'
|
|
7
|
+
import Pop from './useDataColumnPop'
|
|
7
8
|
import { createDialogOptions } from '../../utils/dialog'
|
|
9
|
+
import { getDialogInstance } from '../../utils/dialog'
|
|
8
10
|
|
|
9
|
-
export const rowIndexKey = (row, index
|
|
11
|
+
export const rowIndexKey = (row: any, index: number): string =>
|
|
12
|
+
row ? JSON.stringify(row) : String(index)
|
|
13
|
+
|
|
14
|
+
interface CollectParams {
|
|
15
|
+
max: number
|
|
16
|
+
width: number
|
|
17
|
+
}
|
|
10
18
|
|
|
11
19
|
export function createActionColumnJsx(
|
|
12
|
-
defaultOption,
|
|
13
|
-
oprParams = null,
|
|
14
|
-
collectParams,
|
|
15
|
-
) {
|
|
20
|
+
defaultOption: ActionOption[],
|
|
21
|
+
oprParams: Record<string, any> | null = null,
|
|
22
|
+
collectParams?: boolean | CollectParams,
|
|
23
|
+
): TableColumn | undefined {
|
|
16
24
|
// 粗滤计算操作栏占用宽度
|
|
17
|
-
|
|
18
|
-
const defaultCollectParams = {
|
|
25
|
+
const defaultCollectParams: CollectParams = {
|
|
19
26
|
max: 4,
|
|
20
27
|
width: 80,
|
|
21
28
|
}
|
|
22
|
-
let collect = false
|
|
29
|
+
let collect: CollectParams | false = false
|
|
23
30
|
if (typeof collectParams === 'boolean')
|
|
24
31
|
collect = defaultCollectParams
|
|
25
32
|
else if (typeof collectParams === 'object')
|
|
@@ -31,9 +38,9 @@ export function createActionColumnJsx(
|
|
|
31
38
|
throw new TypeError('需要配置数组')
|
|
32
39
|
}
|
|
33
40
|
console.log('ddd')
|
|
34
|
-
let actions = []
|
|
41
|
+
let actions: ActionOption[] = []
|
|
35
42
|
let width = 0
|
|
36
|
-
const filterAction = []
|
|
43
|
+
const filterAction: ActionOption[] = []
|
|
37
44
|
const isLoading = false
|
|
38
45
|
|
|
39
46
|
if (Array.isArray(defaultOption)) {
|
|
@@ -41,36 +48,21 @@ export function createActionColumnJsx(
|
|
|
41
48
|
actions.forEach((itm, idx) => {
|
|
42
49
|
if (itm.permission) {
|
|
43
50
|
if (checkPermission(itm.permission)) {
|
|
44
|
-
if (!collectParams || idx < collect.max)
|
|
45
|
-
width += itm?.label?.length * 12 + 36
|
|
51
|
+
if (!collectParams || (typeof collect === 'object' && idx < collect.max))
|
|
52
|
+
width += (typeof itm?.label === 'string' ? itm?.label?.length : 10) * 12 + 36
|
|
46
53
|
|
|
47
54
|
filterAction.push(itm)
|
|
48
55
|
}
|
|
49
56
|
}
|
|
50
57
|
else {
|
|
51
|
-
if (!collectParams || idx < collect.max)
|
|
52
|
-
width += itm?.label?.length * 12 + 36
|
|
58
|
+
if (!collectParams || (typeof collect === 'object' && idx < collect.max))
|
|
59
|
+
width += (typeof itm?.label === 'string' ? itm?.label?.length : 10) * 12 + 36
|
|
53
60
|
filterAction.push(itm)
|
|
54
61
|
}
|
|
55
62
|
})
|
|
56
|
-
|
|
57
|
-
// for (const item of actions) {
|
|
58
|
-
// if (!isLoading && item?.loading) isLoading = true
|
|
59
|
-
// if (item.permission && item?.label) {
|
|
60
|
-
// if (hasPermission(item.permission)) {
|
|
61
|
-
// width += item?.label?.length * 12 + 36
|
|
62
|
-
// filterAction.push(item)
|
|
63
|
-
// }
|
|
64
|
-
// } else if (item?.label) {
|
|
65
|
-
// width += item?.label?.length * 12 + 36
|
|
66
|
-
// filterAction.push(item)
|
|
67
|
-
// }
|
|
68
|
-
// }
|
|
69
63
|
}
|
|
70
64
|
|
|
71
65
|
width = Math.max(80, width)
|
|
72
|
-
// return filterAction.length
|
|
73
|
-
// ?
|
|
74
66
|
width += isLoading ? 20 : 0
|
|
75
67
|
|
|
76
68
|
if (collect)
|
|
@@ -84,7 +76,7 @@ export function createActionColumnJsx(
|
|
|
84
76
|
align: 'left',
|
|
85
77
|
width,
|
|
86
78
|
...oprParams,
|
|
87
|
-
render(row, index) {
|
|
79
|
+
render(row: any, index: number): VNode {
|
|
88
80
|
const vNodes = collect
|
|
89
81
|
? (
|
|
90
82
|
<DataColumnCollet
|
|
@@ -108,7 +100,7 @@ export function createActionColumnJsx(
|
|
|
108
100
|
},
|
|
109
101
|
i,
|
|
110
102
|
) => {
|
|
111
|
-
return isRender
|
|
103
|
+
return (typeof isRender === 'function' ? isRender(row) : isRender)
|
|
112
104
|
? (
|
|
113
105
|
mode === 'pop'
|
|
114
106
|
? (
|
|
@@ -121,8 +113,8 @@ export function createActionColumnJsx(
|
|
|
121
113
|
>
|
|
122
114
|
<NButton
|
|
123
115
|
text
|
|
124
|
-
disabled={disabled
|
|
125
|
-
type={disabled && disabled(row) ? 'default' : type}
|
|
116
|
+
disabled={typeof disabled === 'function' ? disabled(row) : disabled}
|
|
117
|
+
type={typeof disabled === 'function' && disabled(row) ? 'default' : type}
|
|
126
118
|
{...action}
|
|
127
119
|
>
|
|
128
120
|
{typeof action?.label === 'function'
|
|
@@ -148,11 +140,11 @@ export function createActionColumnJsx(
|
|
|
148
140
|
: undefined
|
|
149
141
|
},
|
|
150
142
|
)
|
|
151
|
-
.filter(v => v)
|
|
143
|
+
.filter((v): v is VNode => v !== undefined)
|
|
152
144
|
)
|
|
153
|
-
return oprParams?.isRender
|
|
145
|
+
return (oprParams as any)?.isRender
|
|
154
146
|
? (
|
|
155
|
-
oprParams?.render(row)
|
|
147
|
+
(oprParams as any)?.render(row)
|
|
156
148
|
)
|
|
157
149
|
: (
|
|
158
150
|
<NSpace
|
|
@@ -171,9 +163,9 @@ export function createActionColumnJsx(
|
|
|
171
163
|
|
|
172
164
|
/**
|
|
173
165
|
* 创建二维码弹窗
|
|
174
|
-
* @param
|
|
175
|
-
* @param
|
|
176
|
-
* @returns
|
|
166
|
+
* @param row - 行数据
|
|
167
|
+
* @param fn - 获取二维码的函数
|
|
168
|
+
* @returns Promise<boolean>
|
|
177
169
|
*
|
|
178
170
|
* @example
|
|
179
171
|
* import { useQRCode } from '@xmszm/core'
|
|
@@ -192,14 +184,17 @@ export function createActionColumnJsx(
|
|
|
192
184
|
* }
|
|
193
185
|
* })
|
|
194
186
|
*/
|
|
195
|
-
export async function createQRCode(
|
|
187
|
+
export async function createQRCode(
|
|
188
|
+
row: any,
|
|
189
|
+
fn: (() => Promise<string> | string) | null = null,
|
|
190
|
+
): Promise<boolean> {
|
|
196
191
|
const dialogInstance = getDialogInstance()
|
|
197
192
|
|
|
198
193
|
if (!dialogInstance) {
|
|
199
194
|
throw new Error('无法获取 dialog 实例。请使用 useQRCode hook 或在组件中通过 setupConfig 注册 dialog 实例。')
|
|
200
195
|
}
|
|
201
196
|
|
|
202
|
-
const code = ref(null)
|
|
197
|
+
const code = ref<string | null>(null)
|
|
203
198
|
const loading = ref(false)
|
|
204
199
|
|
|
205
200
|
const dialogOptions = createDialogOptions({
|
|
@@ -210,12 +205,12 @@ export async function createQRCode(row, fn = null) {
|
|
|
210
205
|
height: '350px',
|
|
211
206
|
},
|
|
212
207
|
content: () => (
|
|
213
|
-
<div
|
|
208
|
+
<div class="qr-box">
|
|
214
209
|
{loading.value ? <NSpin class="qr-spin" show /> : ''}
|
|
215
|
-
<div
|
|
210
|
+
<div class="qr-img">
|
|
216
211
|
<NImage src={code.value} style={{ width: '100%' }} />
|
|
217
212
|
</div>
|
|
218
|
-
<div
|
|
213
|
+
<div class="qr-title">{loading.value ? '' : row.name}</div>
|
|
219
214
|
</div>
|
|
220
215
|
),
|
|
221
216
|
}, dialogInstance)
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { NButton } from 'naive-ui'
|
|
2
|
-
import { defineComponent, ref } from 'vue'
|
|
2
|
+
import { defineComponent, ref, type VNode } from 'vue'
|
|
3
|
+
import type { ActionOption } from '../../../types/components'
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
action: ActionOption | null
|
|
7
|
+
row: any
|
|
8
|
+
index: number
|
|
9
|
+
}
|
|
3
10
|
|
|
4
11
|
export default defineComponent(
|
|
5
|
-
({ action, row,index }) => {
|
|
12
|
+
({ action, row, index }: Props) => {
|
|
6
13
|
const {
|
|
7
14
|
onClick,
|
|
8
15
|
disabled,
|
|
@@ -10,7 +17,7 @@ export default defineComponent(
|
|
|
10
17
|
loading = false,
|
|
11
18
|
label = null,
|
|
12
19
|
...other
|
|
13
|
-
} = action
|
|
20
|
+
} = action || {}
|
|
14
21
|
const oprBtnLoading = ref(false)
|
|
15
22
|
return () => (
|
|
16
23
|
<NButton
|
|
@@ -21,16 +28,16 @@ export default defineComponent(
|
|
|
21
28
|
if (loading) {
|
|
22
29
|
oprBtnLoading.value = true
|
|
23
30
|
}
|
|
24
|
-
await onClick(row
|
|
31
|
+
await onClick(row)
|
|
25
32
|
}
|
|
26
33
|
finally {
|
|
27
34
|
setTimeout(() => (oprBtnLoading.value = false), 500)
|
|
28
35
|
}
|
|
29
36
|
}
|
|
30
37
|
}}
|
|
31
|
-
disabled={disabled
|
|
38
|
+
disabled={typeof disabled === 'function' ? disabled(row) : disabled}
|
|
32
39
|
loading={oprBtnLoading.value}
|
|
33
|
-
type={disabled && disabled(row) ? 'default' : type}
|
|
40
|
+
type={typeof disabled === 'function' && disabled(row) ? 'default' : type}
|
|
34
41
|
{...other}
|
|
35
42
|
>
|
|
36
43
|
{typeof label === 'function' ? label?.(row) : label}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { NPopconfirm } from 'naive-ui'
|
|
2
|
-
import { defineComponent, ref } from 'vue'
|
|
2
|
+
import { defineComponent, ref, type VNode } from 'vue'
|
|
3
|
+
import type { ActionOption } from '../../../types/components'
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
onClick: ((row: any, index: number) => void | Promise<void>) | null
|
|
7
|
+
row: any
|
|
8
|
+
index: number
|
|
9
|
+
action: ActionOption | null
|
|
10
|
+
}
|
|
3
11
|
|
|
4
12
|
export default defineComponent(
|
|
5
|
-
({ onClick, row, index,action }, { slots }) => {
|
|
13
|
+
({ onClick, row, index, action }: Props, { slots }) => {
|
|
6
14
|
const popLoading = ref(false)
|
|
7
15
|
return () => (
|
|
8
16
|
<NPopconfirm
|
|
@@ -14,7 +22,7 @@ export default defineComponent(
|
|
|
14
22
|
try {
|
|
15
23
|
if (onClick) {
|
|
16
24
|
popLoading.value = true
|
|
17
|
-
await onClick(row,index)
|
|
25
|
+
await onClick(row, index)
|
|
18
26
|
popLoading.value = false
|
|
19
27
|
return true
|
|
20
28
|
}
|
|
@@ -29,7 +37,7 @@ export default defineComponent(
|
|
|
29
37
|
{{
|
|
30
38
|
trigger: slots.default,
|
|
31
39
|
default: () =>
|
|
32
|
-
action?.popProps?.content || action?.content || '确定删除该记录?',
|
|
40
|
+
action?.popProps?.content || (action as any)?.content || '确定删除该记录?',
|
|
33
41
|
}}
|
|
34
42
|
</NPopconfirm>
|
|
35
43
|
)
|
|
@@ -37,7 +45,7 @@ export default defineComponent(
|
|
|
37
45
|
{
|
|
38
46
|
props: {
|
|
39
47
|
onClick: {
|
|
40
|
-
type:
|
|
48
|
+
type: Function as any,
|
|
41
49
|
default: null,
|
|
42
50
|
},
|
|
43
51
|
row: {
|
|
@@ -5,11 +5,9 @@ import {
|
|
|
5
5
|
} from '../enum/options'
|
|
6
6
|
|
|
7
7
|
export function ArrayToObject(
|
|
8
|
-
arr = [],
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
valueField: globalValueField,
|
|
12
|
-
},
|
|
8
|
+
arr: any[] = [],
|
|
9
|
+
labelField: string = globalLabelField,
|
|
10
|
+
valueField: string = globalValueField,
|
|
13
11
|
) {
|
|
14
12
|
return unref(arr).reduce((o, n) => {
|
|
15
13
|
o[n[valueField]] = {
|
|
@@ -21,6 +19,6 @@ export function ArrayToObject(
|
|
|
21
19
|
}, {})
|
|
22
20
|
}
|
|
23
21
|
|
|
24
|
-
export function toArray(v) {
|
|
22
|
+
export function toArray(v: any) {
|
|
25
23
|
return Array.isArray(v) ? v : [v]
|
|
26
24
|
}
|
|
@@ -3,10 +3,24 @@
|
|
|
3
3
|
* 用于统一管理库的外部依赖配置
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* 配置对象类型定义
|
|
8
|
+
*/
|
|
9
|
+
interface ConfigType {
|
|
10
|
+
baseURL: string
|
|
11
|
+
hasPermission: ((permission: string) => boolean) | null
|
|
12
|
+
uploadMethod: ((config: any) => Promise<any>) | null
|
|
13
|
+
dialog: {
|
|
14
|
+
instance: any
|
|
15
|
+
inheritTheme: boolean
|
|
16
|
+
themeOverrides: any
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
6
20
|
/**
|
|
7
21
|
* 配置对象
|
|
8
22
|
*/
|
|
9
|
-
const config = {
|
|
23
|
+
const config: ConfigType = {
|
|
10
24
|
// API 基础地址
|
|
11
25
|
baseURL: '',
|
|
12
26
|
|
|
@@ -54,7 +68,7 @@ const config = {
|
|
|
54
68
|
* }
|
|
55
69
|
* })
|
|
56
70
|
*/
|
|
57
|
-
export function setupConfig(options = {}) {
|
|
71
|
+
export function setupConfig(options: Partial<ConfigType> = {}) {
|
|
58
72
|
if (options.baseURL !== undefined) {
|
|
59
73
|
config.baseURL = options.baseURL
|
|
60
74
|
}
|
|
@@ -42,7 +42,7 @@ export function getDialogInstance() {
|
|
|
42
42
|
* @param {Object} dialogInstance - dialog 实例(从 useDialog 获取)
|
|
43
43
|
* @returns {Object} 处理后的 dialog 选项
|
|
44
44
|
*/
|
|
45
|
-
export function createDialogOptions(options = {}, dialogInstance = null) {
|
|
45
|
+
export function createDialogOptions(options: Record<string, any> = {}, dialogInstance: any = null) {
|
|
46
46
|
const dialogConfig = getDialogConfig()
|
|
47
47
|
|
|
48
48
|
// 如果配置了不继承主题色,则添加 themeOverrides
|
|
@@ -66,7 +66,7 @@ export function createDialogOptions(options = {}, dialogInstance = null) {
|
|
|
66
66
|
* @param {Object} options - dialog 选项
|
|
67
67
|
* @returns {Object} dialog 返回的对象
|
|
68
68
|
*/
|
|
69
|
-
export function createDialog(dialogInstance, options = {}) {
|
|
69
|
+
export function createDialog(dialogInstance: any, options: Record<string, any> = {}) {
|
|
70
70
|
if (!dialogInstance) {
|
|
71
71
|
throw new Error('dialogInstance 是必需的。请在组件中使用 useDialog() 获取实例,然后传递给此函数。')
|
|
72
72
|
}
|
|
@@ -23,12 +23,12 @@ export function registryUpload(fn) {
|
|
|
23
23
|
* @param {AxiosRequestConfig} args - 上传参数
|
|
24
24
|
* @returns {UploadDataPromise} 上传结果Promise
|
|
25
25
|
*/
|
|
26
|
-
export function customUpload(...args) {
|
|
26
|
+
export function customUpload(...args: any[]) {
|
|
27
27
|
const uploadMethod = getUploadMethod()
|
|
28
28
|
if (typeof uploadMethod !== 'function') {
|
|
29
29
|
throw new TypeError('请先通过 setupConfig({ uploadMethod: fn }) 或 registryUpload(fn) 注册上传实现')
|
|
30
30
|
}
|
|
31
|
-
return uploadMethod(...args)
|
|
31
|
+
return (uploadMethod as any)(...args)
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
@@ -37,7 +37,7 @@ export function customUpload(...args) {
|
|
|
37
37
|
* @param {number|null} ossSize - OSS 样式尺寸
|
|
38
38
|
* @returns {string} 完整的文件 URL
|
|
39
39
|
*/
|
|
40
|
-
export function getFileUrl(url, ossSize = null) {
|
|
40
|
+
export function getFileUrl(url: string, ossSize: number | null = null) {
|
|
41
41
|
if (url && !url?.startsWith('http')) {
|
|
42
42
|
const baseURL = getBaseURL()
|
|
43
43
|
if (!baseURL) {
|