@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
package/src/index.ts ADDED
@@ -0,0 +1,58 @@
1
+ export { commonDialogMethod } from './dialog/commonDialog'
2
+ export { useCommonDialog } from './dialog/useCommonDialog'
3
+
4
+ export { default as DataForm } from './form/DataForm.vue'
5
+ export {
6
+ getAllOptions,
7
+ getOptions,
8
+ setupOptions,
9
+ } from './options/defaultOptions'
10
+ export { default as Options } from './options/Options'
11
+ export { default as CommonQuery } from './query/CommonQuery.vue'
12
+
13
+ export { createActionColumnJsx, createQRCode } from './table/opr/useDataColumn'
14
+ export { useQRCode } from './table/opr/useQRCode'
15
+
16
+ export { default as OprButton } from './table/opr/useDataColumnButton'
17
+
18
+ export { default as Pop } from './table/opr/useDataColumnPop'
19
+
20
+ export { toArray } from './utils/array'
21
+
22
+ export {
23
+ cellectChildenPermission,
24
+ handleParams,
25
+ useApiConfig,
26
+ useAuthPermission,
27
+ } from './utils/auth'
28
+
29
+ export { ObjectToArray } from './utils/object'
30
+
31
+ export { ArrayToObject } from './utils/array'
32
+
33
+
34
+
35
+ export { customUpload, registryUpload, getFileUrl } from './utils/upload'
36
+ export { setupConfig, getConfig, getBaseURL, getHasPermission, getUploadMethod, checkPermission, getDialogConfig, registerDialogInstance, getDialogInstance } from './utils/config'
37
+ export { createDialog, createDialogMethods, createDialogOptions } from './utils/dialog'
38
+
39
+ export { default as DataTable } from './table/DataTable.vue'
40
+
41
+
42
+ export { labelField as globalLabelField, valueField as globalValueField } from './enum/options'
43
+
44
+
45
+ export { initRules } from './dialog/utils/dialog'
46
+
47
+ export { ellipsis } from './table/utils/ellipsis'
48
+
49
+ export { initRouteMeta } from './plugin/vite/initRouteMeta'
50
+
51
+ export { orderEnum } from './enum/sort'
52
+
53
+ // 导出插件和指令
54
+ import CorePluginDefault from './plugin/index'
55
+ export { CorePluginDefault as CorePlugin }
56
+ export { install } from './plugin/index'
57
+ export { permissionDirective } from './directives/permission'
58
+ export { registerDirectives, autoRegisterDirectives, getGlobalApp } from './directives/auto-register'
@@ -1,11 +1,36 @@
1
- import { computed, ref, unref, watch } from 'vue'
1
+ import { computed, ref, unref, watch, type Ref, type ComputedRef } from 'vue'
2
+ import type { FormOption } from '../../types/components'
2
3
 
