Skip to content

Commit bea6824

Browse files
committed
feat: update basic-form demo
1 parent 3ec8bb7 commit bea6824

27 files changed

+1083
-446
lines changed

package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,11 @@
4646
"vue": "^3.2.31",
4747
"vue-i18n": "^9.2.0-beta.30",
4848
"vue-router": "^4.0.14",
49-
"xlsx": "^0.18.3"
49+
"vue-types": "^4.1.1",
50+
"xlsx": "^0.18.4"
5051
},
5152
"devDependencies": {
52-
"@commitlint/cli": "^16.2.1",
53+
"@commitlint/cli": "^16.2.3",
5354
"@commitlint/config-conventional": "^16.2.1",
5455
"@types/lodash-es": "^4.17.6",
5556
"@types/node": "^17.0.21",
@@ -62,7 +63,6 @@
6263
"@vue/cli-plugin-typescript": "^5.0.3",
6364
"@vue/cli-plugin-vuex": "^5.0.3",
6465
"@vue/cli-service": "^5.0.3",
65-
"@vue/compiler-sfc": "^3.2.31",
6666
"@vue/eslint-config-typescript": "^10.0.0",
6767
"babel-plugin-import": "^1.13.3",
6868
"commitizen": "^4.2.4",
@@ -76,10 +76,10 @@
7676
"husky": "^7.0.4",
7777
"less": "^4.1.2",
7878
"less-loader": "10.2.0",
79-
"lint-staged": "^12.3.5",
79+
"lint-staged": "^12.3.6",
8080
"path-browserify": "^1.0.1",
8181
"postcss-html": "^1.3.0",
82-
"prettier": "^2.5.1",
82+
"prettier": "^2.6.0",
8383
"regenerator-runtime": "^0.13.9",
8484
"stylelint": "^14.5.3",
8585
"stylelint-config-html": "^1.0.0",

src/api/demos/select.ts

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { request } from '@/utils/request';
2+
3+
/**
4+
* @description Get sample options value
5+
*/
6+
export function optionsListApi(params?: any) {
7+
return request<{ list: { id: string; name: string }[] }>(
8+
{
9+
url: '/select/getDemoOptions',
10+
method: 'get',
11+
params,
12+
},
13+
{
14+
isMock: true,
15+
isGetDataDirectly: true,
16+
},
17+
);
18+
}

src/components/basic/excel/src/ExportExcelModal.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ export const useExportExcelModal = () => {
6767
},
6868
formProps: {
6969
labelWidth: 100,
70-
layout: 'vertical',
7170
schemas: getSchemas(t),
7271
},
7372
});

src/components/core/dynamic-table/src/hooks/useTableForm.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { unref, computed, watchEffect } from 'vue';
2-
import { omit } from 'lodash-es';
32
import type { TableMethods } from './useTableMethods';
43
import type { TableState } from './useTableState';
54
import type { ComputedRef, Slots } from 'vue';
@@ -49,7 +48,7 @@ export function useTableForm({ tableState, slots, tableMethods }: UseTableFormCo
4948
});
5049

