@xmszm/core 0.0.1
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/dist/index.cjs +2 -0
- package/dist/index.mjs +2145 -0
- package/dist/style.css +1 -0
- package/docs/components/dataform.md +61 -0
- package/docs/components/datatable.md +77 -0
- package/docs/components/dialog.md +78 -0
- package/docs/components/options.md +55 -0
- package/docs/components/query.md +49 -0
- package/docs/components/utils.md +56 -0
- package/docs/guide/demo.md +213 -0
- package/docs/guide/quickstart.md +77 -0
- package/docs/index.md +25 -0
- package/docs/usage.md +61 -0
- package/examples/demo.vue +224 -0
- package/package.json +64 -0
- package/src/dialog/commonDialog.jsx +230 -0
- package/src/dialog/style/commonDialog.less +40 -0
- package/src/dialog/utils/dialog.js +82 -0
- package/src/enum/options.js +3 -0
- package/src/enum/sort.jsx +31 -0
- package/src/form/DataForm.vue +125 -0
- package/src/image/ImagesUpload.vue +268 -0
- package/src/image/SvgIcon.vue +30 -0
- package/src/index.js +46 -0
- package/src/list/useList.jsx +99 -0
- package/src/options/Options.jsx +338 -0
- package/src/options/defaultOptions.jsx +580 -0
- package/src/options/options.md +77 -0
- package/src/plugin/vite/initRouteMeta.js +54 -0
- package/src/query/CommonQuery.vue +272 -0
- package/src/store/utils/index.js +6 -0
- package/src/table/DataTable.vue +315 -0
- package/src/table/FilterDialog.vue +157 -0
- package/src/table/opr/DataColumnCollet.jsx +127 -0
- package/src/table/opr/useDataColumn.jsx +196 -0
- package/src/table/opr/useDataColumnButton.jsx +56 -0
- package/src/table/opr/useDataColumnPop.jsx +57 -0
- package/src/table/test.md +248 -0
- package/src/table/utils/ellipsis.js +22 -0
- package/src/utils/array.js +26 -0
- package/src/utils/auth.js +118 -0
- package/src/utils/object.js +32 -0
- package/src/utils/time.js +7 -0
- package/src/utils/upload.js +46 -0
- package/types/index.d.ts +67 -0
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
import { ObjectToArray } from 'core/utils/object'
|
|
2
|
+
|
|
3
|
+
import { NFormItem, NIcon, NSpace } from 'naive-ui'
|
|
4
|
+
import {
|
|
5
|
+
computed,
|
|
6
|
+
defineComponent,
|
|
7
|
+
isRef,
|
|
8
|
+
isVNode,
|
|
9
|
+
ref,
|
|
10
|
+
unref,
|
|
11
|
+
watch,
|
|
12
|
+
} from 'vue'
|
|
13
|
+
import {
|
|
14
|
+
labelField as globalLabelField,
|
|
15
|
+
valueField as globalValueField,
|
|
16
|
+
} from '../enum/options'
|
|
17
|
+
import { getOptions } from './defaultOptions'
|
|
18
|
+
import SvgIcon from '../image/SvgIcon.vue'
|
|
19
|
+
|
|
20
|
+
export default defineComponent(
|
|
21
|
+
(props, { emit }) => {
|
|
22
|
+
const _value = ref(props.value)
|
|
23
|
+
const _isRead = computed(() => props.read || false)
|
|
24
|
+
|
|
25
|
+
let _formRef = props.formRef
|
|
26
|
+
|
|
27
|
+
watch(
|
|
28
|
+
() => props.formRef,
|
|
29
|
+
v => (_formRef = v),
|
|
30
|
+
)
|
|
31
|
+
const _data = computed(() => props.option)
|
|
32
|
+
|
|
33
|
+
function cellcetWayKeys(op) {
|
|
34
|
+
return op.reduce((a, b) => {
|
|
35
|
+
a.push(b?.way ?? 'input')
|
|
36
|
+
const arr = [b?.default, b?.suffix, b?.prefix].reduce((k, k1) => {
|
|
37
|
+
if (Array.isArray(k1)) {
|
|
38
|
+
k = k.concat(k1)
|
|
39
|
+
}
|
|
40
|
+
else if (k1 && Object.keys(k1)?.length) {
|
|
41
|
+
k.push(k1)
|
|
42
|
+
}
|
|
43
|
+
return k
|
|
44
|
+
}, [])
|
|
45
|
+
|
|
46
|
+
console.log(arr)
|
|
47
|
+
|
|
48
|
+
if (arr.length)
|
|
49
|
+
arr.forEach(v => a.push(v?.way ?? 'input'))
|
|
50
|
+
return a
|
|
51
|
+
}, [])
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const _optionsByWayKey = computed(() => [
|
|
55
|
+
...new Set(cellcetWayKeys(props.option)),
|
|
56
|
+
])
|
|
57
|
+
const defaultOption = getOptions(_optionsByWayKey.value)
|
|
58
|
+
console.log(props.option)
|
|
59
|
+
console.log('defaultOption', defaultOption, _optionsByWayKey.value)
|
|
60
|
+
watch(
|
|
61
|
+
() => _value.value,
|
|
62
|
+
(v) => {
|
|
63
|
+
emit('update:value', v)
|
|
64
|
+
}
|
|
65
|
+
,{
|
|
66
|
+
immediate: true,
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
function initProps(cProp) {
|
|
70
|
+
let obj = {}
|
|
71
|
+
const type = typeof cProp
|
|
72
|
+
let handleProps = null
|
|
73
|
+
try {
|
|
74
|
+
if (!cProp) {
|
|
75
|
+
handleProps = cProp
|
|
76
|
+
}
|
|
77
|
+
else if (type === 'string' || type === 'object') {
|
|
78
|
+
handleProps = cProp
|
|
79
|
+
}
|
|
80
|
+
else if (type === 'function') {
|
|
81
|
+
handleProps = cProp(unref(_value), {
|
|
82
|
+
formRef: _formRef,
|
|
83
|
+
resetForm: () => _formRef?.value?.restoreValidation(),
|
|
84
|
+
close: () => props.cancel(),
|
|
85
|
+
setValue,
|
|
86
|
+
})
|
|
87
|
+
}
|
|
88
|
+
if (typeof handleProps === 'object' && !Array.isArray(handleProps)) {
|
|
89
|
+
Object.keys(handleProps).forEach((v) => {
|
|
90
|
+
const item = handleProps[v]
|
|
91
|
+
// console.log(item)
|
|
92
|
+
if (isRef(item))
|
|
93
|
+
obj[v] = unref(item)
|
|
94
|
+
else obj[v] = item
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
obj = handleProps
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return obj
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return {}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
watch(
|
|
109
|
+
() => props.value,
|
|
110
|
+
(v) => {
|
|
111
|
+
console.log(v)
|
|
112
|
+
|
|
113
|
+
_value.value = v
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
immediate: true,
|
|
117
|
+
},
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
function setValue(val) {
|
|
121
|
+
_value.value = val
|
|
122
|
+
}
|
|
123
|
+
function main(item) {
|
|
124
|
+
// console.log('main---重绘?', item)
|
|
125
|
+
return (
|
|
126
|
+
<NSpace
|
|
127
|
+
wrap-item={false}
|
|
128
|
+
wrap={Boolean(item?.isWrap)}
|
|
129
|
+
align="center"
|
|
130
|
+
style={{
|
|
131
|
+
width: '100%',
|
|
132
|
+
}}
|
|
133
|
+
{...(item?.contentProps||{})}
|
|
134
|
+
>
|
|
135
|
+
{initMain(item?.prefix)}
|
|
136
|
+
{initMain(item?.default || item)}
|
|
137
|
+
{initMain(item?.suffix)}
|
|
138
|
+
</NSpace>
|
|
139
|
+
)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
function initMain(dom) {
|
|
143
|
+
if (!dom)
|
|
144
|
+
return
|
|
145
|
+
let domHandle = dom
|
|
146
|
+
|
|
147
|
+
if (typeof dom === 'function')
|
|
148
|
+
domHandle = initProps(dom)
|
|
149
|
+
domHandle = initProps(domHandle)
|
|
150
|
+
|
|
151
|
+
if (isVNode(domHandle)) {
|
|
152
|
+
console.log('??? isVNode')
|
|
153
|
+
return domHandle
|
|
154
|
+
}
|
|
155
|
+
else if (typeof domHandle === 'string') {
|
|
156
|
+
console.log('??? string')
|
|
157
|
+
return domHandle
|
|
158
|
+
}
|
|
159
|
+
else if (Array.isArray(domHandle)) {
|
|
160
|
+
console.log('???')
|
|
161
|
+
|
|
162
|
+
return (
|
|
163
|
+
<>
|
|
164
|
+
{domHandle.map((item, index) => (
|
|
165
|
+
<CreateFormItem item={item} index={index} />
|
|
166
|
+
))}
|
|
167
|
+
</>
|
|
168
|
+
)
|
|
169
|
+
}
|
|
170
|
+
else if (typeof domHandle === 'object') {
|
|
171
|
+
console.log('??? object')
|
|
172
|
+
domHandle.props = initProps(domHandle?.props ?? {})
|
|
173
|
+
return unref(
|
|
174
|
+
computed(() =>
|
|
175
|
+
defaultOption?.[domHandle?.way || 'input']?.(
|
|
176
|
+
handleOptions(domHandle),
|
|
177
|
+
{
|
|
178
|
+
_value: domHandle?.queryType
|
|
179
|
+
? unref(_value)[domHandle?.queryType]
|
|
180
|
+
: unref(_value),
|
|
181
|
+
_formRef: unref(_formRef),
|
|
182
|
+
_isRead: unref(_isRead),
|
|
183
|
+
labelField: globalLabelField,
|
|
184
|
+
valueField: globalValueField,
|
|
185
|
+
},
|
|
186
|
+
),
|
|
187
|
+
),
|
|
188
|
+
)
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function handleOptions(option) {
|
|
193
|
+
if (unref(option.enum))
|
|
194
|
+
option.options = ObjectToArray(unref(option.enum))
|
|
195
|
+
return option
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
function CreateFormItem({ item, index }) {
|
|
199
|
+
item.formItemProps = initProps(item?.formItemProps)
|
|
200
|
+
if (!item.formItemProps)
|
|
201
|
+
item.formItemProps = {}
|
|
202
|
+
if (!item?.formItemProps?.labelWidth && props.formProps?.labelWidth) {
|
|
203
|
+
item.formItemProps.labelWidth = props.formProps?.labelWidth
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<NFormItem
|
|
208
|
+
v-permission={item?.permission}
|
|
209
|
+
key={index}
|
|
210
|
+
showLabel={!item?.noLabel}
|
|
211
|
+
{...item?.formItemProps}
|
|
212
|
+
labelWidth={item?.formItemProps?.labelWidth || 'auto'}
|
|
213
|
+
feedback={initProps(item?.formItemProps?.feedback, 'string')}
|
|
214
|
+
style={{
|
|
215
|
+
padding: '0 15px',
|
|
216
|
+
boxSizing: 'border-box',
|
|
217
|
+
width: '100%',
|
|
218
|
+
...(item?.formItemProps?.style || {}),
|
|
219
|
+
}}
|
|
220
|
+
path={String(item.key)}
|
|
221
|
+
>
|
|
222
|
+
{{
|
|
223
|
+
default: () => main(item),
|
|
224
|
+
label: () => (
|
|
225
|
+
<div
|
|
226
|
+
class={
|
|
227
|
+
item?.labelClass || item?.labelSuffix
|
|
228
|
+
? ` ${item?.labelClass} flex items-center gap-col-9px`
|
|
229
|
+
: ''
|
|
230
|
+
}
|
|
231
|
+
>
|
|
232
|
+
{item?.labelSuffix
|
|
233
|
+
? (
|
|
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
|
+
: (
|
|
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 ? ' ' : ' '}
|
|
259
|
+
`}
|
|
260
|
+
</div>
|
|
261
|
+
),
|
|
262
|
+
}}
|
|
263
|
+
</NFormItem>
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
return () => (
|
|
268
|
+
<NSpace
|
|
269
|
+
wrap-item={false}
|
|
270
|
+
size={[0, 8]}
|
|
271
|
+
style={{
|
|
272
|
+
width: '100%',
|
|
273
|
+
minHeight: '100%',
|
|
274
|
+
alignContent: 'baseline',
|
|
275
|
+
...props.style,
|
|
276
|
+
}}
|
|
277
|
+
>
|
|
278
|
+
{_data.value.map(({ isRender = true, ...item }, index) => {
|
|
279
|
+
return (
|
|
280
|
+
typeof unref(isRender) !== 'boolean'
|
|
281
|
+
? isRender?.(unref(_value))
|
|
282
|
+
: unref(isRender)
|
|
283
|
+
)
|
|
284
|
+
? (
|
|
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
|
+
)
|
|
296
|
+
: null
|
|
297
|
+
})}
|
|
298
|
+
</NSpace>
|
|
299
|
+
)
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
props: {
|
|
303
|
+
option: {
|
|
304
|
+
type: Array,
|
|
305
|
+
default: () => [],
|
|
306
|
+
},
|
|
307
|
+
value: {
|
|
308
|
+
type: Object,
|
|
309
|
+
default: () => ({}),
|
|
310
|
+
},
|
|
311
|
+
read: {
|
|
312
|
+
type: Boolean,
|
|
313
|
+
default: () => false,
|
|
314
|
+
},
|
|
315
|
+
labelField: {
|
|
316
|
+
type: String,
|
|
317
|
+
default: () => globalLabelField,
|
|
318
|
+
},
|
|
319
|
+
valueField: {
|
|
320
|
+
type: String,
|
|
321
|
+
default: () => globalValueField,
|
|
322
|
+
},
|
|
323
|
+
style: {
|
|
324
|
+
type: Object,
|
|
325
|
+
default: () => ({}),
|
|
326
|
+
},
|
|
327
|
+
formRef: {
|
|
328
|
+
type: Object,
|
|
329
|
+
default: () => ({}),
|
|
330
|
+
},
|
|
331
|
+
formProps: {
|
|
332
|
+
type: Object,
|
|
333
|
+
default: () => ({}),
|
|
334
|
+
},
|
|
335
|
+
},
|
|
336
|
+
emits: ['update:value'],
|
|
337
|
+
},
|
|
338
|
+
)
|