@ithinkdt/page 4.1.0 → 4.2.0-0
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/package.json +5 -5
- package/src/crud.js +2 -4
- package/src/data-source.js +7 -8
- package/src/description.js +4 -5
- package/src/form.d.ts +9 -0
- package/src/form.js +27 -18
- package/src/modal.js +1 -1
- package/src/plugin.js +1 -1
- package/src/rules.js +1 -1
- package/src/table.d.ts +11 -0
- package/src/table.js +37 -25
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ithinkdt/page",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0-0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "iThinkDT Page",
|
|
@@ -40,8 +40,8 @@
|
|
|
40
40
|
"sideEffects": false,
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@vueuse/core": "^14.3.0",
|
|
43
|
-
"nanoid": "^5.1.
|
|
44
|
-
"@ithinkdt/common": "
|
|
43
|
+
"nanoid": "^5.1.16",
|
|
44
|
+
"@ithinkdt/common": "~4.2.0-0"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"vue": ">=3.5",
|
|
@@ -49,8 +49,8 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"typescript": "~6.0.3",
|
|
52
|
-
"vite": "^8.
|
|
53
|
-
"vue": "^3.5.
|
|
52
|
+
"vite": "^8.1.4",
|
|
53
|
+
"vue": "^3.5.39",
|
|
54
54
|
"vue-router": "^5.1.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
package/src/crud.js
CHANGED
|
@@ -70,10 +70,7 @@ function _useSimpleCrudModal(crudType, getItems, request, options) {
|
|
|
70
70
|
const setModalType = (crudType) => {
|
|
71
71
|
let type = options.modalType
|
|
72
72
|
if (typeof type === 'function') {
|
|
73
|
-
type = type(
|
|
74
|
-
model: model.value,
|
|
75
|
-
type: crudType,
|
|
76
|
-
})
|
|
73
|
+
type = type(crudType)
|
|
77
74
|
} else if (isRef(type)) {
|
|
78
75
|
type = type.value
|
|
79
76
|
}
|
|
@@ -123,6 +120,7 @@ function _useSimpleCrudModal(crudType, getItems, request, options) {
|
|
|
123
120
|
initial
|
|
124
121
|
.then((res) => {
|
|
125
122
|
model.value = res
|
|
123
|
+
modal.reset(res)
|
|
126
124
|
}).finally(() => {
|
|
127
125
|
loading.value = false
|
|
128
126
|
})
|
package/src/data-source.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { promiseTimeout, until, useAsyncState } from '@vueuse/core'
|
|
2
|
+
import { nanoid } from 'nanoid'
|
|
2
3
|
import { computed, hasInjectionContext, inject, nextTick, reactive, ref, shallowReactive, shallowRef, toRaw, watch } from 'vue'
|
|
3
4
|
|
|
4
5
|
import { PAGE_INJECTION, pageInjection } from './plugin'
|
|
@@ -24,19 +25,17 @@ export function useDs(fetch, options = {}) {
|
|
|
24
25
|
options,
|
|
25
26
|
)
|
|
26
27
|
|
|
27
|
-
let
|
|
28
|
+
let lastId
|
|
28
29
|
const { state, isLoading: loading, error, execute } = useAsyncState(
|
|
29
30
|
async (...params) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
const { promise, resolve, reject } = Promise.withResolvers()
|
|
34
|
-
lastReject = reject
|
|
31
|
+
const currentId = lastId = nanoid()
|
|
32
|
+
const { promise, resolve } = Promise.withResolvers()
|
|
35
33
|
let [res] = await Promise.all([
|
|
36
34
|
Promise.resolve(fetch(...params))
|
|
37
35
|
.finally (() => {
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
if (currentId === lastId) {
|
|
37
|
+
resolve()
|
|
38
|
+
}
|
|
40
39
|
}),
|
|
41
40
|
promiseTimeout(200),
|
|
42
41
|
promise,
|
package/src/description.js
CHANGED
|
@@ -56,10 +56,10 @@ export function useDescriptionsHelper(
|
|
|
56
56
|
|
|
57
57
|
const bindings = { }
|
|
58
58
|
for (const k of Object.keys(options ?? {})) {
|
|
59
|
-
if (k.length > render.length && k.startsWith(render))
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
if (!(k.length > render.length && k.startsWith(render))) continue
|
|
60
|
+
|
|
61
|
+
bindings[uncapitalize(k.slice(render.length))] = options[k]
|
|
62
|
+
delete options[k]
|
|
63
63
|
}
|
|
64
64
|
const bindings0 = computed(() => {
|
|
65
65
|
return Object.fromEntries(Object.entries(bindings)
|
|
@@ -114,7 +114,6 @@ export function useDescriptionsHelper(
|
|
|
114
114
|
scope = effectScope()
|
|
115
115
|
items0.length = 0
|
|
116
116
|
scope.run(() => {
|
|
117
|
-
// eslint-disable-next-line unicorn/no-array-callback-reference
|
|
118
117
|
items0.push(...items({ it, group, model }).filter(Boolean).map(reactive))
|
|
119
118
|
})
|
|
120
119
|
}
|
package/src/form.d.ts
CHANGED
|
@@ -198,6 +198,14 @@ export interface FilterHelper<Model extends {}> extends FormHelper<Model> {
|
|
|
198
198
|
}): void
|
|
199
199
|
custom(this: void, sort: string[]): void
|
|
200
200
|
custom(this: void, reset: true): void
|
|
201
|
+
custom(this: void, batchs: Array<
|
|
202
|
+
| true
|
|
203
|
+
| string[]
|
|
204
|
+
| {
|
|
205
|
+
key: string
|
|
206
|
+
hidden?: boolean | undefined
|
|
207
|
+
}>
|
|
208
|
+
): void
|
|
201
209
|
}
|
|
202
210
|
|
|
203
211
|
export declare function useFilterHelper<Model extends {}>(
|
|
@@ -255,6 +263,7 @@ export type FormModalOptions<Model extends {}> = FormModalOptionsBase & FormHelp
|
|
|
255
263
|
export interface FormModal<Model extends {}> extends Omit<ModalReturns, 'open'> {
|
|
256
264
|
open(this: void, model: MaybePromise<Model>, title?: VNodeChild | (() => VNodeChild)): PromiseLike<Model>
|
|
257
265
|
reinit(this: void): void
|
|
266
|
+
reset(this: void, initial?: Partial<Model>, overwrite?: boolean, reinit?: boolean): Partial<Model>
|
|
258
267
|
}
|
|
259
268
|
export declare function useFormModal<Model extends {}>(options: FormModalOptions<Model>):
|
|
260
269
|
FormModal<Model>
|
package/src/form.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StorageSerializers, toReactive, tryOnScopeDispose, useEventListener, useStorage } from '@vueuse/core'
|
|
2
2
|
import { nanoid } from 'nanoid'
|
|
3
|
-
import { computed, effectScope, h, hasInjectionContext, inject, reactive, readonly, ref, shallowReactive, shallowRef, toRaw, unref } from 'vue'
|
|
3
|
+
import { computed, effectScope, h, hasInjectionContext, inject, nextTick, reactive, readonly, ref, shallowReactive, shallowRef, toRaw, unref } from 'vue'
|
|
4
4
|
import { useRoute } from 'vue-router'
|
|
5
5
|
|
|
6
6
|
import { copy, isNone } from '@ithinkdt/common/object'
|
|
@@ -61,10 +61,10 @@ export function useFormHelper(items, { initial: initial0, rules, onChange, inFil
|
|
|
61
61
|
}
|
|
62
62
|
const bindings = {}
|
|
63
63
|
for (const k of Object.keys(options)) {
|
|
64
|
-
if (k.length > render.length && k.startsWith(render))
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
64
|
+
if (!(k.length > render.length && k.startsWith(render))) continue
|
|
65
|
+
|
|
66
|
+
bindings[uncapitalize(k.slice(render.length))] = options[k]
|
|
67
|
+
delete options[k]
|
|
68
68
|
}
|
|
69
69
|
const bindings0 = computed(() => {
|
|
70
70
|
return Object.fromEntries(Object.entries(bindings)
|
|
@@ -342,25 +342,35 @@ export function useFilterHelper(items, { customizable = false, cached, cacheVers
|
|
|
342
342
|
})
|
|
343
343
|
|
|
344
344
|
const items1 = shallowReactive([])
|
|
345
|
-
|
|
346
|
-
const custom = (params) => {
|
|
345
|
+
const _custom = (params, customs) => {
|
|
347
346
|
if (typeof params === 'boolean') {
|
|
348
|
-
if (params)
|
|
347
|
+
if (params) customs = getDefaultCustom()
|
|
349
348
|
} else if (Array.isArray(params)) {
|
|
350
|
-
customs.
|
|
349
|
+
customs.sort = JSON.stringify(params) === JSON.stringify(returns.items.map(col => col.name))
|
|
351
350
|
? []
|
|
352
351
|
: params
|
|
353
|
-
setCustoms()
|
|
354
352
|
} else {
|
|
355
|
-
customs.
|
|
356
|
-
|
|
357
|
-
|
|
353
|
+
customs.hidden[params.key] = 'hidden' in params ? params.hidden : customs.hidden[params.key]
|
|
354
|
+
const item = returns.items.find(item => item.name === params.key)
|
|
355
|
+
if (item && customs.hidden[params.key] === item.hidden) {
|
|
356
|
+
delete customs.hidden[params.key]
|
|
358
357
|
}
|
|
359
358
|
if (params.hidden) {
|
|
360
359
|
returns.model[params.key] = undefined
|
|
361
360
|
}
|
|
362
|
-
setCustoms()
|
|
363
361
|
}
|
|
362
|
+
return customs
|
|
363
|
+
}
|
|
364
|
+
const custom = (params) => {
|
|
365
|
+
if (!Array.isArray(params) || typeof params[0] === 'string') {
|
|
366
|
+
params = [params]
|
|
367
|
+
}
|
|
368
|
+
let customs0 = customs.value
|
|
369
|
+
for (const params0 of params) {
|
|
370
|
+
customs0 = _custom(params0, customs0)
|
|
371
|
+
}
|
|
372
|
+
setCustoms(customs0)
|
|
373
|
+
|
|
364
374
|
const _items = returns.items
|
|
365
375
|
.map((item, i, arr) => {
|
|
366
376
|
const index = customs.value.sort.indexOf(item.name)
|
|
@@ -425,7 +435,7 @@ export function useFilterHelper(items, { customizable = false, cached, cacheVers
|
|
|
425
435
|
} else {
|
|
426
436
|
useEventListener(globalThis, 'storage', (event) => {
|
|
427
437
|
if (event.key !== key) return
|
|
428
|
-
|
|
438
|
+
nextTick().then(() => read(event.newValue)).then(reinit)
|
|
429
439
|
}, { passive: true })
|
|
430
440
|
}
|
|
431
441
|
|
|
@@ -439,9 +449,7 @@ export function useFilterHelper(items, { customizable = false, cached, cacheVers
|
|
|
439
449
|
const raw = StorageSerializers.object.write([sort, hidden])
|
|
440
450
|
return storage.setItem(key, raw)
|
|
441
451
|
}
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
if (!customizable) {
|
|
452
|
+
} else {
|
|
445
453
|
reinit()
|
|
446
454
|
}
|
|
447
455
|
|
|
@@ -598,6 +606,7 @@ export function useFormModal({ initial, items, rules, onSubmit, submitText, canc
|
|
|
598
606
|
...modal,
|
|
599
607
|
open,
|
|
600
608
|
reinit: form.reinit,
|
|
609
|
+
reset: form.reset,
|
|
601
610
|
})
|
|
602
611
|
return returns
|
|
603
612
|
}
|
package/src/modal.js
CHANGED
|
@@ -12,7 +12,7 @@ export const ModalProvider = defineComponent({
|
|
|
12
12
|
},
|
|
13
13
|
})
|
|
14
14
|
|
|
15
|
-
const ModalInjectionKey = Symbol('
|
|
15
|
+
const ModalInjectionKey = Symbol('__MODAL__')
|
|
16
16
|
|
|
17
17
|
export function useModal({ content, confirmText, confirmLoading, cancelText, cancelLoading, footer, onConfirm, onCancel, onClose, title, ...options }) {
|
|
18
18
|
const { i18n: useI18n, getModalRenderer, addModal } = (hasInjectionContext() ? inject(PAGE_INJECTION, pageInjection) : pageInjection) ?? {}
|
package/src/plugin.js
CHANGED
package/src/rules.js
CHANGED
|
@@ -64,7 +64,7 @@ export const plateNo = (message, options) =>
|
|
|
64
64
|
export const noChinese = (message, options) => pattern(/^[^\u{4E00}-\u{9FA5}]+$/u, message, options)
|
|
65
65
|
export const chinese = (message, options) => pattern(/^[\u{4E00}-\u{9FA5}]+$/u, message, options)
|
|
66
66
|
|
|
67
|
-
export const requiredRuleSymbol = Symbol('
|
|
67
|
+
export const requiredRuleSymbol = Symbol('__RULE_REQUIRED__')
|
|
68
68
|
export function required(message, { required = true, trigger = ['input', 'blur', 'change'] } = {}) {
|
|
69
69
|
return {
|
|
70
70
|
[requiredRuleSymbol]: true,
|
package/src/table.d.ts
CHANGED
|
@@ -189,6 +189,17 @@ export interface TableHelper<Model extends {}> {
|
|
|
189
189
|
}): void
|
|
190
190
|
custom(this: void, sort: string[]): void
|
|
191
191
|
custom(this: void, reset: true): void
|
|
192
|
+
custom(this: void, batchs: Array<
|
|
193
|
+
| true
|
|
194
|
+
| string[]
|
|
195
|
+
| {
|
|
196
|
+
key: string
|
|
197
|
+
hidden?: boolean | undefined
|
|
198
|
+
fixed?: false | 'left' | 'right' | undefined
|
|
199
|
+
width?: number | string | undefined
|
|
200
|
+
}>
|
|
201
|
+
): void
|
|
202
|
+
|
|
192
203
|
dataMode: Ref<'all' | 'selection'>
|
|
193
204
|
reinit(this: void): void
|
|
194
205
|
}
|
package/src/table.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StorageSerializers, tryOnScopeDispose, useEventListener } from '@vueuse/core'
|
|
2
2
|
import { nanoid } from 'nanoid'
|
|
3
|
-
import { computed, effectScope, hasInjectionContext, inject, reactive, ref, shallowReactive, shallowRef, toValue, unref } from 'vue'
|
|
3
|
+
import { computed, effectScope, hasInjectionContext, inject, nextTick, reactive, ref, shallowReactive, shallowRef, toValue, unref } from 'vue'
|
|
4
4
|
import { useRoute } from 'vue-router'
|
|
5
5
|
|
|
6
6
|
import { isNone } from '@ithinkdt/common/object'
|
|
@@ -54,10 +54,10 @@ export function useTableHelper(columns, { customizable, actions, actionWidth, ac
|
|
|
54
54
|
}
|
|
55
55
|
const bindings = {}
|
|
56
56
|
for (const k of Object.keys(options)) {
|
|
57
|
-
if (k.length > render.length && k.startsWith(render))
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
57
|
+
if (!(k.length > render.length && k.startsWith(render))) continue
|
|
58
|
+
|
|
59
|
+
bindings[uncapitalize(k.slice(render.length))] = options[k]
|
|
60
|
+
delete options[k]
|
|
61
61
|
}
|
|
62
62
|
const bindings0 = computed(() => {
|
|
63
63
|
return Object.fromEntries(Object.entries(bindings)
|
|
@@ -124,29 +124,43 @@ export function useTableHelper(columns, { customizable, actions, actionWidth, ac
|
|
|
124
124
|
const columns0 = shallowRef([])
|
|
125
125
|
const columns1 = shallowReactive([])
|
|
126
126
|
|
|
127
|
-
const
|
|
127
|
+
const _custom = (params, customs) => {
|
|
128
128
|
if (typeof params === 'boolean') {
|
|
129
|
-
if (params)
|
|
129
|
+
if (params) customs = getDefaultCustom()
|
|
130
130
|
} else if (Array.isArray(params)) {
|
|
131
|
-
customs.
|
|
131
|
+
customs.sort = JSON.stringify(params) === JSON.stringify(columns0.value.map(col => col.key))
|
|
132
132
|
? []
|
|
133
133
|
: params
|
|
134
|
-
setCustoms()
|
|
135
134
|
} else {
|
|
136
|
-
customs.
|
|
137
|
-
customs.
|
|
138
|
-
customs.
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
135
|
+
customs.hidden[params.key] = 'hidden' in params ? params.hidden : customs.hidden[params.key]
|
|
136
|
+
customs.fixed[params.key] = 'fixed' in params ? params.fixed : customs.fixed[params.key]
|
|
137
|
+
customs.width[params.key] = 'width' in params ? params.width : customs.width[params.key]
|
|
138
|
+
const col = columns0.value.find(col => col.key === params.key)
|
|
139
|
+
if (col) {
|
|
140
|
+
if (customs.hidden[params.key] === col.hidden) {
|
|
141
|
+
delete customs.hidden[params.key]
|
|
142
|
+
}
|
|
143
|
+
if (customs.fixed[params.key] === col.fixed) {
|
|
144
|
+
delete customs.fixed[params.key]
|
|
145
|
+
}
|
|
146
|
+
if (customs.width[params.key] === col.width) {
|
|
147
|
+
delete customs.width[params.key]
|
|
148
|
+
}
|
|
147
149
|
}
|
|
148
|
-
setCustoms()
|
|
149
150
|
}
|
|
151
|
+
return customs
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
const custom = (params) => {
|
|
155
|
+
if (!Array.isArray(params) || typeof params[0] === 'string') {
|
|
156
|
+
params = [params]
|
|
157
|
+
}
|
|
158
|
+
let customs0 = customs.value
|
|
159
|
+
for (const params0 of params) {
|
|
160
|
+
customs0 = _custom(params0, customs0)
|
|
161
|
+
}
|
|
162
|
+
setCustoms(customs0)
|
|
163
|
+
|
|
150
164
|
const columns2 = columns0.value.map((col, i, arr) => {
|
|
151
165
|
const index = customs.value.sort.indexOf(col.key)
|
|
152
166
|
return reactive({
|
|
@@ -344,7 +358,7 @@ export function useTableHelper(columns, { customizable, actions, actionWidth, ac
|
|
|
344
358
|
} else {
|
|
345
359
|
useEventListener(globalThis, 'storage', (event) => {
|
|
346
360
|
if (event.key !== key) return
|
|
347
|
-
|
|
361
|
+
nextTick().then(() => read(event.newValue)).then(reinit)
|
|
348
362
|
}, { passive: true })
|
|
349
363
|
}
|
|
350
364
|
|
|
@@ -360,9 +374,7 @@ export function useTableHelper(columns, { customizable, actions, actionWidth, ac
|
|
|
360
374
|
const raw = StorageSerializers.object.write([sort, hidden, fixed, width])
|
|
361
375
|
return storage.setItem(key, raw)
|
|
362
376
|
}
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
if (!customizable) {
|
|
377
|
+
} else {
|
|
366
378
|
reinit()
|
|
367
379
|
}
|
|
368
380
|
|