@tmagic/form 1.8.0-beta.2 → 1.8.0-beta.20
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/es/Form.vue_vue_type_script_setup_true_lang.js +120 -27
- package/dist/es/FormBox.vue_vue_type_script_setup_true_lang.js +19 -3
- package/dist/es/FormDialog.vue_vue_type_script_setup_true_lang.js +30 -7
- package/dist/es/FormDrawer.vue_vue_type_script_setup_true_lang.js +56 -14
- package/dist/es/containers/Col.vue_vue_type_script_setup_true_lang.js +3 -2
- package/dist/es/containers/Container.vue_vue_type_script_setup_true_lang.js +51 -36
- package/dist/es/containers/Fieldset.vue_vue_type_script_setup_true_lang.js +5 -3
- package/dist/es/containers/FlexLayout.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/containers/FormLabel.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/containers/GroupList.vue_vue_type_script_setup_true_lang.js +7 -6
- package/dist/es/containers/GroupListItem.vue_vue_type_script_setup_true_lang.js +42 -32
- package/dist/es/containers/Panel.vue_vue_type_script_setup_true_lang.js +17 -11
- package/dist/es/containers/Row.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/containers/Step.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/containers/Tabs.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/containers/table/ActionsColumn.vue_vue_type_script_setup_true_lang.js +14 -7
- package/dist/es/containers/table/SortColumn.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/containers/table/Table.vue_vue_type_script_setup_true_lang.js +7 -5
- package/dist/es/containers/table/useTableColumns.js +5 -1
- package/dist/es/containers/table-group-list/TableGroupList.vue_vue_type_script_setup_true_lang.js +3 -2
- package/dist/es/fields/Cascader.vue_vue_type_script_setup_true_lang.js +6 -3
- package/dist/es/fields/Checkbox.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/CheckboxGroup.vue_vue_type_script_setup_true_lang.js +6 -3
- package/dist/es/fields/ColorPicker.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/Date.vue_vue_type_script_setup_true_lang.js +6 -3
- package/dist/es/fields/DateTime.vue_vue_type_script_setup_true_lang.js +6 -3
- package/dist/es/fields/Daterange.vue_vue_type_script_setup_true_lang.js +6 -3
- package/dist/es/fields/Display.vue_vue_type_script_setup_true_lang.js +6 -3
- package/dist/es/fields/DynamicField.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/Hidden.vue_vue_type_script_setup_true_lang.js +1 -1
- package/dist/es/fields/Link.vue_vue_type_script_setup_true_lang.js +30 -8
- package/dist/es/fields/Number.vue_vue_type_script_setup_true_lang.js +8 -3
- package/dist/es/fields/NumberRange.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/RadioGroup.vue_vue_type_script_setup_true_lang.js +21 -10
- package/dist/es/fields/Select.vue_vue_type_script_setup_true_lang.js +7 -3
- package/dist/es/fields/Switch.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/Text.vue_vue_type_script_setup_true_lang.js +113 -78
- package/dist/es/fields/Textarea.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/Time.vue_vue_type_script_setup_true_lang.js +5 -2
- package/dist/es/fields/Timerange.vue_vue_type_script_setup_true_lang.js +7 -4
- package/dist/es/index.js +5 -4
- package/dist/es/plugin.js +4 -0
- package/dist/es/schema.js +12 -1
- package/dist/es/style.css +133 -11
- package/dist/es/submitForm.js +415 -56
- package/dist/es/utils/config.js +4 -1
- package/dist/es/utils/form.js +84 -9
- package/dist/es/utils/typeMatch.js +487 -0
- package/dist/style.css +133 -11
- package/dist/themes/magic-admin.css +509 -0
- package/dist/tmagic-form.umd.cjs +1773 -399
- package/package.json +5 -5
- package/src/Form.vue +163 -30
- package/src/FormBox.vue +11 -0
- package/src/FormDialog.vue +25 -3
- package/src/FormDrawer.vue +51 -12
- package/src/containers/Col.vue +1 -0
- package/src/containers/Container.vue +32 -11
- package/src/containers/Fieldset.vue +5 -2
- package/src/containers/GroupList.vue +1 -1
- package/src/containers/GroupListItem.vue +28 -22
- package/src/containers/Panel.vue +10 -3
- package/src/containers/table/ActionsColumn.vue +10 -4
- package/src/containers/table/Table.vue +1 -0
- package/src/containers/table/useTableColumns.ts +7 -3
- package/src/containers/table-group-list/TableGroupList.vue +7 -1
- package/src/fields/Link.vue +16 -3
- package/src/fields/Number.vue +2 -1
- package/src/fields/RadioGroup.vue +24 -6
- package/src/fields/Text.vue +43 -19
- package/src/index.ts +11 -0
- package/src/plugin.ts +12 -0
- package/src/schema.ts +13 -1
- package/src/submitForm.ts +699 -66
- package/src/theme/container.scss +3 -0
- package/src/theme/fieldset.scss +51 -0
- package/src/theme/form-dialog.scss +1 -1
- package/src/theme/form.scss +6 -0
- package/src/theme/group-list.scss +19 -8
- package/src/theme/index.scss +1 -0
- package/src/theme/link.scss +17 -0
- package/src/theme/panel.scss +1 -1
- package/src/theme/radio-group.scss +23 -0
- package/src/theme/table.scss +11 -1
- package/src/theme/tabs.scss +2 -2
- package/src/theme/text.scss +38 -0
- package/src/theme/themes/magic-admin/index.scss +106 -0
- package/src/utils/config.ts +7 -1
- package/src/utils/form.ts +144 -22
- package/src/utils/typeMatch.ts +870 -0
- package/types/index.d.ts +408 -21
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { FORM_DIFF_CONFIG_KEY } from "./schema.js";
|
|
1
|
+
import { FORM_DIFF_CONFIG_KEY, FORM_TYPE_MATCH_VALID_KEY } from "./schema.js";
|
|
2
|
+
import { applyExtendState, initValue } from "./utils/form.js";
|
|
2
3
|
import { getConfig } from "./utils/config.js";
|
|
3
|
-
import { initValue } from "./utils/form.js";
|
|
4
4
|
import Container_default from "./containers/Container.js";
|
|
5
|
-
import { Fragment, createBlock, createCommentVNode, createElementBlock, createSlots, defineComponent, mergeProps, normalizeStyle, openBlock, provide, reactive, ref, renderList, renderSlot, shallowRef, toRaw, unref, useTemplateRef, watch, watchEffect, withCtx } from "vue";
|
|
5
|
+
import { Fragment, computed, createBlock, createCommentVNode, createElementBlock, createSlots, defineComponent, inject, mergeProps, nextTick, normalizeClass, normalizeStyle, openBlock, provide, reactive, ref, renderList, renderSlot, shallowRef, toRaw, unref, useTemplateRef, watch, watchEffect, withCtx } from "vue";
|
|
6
6
|
import { cloneDeep, isEqual } from "lodash-es";
|
|
7
|
-
import { TMagicForm, tMagicMessage, tMagicMessageBox } from "@tmagic/design";
|
|
7
|
+
import { M_THEME_KEY, TMagicForm, tMagicMessage, tMagicMessageBox } from "@tmagic/design";
|
|
8
8
|
import { setValueByKeyPath } from "@tmagic/utils";
|
|
9
9
|
//#region packages/form/src/Form.vue?vue&type=script&setup=true&lang.ts
|
|
10
|
-
var Form_vue_vue_type_script_setup_true_lang_default =
|
|
10
|
+
var Form_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
11
11
|
name: "MForm",
|
|
12
12
|
__name: "Form",
|
|
13
13
|
props: {
|
|
@@ -20,6 +20,11 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
20
20
|
},
|
|
21
21
|
parentValues: { default: () => ({}) },
|
|
22
22
|
labelWidth: { default: "200px" },
|
|
23
|
+
typeMatchValid: { type: Boolean },
|
|
24
|
+
validateOnInit: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
default: false
|
|
27
|
+
},
|
|
23
28
|
disabled: {
|
|
24
29
|
type: Boolean,
|
|
25
30
|
default: false
|
|
@@ -35,9 +40,14 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
35
40
|
keyProp: { default: "__key" },
|
|
36
41
|
popperClass: {},
|
|
37
42
|
preventSubmitDefault: { type: Boolean },
|
|
43
|
+
useFieldTextInError: {
|
|
44
|
+
type: Boolean,
|
|
45
|
+
default: true
|
|
46
|
+
},
|
|
38
47
|
extendState: {},
|
|
39
48
|
showDiff: {},
|
|
40
|
-
selfDiffFieldTypes: {}
|
|
49
|
+
selfDiffFieldTypes: {},
|
|
50
|
+
theme: {}
|
|
41
51
|
},
|
|
42
52
|
emits: [
|
|
43
53
|
"change",
|
|
@@ -49,6 +59,7 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
49
59
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
50
60
|
const props = __props;
|
|
51
61
|
const emit = __emit;
|
|
62
|
+
provide(FORM_TYPE_MATCH_VALID_KEY, computed(() => props.typeMatchValid));
|
|
52
63
|
const tMagicFormRef = useTemplateRef("tMagicForm");
|
|
53
64
|
const initialized = ref(false);
|
|
54
65
|
const values = ref({});
|
|
@@ -56,6 +67,25 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
56
67
|
const fields = /* @__PURE__ */ new Map();
|
|
57
68
|
const requestFuc = getConfig("request");
|
|
58
69
|
/**
|
|
70
|
+
* 当前表单生效的主题名称:
|
|
71
|
+
* - 优先用本组件自己的 `props.theme`;
|
|
72
|
+
* - 没设置时回退到最近祖先 `<MEditor>` / `<MForm>` provide 的主题,便于内嵌于编辑器
|
|
73
|
+
* 时自动跟随外层主题,无需在每个 `MForm` 上重复传 `theme`。
|
|
74
|
+
*
|
|
75
|
+
* 同时把合并后的值再 provide 出去(见下方 `provide(M_THEME_KEY, ...)`),让 form 子树
|
|
76
|
+
* 里再嵌套的 portal 组件(`TMagicPopover` 等)依然能拿到非空主题。
|
|
77
|
+
*/
|
|
78
|
+
const ancestorTheme = inject(M_THEME_KEY, null);
|
|
79
|
+
const effectiveTheme = computed(() => props.theme || ancestorTheme?.value || "");
|
|
80
|
+
/**
|
|
81
|
+
* 拼到 `formState.popperClass` 上的主题修饰类(仅 `m-theme--<theme>`,
|
|
82
|
+
* 不带 `m-form` / `m-editor` 前缀,因为 Element Plus 弹层节点本身既不是 form 也不是 editor)。
|
|
83
|
+
*
|
|
84
|
+
* 这条类会随所有读 `mForm.popperClass` 的字段(Select / DateTime / Cascader 等)下发到
|
|
85
|
+
* Element Plus 的 `popper-class`,让 portal 节点也命中 `m-theme--<theme>` 上的 CSS 变量。
|
|
86
|
+
*/
|
|
87
|
+
const themeClass = computed(() => effectiveTheme.value ? `m-theme--${effectiveTheme.value}` : "");
|
|
88
|
+
/**
|
|
59
89
|
* formState 实现说明:
|
|
60
90
|
*
|
|
61
91
|
* 1. 与 props 直接对应的字段(config / initValues / lastValues / isCompare / parentValues /
|
|
@@ -71,13 +101,21 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
71
101
|
* 把最新值刷进 formState。
|
|
72
102
|
* - accessor 描述符(`{ get stage() { return ... } }`)按原样写入,调用方可以控制
|
|
73
103
|
* 读时求值,每次读取都会重新执行 getter。
|
|
104
|
+
*
|
|
105
|
+
* 4. `popperClass` 会自动拼接 `themeClass`:调用方传入的 `popperClass` + 当前主题
|
|
106
|
+
* 修饰类(含祖先 `<MEditor>` provide 的主题)。这样所有透传到 Element Plus 弹层
|
|
107
|
+
* `popper-class` 的字段(Select / DateTime / Cascader 等)能自带主题作用域。
|
|
74
108
|
*/
|
|
75
109
|
const formState = reactive({
|
|
76
110
|
get keyProp() {
|
|
77
111
|
return props.keyProp;
|
|
78
112
|
},
|
|
79
113
|
get popperClass() {
|
|
80
|
-
|
|
114
|
+
const userClass = props.popperClass ?? "";
|
|
115
|
+
const tc = themeClass.value;
|
|
116
|
+
if (!userClass) return tc;
|
|
117
|
+
if (!tc) return userClass;
|
|
118
|
+
return `${userClass} ${tc}`;
|
|
81
119
|
},
|
|
82
120
|
get config() {
|
|
83
121
|
return props.config;
|
|
@@ -111,6 +149,17 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
111
149
|
}
|
|
112
150
|
});
|
|
113
151
|
/**
|
|
152
|
+
* formState 的内置 key 快照(keyProp / values / $emit / fields / post 等)。
|
|
153
|
+
*
|
|
154
|
+
* 在 `extendState` 首次合并前捕获,`applyExtendState` 会据此禁止 `extendState`
|
|
155
|
+
* 覆盖这些已有字段(只能新增字段),避免表单核心状态被外部意外改写。
|
|
156
|
+
*
|
|
157
|
+
* 之所以在此处(effect 之外)捕获而不是在 `applyExtendState` 内动态取:
|
|
158
|
+
* `watchEffect` 会在依赖变化时重跑,若动态取,`extendState` 自己新增的字段在第二次
|
|
159
|
+
* 合并时也会被当成「已有 key」而拒绝刷新;这里只锁定内置字段即可规避该问题。
|
|
160
|
+
*/
|
|
161
|
+
const reservedStateKeys = new Set(Reflect.ownKeys(formState));
|
|
162
|
+
/**
|
|
114
163
|
* `extendState` 的同步段(直到第一个 `await` 之前)所访问的任何响应式数据,
|
|
115
164
|
* 都会被 `watchEffect` 自动跟踪。这样可以兼容历史用法 ——
|
|
116
165
|
*
|
|
@@ -125,11 +174,10 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
125
174
|
* 这里不再重复同步;因此 `props.initValues` 这类高频变化也不会再触发
|
|
126
175
|
* `extendState` 重跑(旧版的性能问题修复点)。
|
|
127
176
|
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
* 可以自行控制读时求值;强制 `configurable: true` 以便下一次重跑可再 define。
|
|
177
|
+
* 实现细节:合并逻辑统一收口在 `applyExtendState`(utils/form)——
|
|
178
|
+
* data 描述符走 reactive proxy 的 set 触发依赖通知(与旧版「逐项赋值」语义等价),
|
|
179
|
+
* accessor 描述符按原样 defineProperty 支持读时求值;
|
|
180
|
+
* props 派生的只读 getter 字段(keyProp 等)以普通字段形式返回时会被跳过并告警。
|
|
133
181
|
*/
|
|
134
182
|
watchEffect(async (onCleanup) => {
|
|
135
183
|
const { extendState } = props;
|
|
@@ -146,13 +194,16 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
146
194
|
return;
|
|
147
195
|
}
|
|
148
196
|
if (stale) return;
|
|
149
|
-
|
|
150
|
-
else {
|
|
151
|
-
descriptor.configurable = true;
|
|
152
|
-
Object.defineProperty(formState, key, descriptor);
|
|
153
|
-
}
|
|
197
|
+
applyExtendState(formState, state, reservedStateKeys);
|
|
154
198
|
});
|
|
155
199
|
provide("mForm", formState);
|
|
200
|
+
/**
|
|
201
|
+
* 把生效主题(自身或祖先)再 provide 出去,供 form 子树内含 `Teleport` 的组件
|
|
202
|
+
* (如 `TMagicPopover`)在传送目标上挂 `m-theme--<theme>` 类。
|
|
203
|
+
* 详见 `@tmagic/design/theme.ts`。
|
|
204
|
+
*/
|
|
205
|
+
provide(M_THEME_KEY, effectiveTheme);
|
|
206
|
+
provide("formInline", props.inline);
|
|
156
207
|
provide(FORM_DIFF_CONFIG_KEY, {
|
|
157
208
|
get showDiff() {
|
|
158
209
|
return props.showDiff;
|
|
@@ -171,6 +222,9 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
171
222
|
}).then((value) => {
|
|
172
223
|
values.value = value;
|
|
173
224
|
initialized.value = !props.isCompare;
|
|
225
|
+
if (props.validateOnInit) nextTick(() => {
|
|
226
|
+
tMagicFormRef.value?.validate();
|
|
227
|
+
});
|
|
174
228
|
});
|
|
175
229
|
if (props.isCompare) initValue(formState, {
|
|
176
230
|
initValues: props.lastValues,
|
|
@@ -222,6 +276,23 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
222
276
|
};
|
|
223
277
|
return findInConfig(config, nameParts);
|
|
224
278
|
};
|
|
279
|
+
/**
|
|
280
|
+
* 将校验返回的 invalidFields 汇总为可读的错误文案(多条以 `<br>` 拼接)。
|
|
281
|
+
*
|
|
282
|
+
* 抽离为独立方法,供 `submitForm`(提交校验)与 `validate`(返回错误文案的校验)复用,
|
|
283
|
+
* 保证两种校验入口产出的错误文案格式完全一致。
|
|
284
|
+
*/
|
|
285
|
+
const formatValidateError = (invalidFields) => {
|
|
286
|
+
const error = [];
|
|
287
|
+
Object.entries(invalidFields).forEach(([prop, validateError]) => {
|
|
288
|
+
validateError.forEach(({ field, message }) => {
|
|
289
|
+
const name = field || prop;
|
|
290
|
+
const text = (props.useFieldTextInError ? getTextByName(name, props.config) : void 0) || name;
|
|
291
|
+
error.push(`${text} -> ${message}`);
|
|
292
|
+
});
|
|
293
|
+
});
|
|
294
|
+
return error.join("<br>");
|
|
295
|
+
};
|
|
225
296
|
__expose({
|
|
226
297
|
values,
|
|
227
298
|
lastValuesProcessed,
|
|
@@ -241,22 +312,43 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
241
312
|
return native ? values.value : cloneDeep(toRaw(values.value));
|
|
242
313
|
} catch (invalidFields) {
|
|
243
314
|
emit("error", invalidFields);
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
315
|
+
throw new Error(formatValidateError(invalidFields));
|
|
316
|
+
}
|
|
317
|
+
},
|
|
318
|
+
/**
|
|
319
|
+
* 校验:对表单当前值执行校验,返回汇总后的错误文案。
|
|
320
|
+
*
|
|
321
|
+
* 与 `submitForm` 的区别:
|
|
322
|
+
* - 校验失败时不抛异常、不触发 `error` 事件,而是以返回值形式给出错误文案;
|
|
323
|
+
* - 不重置 `changeRecords`,不改变提交语义,仅用于「探测」当前配置是否合法。
|
|
324
|
+
*
|
|
325
|
+
* 注意:本方法只改变「校验结果的返回方式」,并不负责「不污染页面表单状态」——
|
|
326
|
+
* 若需对一份独立的「配置 + 值」做完全不影响页面上已渲染表单的校验,请使用 `validateForm`
|
|
327
|
+
* (内部会新建一个隐藏的 MForm 实例,通过 `initValues` 传入待校验值,用完即卸载)。
|
|
328
|
+
*
|
|
329
|
+
* 典型用途:作为 `validateForm` 内部复用的校验实现;也可在已渲染的表单实例上主动调用,
|
|
330
|
+
* 根据返回的错误文案自行决定后续处理(如记录节点错误状态)。
|
|
331
|
+
*
|
|
332
|
+
* @returns 校验通过返回空字符串 `''`,否则返回以 `<br>` 拼接的错误文案。
|
|
333
|
+
*/
|
|
334
|
+
validate: async () => {
|
|
335
|
+
try {
|
|
336
|
+
const result = await tMagicFormRef.value?.validate();
|
|
337
|
+
if (result !== true) throw result;
|
|
338
|
+
return "";
|
|
339
|
+
} catch (invalidFields) {
|
|
340
|
+
return formatValidateError(invalidFields);
|
|
253
341
|
}
|
|
254
342
|
},
|
|
255
343
|
getTextByName
|
|
256
344
|
});
|
|
257
345
|
return (_ctx, _cache) => {
|
|
258
346
|
return openBlock(), createBlock(unref(TMagicForm), {
|
|
259
|
-
class:
|
|
347
|
+
class: normalizeClass([
|
|
348
|
+
"m-form",
|
|
349
|
+
effectiveTheme.value ? `m-form--${effectiveTheme.value}` : "",
|
|
350
|
+
effectiveTheme.value ? `m-theme--${effectiveTheme.value}` : ""
|
|
351
|
+
]),
|
|
260
352
|
ref: "tMagicForm",
|
|
261
353
|
model: values.value,
|
|
262
354
|
"label-width": __props.labelWidth,
|
|
@@ -294,6 +386,7 @@ var Form_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineCom
|
|
|
294
386
|
}), 128)) : createCommentVNode("v-if", true)]),
|
|
295
387
|
_: 3
|
|
296
388
|
}, 8, [
|
|
389
|
+
"class",
|
|
297
390
|
"model",
|
|
298
391
|
"label-width",
|
|
299
392
|
"style",
|
|
@@ -3,7 +3,7 @@ import { computed, createElementBlock, createElementVNode, createTextVNode, crea
|
|
|
3
3
|
import { TMagicButton, TMagicScrollbar } from "@tmagic/design";
|
|
4
4
|
//#region packages/form/src/FormBox.vue?vue&type=script&setup=true&lang.ts
|
|
5
5
|
var footerHeight = 60;
|
|
6
|
-
var FormBox_vue_vue_type_script_setup_true_lang_default =
|
|
6
|
+
var FormBox_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
7
7
|
name: "MFormBox",
|
|
8
8
|
__name: "FormBox",
|
|
9
9
|
props: {
|
|
@@ -13,12 +13,21 @@ var FormBox_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ define
|
|
|
13
13
|
width: {},
|
|
14
14
|
height: {},
|
|
15
15
|
labelWidth: {},
|
|
16
|
+
typeMatchValid: { type: Boolean },
|
|
17
|
+
validateOnInit: {
|
|
18
|
+
type: Boolean,
|
|
19
|
+
default: false
|
|
20
|
+
},
|
|
16
21
|
disabled: { type: Boolean },
|
|
17
22
|
size: {},
|
|
18
23
|
confirmText: { default: "确定" },
|
|
19
24
|
inline: { type: Boolean },
|
|
20
25
|
labelPosition: {},
|
|
21
26
|
preventSubmitDefault: { type: Boolean },
|
|
27
|
+
useFieldTextInError: {
|
|
28
|
+
type: Boolean,
|
|
29
|
+
default: true
|
|
30
|
+
},
|
|
22
31
|
extendState: {}
|
|
23
32
|
},
|
|
24
33
|
emits: [
|
|
@@ -45,7 +54,8 @@ var FormBox_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ define
|
|
|
45
54
|
const submitHandler = async () => {
|
|
46
55
|
try {
|
|
47
56
|
const changeRecords = form.value?.changeRecords;
|
|
48
|
-
|
|
57
|
+
const values = await form.value?.submitForm();
|
|
58
|
+
emit("submit", values, { changeRecords });
|
|
49
59
|
} catch (e) {
|
|
50
60
|
emit("error", e);
|
|
51
61
|
}
|
|
@@ -81,7 +91,10 @@ var FormBox_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ define
|
|
|
81
91
|
"label-position": __props.labelPosition,
|
|
82
92
|
inline: __props.inline,
|
|
83
93
|
"prevent-submit-default": __props.preventSubmitDefault,
|
|
94
|
+
"use-field-text-in-error": __props.useFieldTextInError,
|
|
84
95
|
"extend-state": __props.extendState,
|
|
96
|
+
"type-match-valid": __props.typeMatchValid,
|
|
97
|
+
"validate-on-init": __props.validateOnInit,
|
|
85
98
|
onChange: changeHandler
|
|
86
99
|
}, null, 8, [
|
|
87
100
|
"size",
|
|
@@ -93,7 +106,10 @@ var FormBox_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ define
|
|
|
93
106
|
"label-position",
|
|
94
107
|
"inline",
|
|
95
108
|
"prevent-submit-default",
|
|
96
|
-
"
|
|
109
|
+
"use-field-text-in-error",
|
|
110
|
+
"extend-state",
|
|
111
|
+
"type-match-valid",
|
|
112
|
+
"validate-on-init"
|
|
97
113
|
]), renderSlot(_ctx.$slots, "default")]),
|
|
98
114
|
_: 3
|
|
99
115
|
})], 4), createElementVNode("div", {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import Form_default from "./Form.js";
|
|
2
|
-
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, normalizeStyle, openBlock, ref, renderSlot, toDisplayString, unref, withCtx } from "vue";
|
|
3
|
-
import { TMagicButton, TMagicCol, TMagicDialog, TMagicRow } from "@tmagic/design";
|
|
2
|
+
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, inject, normalizeClass, normalizeStyle, openBlock, provide, ref, renderSlot, toDisplayString, unref, withCtx } from "vue";
|
|
3
|
+
import { M_THEME_KEY, TMagicButton, TMagicCol, TMagicDialog, TMagicRow } from "@tmagic/design";
|
|
4
4
|
//#region packages/form/src/FormDialog.vue?vue&type=script&setup=true&lang.ts
|
|
5
5
|
var _hoisted_1 = { style: { "min-height": "1px" } };
|
|
6
|
-
var FormDialog_vue_vue_type_script_setup_true_lang_default =
|
|
6
|
+
var FormDialog_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
7
7
|
name: "MFormDialog",
|
|
8
8
|
__name: "FormDialog",
|
|
9
9
|
props: {
|
|
@@ -12,6 +12,11 @@ var FormDialog_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
12
12
|
parentValues: {},
|
|
13
13
|
width: {},
|
|
14
14
|
labelWidth: {},
|
|
15
|
+
typeMatchValid: { type: Boolean },
|
|
16
|
+
validateOnInit: {
|
|
17
|
+
type: Boolean,
|
|
18
|
+
default: false
|
|
19
|
+
},
|
|
15
20
|
fullscreen: { type: Boolean },
|
|
16
21
|
disabled: { type: Boolean },
|
|
17
22
|
title: {},
|
|
@@ -41,7 +46,12 @@ var FormDialog_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
41
46
|
type: Boolean,
|
|
42
47
|
default: true
|
|
43
48
|
},
|
|
44
|
-
|
|
49
|
+
useFieldTextInError: {
|
|
50
|
+
type: Boolean,
|
|
51
|
+
default: true
|
|
52
|
+
},
|
|
53
|
+
extendState: {},
|
|
54
|
+
theme: {}
|
|
45
55
|
},
|
|
46
56
|
emits: [
|
|
47
57
|
"close",
|
|
@@ -51,6 +61,9 @@ var FormDialog_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
51
61
|
],
|
|
52
62
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
53
63
|
const props = __props;
|
|
64
|
+
const ancestorTheme = inject(M_THEME_KEY, null);
|
|
65
|
+
const effectiveTheme = computed(() => props.theme || ancestorTheme?.value || "");
|
|
66
|
+
provide(M_THEME_KEY, effectiveTheme);
|
|
54
67
|
const emit = __emit;
|
|
55
68
|
const form = ref();
|
|
56
69
|
const dialogVisible = ref(false);
|
|
@@ -74,7 +87,8 @@ var FormDialog_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
74
87
|
const save = async () => {
|
|
75
88
|
try {
|
|
76
89
|
const changeRecords = [...form.value?.changeRecords || []];
|
|
77
|
-
|
|
90
|
+
const values = await form.value?.submitForm();
|
|
91
|
+
emit("submit", values, { changeRecords });
|
|
78
92
|
} catch (e) {
|
|
79
93
|
emit("error", e);
|
|
80
94
|
}
|
|
@@ -110,7 +124,7 @@ var FormDialog_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
110
124
|
return openBlock(), createBlock(unref(TMagicDialog), {
|
|
111
125
|
modelValue: dialogVisible.value,
|
|
112
126
|
"onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => dialogVisible.value = $event),
|
|
113
|
-
class: "m-form-dialog",
|
|
127
|
+
class: normalizeClass(["m-form-dialog", effectiveTheme.value ? `m-theme--${effectiveTheme.value}` : ""]),
|
|
114
128
|
top: "20px",
|
|
115
129
|
"append-to-body": "",
|
|
116
130
|
title: __props.title,
|
|
@@ -191,7 +205,11 @@ var FormDialog_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
191
205
|
"label-position": __props.labelPosition,
|
|
192
206
|
inline: __props.inline,
|
|
193
207
|
"prevent-submit-default": __props.preventSubmitDefault,
|
|
208
|
+
"use-field-text-in-error": __props.useFieldTextInError,
|
|
209
|
+
"type-match-valid": __props.typeMatchValid,
|
|
210
|
+
"validate-on-init": __props.validateOnInit,
|
|
194
211
|
"extend-state": __props.extendState,
|
|
212
|
+
theme: effectiveTheme.value,
|
|
195
213
|
onChange: changeHandler
|
|
196
214
|
}, null, 8, [
|
|
197
215
|
"modelValue",
|
|
@@ -204,11 +222,16 @@ var FormDialog_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
204
222
|
"label-position",
|
|
205
223
|
"inline",
|
|
206
224
|
"prevent-submit-default",
|
|
207
|
-
"
|
|
225
|
+
"use-field-text-in-error",
|
|
226
|
+
"type-match-valid",
|
|
227
|
+
"validate-on-init",
|
|
228
|
+
"extend-state",
|
|
229
|
+
"theme"
|
|
208
230
|
]), renderSlot(_ctx.$slots, "default")], 4)) : createCommentVNode("v-if", true)]),
|
|
209
231
|
_: 3
|
|
210
232
|
}, 8, [
|
|
211
233
|
"modelValue",
|
|
234
|
+
"class",
|
|
212
235
|
"title",
|
|
213
236
|
"width",
|
|
214
237
|
"zIndex",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import Form_default from "./Form.js";
|
|
2
|
-
import { createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, openBlock, ref, renderSlot, toDisplayString, unref, watchEffect, withCtx } from "vue";
|
|
3
|
-
import { TMagicButton, TMagicCol, TMagicDrawer, TMagicRow } from "@tmagic/design";
|
|
2
|
+
import { computed, createBlock, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, createVNode, defineComponent, inject, normalizeClass, openBlock, provide, ref, renderSlot, toDisplayString, unref, watchEffect, withCtx } from "vue";
|
|
3
|
+
import { M_THEME_KEY, TMagicButton, TMagicCol, TMagicDrawer, TMagicRow } from "@tmagic/design";
|
|
4
4
|
//#region packages/form/src/FormDrawer.vue?vue&type=script&setup=true&lang.ts
|
|
5
5
|
var _hoisted_1 = { style: { "min-height": "1px" } };
|
|
6
|
-
var FormDrawer_vue_vue_type_script_setup_true_lang_default =
|
|
7
|
-
name: "
|
|
6
|
+
var FormDrawer_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
7
|
+
name: "MFormDrawer",
|
|
8
8
|
__name: "FormDrawer",
|
|
9
9
|
props: {
|
|
10
10
|
config: { default: () => [] },
|
|
@@ -12,6 +12,11 @@ var FormDrawer_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
12
12
|
parentValues: {},
|
|
13
13
|
width: {},
|
|
14
14
|
labelWidth: {},
|
|
15
|
+
typeMatchValid: { type: Boolean },
|
|
16
|
+
validateOnInit: {
|
|
17
|
+
type: Boolean,
|
|
18
|
+
default: false
|
|
19
|
+
},
|
|
15
20
|
disabled: { type: Boolean },
|
|
16
21
|
closeOnPressEscape: {
|
|
17
22
|
type: Boolean,
|
|
@@ -24,8 +29,13 @@ var FormDrawer_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
24
29
|
inline: { type: Boolean },
|
|
25
30
|
labelPosition: {},
|
|
26
31
|
preventSubmitDefault: { type: Boolean },
|
|
32
|
+
useFieldTextInError: {
|
|
33
|
+
type: Boolean,
|
|
34
|
+
default: true
|
|
35
|
+
},
|
|
27
36
|
beforeClose: {},
|
|
28
|
-
extendState: {}
|
|
37
|
+
extendState: {},
|
|
38
|
+
theme: {}
|
|
29
39
|
},
|
|
30
40
|
emits: [
|
|
31
41
|
"close",
|
|
@@ -37,11 +47,15 @@ var FormDrawer_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
37
47
|
"opened"
|
|
38
48
|
],
|
|
39
49
|
setup(__props, { expose: __expose, emit: __emit }) {
|
|
50
|
+
const props = __props;
|
|
51
|
+
const ancestorTheme = inject(M_THEME_KEY, null);
|
|
52
|
+
const effectiveTheme = computed(() => props.theme || ancestorTheme?.value || "");
|
|
53
|
+
provide(M_THEME_KEY, effectiveTheme);
|
|
40
54
|
const emit = __emit;
|
|
41
55
|
const drawer = ref();
|
|
42
56
|
const form = ref();
|
|
43
57
|
const drawerBody = ref();
|
|
44
|
-
const
|
|
58
|
+
const dialogVisible = ref(false);
|
|
45
59
|
const saveFetch = ref(false);
|
|
46
60
|
const bodyHeight = ref(0);
|
|
47
61
|
watchEffect(() => {
|
|
@@ -50,7 +64,8 @@ var FormDrawer_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
50
64
|
const submitHandler = async () => {
|
|
51
65
|
try {
|
|
52
66
|
const changeRecords = form.value?.changeRecords;
|
|
53
|
-
|
|
67
|
+
const values = await form.value?.submitForm();
|
|
68
|
+
emit("submit", values, { changeRecords });
|
|
54
69
|
} catch (e) {
|
|
55
70
|
emit("error", e);
|
|
56
71
|
}
|
|
@@ -71,30 +86,48 @@ var FormDrawer_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
71
86
|
emit("closed");
|
|
72
87
|
};
|
|
73
88
|
const show = () => {
|
|
74
|
-
|
|
89
|
+
dialogVisible.value = true;
|
|
75
90
|
};
|
|
76
91
|
const hide = () => {
|
|
77
|
-
|
|
92
|
+
dialogVisible.value = false;
|
|
93
|
+
};
|
|
94
|
+
const close = () => {
|
|
95
|
+
dialogVisible.value = false;
|
|
96
|
+
};
|
|
97
|
+
const cancel = () => {
|
|
98
|
+
hide();
|
|
78
99
|
};
|
|
79
100
|
/** 用于关闭 Drawer, 该方法会调用传入的 before-close 方法 */
|
|
80
101
|
const handleClose = () => {
|
|
81
102
|
drawer.value?.handleClose();
|
|
82
103
|
};
|
|
104
|
+
const save = async () => {
|
|
105
|
+
try {
|
|
106
|
+
const changeRecords = [...form.value?.changeRecords || []];
|
|
107
|
+
const values = await form.value?.submitForm();
|
|
108
|
+
emit("submit", values, { changeRecords });
|
|
109
|
+
} catch (e) {
|
|
110
|
+
emit("error", e);
|
|
111
|
+
}
|
|
112
|
+
};
|
|
83
113
|
__expose({
|
|
84
114
|
form,
|
|
85
115
|
saveFetch,
|
|
86
116
|
bodyHeight,
|
|
117
|
+
close,
|
|
87
118
|
show,
|
|
88
119
|
hide,
|
|
120
|
+
save,
|
|
121
|
+
cancel,
|
|
89
122
|
handleClose
|
|
90
123
|
});
|
|
91
124
|
return (_ctx, _cache) => {
|
|
92
125
|
return openBlock(), createBlock(unref(TMagicDrawer), {
|
|
93
|
-
class: "m-form-drawer",
|
|
126
|
+
class: normalizeClass(["m-form-drawer", effectiveTheme.value ? `m-theme--${effectiveTheme.value}` : ""]),
|
|
94
127
|
ref_key: "drawer",
|
|
95
128
|
ref: drawer,
|
|
96
|
-
modelValue:
|
|
97
|
-
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) =>
|
|
129
|
+
modelValue: dialogVisible.value,
|
|
130
|
+
"onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => dialogVisible.value = $event),
|
|
98
131
|
title: __props.title,
|
|
99
132
|
"close-on-press-escape": __props.closeOnPressEscape,
|
|
100
133
|
"append-to-body": true,
|
|
@@ -132,7 +165,7 @@ var FormDrawer_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
132
165
|
})]),
|
|
133
166
|
_: 3
|
|
134
167
|
})]),
|
|
135
|
-
default: withCtx(() => [
|
|
168
|
+
default: withCtx(() => [dialogVisible.value ? (openBlock(), createElementBlock("div", {
|
|
136
169
|
key: 0,
|
|
137
170
|
ref_key: "drawerBody",
|
|
138
171
|
ref: drawerBody,
|
|
@@ -149,7 +182,11 @@ var FormDrawer_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
149
182
|
"label-position": __props.labelPosition,
|
|
150
183
|
inline: __props.inline,
|
|
151
184
|
"prevent-submit-default": __props.preventSubmitDefault,
|
|
185
|
+
"use-field-text-in-error": __props.useFieldTextInError,
|
|
186
|
+
"type-match-valid": __props.typeMatchValid,
|
|
187
|
+
"validate-on-init": __props.validateOnInit,
|
|
152
188
|
"extend-state": __props.extendState,
|
|
189
|
+
theme: effectiveTheme.value,
|
|
153
190
|
onChange: changeHandler
|
|
154
191
|
}, null, 8, [
|
|
155
192
|
"size",
|
|
@@ -161,10 +198,15 @@ var FormDrawer_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ def
|
|
|
161
198
|
"label-position",
|
|
162
199
|
"inline",
|
|
163
200
|
"prevent-submit-default",
|
|
164
|
-
"
|
|
201
|
+
"use-field-text-in-error",
|
|
202
|
+
"type-match-valid",
|
|
203
|
+
"validate-on-init",
|
|
204
|
+
"extend-state",
|
|
205
|
+
"theme"
|
|
165
206
|
]), renderSlot(_ctx.$slots, "default")], 512)) : createCommentVNode("v-if", true)]),
|
|
166
207
|
_: 3
|
|
167
208
|
}, 8, [
|
|
209
|
+
"class",
|
|
168
210
|
"modelValue",
|
|
169
211
|
"title",
|
|
170
212
|
"close-on-press-escape",
|
|
@@ -3,7 +3,7 @@ import Container_default from "./Container.js";
|
|
|
3
3
|
import { computed, createBlock, createVNode, defineComponent, inject, openBlock, unref, vShow, withCtx, withDirectives } from "vue";
|
|
4
4
|
import { TMagicCol } from "@tmagic/design";
|
|
5
5
|
//#region packages/form/src/containers/Col.vue?vue&type=script&setup=true&lang.ts
|
|
6
|
-
var Col_vue_vue_type_script_setup_true_lang_default =
|
|
6
|
+
var Col_vue_vue_type_script_setup_true_lang_default = /*@__PURE__*/ defineComponent({
|
|
7
7
|
name: "MFormCol",
|
|
8
8
|
__name: "Col",
|
|
9
9
|
props: {
|
|
@@ -40,7 +40,8 @@ var Col_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ defineComp
|
|
|
40
40
|
size: __props.size,
|
|
41
41
|
disabled: __props.disabled,
|
|
42
42
|
onChange: changeHandler,
|
|
43
|
-
onAddDiffCount
|
|
43
|
+
onAddDiffCount,
|
|
44
|
+
"is-in-row": true
|
|
44
45
|
}, null, 8, [
|
|
45
46
|
"model",
|
|
46
47
|
"lastValues",
|