Commit 498278660112a52b7c6e608159d20920d6047e04

Authored by vben
1 parent 81baf1d5

fix(form): fix updateSchema error #100

src/components/Form/index.ts
1 -export { default as BasicForm } from './src/BasicForm.vue'; 1 +import BasicFormLib from './src/BasicForm.vue';
  2 +import { withInstall } from '../util';
2 3
3 export * from './src/types/form'; 4 export * from './src/types/form';
4 export * from './src/types/formItem'; 5 export * from './src/types/formItem';
5 6
6 export { useComponentRegister } from './src/hooks/useComponentRegister'; 7 export { useComponentRegister } from './src/hooks/useComponentRegister';
7 export { useForm } from './src/hooks/useForm'; 8 export { useForm } from './src/hooks/useForm';
  9 +
  10 +export const BasicForm = withInstall(BasicFormLib);
src/components/Form/src/BasicForm.vue
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 </template> 16 </template>
17 </FormItem> 17 </FormItem>
18 </template> 18 </template>
  19 +
19 <FormAction 20 <FormAction
20 v-bind="{ ...getActionPropsRef, ...advanceState }" 21 v-bind="{ ...getActionPropsRef, ...advanceState }"
21 @toggle-advanced="handleToggleAdvanced" 22 @toggle-advanced="handleToggleAdvanced"
@@ -30,7 +31,17 @@ @@ -30,7 +31,17 @@
30 import type { Ref, WatchStopHandle } from 'vue'; 31 import type { Ref, WatchStopHandle } from 'vue';
31 import type { ValidateFields } from 'ant-design-vue/lib/form/interface'; 32 import type { ValidateFields } from 'ant-design-vue/lib/form/interface';
32 33
33 - import { defineComponent, reactive, ref, computed, unref, toRef, onMounted, watch } from 'vue'; 34 + import {
  35 + defineComponent,
  36 + reactive,
  37 + ref,
  38 + computed,
  39 + unref,
  40 + toRef,
  41 + onMounted,
  42 + watch,
  43 + toRefs,
  44 + } from 'vue';
