@ithinkdt/page 4.2.0 → 4.2.2
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 +1 -0
- package/package.json +7 -7
- package/src/crud.d.ts +14 -8
- package/src/crud.js +6 -0
- package/src/description.js +1 -1
- package/src/form.d.ts +14 -5
- package/src/form.js +8 -4
- package/src/modal.d.ts +11 -3
- package/src/modal.js +17 -8
- package/src/rules.js +1 -1
- package/src/table.js +5 -1
package/README.md
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ithinkdt/page",
|
|
3
|
-
"version": "4.2.
|
|
3
|
+
"version": "4.2.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "iThinkDT Page",
|
|
@@ -39,9 +39,9 @@
|
|
|
39
39
|
},
|
|
40
40
|
"sideEffects": false,
|
|
41
41
|
"dependencies": {
|
|
42
|
-
"@vueuse/core": "^14.
|
|
43
|
-
"nanoid": "^6.0.
|
|
44
|
-
"@ithinkdt/common": "~4.2.
|
|
42
|
+
"@vueuse/core": "^14.4.0",
|
|
43
|
+
"nanoid": "^6.0.1",
|
|
44
|
+
"@ithinkdt/common": "~4.2.1"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"vue": ">=3.5",
|
|
@@ -49,9 +49,9 @@
|
|
|
49
49
|
},
|
|
50
50
|
"devDependencies": {
|
|
51
51
|
"typescript": "~6.0.3",
|
|
52
|
-
"vite": "^8.1
|
|
53
|
-
"vue": "^3.5.
|
|
54
|
-
"vue-router": "^5.
|
|
52
|
+
"vite": "^8.2.1",
|
|
53
|
+
"vue": "^3.5.41",
|
|
54
|
+
"vue-router": "^5.2.0"
|
|
55
55
|
},
|
|
56
56
|
"scripts": {
|
|
57
57
|
"release": "pnpm publish --no-git-checks"
|
package/src/crud.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { MaybeRef, VNodeChild } from 'vue'
|
|
2
2
|
|
|
3
|
-
import { Awaitable, Falsely, MaybeArray } from '@ithinkdt/common/typed'
|
|
3
|
+
import { Awaitable, Falsely, MaybeArray, MaybePromise } from '@ithinkdt/common/typed'
|
|
4
4
|
|
|
5
5
|
import { PresetKeyField, _DataWithPresetKeyField } from './data-source.js'
|
|
6
6
|
import { FormItemHelper, FormItemOptions, FormModalOptionsBase } from './form.js'
|
|
7
|
+
import { ModalRenderParam } from './modal.js'
|
|
7
8
|
|
|
8
9
|
export interface CrudConfirmParams {
|
|
9
10
|
title: () => VNodeChild
|
|
@@ -71,13 +72,18 @@ type SimpleCrudOptions<
|
|
|
71
72
|
submitText?: VNodeChild | (() => VNodeChild)
|
|
72
73
|
cancelText?: VNodeChild | (() => VNodeChild)
|
|
73
74
|
action?: (
|
|
74
|
-
params: {
|
|
75
|
-
onSubmit(this: void):
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
75
|
+
params: Omit<ModalRenderParam, 'onConfirm'> & {
|
|
76
|
+
onSubmit(this: void): MaybePromise<boolean | void>
|
|
77
|
+
} & ({ /** @reactively */ model: CreateParams, type: 'create' }
|
|
78
|
+
| { /** @reactively */ model: UpdateParams, type: 'edit' }
|
|
79
|
+
| { /** @reactively */ model: DetailEntity, type: 'view' }),
|
|
80
|
+
) => VNodeChild
|
|
81
|
+
actionExtra?: (
|
|
82
|
+
params: Omit<ModalRenderParam, 'onConfirm'> & {
|
|
83
|
+
onSubmit(this: void): MaybePromise<boolean | void>
|
|
84
|
+
} & ({ /** @reactively */ model: CreateParams, type: 'create' }
|
|
85
|
+
| { /** @reactively */ model: UpdateParams, type: 'edit' }
|
|
86
|
+
| { /** @reactively */ model: DetailEntity, type: 'view' }),
|
|
81
87
|
) => VNodeChild
|
|
82
88
|
resizable?: MaybeRef<boolean | undefined>
|
|
83
89
|
draggable?: MaybeRef<boolean | undefined>
|
package/src/crud.js
CHANGED
|
@@ -100,6 +100,12 @@ function _useSimpleCrudModal(crudType, getItems, request, options) {
|
|
|
100
100
|
type: crudType,
|
|
101
101
|
})
|
|
102
102
|
: undefined,
|
|
103
|
+
actionExtra: options.actionExtra
|
|
104
|
+
? params => options.actionExtra({
|
|
105
|
+
...params,
|
|
106
|
+
type: crudType,
|
|
107
|
+
})
|
|
108
|
+
: undefined,
|
|
103
109
|
})
|
|
104
110
|
|
|
105
111
|
return {
|
package/src/description.js
CHANGED
|
@@ -78,7 +78,7 @@ export function useDescriptionsHelper(
|
|
|
78
78
|
|
|
79
79
|
ignoreDefaultEmptyRender_ ??= options?.ignoreDefaultEmptyRender
|
|
80
80
|
const render0 = (model) => {
|
|
81
|
-
if (!unref(ignoreDefaultEmptyRender_) &&
|
|
81
|
+
if (renderEmptyValue && !unref(ignoreDefaultEmptyRender_) && prop[0] !== '$' && isNone(model[prop])) {
|
|
82
82
|
return renderEmptyValue(type_, 'description')
|
|
83
83
|
}
|
|
84
84
|
return render_(model)
|
package/src/form.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { ComputedRef, MaybeRef, MaybeRefOrGetter, VNodeChild } from 'vue'
|
|
|
2
2
|
|
|
3
3
|
import { Awaitable, MaybeArray, MaybePromise } from '@ithinkdt/common'
|
|
4
4
|
|
|
5
|
-
import { ModalDialogOptions, ModalDrawerOptions, ModalReturns } from './modal.js'
|
|
5
|
+
import { ModalDialogOptions, ModalDrawerOptions, ModalRenderParam, ModalReturns } from './modal.js'
|
|
6
6
|
|
|
7
7
|
export type ValidationTrigger = MaybeArray<'input' | 'blur' | (string & {})>
|
|
8
8
|
|
|
@@ -218,6 +218,7 @@ export interface FormRenderExtraOptions {
|
|
|
218
218
|
|
|
219
219
|
export interface FormRenderParam extends FormRenderExtraOptions, Omit<FormHelper<Record<string, unknown>>, 'invalid'> {
|
|
220
220
|
inModal: boolean
|
|
221
|
+
modalType: 'dialog' | 'drawer'
|
|
221
222
|
readonly: boolean
|
|
222
223
|
invalid: boolean
|
|
223
224
|
handleSubmit(this: void, model: Record<string, unknown>): Promise<boolean | void>
|
|
@@ -247,10 +248,18 @@ export type FormModalOptions<Model extends {}> = FormModalOptionsBase & FormHelp
|
|
|
247
248
|
submitText?: VNodeChild | (() => VNodeChild)
|
|
248
249
|
readonly?: MaybeRefOrGetter<boolean>
|
|
249
250
|
action?: (
|
|
250
|
-
params: {
|
|
251
|
-
onSubmit(this: void):
|
|
252
|
-
|
|
253
|
-
|
|
251
|
+
params: Omit<ModalRenderParam, 'onConfirm'> & {
|
|
252
|
+
onSubmit(this: void): MaybePromise<boolean | void>
|
|
253
|
+
/**
|
|
254
|
+
* 数据
|
|
255
|
+
* @reactively
|
|
256
|
+
*/
|
|
257
|
+
model: Partial<Model>
|
|
258
|
+
},
|
|
259
|
+
) => VNodeChild
|
|
260
|
+
actionExtra?: (
|
|
261
|
+
params: Omit<ModalRenderParam, 'onConfirm'> & {
|
|
262
|
+
onSubmit(this: void): MaybePromise<boolean | void>
|
|
254
263
|
/**
|
|
255
264
|
* 数据
|
|
256
265
|
* @reactively
|
package/src/form.js
CHANGED
|
@@ -84,7 +84,7 @@ export function useFormHelper(items, { initial: initial0, rules, onChange, inFil
|
|
|
84
84
|
|
|
85
85
|
ignoreDefaultEmptyRender_ ??= options?.ignoreDefaultEmptyRender
|
|
86
86
|
const render0 = (params, model) => {
|
|
87
|
-
if (!unref(ignoreDefaultEmptyRender_) &&
|
|
87
|
+
if (renderEmptyValue && !unref(ignoreDefaultEmptyRender_) && name[0] !== '$' && params?.readonly && isNone(model[name])) {
|
|
88
88
|
return renderEmptyValue(type_, 'form')
|
|
89
89
|
}
|
|
90
90
|
return render_(params, model)
|
|
@@ -125,7 +125,7 @@ export function useFormHelper(items, { initial: initial0, rules, onChange, inFil
|
|
|
125
125
|
),
|
|
126
126
|
)
|
|
127
127
|
let result2
|
|
128
|
-
if (!
|
|
128
|
+
if (!prop0 && !invalid.value) {
|
|
129
129
|
const ret = await beforeSubmit(prop)
|
|
130
130
|
result2 = ret[1]
|
|
131
131
|
}
|
|
@@ -502,7 +502,7 @@ export class ValidationError extends Error {
|
|
|
502
502
|
}
|
|
503
503
|
}
|
|
504
504
|
|
|
505
|
-
export function useFormModal({ initial, items, rules, onSubmit, submitText, cancelText, action, readonly = false, ...options }) {
|
|
505
|
+
export function useFormModal({ initial, items, rules, onSubmit, submitText, cancelText, action, actionExtra, readonly = false, ...options }) {
|
|
506
506
|
const { i18n: useI18n, getFormRenderer } = (hasInjectionContext() ? inject(PAGE_INJECTION, pageInjection) : pageInjection) ?? {}
|
|
507
507
|
if (!getFormRenderer) {
|
|
508
508
|
throw new Error('`useFormModal` not found `getFormRenderer` in injection, please install the page plugin.')
|
|
@@ -542,6 +542,7 @@ export function useFormModal({ initial, items, rules, onSubmit, submitText, canc
|
|
|
542
542
|
...options,
|
|
543
543
|
readonly,
|
|
544
544
|
inModal: true,
|
|
545
|
+
modalType: unref(options.type) ?? 'dialog',
|
|
545
546
|
validation: validation.value,
|
|
546
547
|
restoreValidation: (props) => {
|
|
547
548
|
form.restoreValidation(props)
|
|
@@ -582,7 +583,10 @@ export function useFormModal({ initial, items, rules, onSubmit, submitText, canc
|
|
|
582
583
|
validation2.value = {}
|
|
583
584
|
},
|
|
584
585
|
footer: action
|
|
585
|
-
? params => action({ ...params, model: form.model })
|
|
586
|
+
? params => action({ ...params, onSubmit: params.onConfirm, model: form.model })
|
|
587
|
+
: undefined,
|
|
588
|
+
footerExtra: actionExtra
|
|
589
|
+
? params => actionExtra({ ...params, onSubmit: params.onConfirm, model: form.model })
|
|
586
590
|
: undefined,
|
|
587
591
|
})
|
|
588
592
|
|
package/src/modal.d.ts
CHANGED
|
@@ -12,6 +12,7 @@ export interface ModalOptionsBase {
|
|
|
12
12
|
cancelDisabled?: MaybeRef<boolean | undefined>
|
|
13
13
|
cancelLoading?: MaybeRef<boolean | undefined>
|
|
14
14
|
footer?: VNodeChild | ((params: ModalRenderParam) => VNodeChild)
|
|
15
|
+
footerExtra?: VNodeChild | ((params: ModalRenderParam) => VNodeChild)
|
|
15
16
|
closable?: MaybeRef<boolean | undefined>
|
|
16
17
|
closeOnEsc?: MaybeRef<boolean | undefined>
|
|
17
18
|
showMask?: MaybeRef<boolean | undefined>
|
|
@@ -41,6 +42,7 @@ export interface ModalRenderParam {
|
|
|
41
42
|
title: VNodeChild
|
|
42
43
|
content: VNodeChild
|
|
43
44
|
footer: VNodeChild
|
|
45
|
+
footerExtra: VNodeChild
|
|
44
46
|
visible: boolean
|
|
45
47
|
loading: boolean | undefined
|
|
46
48
|
resizable: boolean | undefined
|
|
@@ -77,8 +79,14 @@ export declare function useModal(options: ModalDrawerOptions | ModalDialogOption
|
|
|
77
79
|
ModalReturns
|
|
78
80
|
& [open: ModalReturns['open'], close: ModalReturns['close'], visible: ComputedRef<boolean>]
|
|
79
81
|
|
|
80
|
-
export declare function useModalRef():
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
export declare function useModalRef(): {
|
|
83
|
+
inModal: true
|
|
84
|
+
modalType: ComputedRef<'dialog' | 'drawer'>
|
|
85
|
+
visible: ComputedRef<boolean>
|
|
86
|
+
close: ModalReturns['close']
|
|
87
|
+
setTitle: (title: ModalOptionsBase['title']) => void
|
|
88
|
+
} | {
|
|
89
|
+
inModal: false
|
|
90
|
+
}
|
|
83
91
|
|
|
84
92
|
export declare const ModalProvider: DefineComponent<{}>
|
package/src/modal.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { tryOnScopeDispose } from '@vueuse/core'
|
|
2
2
|
import { nanoid } from 'nanoid'
|
|
3
|
-
import { computed, defineComponent, h, hasInjectionContext, inject, isVNode, provide, reactive, ref, toValue, unref } from 'vue'
|
|
3
|
+
import { computed, defineComponent, h, hasInjectionContext, inject, isVNode, onActivated, onDeactivated, provide, reactive, ref, toValue, unref } from 'vue'
|
|
4
4
|
|
|
5
5
|
import { IgnoreRejectionError, PAGE_INJECTION, pageInjection } from './plugin.js'
|
|
6
6
|
|
|
@@ -14,7 +14,7 @@ export const ModalProvider = defineComponent({
|
|
|
14
14
|
|
|
15
15
|
const ModalInjectionKey = Symbol('__MODAL__')
|
|
16
16
|
|
|
17
|
-
export function useModal({ content, confirmText, confirmLoading, cancelText, cancelLoading, footer, onConfirm, onCancel, onClose, title, ...options }) {
|
|
17
|
+
export function useModal({ content, confirmText, confirmLoading, cancelText, cancelLoading, footer, footerExtra, onConfirm, onCancel, onClose, title, ...options }) {
|
|
18
18
|
const { i18n: useI18n, getModalRenderer, addModal } = (hasInjectionContext() ? inject(PAGE_INJECTION, pageInjection) : pageInjection) ?? {}
|
|
19
19
|
if (!getModalRenderer) {
|
|
20
20
|
throw new Error('`useModal` not found `getModalRenderer` in injection, please install the page plugin.')
|
|
@@ -24,6 +24,14 @@ export function useModal({ content, confirmText, confirmLoading, cancelText, can
|
|
|
24
24
|
|
|
25
25
|
const title2 = ref()
|
|
26
26
|
const visible = ref(false)
|
|
27
|
+
let visibleSaved = visible.value
|
|
28
|
+
onActivated(() => {
|
|
29
|
+
visible.value = visibleSaved
|
|
30
|
+
})
|
|
31
|
+
onDeactivated(() => {
|
|
32
|
+
visibleSaved = visible.value
|
|
33
|
+
visible.value = false
|
|
34
|
+
})
|
|
27
35
|
let resolve0, reject0
|
|
28
36
|
const open = (title0) => {
|
|
29
37
|
if (visible.value) {
|
|
@@ -100,6 +108,7 @@ export function useModal({ content, confirmText, confirmLoading, cancelText, can
|
|
|
100
108
|
props: {},
|
|
101
109
|
setup() {
|
|
102
110
|
provide(ModalInjectionKey, {
|
|
111
|
+
modalType: computed(() => unref(renderParam.type) ?? 'dialog'),
|
|
103
112
|
visible,
|
|
104
113
|
close,
|
|
105
114
|
title2,
|
|
@@ -111,6 +120,7 @@ export function useModal({ content, confirmText, confirmLoading, cancelText, can
|
|
|
111
120
|
title: toValue(title2.value ?? title),
|
|
112
121
|
content: toValue(content),
|
|
113
122
|
footer: isVNode(footer) ? footer : footer === null ? null : footer?.(renderParam),
|
|
123
|
+
footerExtra: isVNode(footerExtra) ? footerExtra : footerExtra?.(renderParam),
|
|
114
124
|
confirmText: toValue(confirmText ?? (confirmText === null ? null : t('common.confirm.defaultOk'))),
|
|
115
125
|
cancelText: toValue(cancelText ?? (cancelText === null ? null : t('common.page.form.cancelText'))),
|
|
116
126
|
})
|
|
@@ -130,10 +140,9 @@ export function useModal({ content, confirmText, confirmLoading, cancelText, can
|
|
|
130
140
|
|
|
131
141
|
export function useModalRef() {
|
|
132
142
|
const modal = inject(ModalInjectionKey, null)
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
return returns
|
|
143
|
+
return {
|
|
144
|
+
...modal,
|
|
145
|
+
inModal: !!modal,
|
|
146
|
+
setTitle: (title2) => { modal && (modal.title2.value = title2) },
|
|
147
|
+
}
|
|
139
148
|
}
|
package/src/rules.js
CHANGED
|
@@ -70,7 +70,7 @@ export function required(message, { required = true, trigger = ['input', 'blur',
|
|
|
70
70
|
[requiredRuleSymbol]: true,
|
|
71
71
|
trigger,
|
|
72
72
|
validator: (value) => {
|
|
73
|
-
if (
|
|
73
|
+
if (typeof value === 'number' || typeof value === 'bigint' || typeof value === 'boolean' || !unref(required)) return
|
|
74
74
|
if (value === undefined || value === null) {
|
|
75
75
|
return message(value, { required: true })
|
|
76
76
|
}
|
package/src/table.js
CHANGED
|
@@ -76,7 +76,7 @@ export function useTableHelper(columns, { customizable, actions, actionWidth, ac
|
|
|
76
76
|
|
|
77
77
|
ignoreDefaultEmptyRender_ ??= options?.ignoreDefaultEmptyRender
|
|
78
78
|
const render0 = (record, i) => {
|
|
79
|
-
if (!unref(ignoreDefaultEmptyRender_) &&
|
|
79
|
+
if (renderEmptyValue && !unref(ignoreDefaultEmptyRender_) && prop[0] !== '$' && isNone(record[prop])) {
|
|
80
80
|
return renderEmptyValue(type_, 'description')
|
|
81
81
|
}
|
|
82
82
|
return render_(record, i)
|
|
@@ -281,6 +281,9 @@ export function useTableHelper(columns, { customizable, actions, actionWidth, ac
|
|
|
281
281
|
prop: '$expand',
|
|
282
282
|
type: 'expand',
|
|
283
283
|
expandable: typeof expandable === 'function' ? expandable : undefined,
|
|
284
|
+
width: 40,
|
|
285
|
+
maxWidth: 40,
|
|
286
|
+
resizable: false,
|
|
284
287
|
renderExpand,
|
|
285
288
|
hidden: computed(() => unref(expandable) === false),
|
|
286
289
|
fixed: 'left',
|
|
@@ -302,6 +305,7 @@ export function useTableHelper(columns, { customizable, actions, actionWidth, ac
|
|
|
302
305
|
width: 50,
|
|
303
306
|
maxWidth: 50,
|
|
304
307
|
visible: false,
|
|
308
|
+
resizable: false,
|
|
305
309
|
},
|
|
306
310
|
)
|
|
307
311
|
}
|