Commit 1c075a7a32dd05454bc45d4eb686e2234c3c6175

Authored by vben
1 parent 5cff73bc

fix: reset back to default value after fixing form query

CHANGELOG.zh_CN.md
... ... @@ -3,6 +3,7 @@
3 3 ### 🐛 Bug Fixes
4 4  
5 5 - 修复抽屉组件自动高度及显示 footer 显示问题
  6 +- 修复表单查询后重置回默认值
6 7  
7 8 # 2.0.0-rc.4 (2020-10-21)
8 9  
... ...
lint-staged.config.js
... ... @@ -2,7 +2,7 @@ module.exports = {
2 2 '*.{js,jsx,ts,tsx}': ['eslint --fix', 'prettier --write'],
3 3 '{!(package)*.json,*.code-snippets,.!(browserslist)*rc}': ['prettier --write--parser json'],
4 4 'package.json': ['prettier --write'],
5   - '*.vue': ['prettier --write', 'stylelint --fix', 'git add .'],
6   - '*.{scss,less,styl,css,html}': ['stylelint --fix', 'prettier --write', 'git add .'],
  5 + '*.vue': ['prettier --write', 'stylelint --fix'],
  6 + '*.{scss,less,styl,css,html}': ['stylelint --fix', 'prettier --write'],
7 7 '*.md': ['prettier --write'],
8 8 };
... ...
src/components/Basic/src/BasicArrow.vue
... ... @@ -51,9 +51,6 @@
51 51  
52 52 &__active {
53 53 transform: rotate(90deg);
54   - // > span {
55   - // transform: rotate(90deg);
56   - // }
57 54 }
58 55 }
59 56 </style>
... ...
src/components/Form/src/BasicForm.vue
... ... @@ -6,7 +6,7 @@
6 6 <FormItem
7 7 :schema="schema"
8 8 :formProps="getProps"
9   - :allDefaultValues="getAllDefaultValues"
  9 + :allDefaultValues="defaultValueRef"
10 10 :formModel="formModel"
11 11 >
12 12 <template #[item]="data" v-for="item in Object.keys($slots)">
... ... @@ -56,8 +56,8 @@
56 56  
57 57 export default defineComponent({
58 58 name: 'BasicForm',
59   - inheritAttrs: false,
60 59 components: { FormItem, Form, Row, FormAction },
  60 + inheritAttrs: false,
61 61 props: basicProps,
62 62 emits: ['advanced-change', 'reset', 'submit', 'register'],
63 63 setup(props, { emit }) {
... ... @@ -68,6 +68,7 @@
68 68 isLoad: false,
69 69 actionSpan: 6,
70 70 });
  71 + const defaultValueRef = ref<any>({});
71 72 const propsRef = ref<Partial<FormProps>>({});
72 73 const schemaRef = ref<FormSchema[] | null>(null);
73 74 const formElRef = ref<Nullable<FormType>>(null);
... ... @@ -132,17 +133,6 @@
132 133 return schemas as FormSchema[];
133 134 });
134 135  
135   - const getAllDefaultValues = computed(() => {
136   - const schemas = unref(getSchema);
137   - const obj: any = {};
138   - schemas.forEach((item) => {
139   - if (item.defaultValue) {
140   - obj[item.field] = item.defaultValue;
141   - (formModel as any)[item.field] = item.defaultValue;
142   - }
143   - });
144   - return obj;
145   - });
146 136 const getEmptySpanRef = computed((): number => {
147 137 if (!advanceState.isAdvanced) {
148 138 return 0;
... ... @@ -174,6 +164,19 @@
174 164 },
175 165 { immediate: true }
176 166 );
  167 +
  168 + function initDefault() {
  169 + const schemas = unref(getSchema);
  170 + const obj: any = {};
  171 + schemas.forEach((item) => {
  172 + if (item.defaultValue) {
  173 + obj[item.field] = item.defaultValue;
  174 + (formModel as any)[item.field] = item.defaultValue;
  175 + }
  176 + });
  177 + defaultValueRef.value = obj;
  178 + }
  179 +
177 180 function updateAdvanced() {
178 181 let itemColSum = 0;
179 182 let realItemColSum = 0;
... ... @@ -191,7 +194,7 @@
191 194 model: formModel,
192 195 field: schema.field,
193 196 values: {
194   - ...getAllDefaultValues,
  197 + ...unerf(defaultValueRef),
195 198 ...formModel,
196 199 },
197 200 });
... ... @@ -343,6 +346,7 @@
343 346 }
344 347 schemaRef.value = schemaList as any;
345 348 }
  349 +
346 350 /**
347 351 * @description: 根据字段名删除
348 352 */
... ... @@ -354,6 +358,7 @@
354 358 }
355 359 }
356 360 }
  361 +