3
- export function useList(source = [], filterOptions = []) {
4
+ interface QueryModel {
5
+ andQuery?: Record<string, any>
6
+ likeQuery?: Record<string, any>
7
+ [key: string]: any
8
+ }
9
+
10
+ interface FilterOption extends FormOption {
11
+ queryType?: string
12
+ value?: any
13
+ type?: string
14
+ }
15
+
16
+ interface UseListReturn {
17
+ loading: Ref<boolean>
18
+ data: Ref<any[]>
19
+ model: Ref<QueryModel>
20
+ initData: () => void
21
+ onSearch: () => void
22
+ onClear: () => void
23
+ }
24
+
25
+ export function useList(
26
+ source: any[] = [],
27
+ filterOptions: FormOption[] = [],
28
+ ): UseListReturn {
4
29
  const loading = ref(false)
5
- const data = ref([])
30
+ const data = ref<any[]>([])
6
31
  const sourceList = computed(() => unref(source))
7
32
 
8
- const model = ref({
33
+ const model = ref<QueryModel>({
9
34
  andQuery: {},
10
35
  likeQuery: {},
11
36
  })
@@ -52,17 +77,21 @@ export function useList(source = [], filterOptions = []) {
52
77
  }
53
78
 
54
79
  export const matchMethod = {
55
- andQuery: (data, value) =>
80
+ andQuery: (data: any, value: any): boolean =>
56
81
  Array.isArray(value) ? value.includes(data) : data === value,
57
- likeQuery: (data, value) => data?.indexOf(value) > -1,
82
+ likeQuery: (data: string | undefined, value: string): boolean =>
83
+ data?.indexOf(value) > -1 || false,
58
84
  }
59
85
 
60
- export function handleFilterValue(runOptions, model) {
86
+ export function handleFilterValue(
87
+ runOptions: FormOption[],
88
+ model: QueryModel,
89
+ ): FilterOption[] {
61
90
  console.log('handleFilterValue', runOptions)
62
91
 
63
92
  return runOptions
64
93
  .map((v) => {
65
- const filedValue = v?.key || v?.value
94
+ const filedValue = (v?.key as string) || (v as any)?.value
66
95
  const value = v?.queryType
67
96
  ? model?.[v?.queryType]?.[filedValue]
68
97
  : model?.[filedValue]
@@ -72,24 +101,30 @@ export function handleFilterValue(runOptions, model) {
72
101
  key: filedValue,
73
102
  type: v?.queryType,
74
103
  value,
75
- }
104
+ } as FilterOption
76
105
  : undefined
77
106
  })
78
- .filter(v => v)
107
+ .filter((v): v is FilterOption => v !== undefined)
79
108
  }
80
109
 
81
- export function handleFilterOption(runOption, options) {
110
+ export function handleFilterOption(
111
+ runOption: FilterOption[],
112
+ options: any[],
113
+ ): any[] {
82
114
  console.log('runOption', runOption)
83
115
 
84
116
  if (runOption.length) {
85
117
  return options?.filter(item =>
86
118
  runOption.length === 1
87
- ? matchMethod?.[runOption?.[0].type](
88
- item?.[runOption?.[0]?.key],
119
+ ? matchMethod?.[runOption?.[0].type as keyof typeof matchMethod]?.(
120
+ item?.[runOption?.[0]?.key as string],
89
121
  runOption?.[0]?.value,
90
122
  )
91
123
  : runOption?.every(v =>
92
- matchMethod?.[v.type](item?.[v.key], v.value),
124
+ matchMethod?.[v.type as keyof typeof matchMethod]?.(
125
+ item?.[v.key as string],
126
+ v.value,
127
+ ),
93
128
  ),
94
129
  )
95
130
  }
@@ -1,4 +1,5 @@
1
- import { ObjectToArray } from 'core/utils/object'
1
+ import { ObjectToArray } from '../utils/object'
2
+ import type { FormOption, OptionsProps } from '../../types/components'
2
3
 
3
4
  import { NFormItem, NIcon, NSpace } from 'naive-ui'
4
5
  import {
@@ -9,6 +10,7 @@ import {
9
10
  ref,
10
11
  unref,
11
12
  watch,
13
+ type VNode,
12
14
  } from 'vue'
13
15
  import {
14
16
  labelField as globalLabelField,
@@ -16,24 +18,38 @@ import {
16
18
  } from '../enum/options'
17
19
  import { getOptions } from './defaultOptions'
18
20
  import SvgIcon from '../image/SvgIcon.vue'
21
+ import { registerDirectives, getGlobalApp } from '../directives/auto-register'
22
+ import { getCurrentInstance } from 'vue'
19
23
 
20
24
  export default defineComponent(
21
- (props, { emit }) => {
22
- const _value = ref(props.value)
25
+ (props: OptionsProps, { emit }) => {
26
+ // 自动注册 corePermission 指令(如果尚未注册)
27
+ // 必须在组件渲染前注册,确保指令可用
28
+ const instance = getCurrentInstance()
29
+ if (instance?.appContext?.app) {
30
+ registerDirectives(instance.appContext.app)
31
+ } else {
32
+ // 如果无法从实例获取,尝试使用全局应用实例
33
+ const globalApp = getGlobalApp()
34
+ if (globalApp) {
35
+ registerDirectives(globalApp)
36
+ }
37
+ }
38
+ const _value = ref(props.value || {})
23
39
  const _isRead = computed(() => props.read || false)
24
40
 
25
- let _formRef = props.formRef
41
+ let _formRef: any = props.formRef
26
42
 
27
43
  watch(
28
44
  () => props.formRef,
29
- v => (_formRef = v),
45
+ (v) => (_formRef = v),
30
46
  )
31
- const _data = computed(() => props.option)
47
+ const _data = computed(() => props.option || [])
32
48
 
33
- function cellcetWayKeys(op) {
34
- return op.reduce((a, b) => {
49
+ function cellcetWayKeys(op: FormOption[]): string[] {
50
+ return op.reduce((a: string[], b: FormOption) => {
35
51
  a.push(b?.way ?? 'input')
36
- const arr = [b?.default, b?.suffix, b?.prefix].reduce((k, k1) => {
52
+ const arr = [b?.default, b?.suffix, b?.prefix].reduce((k: any[], k1: any) => {
37
53
  if (Array.isArray(k1)) {
38
54
  k = k.concat(k1)
39
55
  }
@@ -46,13 +62,13 @@ export default defineComponent(
46
62
  console.log(arr)
47
63
 
48
64
  if (arr.length)
49
- arr.forEach(v => a.push(v?.way ?? 'input'))
65
+ arr.forEach((v: any) => a.push(v?.way ?? 'input'))
50
66
  return a
51
67
  }, [])
52
68
  }
53
69
 
54
70
  const _optionsByWayKey = computed(() => [
55
- ...new Set(cellcetWayKeys(props.option)),
71
+ ...new Set(cellcetWayKeys(props.option || [])),
56
72
  ])
57
73
  const defaultOption = getOptions(_optionsByWayKey.value)
58
74
  console.log(props.option)
@@ -61,15 +77,15 @@ export default defineComponent(
61
77
  () => _value.value,
62
78
  (v) => {
63
79
  emit('update:value', v)
64
- }
65
- ,{
66
- immediate: true,
67
- })
80
+ },
81
+ {
82
+ immediate: true,
83
+ })
68
84
 
69
- function initProps(cProp) {
70
- let obj = {}
85
+ function initProps(cProp: any, typeHint?: string): any {
86
+ let obj: any = {}
71
87
  const type = typeof cProp
72
- let handleProps = null
88
+ let handleProps: any = null
73
89
  try {
74
90
  if (!cProp) {
75
91
  handleProps = cProp
@@ -81,14 +97,13 @@ export default defineComponent(
81
97
  handleProps = cProp(unref(_value), {
82
98
  formRef: _formRef,
83
99
  resetForm: () => _formRef?.value?.restoreValidation(),
84
- close: () => props.cancel(),
100
+ close: () => (props as any).cancel?.(),
85
101
  setValue,
86
102
  })
87
103
  }
88
104
  if (typeof handleProps === 'object' && !Array.isArray(handleProps)) {
89
105
  Object.keys(handleProps).forEach((v) => {
90
106
  const item = handleProps[v]
91
- // console.log(item)
92
107
  if (isRef(item))
93
108
  obj[v] = unref(item)
94
109
  else obj[v] = item
@@ -110,18 +125,17 @@ export default defineComponent(
110
125
  (v) => {
111
126
  console.log(v)
112
127
 
113
- _value.value = v
128
+ _value.value = v || {}
114
129
  },
115
130
  {
116
131
  immediate: true,
117
132
  },
118
133
  )
119
134
 
120
- function setValue(val) {
135
+ function setValue(val: any) {
121
136
  _value.value = val
122
137
  }
123
- function main(item) {
124
- // console.log('main---重绘?', item)
138
+ function main(item: FormOption): VNode {
125
139
  return (
126
140
  <NSpace
127
141
  wrap-item={false}
@@ -130,7 +144,7 @@ export default defineComponent(
130
144
  style={{
131
145
  width: '100%',
132
146
  }}
133
- {...(item?.contentProps||{})}
147
+ {...(item?.contentProps || {})}
134
148
  >
135
149
  {initMain(item?.prefix)}
136
150
  {initMain(item?.default || item)}
@@ -139,7 +153,7 @@ export default defineComponent(
139
153
  )
140
154
  }
141
155
 
142
- function initMain(dom) {
156
+ function initMain(dom: any): VNode | string | null | undefined {
143
157
  if (!dom)
144
158
  return
145
159
  let domHandle = dom
@@ -161,11 +175,11 @@ export default defineComponent(
161
175
 
162
176
  return (
163
177
  <>
164
- {domHandle.map((item, index) => (
178
+ {domHandle.map((item: any, index: number) => (
165
179
  <CreateFormItem item={item} index={index} />
166
180
  ))}
167
181
  </>
168
- )
182
+ ) as any
169
183
  }
170
184
  else if (typeof domHandle === 'object') {
171
185
  console.log('??? object')
@@ -187,35 +201,36 @@ export default defineComponent(
187
201
  ),
188
202
  )
189
203
  }
204
+ return null
190
205
  }
191
206
 
192
- function handleOptions(option) {
207
+ function handleOptions(option: FormOption): FormOption {
193
208
  if (unref(option.enum))
194
209
  option.options = ObjectToArray(unref(option.enum))
195
210
  return option
196
211
  }
197
212
 
198
- function CreateFormItem({ item, index }) {
213
+ function CreateFormItem({ item, index }: { item: FormOption; index: number }): VNode {
199
214
  item.formItemProps = initProps(item?.formItemProps)
200
215
  if (!item.formItemProps)
201
216
  item.formItemProps = {}
202
- if (!item?.formItemProps?.labelWidth && props.formProps?.labelWidth) {
203
- item.formItemProps.labelWidth = props.formProps?.labelWidth
217
+ if (!(item.formItemProps as any)?.labelWidth && (props.formProps as any)?.labelWidth) {
218
+ (item.formItemProps as any).labelWidth = (props.formProps as any)?.labelWidth
204
219
  }
205
220
 
206
221
  return (
207
222
  <NFormItem
208
- v-permission={item?.permission}
223
+ v-corePermission={item?.permission}
209
224
  key={index}
210
225
  showLabel={!item?.noLabel}
211
226
  {...item?.formItemProps}
212
- labelWidth={item?.formItemProps?.labelWidth || 'auto'}
213
- feedback={initProps(item?.formItemProps?.feedback, 'string')}
227
+ labelWidth={(item?.formItemProps as any)?.labelWidth || 'auto'}
228
+ feedback={initProps((item?.formItemProps as any)?.feedback, 'string')}
214
229
  style={{
215
230
  padding: '0 15px',
216
231
  boxSizing: 'border-box',
217
232
  width: '100%',
218
- ...(item?.formItemProps?.style || {}),
233
+ ...((item?.formItemProps as any)?.style || {}),
219
234
  }}
220
235
  path={String(item.key)}
221
236
  >
@@ -231,31 +246,30 @@ export default defineComponent(
231
246
  >
232
247
  {item?.labelSuffix
233
248
  ? (
234
- typeof item?.labelSuffix === 'string'
235
- ? (
236
- <NIcon
237
- {...{
238
- class: 'wh-20px c-inherit',
239
- ...item?.labelSuffixProps,
240
- }}
241
- >
242
- <SvgIcon name={item?.labelSuffix} />
243
- </NIcon>
244
- )
245
- : (
246
- item?.labelSuffix?.()
247
- )
248
- )
249
+ typeof item?.labelSuffix === 'string'
250
+ ? (
251
+ <NIcon
252
+ {...{
253
+ class: 'wh-20px c-inherit',
254
+ ...item?.labelSuffixProps,
255
+ }}
256
+ >
257
+ <SvgIcon name={item?.labelSuffix} />
258
+ </NIcon>
259
+ )
260
+ : (
261
+ item?.labelSuffix?.()
262
+ )
263
+ )
249
264
  : (
250
- <></>
251
- )}
252
- {`${
253
- unref(
254
- typeof item?.[props.labelField] === 'function'
255
- ? item?.[props.labelField]?.()
256
- : item?.[props.labelField],
257
- ) || ''
258
- } ${_isRead.value || item.read ? ' ' : ' '}
265
+ <></>
266
+ )}
267
+ {`${unref(
268
+ typeof item?.[props.labelField || 'label'] === 'function'
269
+ ? item?.[props.labelField || 'label']?.()
270
+ : item?.[props.labelField || 'label'],
271
+ ) || ''
272
+ } ${_isRead.value || item.read ? ' ' : ' '}
259
273
  `}
260
274
  </div>
261
275
  ),
@@ -275,24 +289,24 @@ export default defineComponent(
275
289
  ...props.style,
276
290
  }}
277
291
  >
278
- {_data.value.map(({ isRender = true, ...item }, index) => {
292
+ {_data.value.map(({ isRender = true, ...item }: any, index: number) => {
279
293
  return (
280
294
  typeof unref(isRender) !== 'boolean'
281
295
  ? isRender?.(unref(_value))
282
296
  : unref(isRender)
283
297
  )
284
298
  ? (
285
- item?.render
286
- ? (
287
- item?.render(unref(_value), index, {
288
- setValue,
289
- value: unref(_value),
290
- })
291
- )
292
- : (
293
- <CreateFormItem item={item} index={index} />
294
- )
295
- )
299
+ item?.render
300
+ ? (
301
+ item?.render(unref(_value), index, {
302
+ setValue,
303
+ value: unref(_value),
304
+ })
305
+ )
306
+ : (
307
+ <CreateFormItem item={item} index={index} />
308
+ )
309
+ )
296
310
  : null
297
311
  })}
298
312
  </NSpace>