@tmagic/form 1.3.9 → 1.3.10
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/style.css +11 -0
- package/dist/tmagic-form.js +156 -83
- package/dist/tmagic-form.js.map +1 -1
- package/dist/tmagic-form.umd.cjs +155 -81
- package/dist/tmagic-form.umd.cjs.map +1 -1
- package/package.json +3 -3
- package/src/containers/Container.vue +2 -1
- package/src/containers/GroupListItem.vue +4 -4
- package/src/containers/Panel.vue +1 -1
- package/src/containers/Table.vue +11 -5
- package/src/fields/Link.vue +1 -1
- package/src/fields/Text.vue +69 -25
- package/src/index.ts +5 -0
- package/src/schema.ts +2 -1
- package/src/theme/index.scss +1 -0
- package/src/theme/table.scss +4 -0
- package/src/theme/text.scss +6 -0
- package/types/index.d.ts +2 -0
- package/types/schema.d.ts +2 -1
- package/src/utils/createForm.ts +0 -25
- package/types/utils/createForm.d.ts +0 -3
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "1.3.
|
|
2
|
+
"version": "1.3.10",
|
|
3
3
|
"name": "@tmagic/form",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": [
|
|
@@ -32,8 +32,8 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@element-plus/icons-vue": "^2.3.1",
|
|
35
|
-
"@tmagic/design": "1.3.
|
|
36
|
-
"@tmagic/utils": "1.3.
|
|
35
|
+
"@tmagic/design": "1.3.10",
|
|
36
|
+
"@tmagic/utils": "1.3.10",
|
|
37
37
|
"lodash-es": "^4.17.21",
|
|
38
38
|
"sortablejs": "^1.14.0",
|
|
39
39
|
"vue": "^3.3.8"
|
|
@@ -212,7 +212,7 @@
|
|
|
212
212
|
</template>
|
|
213
213
|
|
|
214
214
|
<div style="text-align: center" v-if="config.expand && type !== 'fieldset'">
|
|
215
|
-
<TMagicButton type="primary" size="small" :disabled="false"
|
|
215
|
+
<TMagicButton type="primary" size="small" :disabled="false" link @click="expandHandler">{{
|
|
216
216
|
expand ? '收起配置' : '展开更多配置'
|
|
217
217
|
}}</TMagicButton>
|
|
218
218
|
</div>
|
|
@@ -312,6 +312,7 @@ const type = computed((): string => {
|
|
|
312
312
|
});
|
|
313
313
|
}
|
|
314
314
|
if (type === 'form') return '';
|
|
315
|
+
if (type === 'container') return '';
|
|
315
316
|
return type?.replace(/([A-Z])/g, '-$1').toLowerCase() || (items.value ? '' : 'text');
|
|
316
317
|
});
|
|
317
318
|
|
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<div class="m-fields-group-list-item">
|
|
3
3
|
<div>
|
|
4
|
-
<TMagicButton
|
|
4
|
+
<TMagicButton link :disabled="disabled" :icon="expand ? CaretBottom : CaretRight" @click="expandHandler">{{
|
|
5
5
|
title
|
|
6
6
|
}}</TMagicButton>
|
|
7
7
|
|
|
8
8
|
<TMagicButton
|
|
9
9
|
v-show="showDelete(parseInt(String(index)))"
|
|
10
10
|
style="color: #f56c6c"
|
|
11
|
-
|
|
11
|
+
link
|
|
12
12
|
:icon="Delete"
|
|
13
13
|
:disabled="disabled"
|
|
14
14
|
@click="removeHandler"
|
|
15
15
|
></TMagicButton>
|
|
16
16
|
|
|
17
17
|
<template v-if="movable()">
|
|
18
|
-
<TMagicButton v-show="index !== 0"
|
|
18
|
+
<TMagicButton v-show="index !== 0" link :disabled="disabled" size="small" @click="changeOrder(-1)"
|
|
19
19
|
>上移<TMagicIcon><CaretTop /></TMagicIcon
|
|
20
20
|
></TMagicButton>
|
|
21
|
-
<TMagicButton v-show="index !== length - 1" :disabled="disabled"
|
|
21
|
+
<TMagicButton v-show="index !== length - 1" :disabled="disabled" link size="small" @click="changeOrder(1)"
|
|
22
22
|
>下移<TMagicIcon><CaretBottom /></TMagicIcon
|
|
23
23
|
></TMagicButton>
|
|
24
24
|
</template>
|
package/src/containers/Panel.vue
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
>
|
|
7
7
|
<template #header>
|
|
8
8
|
<div style="width: 100%; display: flex; align-items: center">
|
|
9
|
-
<TMagicButton style="padding: 0"
|
|
9
|
+
<TMagicButton style="padding: 0" link :icon="expand ? CaretBottom : CaretRight" @click="expand = !expand">
|
|
10
10
|
</TMagicButton>
|
|
11
11
|
<span v-if="config && config.extra" v-html="config.extra" class="m-form-tip"></span>
|
|
12
12
|
<slot name="header">{{ filter(config.title) }}</slot>
|
package/src/containers/Table.vue
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div>
|
|
2
|
+
<div class="m-fields-table-wrap">
|
|
3
3
|
<teleport to="body" :disabled="!isFullscreen">
|
|
4
4
|
<div ref="mTable" class="m-fields-table" :class="{ 'm-fields-table-item-extra': config.itemExtra }">
|
|
5
5
|
<span v-if="config.extra" style="color: rgba(0, 0, 0, 0.45)" v-html="config.extra"></span>
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
type="primary"
|
|
55
55
|
:icon="ArrowUp"
|
|
56
56
|
:disabled="disabled"
|
|
57
|
-
|
|
57
|
+
link
|
|
58
58
|
@click="upHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
59
59
|
@dblclick="topHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
60
60
|
></TMagicButton>
|
|
@@ -70,7 +70,7 @@
|
|
|
70
70
|
type="primary"
|
|
71
71
|
:icon="ArrowDown"
|
|
72
72
|
:disabled="disabled"
|
|
73
|
-
|
|
73
|
+
link
|
|
74
74
|
@click="downHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
75
75
|
@dblclick="bottomHandler(scope.$index + 1 + pagecontext * pagesize - 1)"
|
|
76
76
|
></TMagicButton>
|
|
@@ -202,6 +202,7 @@ import {
|
|
|
202
202
|
TMagicTableColumn,
|
|
203
203
|
TMagicTooltip,
|
|
204
204
|
TMagicUpload,
|
|
205
|
+
useZIndex,
|
|
205
206
|
} from '@tmagic/design';
|
|
206
207
|
import { asyncLoadJs, sleep } from '@tmagic/utils';
|
|
207
208
|
|
|
@@ -246,6 +247,8 @@ const emit = defineEmits(['change', 'select', 'addDiffCount']);
|
|
|
246
247
|
let timer: any | null = null;
|
|
247
248
|
const mForm = inject<FormState | undefined>('mForm');
|
|
248
249
|
|
|
250
|
+
const { nextZIndex } = useZIndex();
|
|
251
|
+
|
|
249
252
|
const tMagicTable = ref<InstanceType<typeof TMagicTable>>();
|
|
250
253
|
const excelBtn = ref<InstanceType<typeof TMagicUpload>>();
|
|
251
254
|
const mTable = ref<HTMLDivElement>();
|
|
@@ -620,11 +623,14 @@ const toggleMode = () => {
|
|
|
620
623
|
};
|
|
621
624
|
|
|
622
625
|
const toggleFullscreen = () => {
|
|
626
|
+
if (!mTable.value) return;
|
|
627
|
+
|
|
623
628
|
if (isFullscreen.value) {
|
|
624
|
-
mTable.value
|
|
629
|
+
mTable.value.classList.remove('fixed');
|
|
625
630
|
isFullscreen.value = false;
|
|
626
631
|
} else {
|
|
627
|
-
mTable.value
|
|
632
|
+
mTable.value.classList.add('fixed');
|
|
633
|
+
mTable.value.style.zIndex = `${nextZIndex()}`;
|
|
628
634
|
isFullscreen.value = true;
|
|
629
635
|
}
|
|
630
636
|
};
|
package/src/fields/Link.vue
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<a v-if="config.href && !disabled" target="_blank" :href="href" :style="config.css || {}">{{ displayText }}</a>
|
|
3
3
|
<span v-else-if="config.href && disabled" :style="config.disabledCss || {}">{{ displayText }}</span>
|
|
4
4
|
<div v-else class="m-fields-link">
|
|
5
|
-
<TMagicButton
|
|
5
|
+
<TMagicButton link type="primary" @click="editHandler">点击编辑</TMagicButton>
|
|
6
6
|
<FormDialog
|
|
7
7
|
ref="editor"
|
|
8
8
|
:title="config.formTitle || '编辑扩展配置'"
|
package/src/fields/Text.vue
CHANGED
|
@@ -1,32 +1,43 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
:disabled="disabled"
|
|
8
|
-
@change="changeHandler"
|
|
9
|
-
@input="inputHandler"
|
|
10
|
-
@keyup="keyUpHandler($event)"
|
|
11
|
-
>
|
|
12
|
-
<template #append v-if="config.append">
|
|
13
|
-
<span v-if="typeof config.append === 'string'">{{ config.append }}</span>
|
|
14
|
-
<TMagicButton
|
|
15
|
-
v-if="typeof config.append === 'object' && config.append.type === 'button'"
|
|
16
|
-
style="color: #409eff"
|
|
2
|
+
<TMagicPopover :visible="popoverVisible" width="220px">
|
|
3
|
+
<template #reference>
|
|
4
|
+
<TMagicInput
|
|
5
|
+
v-model="model[name]"
|
|
6
|
+
clearable
|
|
17
7
|
:size="size"
|
|
18
|
-
|
|
8
|
+
:placeholder="config.placeholder"
|
|
9
|
+
:disabled="disabled"
|
|
10
|
+
@change="changeHandler"
|
|
11
|
+
@input="inputHandler"
|
|
12
|
+
@keyup="keyUpHandler($event)"
|
|
19
13
|
>
|
|
20
|
-
|
|
21
|
-
|
|
14
|
+
<template #append v-if="appendConfig">
|
|
15
|
+
<TMagicButton
|
|
16
|
+
v-if="appendConfig.type === 'button'"
|
|
17
|
+
style="color: #409eff"
|
|
18
|
+
:size="size"
|
|
19
|
+
@click.prevent="buttonClickHandler"
|
|
20
|
+
>
|
|
21
|
+
{{ appendConfig.text }}
|
|
22
|
+
</TMagicButton>
|
|
23
|
+
</template>
|
|
24
|
+
</TMagicInput>
|
|
22
25
|
</template>
|
|
23
|
-
|
|
26
|
+
|
|
27
|
+
<div class="m-form-item__content">
|
|
28
|
+
<div class="m-form-validate__warning">输入内容前后有空格,是否移除空格?</div>
|
|
29
|
+
<div style="display: flex; justify-content: flex-end">
|
|
30
|
+
<TMagicButton type="text" size="small" @click="popoverVisible = false">保持原样</TMagicButton>
|
|
31
|
+
<TMagicButton type="primary" size="small" @click="confirmTrimHandler">移除空格</TMagicButton>
|
|
32
|
+
</div>
|
|
33
|
+
</div>
|
|
34
|
+
</TMagicPopover>
|
|
24
35
|
</template>
|
|
25
36
|
|
|
26
37
|
<script lang="ts" setup>
|
|
27
|
-
import { inject } from 'vue';
|
|
38
|
+
import { computed, inject, ref } from 'vue';
|
|
28
39
|
|
|
29
|
-
import { TMagicButton, TMagicInput } from '@tmagic/design';
|
|
40
|
+
import { TMagicButton, TMagicInput, TMagicPopover } from '@tmagic/design';
|
|
30
41
|
import { isNumber } from '@tmagic/utils';
|
|
31
42
|
|
|
32
43
|
import type { FieldProps, FormState, TextConfig } from '../schema';
|
|
@@ -47,20 +58,53 @@ useAddField(props.prop);
|
|
|
47
58
|
|
|
48
59
|
const mForm = inject<FormState | undefined>('mForm');
|
|
49
60
|
|
|
61
|
+
const appendConfig = computed(() => {
|
|
62
|
+
if (typeof props.config.append === 'string') {
|
|
63
|
+
return {
|
|
64
|
+
text: props.config.append,
|
|
65
|
+
type: 'button',
|
|
66
|
+
handler: undefined,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (props.config.append && typeof props.config.append === 'object') {
|
|
71
|
+
if (props.config.append.value === 0) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return props.config.append;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return false;
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
const popoverVisible = ref(false);
|
|
82
|
+
|
|
83
|
+
const confirmTrimHandler = () => {
|
|
84
|
+
emit('change', props.model[props.name].trim() || '');
|
|
85
|
+
popoverVisible.value = false;
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const checkWhiteSpace = (value: unknown) => {
|
|
89
|
+
if (typeof value === 'string' && !props.config.trim) {
|
|
90
|
+
popoverVisible.value = value.trim() !== value;
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
50
94
|
const changeHandler = (value: string) => {
|
|
51
95
|
emit('change', value);
|
|
52
96
|
};
|
|
53
97
|
|
|
54
98
|
const inputHandler = (v: string) => {
|
|
99
|
+
checkWhiteSpace(v);
|
|
55
100
|
emit('input', v);
|
|
56
101
|
mForm?.$emit('field-input', props.prop, v);
|
|
57
102
|
};
|
|
58
103
|
|
|
59
104
|
const buttonClickHandler = () => {
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
props.config.append.handler(mForm, {
|
|
105
|
+
if (!appendConfig.value) return;
|
|
106
|
+
if (typeof appendConfig.value.handler === 'function') {
|
|
107
|
+
appendConfig.value.handler(mForm, {
|
|
64
108
|
model: props.model,
|
|
65
109
|
values: mForm?.values,
|
|
66
110
|
});
|
package/src/index.ts
CHANGED
|
@@ -49,6 +49,7 @@ import Timerange from './fields/Timerange.vue';
|
|
|
49
49
|
import { setConfig } from './utils/config';
|
|
50
50
|
import Form from './Form.vue';
|
|
51
51
|
import FormDialog from './FormDialog.vue';
|
|
52
|
+
import type { FormConfig } from './schema';
|
|
52
53
|
|
|
53
54
|
import './theme/index.scss';
|
|
54
55
|
|
|
@@ -88,6 +89,10 @@ export { default as MSelect } from './fields/Select.vue';
|
|
|
88
89
|
export { default as MCascader } from './fields/Cascader.vue';
|
|
89
90
|
export { default as MDynamicField } from './fields/DynamicField.vue';
|
|
90
91
|
|
|
92
|
+
export const createForm = function (config: FormConfig) {
|
|
93
|
+
return config;
|
|
94
|
+
};
|
|
95
|
+
|
|
91
96
|
export interface InstallOptions {
|
|
92
97
|
[key: string]: any;
|
|
93
98
|
}
|
package/src/schema.ts
CHANGED
package/src/theme/index.scss
CHANGED
package/src/theme/table.scss
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { App } from 'vue';
|
|
2
|
+
import type { FormConfig } from './schema';
|
|
2
3
|
import './theme/index.scss';
|
|
3
4
|
export * from './schema';
|
|
4
5
|
export * from './utils/form';
|
|
@@ -34,6 +35,7 @@ export { default as MLink } from './fields/Link.vue';
|
|
|
34
35
|
export { default as MSelect } from './fields/Select.vue';
|
|
35
36
|
export { default as MCascader } from './fields/Cascader.vue';
|
|
36
37
|
export { default as MDynamicField } from './fields/DynamicField.vue';
|
|
38
|
+
export declare const createForm: (config: FormConfig) => FormConfig;
|
|
37
39
|
export interface InstallOptions {
|
|
38
40
|
[key: string]: any;
|
|
39
41
|
}
|
package/types/schema.d.ts
CHANGED
|
@@ -248,8 +248,9 @@ export interface TextConfig extends FormItem, Input {
|
|
|
248
248
|
/** 后置元素,一般为标签或按钮 */
|
|
249
249
|
append?: string | {
|
|
250
250
|
text: string;
|
|
251
|
+
value?: 0 | 1;
|
|
251
252
|
type: 'button';
|
|
252
|
-
handler
|
|
253
|
+
handler?: (mForm: FormState | undefined, data: {
|
|
253
254
|
model: any;
|
|
254
255
|
values: any;
|
|
255
256
|
}) => void;
|
package/src/utils/createForm.ts
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Tencent is pleased to support the open source community by making TMagicEditor available.
|
|
3
|
-
*
|
|
4
|
-
* Copyright (C) 2023 THL A29 Limited, a Tencent company. All rights reserved.
|
|
5
|
-
*
|
|
6
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
-
* you may not use this file except in compliance with the License.
|
|
8
|
-
* You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
-
* See the License for the specific language governing permissions and
|
|
16
|
-
* limitations under the License.
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import { FormConfig } from '../schema';
|
|
20
|
-
|
|
21
|
-
export const createForm = function (config: FormConfig) {
|
|
22
|
-
return config;
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
export default createForm;
|