@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.
Files changed (77) hide show
  1. package/README.md +187 -0
  2. package/dist/index.cjs +2 -2
  3. package/dist/index.mjs +1431 -1170
  4. package/dist/plugin/vite/initRouteMeta.cjs +1 -0
  5. package/dist/plugin/vite/initRouteMeta.mjs +13 -0
  6. package/dist/style.css +1 -1
  7. package/docs/.vitepress/config.mjs +91 -0
  8. package/docs/components/config-options.md +125 -0
  9. package/docs/components/dataform.md +176 -23
  10. package/docs/components/datatable.md +58 -39
  11. package/docs/components/dialog.md +158 -19
  12. package/docs/components/options.md +44 -15
  13. package/docs/components/query.md +68 -14
  14. package/docs/components/utils.md +124 -16
  15. package/docs/guide/changelog.md +81 -0
  16. package/docs/guide/config.md +415 -0
  17. package/docs/guide/demo.md +2 -2
  18. package/docs/guide/local-development.md +109 -0
  19. package/docs/guide/quickstart.md +40 -11
  20. package/docs/index.md +3 -3
  21. package/docs/usage.md +30 -6
  22. package/examples/README.md +46 -0
  23. package/examples/index.html +14 -0
  24. package/examples/package.json +25 -0
  25. package/examples/pnpm-lock.yaml +1569 -0
  26. package/examples/pnpm-workspace.yaml +3 -0
  27. package/examples/src/AdminSystem.vue +870 -0
  28. package/examples/src/App.vue +330 -0
  29. package/examples/src/Introduction.vue +307 -0
  30. package/examples/src/main.js +22 -0
  31. package/examples/src/utils/permission.js +16 -0
  32. package/examples/src/utils/request.js +10 -0
  33. package/examples/vite.config.js +41 -0
  34. package/package.json +13 -4
  35. package/src/dialog/commonDialog.tsx +285 -0
  36. package/src/dialog/useCommonDialog.ts +41 -0
  37. package/src/dialog/utils/{dialog.js → dialog.ts} +2 -0
  38. package/src/directives/auto-register.ts +57 -0
  39. package/src/directives/permission.ts +67 -0
  40. package/src/enum/sort.tsx +45 -0
  41. package/src/form/DataForm.vue +34 -52
  42. package/src/index.ts +58 -0
  43. package/src/list/{useList.jsx → useList.tsx} +49 -14
  44. package/src/options/{Options.jsx → Options.tsx} +86 -72
  45. package/src/options/defaultOptions.tsx +656 -0
  46. package/src/plugin/index.ts +20 -0
  47. package/src/query/CommonQuery.vue +65 -90
  48. package/src/table/DataTable.vue +82 -95
  49. package/src/table/opr/{DataColumnCollet.jsx → DataColumnCollet.tsx} +18 -8
  50. package/src/table/opr/useDataColumn.tsx +226 -0
  51. package/src/table/opr/{useDataColumnButton.jsx → useDataColumnButton.tsx} +13 -6
  52. package/src/table/opr/{useDataColumnPop.jsx → useDataColumnPop.tsx} +13 -5
  53. package/src/table/opr/useQRCode.ts +40 -0
  54. package/src/utils/{array.js → array.ts} +4 -6
  55. package/src/utils/config.ts +192 -0
  56. package/src/utils/dialog.ts +110 -0
  57. package/src/utils/{object.js → object.ts} +1 -0
  58. package/src/utils/upload.ts +53 -0
  59. package/types/auto-imports.d.ts +78 -0
  60. package/types/components.d.ts +402 -0
  61. package/types/index.d.ts +145 -7
  62. package/types/plugin/vite/initRouteMeta.d.ts +23 -0
  63. package/types/src.d.ts +55 -0
  64. package/types/vue-shim.d.ts +9 -0
  65. package/examples/demo.vue +0 -224
  66. package/src/dialog/commonDialog.jsx +0 -230
  67. package/src/enum/sort.jsx +0 -31
  68. package/src/index.js +0 -46
  69. package/src/options/defaultOptions.jsx +0 -580
  70. package/src/table/opr/useDataColumn.jsx +0 -196
  71. package/src/utils/upload.js +0 -46
  72. /package/src/enum/{options.js → options.ts} +0 -0
  73. /package/src/plugin/vite/{initRouteMeta.js → initRouteMeta.ts} +0 -0
  74. /package/src/store/utils/{index.js → index.ts} +0 -0
  75. /package/src/table/utils/{ellipsis.js → ellipsis.ts} +0 -0
  76. /package/src/utils/{auth.js → auth.ts} +0 -0
  77. /package/src/utils/{time.js → time.ts} +0 -0