357 362 /**
358 363 * @description: 往某个字段后面插入,如果没有插入最后一个
359 364 */
... ... @@ -400,7 +405,6 @@
400 405 }
401 406 });
402 407 });
403   -
404 408 schemaRef.value = unique(schema, 'field') as any;
405 409 }
406 410  
... ... @@ -412,6 +416,7 @@
412 416 toRef(props, 'transformDateFunc'),
413 417 toRef(props, 'fieldMapToTime')
414 418 );
  419 +
415 420 function getFieldsValue(): any {
416 421 const formEl = unref(formElRef);
417 422 if (!formEl) return;
... ... @@ -426,6 +431,7 @@
426 431 return item.field === key ? dateItemType.includes(item.component!) : false;
427 432 });
428 433 }
  434 +
429 435 /**
430 436 * @description:设置表单
431 437 */
... ... @@ -438,6 +444,7 @@
438 444 if (!formElRef.value) return;
439 445 return formElRef.value.validateFields(nameList);
440 446 }
  447 +
441 448 function validate(nameList?: NamePath[] | undefined) {
442 449 if (!formElRef.value) return;
443 450 return formElRef.value.validate(nameList);
... ... @@ -460,14 +467,17 @@
460 467 validateFields: validateFields as ValidateFields,
461 468 validate: validate as ValidateFields,
462 469 };
  470 +
463 471 onMounted(() => {
  472 + initDefault();
464 473 emit('register', methods);
465 474 });
  475 +
466 476 return {
467 477 handleToggleAdvanced,
468 478 formModel,
469 479 getActionPropsRef,
470   - getAllDefaultValues,
  480 + defaultValueRef,
471 481 advanceState,
472 482 getProps,
473 483 formElRef,
... ...
src/components/Table/src/BasicTable.vue
... ... @@ -216,34 +216,36 @@
216 216 fetch();
217 217 }
218 218  
  219 + function handleSummary() {
  220 + if (unref(getMergeProps).showSummary) {
  221 + nextTick(() => {
  222 + const tableEl = unref(tableElRef);
  223 + if (!tableEl) {
  224 + return;
  225 + }
  226 + const bodyDomList = tableEl.$el.querySelectorAll('.ant-table-body') as HTMLDivElement[];
  227 + const bodyDom = bodyDomList[0];
  228 + useEvent({
  229 + el: bodyDom,
  230 + name: 'scroll',
  231 + listener: () => {
  232 + const footerBodyDom = tableEl.$el.querySelector(
  233 + '.ant-table-footer .ant-table-body'
  234 + ) as HTMLDivElement;
  235 + if (!footerBodyDom || !bodyDom) return;
  236 + footerBodyDom.scrollLeft = bodyDom.scrollLeft;
  237 + },
  238 + wait: 0,
  239 + options: true,
  240 + });
  241 + });
  242 + }
  243 + }
  244 +
219 245 watch(
220 246 () => unref(getDataSourceRef),
221 247 () => {
222   - if (unref(getMergeProps).showSummary) {
223   - nextTick(() => {
224   - const tableEl = unref(tableElRef);
225   - if (!tableEl) {
226   - return;
227   - }
228   - const bodyDomList = tableEl.$el.querySelectorAll(
229   - '.ant-table-body'
230   - ) as HTMLDivElement[];
231   - const bodyDom = bodyDomList[0];
232   - useEvent({
233   - el: bodyDom,
234   - name: 'scroll',
235   - listener: () => {
236   - const footerBodyDom = tableEl.$el.querySelector(
237   - '.ant-table-footer .ant-table-body'
238   - ) as HTMLDivElement;
239   - if (!footerBodyDom || !bodyDom) return;
240   - footerBodyDom.scrollLeft = bodyDom.scrollLeft;
241   - },
242   - wait: 0,
243   - options: true,
244   - });
245   - });
246   - }
  248 + handleSummary();
247 249 },
248 250 { immediate: true }
249 251 );
... ...
src/views/demo/table/tableData.tsx
... ... @@ -227,7 +227,33 @@ export const getAdvanceSchema = (itemNumber = 6): FormSchema[] =&gt; {
227 227 export function getFormConfig(): Partial<FormProps> {
228 228 return {
229 229 labelWidth: 100,
230   - schemas: getAdvanceSchema(6),
  230 + schemas: [
  231 + ...getAdvanceSchema(5),
  232 + {
  233 + field: `field11`,
  234 + label: `字段33`,
  235 + component: 'Select',
  236 + defaultValue: '1',
  237 + componentProps: {
  238 + options: [
  239 + {
  240 + label: '选项1',
  241 + value: '1',
  242 + key: '1',
  243 + },
  244 + {
  245 + label: '选项2',
  246 + value: '2',
  247 + key: '2',
  248 + },
  249 + ],
  250 + },
  251 + colProps: {
  252 + xl: 12,
  253 + xxl: 8,
  254 + },
  255 + },
  256 + ],
231 257 };
232 258 }
233 259 export function getBasicData() {
... ...