34 import { Form, Row } from 'ant-design-vue'; 45 import { Form, Row } from 'ant-design-vue';
35 import FormItem from './FormItem'; 46 import FormItem from './FormItem';
36 import { basicProps } from './props'; 47 import { basicProps } from './props';
@@ -103,6 +114,7 @@ @@ -103,6 +114,7 @@
103 const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any); 114 const schemas: FormSchema[] = unref(schemaRef) || (unref(getProps).schemas as any);
104 for (const schema of schemas) { 115 for (const schema of schemas) {
105 const { defaultValue, component } = schema; 116 const { defaultValue, component } = schema;
  117 + // handle date type
106 if (defaultValue && dateItemType.includes(component)) { 118 if (defaultValue && dateItemType.includes(component)) {
107 if (!Array.isArray(defaultValue)) { 119 if (!Array.isArray(defaultValue)) {
108 schema.defaultValue = moment(defaultValue); 120 schema.defaultValue = moment(defaultValue);
@@ -127,10 +139,10 @@ @@ -127,10 +139,10 @@
127 formModel, 139 formModel,
128 defaultValueRef, 140 defaultValueRef,
129 }); 141 });
130 - 142 + const { transformDateFunc, fieldMapToTime } = toRefs(props);
131 const { handleFormValues, initDefault } = useFormValues({ 143 const { handleFormValues, initDefault } = useFormValues({
132 - transformDateFuncRef: toRef(props, 'transformDateFunc') as Ref<Fn<any>>,  
133 - fieldMapToTimeRef: toRef(props, 'fieldMapToTime'), 144 + transformDateFuncRef: transformDateFunc as Ref<Fn<any>>,
  145 + fieldMapToTimeRef: fieldMapToTime,
134 defaultValueRef, 146 defaultValueRef,
135 getSchema, 147 getSchema,
136 formModel, 148 formModel,
src/components/Form/src/FormAction.tsx
@@ -7,28 +7,17 @@ import { BasicArrow } from &#39;/@/components/Basic/index&#39;; @@ -7,28 +7,17 @@ import { BasicArrow } from &#39;/@/components/Basic/index&#39;;
7 7
8 import { getSlot } from '/@/utils/helper/tsxHelper'; 8 import { getSlot } from '/@/utils/helper/tsxHelper';
9 import { useI18n } from '/@/hooks/web/useI18n'; 9 import { useI18n } from '/@/hooks/web/useI18n';
  10 +import { propTypes } from '/@/utils/propTypes';
10 11
11 const { t } = useI18n('component.form'); 12 const { t } = useI18n('component.form');
12 13
13 export default defineComponent({ 14 export default defineComponent({
14 name: 'BasicFormAction', 15 name: 'BasicFormAction',
15 props: { 16 props: {
16 - show: {  
17 - type: Boolean,  
18 - default: true,  
19 - },  
20 - showResetButton: {  
21 - type: Boolean,  
22 - default: true,  
23 - },  
24 - showSubmitButton: {  
25 - type: Boolean,  
26 - default: true,  
27 - },  
28 - showAdvancedButton: {  
29 - type: Boolean,  
30 - default: true,  
31 - }, 17 + show: propTypes.bool.def(true),
  18 + showResetButton: propTypes.bool.def(true),
  19 + showSubmitButton: propTypes.bool.def(true),
  20 + showAdvancedButton: propTypes.bool.def(true),
32 resetButtonOptions: { 21 resetButtonOptions: {
33 type: Object as PropType<any>, 22 type: Object as PropType<any>,
34 default: {}, 23 default: {},
@@ -41,18 +30,9 @@ export default defineComponent({ @@ -41,18 +30,9 @@ export default defineComponent({
41 type: Object as PropType<any>, 30 type: Object as PropType<any>,
42 default: {}, 31 default: {},
43 }, 32 },
44 - actionSpan: {  
45 - type: Number,  
46 - default: 6,  
47 - },  
48 - isAdvanced: {  
49 - type: Boolean,  
50 - default: false,  
51 - },  
52 - hideAdvanceBtn: {  
53 - type: Boolean,  
54 - default: false,  
55 - }, 33 + actionSpan: propTypes.number.def(6),
  34 + isAdvanced: propTypes.bool,
  35 + hideAdvanceBtn: propTypes.bool,
56 }, 36 },
57 emits: ['toggle-advanced'], 37 emits: ['toggle-advanced'],
58 setup(props, { slots, emit }) { 38 setup(props, { slots, emit }) {
@@ -87,19 +67,53 @@ export default defineComponent({ @@ -87,19 +67,53 @@ export default defineComponent({
87 emit('toggle-advanced'); 67 emit('toggle-advanced');
88 } 68 }
89 69
  70 + function renderAdvanceButton() {
  71 + const { showAdvancedButton, hideAdvanceBtn, isAdvanced } = props;
  72 +
  73 + if (!showAdvancedButton || !!hideAdvanceBtn) {
  74 + return null;
  75 + }
  76 + return (
  77 + <Button type="default" class="mr-2" onClick={toggleAdvanced}>
  78 + {() => (
  79 + <>
  80 + {isAdvanced ? t('putAway') : t('unfold')}
  81 + <BasicArrow expand={!isAdvanced} top />
  82 + </>
  83 + )}
  84 + </Button>
  85 + );
  86 + }
  87 +
  88 + function renderResetButton() {
  89 + const { showResetButton } = props;
  90 + if (!showResetButton) {
  91 + return null;
  92 + }
  93 + return (
  94 + <Button type="default" class="mr-2" {...unref(getResetBtnOptionsRef)}>
  95 + {() => unref(getResetBtnOptionsRef).text}
  96 + </Button>
  97 + );
  98 + }
  99 +
  100 + function renderSubmitButton() {
  101 + const { showSubmitButton } = props;
  102 + if (!showSubmitButton) {
  103 + return null;
  104 + }
  105 + return (
  106 + <Button type="primary" {...unref(getSubmitBtnOptionsRef)}>
  107 + {() => unref(getSubmitBtnOptionsRef).text}
  108 + </Button>
  109 + );
  110 + }
  111 +
90 return () => { 112 return () => {
91 if (!props.show) { 113 if (!props.show) {
92 - return; 114 + return null;
93 } 115 }
94 116
95 - const {  
96 - showAdvancedButton,  
97 - hideAdvanceBtn,  
98 - isAdvanced,  
99 - showResetButton,  
100 - showSubmitButton,  
101 - } = props;  
102 -  
103 return ( 117 return (
104 <Col {...unref(actionColOpt)} style={{ textAlign: 'right' }}> 118 <Col {...unref(actionColOpt)} style={{ textAlign: 'right' }}>
105 {() => ( 119 {() => (
@@ -107,30 +121,13 @@ export default defineComponent({ @@ -107,30 +121,13 @@ export default defineComponent({
107 {() => ( 121 {() => (
108 <> 122 <>
109 {getSlot(slots, 'advanceBefore')} 123 {getSlot(slots, 'advanceBefore')}
110 - {showAdvancedButton && !hideAdvanceBtn && (  
111 - <Button type="default" class="mr-2" onClick={toggleAdvanced}>  
112 - {() => (  
113 - <>  
114 - {isAdvanced ? t('putAway') : t('unfold')}  
115 - <BasicArrow expand={!isAdvanced} top />  
116 - </>  
117 - )}  
118 - </Button>  
119 - )} 124 + {renderAdvanceButton()}
120 125
121 {getSlot(slots, 'resetBefore')} 126 {getSlot(slots, 'resetBefore')}
122 - {showResetButton && (  
123 - <Button type="default" class="mr-2" {...unref(getResetBtnOptionsRef)}>  
124 - {() => unref(getResetBtnOptionsRef).text}  
125 - </Button>  
126 - )} 127 + {renderResetButton()}
127 128
128 {getSlot(slots, 'submitBefore')} 129 {getSlot(slots, 'submitBefore')}
129 - {showSubmitButton && (  
130 - <Button type="primary" {...unref(getSubmitBtnOptionsRef)}>  
131 - {() => unref(getSubmitBtnOptionsRef).text}  
132 - </Button>  
133 - )} 130 + {renderSubmitButton()}
134 131
135 {getSlot(slots, 'submitAfter')} 132 {getSlot(slots, 'submitAfter')}
136 </> 133 </>
src/components/Form/src/props.ts
@@ -5,7 +5,7 @@ import { TableActionType } from &#39;/@/components/Table&#39;; @@ -5,7 +5,7 @@ import { TableActionType } from &#39;/@/components/Table&#39;;
5 5
6 export const basicProps = { 6 export const basicProps = {
7 model: { 7 model: {
8 - type: Object as PropType<any>, 8 + type: Object as PropType<Record<string, any>>,
9 default: {}, 9 default: {},
10 }, 10 },
11 // ๆ ‡็ญพๅฎฝๅบฆ ๅ›บๅฎšๅฎฝๅบฆ 11 // ๆ ‡็ญพๅฎฝๅบฆ ๅ›บๅฎšๅฎฝๅบฆ
src/router/menus/index.ts
@@ -13,7 +13,9 @@ import modules from &#39;globby!/@/router/menus/modules/**/*.@(ts)&#39;; @@ -13,7 +13,9 @@ import modules from &#39;globby!/@/router/menus/modules/**/*.@(ts)&#39;;
13 const menuModules: MenuModule[] = []; 13 const menuModules: MenuModule[] = [];
14 14
15 Object.keys(modules).forEach((key) => { 15 Object.keys(modules).forEach((key) => {
16 - menuModules.push(modules[key]); 16 + const moduleItem = modules[key];
  17 + const menuModule = Array.isArray(moduleItem) ? [...moduleItem] : [moduleItem];
  18 + menuModules.push(...menuModule);
17 }); 19 });
18 20
19 // =========================== 21 // ===========================
@@ -25,6 +27,7 @@ const staticMenus: Menu[] = []; @@ -25,6 +27,7 @@ const staticMenus: Menu[] = [];
25 menuModules.sort((a, b) => { 27 menuModules.sort((a, b) => {
26 return (a.orderNo || 0) - (b.orderNo || 0); 28 return (a.orderNo || 0) - (b.orderNo || 0);
27 }); 29 });
  30 +
28 for (const menu of menuModules) { 31 for (const menu of menuModules) {
29 staticMenus.push(transformMenuModule(menu)); 32 staticMenus.push(transformMenuModule(menu));
30 } 33 }
src/router/menus/modules/dashboard.ts
1 import type { MenuModule } from '/@/router/types.d'; 1 import type { MenuModule } from '/@/router/types.d';
2 2
3 -const menu: MenuModule = {  
4 - orderNo: 10,  
5 - menu: {  
6 - name: 'routes.dashboard.dashboard',  
7 - path: '/dashboard',  
8 - children: [  
9 - {  
10 - path: '/workbench',  
11 - name: 'routes.dashboard.workbench',  
12 - },  
13 - {  
14 - path: '/analysis',  
15 - name: 'routes.dashboard.analysis',  
16 - },  
17 - {  
18 - path: '/welcome',  
19 - name: 'routes.dashboard.welcome',  
20 - },  
21 - ], 3 +const menu: MenuModule[] = [
  4 + {
  5 + orderNo: 0,
  6 + menu: {
  7 + path: '/dashboard/welcome',
  8 + name: 'routes.dashboard.welcome',
  9 + },
22 }, 10 },
23 -}; 11 + {
  12 + orderNo: 10,
  13 + menu: {
  14 + name: 'routes.dashboard.dashboard',
  15 + path: '/dashboard',
  16 + children: [
  17 + {
  18 + path: '/workbench',
  19 + name: 'routes.dashboard.workbench',
  20 + },
  21 + {
  22 + path: '/analysis',
  23 + name: 'routes.dashboard.analysis',
  24 + },
  25 + // {
  26 + // path: '/welcome',
  27 + // name: 'routes.dashboard.welcome',
  28 + // },
  29 + ],
  30 + },
  31 + },
  32 +];
24 export default menu; 33 export default menu;
src/router/routes/modules/dashboard.ts
@@ -7,7 +7,7 @@ const dashboard: AppRouteModule = { @@ -7,7 +7,7 @@ const dashboard: AppRouteModule = {
7 path: '/dashboard', 7 path: '/dashboard',
8 name: 'Dashboard', 8 name: 'Dashboard',
9 component: PAGE_LAYOUT_COMPONENT, 9 component: PAGE_LAYOUT_COMPONENT,
10 - redirect: '/dashboard/workbench', 10 + redirect: '/dashboard/welcome',
11 meta: { 11 meta: {
12 icon: 'ant-design:home-outlined', 12 icon: 'ant-design:home-outlined',
13 title: 'routes.dashboard.dashboard', 13 title: 'routes.dashboard.dashboard',
@@ -21,6 +21,8 @@ const dashboard: AppRouteModule = { @@ -21,6 +21,8 @@ const dashboard: AppRouteModule = {
21 component: () => import('/@/views/dashboard/welcome/index.vue'), 21 component: () => import('/@/views/dashboard/welcome/index.vue'),
22 meta: { 22 meta: {
23 title: 'routes.dashboard.welcome', 23 title: 'routes.dashboard.welcome',
  24 + affix: true,
  25 + icon: 'ant-design:home-outlined',
24 }, 26 },
25 }, 27 },
26 { 28 {
@@ -29,7 +31,6 @@ const dashboard: AppRouteModule = { @@ -29,7 +31,6 @@ const dashboard: AppRouteModule = {
29 component: () => import('/@/views/dashboard/workbench/index.vue'), 31 component: () => import('/@/views/dashboard/workbench/index.vue'),
30 meta: { 32 meta: {
31 title: 'routes.dashboard.workbench', 33 title: 'routes.dashboard.workbench',
32 - affix: true,  
33 }, 34 },
34 }, 35 },
35 { 36 {
src/utils/index.ts
1 export const timestamp = () => +Date.now(); 1 export const timestamp = () => +Date.now();
  2 +import { isObject } from '/@/utils/is';
2 export const clamp = (n: number, min: number, max: number) => Math.min(max, Math.max(min, n)); 3 export const clamp = (n: number, min: number, max: number) => Math.min(max, Math.max(min, n));
3 export const noop = () => {}; 4 export const noop = () => {};
4 export const now = () => Date.now(); 5 export const now = () => Date.now();
@@ -40,10 +41,7 @@ export function setObjToUrlParams(baseUrl: string, obj: any): string { @@ -40,10 +41,7 @@ export function setObjToUrlParams(baseUrl: string, obj: any): string {
40 export function deepMerge<T = any>(src: any, target: any): T { 41 export function deepMerge<T = any>(src: any, target: any): T {
41 let key: string; 42 let key: string;
42 for (key in target) { 43 for (key in target) {
43 - src[key] =  
44 - src[key] && src[key].toString() === '[object Object]'  
45 - ? deepMerge(src[key], target[key])  
46 - : (src[key] = target[key]); 44 + src[key] = isObject(src[key]) ? deepMerge(src[key], target[key]) : (src[key] = target[key]);
47 } 45 }
48 return src; 46 return src;
49 } 47 }
vite.config.ts
@@ -89,7 +89,7 @@ const viteConfig: UserConfig = { @@ -89,7 +89,7 @@ const viteConfig: UserConfig = {
89 * Transpile target for esbuild. 89 * Transpile target for esbuild.
90 * @default 'es2020' 90 * @default 'es2020'
91 */ 91 */
92 - esbuildTarget: 'es2020', 92 + esbuildTarget: 'es2019',
93 /** 93 /**
94 * Whether to log asset info to console 94 * Whether to log asset info to console
95 * @default false 95 * @default false