@@ -0,0 +1,656 @@
1
+ import DataTable from '../table/DataTable.vue'
2
+ import dayjs from 'dayjs'
3
+ import {
4
+ NButton,
5
+ NCheckbox,
6
+ NCheckboxGroup,
7
+ NDatePicker,
8
+ NDivider,
9
+ NEllipsis,
10
+ NIcon,
11
+ NInput,
12
+ NInputNumber,
13
+ NProgress,
14
+ NRadio,
15
+ NRadioGroup,
16
+ NSelect,
17
+ NSpace,
18
+ NSwitch,
19
+ NText,
20
+ NTimePicker,
21
+ NUpload,
22
+ NUploadDragger,
23
+ } from 'naive-ui'
24
+ import { ArchiveOutline } from '@vicons/ionicons5'
25
+ import { unref, type VNode, type Ref, type ComputedRef } from 'vue'
26
+ import type { FormOption } from '../../types/components'
27
+ import {
28
+ labelField as globalLabelField,
29
+ valueField as globalValueField,
30
+ } from '../enum/options'
31
+ import ImagesUpload from '../image/ImagesUpload.vue'
32
+ import { ArrayToObject } from '../utils/array'
33
+
34
+ import { timeFormat } from '../utils/time'
35
+
36
+ interface OptionContext {
37
+ _value: Ref<Record<string, any>> | Record<string, any>
38
+ _isRead: ComputedRef<boolean> | boolean
39
+ labelField?: string
40
+ valueField?: string
41
+ _formRef?: any
42
+ }
43
+
44
+ interface OptionParams {
45
+ label?: string | (() => string)
46
+ key: string | string[]
47
+ props?: Record<string, any>
48
+ readProps?: Record<string, any>
49
+ format?: (value: any, options?: any) => any
50
+ formatTime?: string
51
+ type?: string
52
+ read?: boolean
53
+ options?: any[] | ((value: any) => any[])
54
+ loading?: boolean | Ref<boolean>
55
+ radioLabelProps?: (v: any) => Record<string, any>
56
+ text?: string
57
+ onClick?: (value: any) => void
58
+ pageState?: any
59
+ opr?: any
60
+ [key: string]: any
61
+ }
62
+
63
+ type OptionFunction = (params: OptionParams, context: OptionContext) => VNode
64
+
65
+ const defaultOptions: Record<string, OptionFunction> = {
66
+ input: (
67
+ { label, key, props, readProps, format = null, read }: OptionParams,
68
+ { _value, _isRead }: OptionContext,
69
+ ): VNode => {
70
+ const value = unref(_value)
71
+ const isRead = unref(_isRead)
72
+ return (read ?? isRead)
73
+ ? (
74
+ <NEllipsis {...readProps}>
75
+ {format
76
+ ? format?.(value[key as string], value)
77
+ : value[key as string]}
78
+ </NEllipsis>
79
+ )
80
+ : (
81
+ <NInput
82
+ v-model:value={value[key as string]}
83
+ clearable
84
+ placeholder={`请输入${unref(label)}`}
85
+ {...props}
86
+ >
87
+ {{
88
+ ...(props?.slots || {}),
89
+ }}
90
+ </NInput>
91
+ )
92
+ },
93
+ select: (
94
+ { label, key, props, options = [], loading = false, format = null, read }: OptionParams,
95
+ { _value, _isRead }: OptionContext,
96
+ ): VNode => {
97
+ const value = unref(_value)
98
+ const isRead = unref(_isRead)
99
+ const fnOptions = Array.isArray(options)
100
+ ? options
101
+ : typeof options === 'function'
102
+ ? options(value[key as string])
103
+ : []
104
+ return (read ?? isRead)
105
+ ? (
106
+ <div>
107
+ {format
108
+ ? format?.(value[key as string], fnOptions)
109
+ : ArrayToObject(
110
+ fnOptions,
111
+ props?.labelField || globalLabelField,
112
+ props?.valueField || globalValueField,
113
+ )?.[value[key as string]]?.[props?.labelField || globalLabelField] || value[key as string]}
114
+ </div>
115
+ )
116
+ : (
117
+ <NSelect
118
+ v-model:value={value[key as string]}
119
+ options={fnOptions}
120
+ loading={unref(loading)}
121
+ clearable
122
+ filterable
123
+ fallback-option={() => {
124
+ if (!props?.asyncFallback)
125
+ value[key as string] = null
126
+ return false
127
+ }}
128
+ labelField={props?.labelField || globalLabelField}
129
+ valueField={props?.valueField || globalValueField}
130
+ placeholder={`请选择${unref(label)}`}
131
+ style="width:100%"
132
+ max-tag-count="responsive"
133
+ {...props}
134
+ >
135
+ {{
136
+ ...(props?.slots || {}),
137
+ }}
138
+ </NSelect>
139
+ )
140
+ },
141
+ date: (
142
+ {
143
+ label,
144
+ key,
145
+ props,
146
+ formatTime = 'YYYY-MM-DD',
147
+ type = 'date',
148
+ format,
149
+ read,
150
+ }: OptionParams,
151
+ { _value, _isRead }: OptionContext,
152
+ ): VNode => {
153
+ const value = unref(_value)
154
+ const isRead = unref(_isRead)
155
+ return (read ?? isRead)
156
+ ? (
157
+ <div>
158
+ {format ? format?.(value[key as string]) : timeFormat(value[key as string], formatTime)}
159
+ </div>
160
+ )
161
+ : (
162
+ <NDatePicker
163
+ formatted-value={value[key as string]}
164
+ onUpdate:formatted-value={(v: string) => {
165
+ value[key as string] = v
166
+ }}
167
+ type={type as any}
168
+ clearable
169
+ placeholder={`请选择${unref(label)}`}
170
+ update-value-on-close={!['year']?.includes(props?.type)}
171
+ style="width:100%"
172
+ {...props}
173
+ >
174
+ {{
175
+ ...(props?.slots || {}),
176
+ }}
177
+ </NDatePicker>
178
+ )
179
+ },
180
+ time: (
181
+ { label, key, props, format, formatTime = 'YYYY-MM-DD', read }: OptionParams,
182
+ { _value, _isRead }: OptionContext,
183
+ ): VNode => {
184
+ const value = unref(_value)
185
+ const isRead = unref(_isRead)
186
+ return (read ?? isRead)
187
+ ? (
188
+ <div>
189
+ {format ? format?.(value[key as string]) : timeFormat(value[key as string], formatTime)}
190
+ </div>
191
+ )
192
+ : (
193
+ <NTimePicker
194
+ formatted-value={value[key as string]}
195
+ onUpdate:value={(_: any, v: string) => {
196
+ console.log('v', v)
197
+ value[key as string] = v
198
+ }}
199
+ clearable
200
+ format="HH:mm:ss"
201
+ style="width:100%"
202
+ placeholder={`请选择${unref(label)}`}
203
+ {...props}
204
+ >
205
+ {{
206
+ ...(props?.slots || {}),
207
+ }}
208
+ </NTimePicker>
209
+ )
210
+ },
211
+ dateRange: (
212
+ { key, props, type = 'datetimerange', read }: OptionParams,
213
+ { _value, _isRead }: OptionContext,
214
+ ): VNode => {
215
+ const value = unref(_value)
216
+ const isRead = unref(_isRead)
217
+ const timeEnum: Record<string, string> = {
218
+ date: 'YYYY-MM-DD',
219
+ datetime: 'YYYY-MM-DD HH:mm:ss',
220
+ time: 'HH:mm:ss',
221
+ datetimerange: 'YYYY-MM-DD HH:mm:ss',
222
+ daterange: 'YYYY-MM-DD',
223
+ }
224
+ const formatStr = props?.format
225
+ ? props?.format?.replace('yyyy', 'YYYY')?.replace('dd', 'DD')
226
+ : timeEnum[props?.type || type]
227
+
228
+ console.log('formatStr type', type)
229
+ console.log('formatStr', formatStr)
230
+
231
+ return (read ?? isRead)
232
+ ? (
233
+ <div>
234
+ {Array.isArray(key)
235
+ ? `${value?.[key?.[0]]} - ${value?.[key?.[1]]}`
236
+ : value?.[key as string]}
237
+ </div>
238
+ )
239
+ : (
240
+ <NDatePicker
241
+ formatted-value={
242
+ Array.isArray(key)
243
+ ? value?.[key?.[0]] && value?.[key?.[1]]
244
+ ? [
245
+ dayjs(value?.[key?.[0]]).format(formatStr),
246
+ dayjs(value?.[key?.[1]]).format(formatStr),
247
+ ]
248
+ : null
249
+ : value?.[key as string] || null
250
+ }
251
+ onUpdate:formatted-value={(v: string[] | null) => {
252
+ console.log(v)
253
+
254
+ if (v && ![timeEnum.datetime, timeEnum.datetimerange].includes(formatStr)) {
255
+ v = v.map((d, i) =>
256
+ dayjs(d, formatStr)
257
+ [!i ? 'startOf' : 'endOf']('day')
258
+ .format(formatStr),
259
+ ) as any
260
+ }
261
+ if (Array.isArray(key)) {
262
+ value[key?.[0]] = v?.[0]
263
+ value[key?.[1]] = v?.[1]
264
+ }
265
+ else {
266
+ value[key as string] = v as any
267
+ }
268
+ }}
269
+ update-value-on-close={!['year', 'month']?.includes(props?.type)}
270
+ type={type as any}
271
+ clearable
272
+ style="width:100%"
273
+ {...props}
274
+ >
275
+ {{
276
+ ...(props?.slots || {}),
277
+ }}
278
+ </NDatePicker>
279
+ )
280
+ },
281
+ radio: (
282
+ { key, options = [], props, radioLabelProps, read }: OptionParams,
283
+ { _value, _isRead, labelField, valueField }: OptionContext,
284
+ ): VNode => {
285
+ const value = unref(_value)
286
+ const isRead = unref(_isRead)
287
+ return (read ?? isRead)
288
+ ? (
289
+ <div>
290
+ {
291
+ ArrayToObject(
292
+ Array.isArray(options) ? options : [],
293
+ props?.labelField || labelField || globalLabelField,
294
+ props?.valueField || valueField || globalValueField,
295
+ )?.[value[key as string]]?.[props?.labelField || labelField || globalLabelField]
296
+ }
297
+ </div>
298
+ )
299
+ : (
300
+ <NRadioGroup
301
+ style={{ width: '100%' }}
302
+ v-model:value={value[key as string]}
303
+ {...props}
304
+ >
305
+ {{
306
+ ...(props?.slots || {}),
307
+ default: () => (
308
+ <NSpace item-wrap={false} {...(props?.radioProps || {})}>
309
+ {(Array.isArray(options) ? options : [])?.map((v: any) => (
310
+ <NRadio
311
+ key={v.value}
312
+ value={v?.[props?.valueField || valueField || globalValueField]}
313
+ class="items-center"
314
+ >
315
+ <div {...(radioLabelProps?.(v) || {})}>
316
+ {v?.[props?.labelField || labelField || globalLabelField]}
317
+ </div>
318
+ </NRadio>
319
+ ))}
320
+ </NSpace>
321
+ ),
322
+ }}
323
+ </NRadioGroup>
324
+ )
325
+ },
326
+ inputPhone: ({ label, key, props, read }: OptionParams, { _value, _isRead }: OptionContext): VNode => {
327
+ const value = unref(_value)
328
+ const isRead = unref(_isRead)
329
+ return (read ?? isRead)
330
+ ? (
331
+ <div>{value[key as string]}</div>
332
+ )
333
+ : (
334
+ <NInput
335
+ v-model:value={value[key as string]}
336
+ clearable
337
+ style="width:100%"
338
+ allow-input={(v: string) => !v || /^\d$/.test(v) || v.length <= 11}
339
+ placeholder={`请输入${unref(label)}`}
340
+ {...props}
341
+ >
342
+ {{
343
+ ...props?.slots,
344
+ }}
345
+ </NInput>
346
+ )
347
+ },
348
+ inputNumber: ({ label, key, props, read }: OptionParams, { _value, _isRead }: OptionContext): VNode => {
349
+ const value = unref(_value)
350
+ const isRead = unref(_isRead)
351
+ return (read ?? isRead)
352
+ ? (
353
+ <div>{value[key as string]}</div>
354
+ )
355
+ : (
356
+ <NInputNumber
357
+ value={
358
+ typeof value[key as string] === 'string' && value[key as string]
359
+ ? Number(value[key as string])
360
+ : value[key as string]
361
+ }
362
+ onUpdate:value={(v: number | null) => {
363
+ value[key as string] = v
364
+ }}
365
+ showButton={false}
366
+ clearable
367
+ style="width:100%"
368
+ placeholder={`请输入${unref(label)}`}
369
+ min={0}
370
+ {...props}
371
+ >
372
+ {{
373
+ ...(props?.slots || {}),
374
+ }}
375
+ </NInputNumber>
376
+ )
377
+ },
378
+ uploadFile: ({ key, props }: OptionParams, { _value }: OptionContext): VNode => {
379
+ const value = unref(_value)
380
+ return (
381
+ <NUpload
382
+ multiple
383
+ max={1}
384
+ accept=".xls,.xlsx"
385
+ v-model:file-list={value[key as string]}
386
+ {...props}
387
+ >
388
+ <NUploadDragger>
389
+ <div style="margin-bottom: 12px">
390
+ <NIcon size="48" depth={3}>
391
+ <ArchiveOutline />
392
+ </NIcon>
393
+ </div>
394
+ <NText style="font-size: 16px">点击或者拖动文件到该区域来上传</NText>
395
+ </NUploadDragger>
396
+ </NUpload>
397
+ )
398
+ },
399
+ dataTable: (
400
+ { key, loading = false, props, options, opr, pageState }: OptionParams,
401
+ { _value, _isRead }: OptionContext,
402
+ ): VNode => {
403
+ const value = unref(_value)
404
+ console.log(loading)
405
+ console.log(pageState)
406
+
407
+ const tableData = pageState?.data?.length ? pageState.data : value[key as string]
408
+ const tableColumns = Array.isArray(options) ? options : typeof options === 'function' ? options(value[key as string]) : []
409
+
410
+ const dataTableProps = {
411
+ data: tableData as any[],
412
+ columns: tableColumns as import('../../types/components').TableColumn[],
413
+ maxHeight: 200,
414
+ minHeight: 200,
415
+ isEllipsis: false,
416
+ oprColumns: opr as import('../../types/components').TableColumn | null,
417
+ loading: pageState?.loading as boolean,
418
+ ...props
419
+ } as import('../../types/components').DataTableProps & Record<string, any>
420
+
421
+ return (
422
+ <DataTable {...dataTableProps} />
423
+ )
424
+ },
425
+ progress: ({ key, props }: OptionParams, { _value }: OptionContext): VNode => {
426
+ const value = unref(_value)
427
+ return <NProgress percentage={value[key as string]} {...props} />
428
+ },
429
+ line: (): VNode => <NDivider />,
430
+
431
+ image: ({ key, props, read }: OptionParams, { _isRead, _value }: OptionContext): VNode => {
432
+ const value = unref(_value)
433
+ const isRead = unref(_isRead)
434
+ return (
435
+ <ImagesUpload
436
+ v-model:value={value[key as string]}
437
+ max={1}
438
+ {...props}
439
+ read={read ?? isRead}
440
+ />
441
+ )
442
+ },
443
+ button: ({ onClick, props, text }: OptionParams, { _value }: OptionContext): VNode => {
444
+ const value = unref(_value)
445
+ return (
446
+ <NButton
447
+ type="info"
448
+ {...props}
449
+ onClick={() =>
450
+ props?.onClick
451
+ ? props?.onClick(value)
452
+ : onClick?.(value)}
453
+ >
454
+ {text}
455
+ </NButton>
456
+ )
457
+ },
458
+ switch: ({ key, props, read }: OptionParams, { _isRead, _value }: OptionContext): VNode => {
459
+ const value = unref(_value)
460
+ const isRead = unref(_isRead)
461
+ return (read ?? isRead)
462
+ ? (
463
+ <div>{value[key as string] ? '是' : '否'}</div>
464
+ )
465
+ : (
466
+ <NSwitch v-model:value={value[key as string]} {...props}>
467
+ {{
468
+ ...(props?.slots || {}),
469
+ }}
470
+ </NSwitch>
471
+ )
472
+ },
473
+ checkbox: (
474
+ { key, options = [], props, read }: OptionParams,
475
+ { _value, _isRead, labelField, valueField }: OptionContext,
476
+ ): VNode => {
477
+ const value = unref(_value)
478
+ const isRead = unref(_isRead)
479
+ return (read ?? isRead)
480
+ ? (
481
+ <div>
482
+ {(Array.isArray(options) ? options : [])
483
+ ?.filter((v: any) =>
484
+ value[key as string]?.includes(
485
+ v[props?.valueField || valueField || globalValueField],
486
+ ),
487
+ )
488
+ ?.map((v: any) => v[props?.labelField || labelField || globalLabelField])
489
+ ?.join('、')}
490
+ </div>
491
+ )
492
+ : (
493
+ <NCheckboxGroup
494
+ v-model:value={value[key as string]}
495
+ style={{ width: '100%' }}
496
+ {...props}
497
+ >
498
+ {{
499
+ ...(props?.slots || {}),
500
+ default: () => (
501
+ <NSpace {...(props?.checkBoxProps || {})}>
502
+ {(Array.isArray(options) ? options : [])?.map((v: any) => (
503
+ <NCheckbox
504
+ key={v?.[props?.valueField || valueField || globalValueField]}
505
+ value={
506
+ v?.[props?.valueField || valueField || globalValueField]
507
+ }
508
+ >
509
+ {v?.[props?.labelField || labelField || globalLabelField]}
510
+ </NCheckbox>
511
+ ))}
512
+ </NSpace>
513
+ ),
514
+ }}
515
+ </NCheckboxGroup>
516
+ )
517
+ },
518
+ filterList: ({ key, props, options }: OptionParams, { _value }: OptionContext): VNode => {
519
+ const value = unref(_value)
520
+ // FilterSelect 可能是外部组件,暂时注释掉
521
+ // return (
522
+ // <FilterSelect
523
+ // v-model:value={value[key as string]}
524
+ // option={options}
525
+ // clearable
526
+ // filterButtonKey={['all', 'selectDefault']}
527
+ // {...props}
528
+ // />
529
+ // )
530
+ return <div>FilterSelect 组件需要外部提供</div>
531
+ },
532
+ }
533
+
534
+ let extendOptions: Record<string, OptionFunction> = {}
535
+
536
+ class DefaultOptions {
537
+ defaultMap: Map<string, OptionFunction> | null = null
538
+ extendOptions: Record<string, OptionFunction> | null = null
539
+
540
+ constructor() {
541
+ console.log('DefaultOptions init')
542
+
543
+ this.defaultMap = null
544
+ this.init()
545
+ }
546
+
547
+ set(key: string, fn: OptionFunction): void {
548
+ if (!this.defaultMap) return
549
+ this.defaultMap.set(key, fn)
550
+ }
551
+
552
+ get(key: string): OptionFunction | undefined {
553
+ if (!this.defaultMap) return undefined
554
+ return this.defaultMap.get(key)
555
+ }
556
+
557
+ clear(): void {
558
+ this.defaultMap?.clear()
559
+ }
560
+
561
+ setupOptions(key: string, fn: OptionFunction): void {
562
+ if (!this.defaultMap) return
563
+ const keys = this.defaultMap.size > 0 ? [...this.defaultMap.keys()] : []
564
+ if (this.defaultMap.has(key))
565
+ return console.error(`${key} 已存在,不能使用${keys?.join('、')}`)
566
+ this.defaultMap.set(key, fn)
567
+ }
568
+
569
+ setupExtendOptions(key: string, fn: OptionFunction): void {
570
+ if (!extendOptions) extendOptions = {}
571
+ if (!extendOptions?.[key]) {
572
+ extendOptions[key] = fn
573
+ }
574
+ }
575
+
576
+ getAllOptions(): Record<string, OptionFunction> {
577
+ const options: Record<string, OptionFunction> = {}
578
+ this.defaultMap?.forEach((v, key) => {
579
+ options[key] = v
580
+ })
581
+
582
+ return options
583
+ }
584
+
585
+ getOptions(keys: string[] = []): Record<string, OptionFunction> {
586
+ console.log('getOptions', this.defaultMap)
587
+ const options: Record<string, OptionFunction> = {}
588
+ keys.forEach((key) => {
589
+ if (this.defaultMap?.has(key))
590
+ options[key] = this.defaultMap.get(key)!
591
+ })
592
+
593
+ return options
594
+ }
595
+
596
+ initOptions(options: Record<string, OptionFunction> = {}): void {
597
+ Object.keys(options).forEach((key) => {
598
+ this.setupOptions(key, options[key])
599
+ })
600
+ }
601
+
602
+ initSetup(callback?: () => void): void {
603
+ if (this.defaultMap)
604
+ this.clear()
605
+ this.defaultMap = new Map<string, OptionFunction>()
606
+ this.initOptions(defaultOptions)
607
+ callback && callback()
608
+ if (import.meta.hot) {
609
+ if (Object.keys(extendOptions).length)
610
+ import.meta.hot.data.extendOptions = extendOptions
611
+ else extendOptions = import.meta.hot?.data?.extendOptions || {}
612
+ }
613
+ this.initOptions(extendOptions)
614
+ }
615
+
616
+ init(callback?: () => void): void {
617
+ this.initSetup(callback)
618
+ }
619
+ }
620
+
621
+ const defaultOptionsMap = new DefaultOptions()
622
+
623
+ /**
624
+ * 初始化默认选项
625
+ * @param options - 选项对象
626
+ */
627
+ export const initOptions = (options: Record<string, OptionFunction>): void =>
628
+ defaultOptionsMap.initOptions(options)
629
+
630
+ export default (callback?: () => void): void => defaultOptionsMap.init(callback)
631
+
632
+ /**
633
+ * 获取选项
634
+ * @param keys - 选项键数组
635
+ * @returns 选项对象
636
+ */
637
+ export const getOptions = (keys: string[] = []): Record<string, OptionFunction> =>
638
+ defaultOptionsMap.getOptions(keys)
639
+
640
+ /**
641
+ * 获取所有选项
642
+ * @returns 所有选项对象
643
+ */
644
+ export function getAllOptions(): Record<string, OptionFunction> {
645
+ return defaultOptionsMap.getAllOptions()
646
+ }
647
+
648
+ /**
649
+ * 注册一个选项
650
+ * @param key - 选项键
651
+ * @param fn - 选项函数
652
+ * @example setupOptions('input',({},{_value,_isRead})=>{})
653
+ */
654
+ export function setupOptions(key: string, fn: OptionFunction): void {
655
+ return defaultOptionsMap.setupExtendOptions(key, fn)
656
+ }
@@ -0,0 +1,20 @@
1
+ /**
2
+ * 库插件
3
+ * 用于注册指令等全局功能
4
+ */
5
+ import { registerDirectives } from '../directives/auto-register'
6
+
7
+ /**
8
+ * 安装插件
9
+ * @param {Object} app - Vue 应用实例
10
+ * @param {Object} options - 插件选项
11
+ */
12
+ export function install(app, options = {}) {
13
+ // 注册所有指令(使用 corePermission 名称)
14
+ registerDirectives(app)
15
+ }
16
+
17
+ export default {
18
+ install,
19
+ }
20
+