5150
// 同步外部对props的修改
52-
watchEffect(() => getQueryFormRef()?.setSchemaFormProps(omit(unref(getFormProps), 'schemas')), {
51+
watchEffect(() => getQueryFormRef()?.setSchemaFormProps(unref(getFormProps)), {
5352
flush: 'post',
5453
});
5554

src/components/core/schema-form/index.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
// export { default as SchemaForm } from './schema-form.vue'
21
import SchemaForm from './src/schema-form.vue';
32
import type { DefineComponent } from 'vue';
43
import type { SchemaFormProps } from './src/schema-form';
54

6-
export * from './src/types/form';
7-
export * from './src/types/formItem';
5+
export * from './src/types/';
86
export * from './src/schema-form';
9-
107
export * from './src/hooks/';
8+
export * from './src/components/';
119

1210
export { SchemaForm };
1311

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
<template>
2+
<Select
3+
v-bind="getProps"
4+
:options="getOptions"
5+
@dropdown-visible-change="handleFetch"
6+
@change="handleChange"
7+
>
8+
<template v-for="item in Object.keys($slots)" #[item]="data">
9+
<slot :name="item" v-bind="data || {}"></slot>
10+
</template>
11+
<template v-if="loading" #suffixIcon>
12+
<LoadingOutlined spin />
13+
</template>
14+
<template v-if="loading" #notFoundContent>
15+
<span>
16+
<LoadingOutlined spin class="mr-1" />
17+
{{ t('component.form.apiSelectNotFound') }}
18+
</span>
19+
</template>
20+
</Select>
21+
</template>
22+
<script lang="ts" setup>
23+
import { PropType, ref, watchEffect, computed, unref, watch } from 'vue';
24+
import { get, omit } from 'lodash-es';
25+
import { LoadingOutlined } from '@ant-design/icons-vue';
26+
import { selectProps } from 'ant-design-vue/es/select';
27+
import { Select } from 'ant-design-vue';
28+
import { isFunction } from '@/utils/is';
29+
import { useI18n } from '@/hooks/useI18n';
30+
import { propTypes } from '@/utils/propTypes';
31+
32+
type OptionsItem = { label: string; value: string; disabled?: boolean };
33+
34+
defineOptions({
35+
name: 'ApiSelect',
36+
inheritAttrs: false,
37+
});
38+
39+
const props = defineProps({
40+
...selectProps(),
41+
value: [Array, Object, String, Number],
42+
numberToString: propTypes.bool,
43+
api: {
44+
type: Function as PropType<(arg?: Recordable) => Promise<any>>,
45+
default: null,
46+
},
47+
// api params
48+
params: {
49+
type: Object as PropType<Recordable>,
50+
default: () => ({}),
51+
},
52+
// support xxx.xxx.xx
53+
resultField: propTypes.string.def(''),
54+
labelField: propTypes.string.def('label'),
55+
valueField: propTypes.string.def('value'),
56+
immediate: propTypes.bool.def(true),
57+
alwaysLoad: propTypes.bool.def(false),
58+
});
59+
60+
const emit = defineEmits(['options-change', 'change']);
61+
62+
const options = ref<OptionsItem[]>([]);
63+
const loading = ref(false);
64+
const isFirstLoad = ref(true);
65+
const emitData = ref<any[]>([]);
66+
const { t } = useI18n();
67+
68+
const getProps = computed(() => props as Recordable);
69+
70+
// Embedded in the form, just use the hook binding to perform form verification
71+
72+
const getOptions = computed(() => {
73+
const { labelField, valueField, numberToString } = props;
74+
75+
return unref(options).reduce((prev, next: Recordable) => {
76+
if (next) {
77+
const value = next[valueField];
78+
prev.push({
79+
...omit(next, [labelField, valueField]),
80+
label: next[labelField],
81+
value: numberToString ? `${value}` : value,
82+
});
83+
}
84+
return prev;
85+
}, [] as OptionsItem[]);
86+
});
87+
88+
watchEffect(() => {
89+
props.immediate && !props.alwaysLoad && fetch();
90+
});
91+
92+
watch(
93+
() => props.params,
94+
() => {
95+
!unref(isFirstLoad) && fetch();
96+
},
97+
{ deep: true },
98+
);
99+
100+
async function fetch() {
101+
const api = props.api;
102+
if (!api || !isFunction(api)) return;
103+
options.value = [];
104+
try {
105+
loading.value = true;
106+
const res = await api(props.params);
107+
if (Array.isArray(res)) {
108+
options.value = res;
109+
emitChange();
110+
return;
111+
}
112+
if (props.resultField) {
113+
options.value = get(res, props.resultField) || [];
114+
}
115+
emitChange();
116+
} catch (error) {
117+
console.warn(error);
118+
} finally {
119+
loading.value = false;
120+
}
121+
}
122+
123+
async function handleFetch(visible) {
124+
if (visible) {
125+
if (props.alwaysLoad) {
126+
await fetch();
127+
} else if (!props.immediate && unref(isFirstLoad)) {
128+
await fetch();
129+
isFirstLoad.value = false;
130+
}
131+
}
132+
}
133+
134+
function emitChange() {
135+
emit('options-change', unref(getOptions));
136+
}
137+
138+
function handleChange(_, ...args) {
139+
emitData.value = args;
140+
}
141+
</script>

src/components/core/schema-form/src/components/form-action.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
import { computed, type PropType } from 'vue';
4444
import { Form, Col } from 'ant-design-vue';
4545
import { useFormContext } from '../hooks/useFormContext';
46-
import type { ColEx } from '../types/index';
46+
import type { ColEx } from '../types/component';
4747
import { Button, ButtonProps } from '@/components/basic/button';
4848
import { BasicArrow } from '@/components/basic/basic-arrow';
4949
import { useI18n } from '@/hooks/useI18n';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as ApiSelect } from './ApiSelect.vue';

src/components/core/schema-form/src/helper.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import dayjs from 'dayjs';
22
import type { ValidationRule } from 'ant-design-vue/es/form/Form';
3-
import type { ComponentMapType } from './types';
3+
import type { ComponentMapType } from './types/component';
44
import { isNumber } from '@/utils/is';
55
import { useI18n } from '@/hooks/useI18n';
66

src/components/core/schema-form/src/hooks/useAdvanced.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { computed, unref, watch } from 'vue';
22
import type { SchemaFormEmitFn } from '../schema-form';
3-
import type { ColEx } from '../types';
3+
import type { ColEx } from '../types/component';
44
import type { SchemaFormType } from './';
55
import { isBoolean, isFunction, isNumber, isObject } from '@/utils/is';
66
import { useBreakpoint } from '@/hooks/event/useBreakpoint';
@@ -40,7 +40,7 @@ export const useAdvanced = ({ instance, emit }: UseAdvancedContext) => {
4040
() => {
4141
const { showAdvancedButton } = unref(getFormProps);
4242
if (showAdvancedButton) {
43-
requestIdleCallback(updateAdvanced);
43+
updateAdvanced();
4444
}
4545
},
4646
{ immediate: true },

0 commit comments

Comments
 (0)