diff --git a/packages/form/package.json b/packages/form/package.json index 91787a0f..ae73de35 100644 --- a/packages/form/package.json +++ b/packages/form/package.json @@ -35,14 +35,13 @@ }, "dependencies": { "@element-plus/icons-vue": "^2.0.9", + "@tmagic/design": "1.2.0-beta.2", "@tmagic/utils": "1.2.0-beta.2", - "element-plus": "^2.2.17", "lodash-es": "^4.17.21", "sortablejs": "^1.14.0", "vue": "^3.2.37" }, "peerDependencies": { - "element-plus": "^2.2.17", "vue": "^3.2.37" }, "devDependencies": { diff --git a/packages/form/src/Form.vue b/packages/form/src/Form.vue index c8d7b3d9..4bd33d99 100644 --- a/packages/form/src/Form.vue +++ b/packages/form/src/Form.vue @@ -1,7 +1,7 @@ - diff --git a/packages/form/src/FormDialog.vue b/packages/form/src/FormDialog.vue index 0c8e9cbe..3cb5e38d 100644 --- a/packages/form/src/FormDialog.vue +++ b/packages/form/src/FormDialog.vue @@ -1,5 +1,5 @@ - diff --git a/packages/form/src/containers/Col.vue b/packages/form/src/containers/Col.vue index 4e7718a9..ca776ff5 100644 --- a/packages/form/src/containers/Col.vue +++ b/packages/form/src/containers/Col.vue @@ -1,6 +1,6 @@ - diff --git a/packages/form/src/containers/Container.vue b/packages/form/src/containers/Container.vue index 73bb8e46..659ab0ed 100644 --- a/packages/form/src/containers/Container.vue +++ b/packages/form/src/containers/Container.vue @@ -30,7 +30,7 @@ > - +
- + - - + + - +
- {{ expand ? '收起配置' : '展开更多配置' }} + {{ expand ? '收起配置' : '展开更多配置' }}
- diff --git a/packages/form/src/containers/Fieldset.vue b/packages/form/src/containers/Fieldset.vue index 33a50536..876fca48 100644 --- a/packages/form/src/containers/Fieldset.vue +++ b/packages/form/src/containers/Fieldset.vue @@ -5,13 +5,13 @@ :style="show ? 'padding: 15px 15px 0 5px;' : 'border: 0'" > - + > @@ -20,7 +20,7 @@
- + >
@@ -55,8 +55,12 @@ diff --git a/packages/form/src/containers/GroupListItem.vue b/packages/form/src/containers/GroupListItem.vue index 78040efb..d218ea93 100644 --- a/packages/form/src/containers/GroupListItem.vue +++ b/packages/form/src/containers/GroupListItem.vue @@ -1,33 +1,33 @@ - diff --git a/packages/form/src/containers/Panel.vue b/packages/form/src/containers/Panel.vue index 081caefc..2b61cff6 100644 --- a/packages/form/src/containers/Panel.vue +++ b/packages/form/src/containers/Panel.vue @@ -1,5 +1,5 @@ - diff --git a/packages/form/src/containers/Row.vue b/packages/form/src/containers/Row.vue index da07d110..9bb9bfde 100644 --- a/packages/form/src/containers/Row.vue +++ b/packages/form/src/containers/Row.vue @@ -1,5 +1,5 @@ - diff --git a/packages/form/src/containers/Step.vue b/packages/form/src/containers/Step.vue index 80113d33..5e4c7cef 100644 --- a/packages/form/src/containers/Step.vue +++ b/packages/form/src/containers/Step.vue @@ -1,82 +1,70 @@ - diff --git a/packages/form/src/containers/Table.vue b/packages/form/src/containers/Table.vue index 02baa75d..56f80467 100644 --- a/packages/form/src/containers/Table.vue +++ b/packages/form/src/containers/Table.vue @@ -2,10 +2,10 @@
- - + - + - + - + - + - + - + - + > - + - + - - + + - 添加   - 展开配置添加   + 展开配置 - {{ isFullscreen ? '退出全屏' : '全屏编辑' }} - - + - 导入EXCEL 导入EXCEL   - 清空 + 清空
- - +
- diff --git a/packages/form/src/containers/Tabs.vue b/packages/form/src/containers/Tabs.vue index e3626a8d..7111cc97 100644 --- a/packages/form/src/containers/Tabs.vue +++ b/packages/form/src/containers/Tabs.vue @@ -1,5 +1,5 @@ - diff --git a/packages/form/src/fields/Cascader.vue b/packages/form/src/fields/Cascader.vue index 7eed7eac..08be296a 100644 --- a/packages/form/src/fields/Cascader.vue +++ b/packages/form/src/fields/Cascader.vue @@ -1,146 +1,98 @@ - diff --git a/packages/form/src/fields/Checkbox.vue b/packages/form/src/fields/Checkbox.vue index abd77dab..a6d25d64 100644 --- a/packages/form/src/fields/Checkbox.vue +++ b/packages/form/src/fields/Checkbox.vue @@ -1,67 +1,63 @@ - diff --git a/packages/form/src/fields/CheckboxGroup.vue b/packages/form/src/fields/CheckboxGroup.vue index f276220f..bbf9a8a7 100644 --- a/packages/form/src/fields/CheckboxGroup.vue +++ b/packages/form/src/fields/CheckboxGroup.vue @@ -1,44 +1,42 @@ - diff --git a/packages/form/src/fields/ColorPicker.vue b/packages/form/src/fields/ColorPicker.vue index 4f49c7bc..797dc4bf 100644 --- a/packages/form/src/fields/ColorPicker.vue +++ b/packages/form/src/fields/ColorPicker.vue @@ -1,14 +1,16 @@ diff --git a/packages/form/src/fields/DateTime.vue b/packages/form/src/fields/DateTime.vue index aa178fb1..68665f01 100644 --- a/packages/form/src/fields/DateTime.vue +++ b/packages/form/src/fields/DateTime.vue @@ -1,5 +1,5 @@ - diff --git a/packages/form/src/fields/Daterange.vue b/packages/form/src/fields/Daterange.vue index 7ecb30fa..49484fc7 100644 --- a/packages/form/src/fields/Daterange.vue +++ b/packages/form/src/fields/Daterange.vue @@ -1,5 +1,5 @@ diff --git a/packages/form/src/fields/Link.vue b/packages/form/src/fields/Link.vue index e635e4c2..1b49ad6f 100644 --- a/packages/form/src/fields/Link.vue +++ b/packages/form/src/fields/Link.vue @@ -2,8 +2,8 @@ {{ displayText }} {{ displayText }} - diff --git a/packages/form/src/fields/Number.vue b/packages/form/src/fields/Number.vue index e7ddae2f..585b60ab 100644 --- a/packages/form/src/fields/Number.vue +++ b/packages/form/src/fields/Number.vue @@ -1,5 +1,5 @@ - diff --git a/packages/form/src/fields/RadioGroup.vue b/packages/form/src/fields/RadioGroup.vue index b7a92217..1e75ba14 100644 --- a/packages/form/src/fields/RadioGroup.vue +++ b/packages/form/src/fields/RadioGroup.vue @@ -1,33 +1,33 @@ - diff --git a/packages/form/src/fields/Select.vue b/packages/form/src/fields/Select.vue index 3770222d..0140d18a 100644 --- a/packages/form/src/fields/Select.vue +++ b/packages/form/src/fields/Select.vue @@ -1,10 +1,10 @@ - diff --git a/packages/form/src/fields/SelectOptionGroups.vue b/packages/form/src/fields/SelectOptionGroups.vue index 8e9d7fd3..81a8a404 100644 --- a/packages/form/src/fields/SelectOptionGroups.vue +++ b/packages/form/src/fields/SelectOptionGroups.vue @@ -1,17 +1,19 @@ diff --git a/packages/form/src/fields/Text.vue b/packages/form/src/fields/Text.vue index 02c63c1f..ecfff00b 100644 --- a/packages/form/src/fields/Text.vue +++ b/packages/form/src/fields/Text.vue @@ -1,6 +1,6 @@ - + - diff --git a/packages/form/src/fields/Textarea.vue b/packages/form/src/fields/Textarea.vue index 4a7a673e..4bdb6cb6 100644 --- a/packages/form/src/fields/Textarea.vue +++ b/packages/form/src/fields/Textarea.vue @@ -1,5 +1,5 @@ - diff --git a/packages/form/src/fields/Time.vue b/packages/form/src/fields/Time.vue index 909166d5..5e4305be 100644 --- a/packages/form/src/fields/Time.vue +++ b/packages/form/src/fields/Time.vue @@ -1,46 +1,35 @@ - diff --git a/packages/form/src/index.ts b/packages/form/src/index.ts index b2ed42f3..27dc3c97 100644 --- a/packages/form/src/index.ts +++ b/packages/form/src/index.ts @@ -18,6 +18,8 @@ import { App } from 'vue'; +import TMagicDesign from '@tmagic/design'; + import Container from './containers/Container.vue'; import Fieldset from './containers/Fieldset.vue'; import GroupList from './containers/GroupList.vue'; @@ -53,7 +55,6 @@ import './theme/index.scss'; export * from './schema'; export * from './utils/form'; export * from './utils/useAddField'; -export { default as fieldProps } from './utils/fieldProps'; export { default as MForm } from './Form.vue'; export { default as MFormDialog } from './FormDialog.vue'; @@ -86,40 +87,42 @@ export { default as MDynamicField } from './fields/DynamicField.vue'; const defaultInstallOpt = {}; const install = (app: App, opt: any) => { + app.use(TMagicDesign, opt.uiAdapter); + const option = Object.assign(defaultInstallOpt, opt); // eslint-disable-next-line no-param-reassign app.config.globalProperties.$MAGIC_FORM = option; setConfig(option); - app.component(Form.name, Form); - app.component(FormDialog.name, FormDialog); - app.component(Container.name, Container); + app.component('m-form', Form); + app.component('m-form-dialog', FormDialog); + app.component('m-form-container', Container); app.component('m-form-fieldset', Fieldset); - app.component(GroupList.name, GroupList); - app.component(Panel.name, Panel); - app.component(Row.name, Row); - app.component(MStep.name, MStep); + app.component('m-form-group-list', GroupList); + app.component('m-form-panel', Panel); + app.component('m-form-row', Row); + app.component('m-form-step', MStep); app.component('m-form-table', Table); - app.component(Tabs.name, Tabs); - app.component(Text.name, Text); - app.component(Number.name, Number); - app.component(Textarea.name, Textarea); + app.component('m-form-tab', Tabs); + app.component('m-fields-text', Text); + app.component('m-fields-number', Number); + app.component('m-fields-textarea', Textarea); app.component('m-fields-hidden', Hidden); - app.component(Date.name, Date); - app.component(DateTime.name, DateTime); - app.component(Time.name, Time); - app.component(Checkbox.name, Checkbox); - app.component(Switch.name, Switch); + app.component('m-fields-date', Date); + app.component('m-fields-datetime', DateTime); app.component('m-fields-daterange', Daterange); + app.component('m-fields-time', Time); + app.component('m-fields-checkbox', Checkbox); + app.component('m-fields-switch', Switch); app.component('m-fields-color-picker', ColorPicker); - app.component(CheckboxGroup.name, CheckboxGroup); - app.component(RadioGroup.name, RadioGroup); + app.component('m-fields-checkbox-group', CheckboxGroup); + app.component('m-fields-radio-group', RadioGroup); app.component('m-fields-display', Display); - app.component(Link.name, Link); - app.component(Select.name, Select); - app.component(Cascader.name, Cascader); - app.component(DynamicField.name, DynamicField); + app.component('m-fields-link', Link); + app.component('m-fields-select', Select); + app.component('m-fields-cascader', Cascader); + app.component('m-fields-dynamic-field', DynamicField); }; export default { diff --git a/packages/form/src/schema.ts b/packages/form/src/schema.ts index 9c0b9709..f1ca4531 100644 --- a/packages/form/src/schema.ts +++ b/packages/form/src/schema.ts @@ -16,6 +16,11 @@ * limitations under the License. */ +export interface ValidateError { + message: string; + field: string; +} + /** * 整个表单的数据,会注入到各个组件中去 */ @@ -167,7 +172,7 @@ type DefaultValueFunction = (mForm: FormState | undefined) => any; /** * 下拉选择器选项配置 */ -export interface SelectOption { +export interface SelectConfigOption { /** 选项的标签 */ text: string | SelectOptionTextFunction; /** 选项的值 */ @@ -176,10 +181,19 @@ export interface SelectOption { disabled?: boolean; } +export interface SelectOption { + /** 选项的标签 */ + text: string; + /** 选项的值 */ + value: any; + /** 是否禁用该选项 */ + disabled?: boolean; +} + /** * 下拉选择器分组选项配置 */ -export interface SelectGroupOption { +export interface SelectConfigGroupOption { /** 分组的组名 */ label: string; /** 是否禁用该选项组 */ @@ -194,6 +208,21 @@ export interface SelectGroupOption { }[]; } +export interface SelectGroupOption { + /** 分组的组名 */ + label: string; + /** 是否禁用该选项组 */ + disabled: boolean; + options: { + /** 选项的标签 */ + label: string; + /** 选项的值 */ + value: any; + /** 是否禁用该选项 */ + disabled?: boolean; + }[]; +} + type SelectOptionFunction = ( mForm: FormState | undefined, data: { @@ -226,11 +255,11 @@ type RemoteSelectOptionRequestFunction = ( }, ) => any; -type RemoteSelectOptionItemFunction = (optionsData: Record) => SelectOption[]; +type RemoteSelectOptionItemFunction = (optionsData: Record) => SelectOption[] | SelectGroupOption[]; type SelectOptionValueFunction = (item: Record) => any; type SelectOptionTextFunction = (item: Record) => string; -interface CascaderOption { +export interface CascaderOption { /** 指定选项的值为选项对象的某个属性值 */ value: any; /** 指定选项标签为选项对象的某个属性值 */ @@ -302,7 +331,7 @@ export interface NumberConfig extends FormItem { min?: number; max?: number; step?: number; - placeholder?: number; + placeholder?: string; } /** @@ -361,7 +390,7 @@ export interface SwitchConfig extends FormItem { export interface RadioGroupConfig extends FormItem { type: 'radio-group'; options: { - values: string | number | boolean; + value: string | number | boolean; text: string; }[]; } @@ -381,6 +410,7 @@ export interface CheckboxGroupConfig extends FormItem { options: { value: any; text: string; + disabled?: boolean; }[]; } @@ -394,7 +424,7 @@ export interface SelectConfig extends FormItem, Input { valueKey?: string; allowCreate?: boolean; group?: boolean; - options: SelectOption[] | SelectGroupOption[] | SelectOptionFunction; + options: SelectConfigOption[] | SelectConfigGroupOption[] | SelectOptionFunction; remote: true; option: { url: string; @@ -520,7 +550,7 @@ export interface TabPaneConfig { } export interface TabConfig extends FormItem, ContainerCommonConfig { type: 'tab' | 'dynamic-tab'; - tabType?: 'tab'; + tabType?: string; editable?: boolean; dynamic?: boolean; tabPosition?: 'top' | 'right' | 'bottom' | 'left'; diff --git a/packages/form/src/utils/fieldProps.ts b/packages/form/src/utils/fieldProps.ts deleted file mode 100644 index 2df07ae1..00000000 --- a/packages/form/src/utils/fieldProps.ts +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Tencent is pleased to support the open source community by making TMagicEditor available. - * - * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import { PropType } from 'vue'; - -export default { - model: { - type: Object, - required: true, - default: () => ({}), - }, - name: { - type: String, - default: '', - }, - disabled: { - type: Boolean, - default: false, - }, - size: String as PropType<'mini' | 'small' | 'medium'>, - prop: String, - initValues: Object, - values: Object, -}; diff --git a/packages/form/vite.config.ts b/packages/form/vite.config.ts index 12e56879..b7653ac4 100644 --- a/packages/form/vite.config.ts +++ b/packages/form/vite.config.ts @@ -30,7 +30,10 @@ export default defineConfig({ alias: process.env.NODE_ENV === 'production' ? [] - : [{ find: /^@tmagic\/utils/, replacement: path.join(__dirname, '../utils/src/index.ts') }], + : [ + { find: /^@tmagic\/utils/, replacement: path.join(__dirname, '../utils/src/index.ts') }, + { find: /^@tmagic\/design/, replacement: path.join(__dirname, '../design/src/index.ts') }, + ], }, build: {