提交 6cf57367 authored 作者: leon's avatar leon

fix ApiSelect.vue 重复查询问题

上级 07c762f0
......@@ -124,6 +124,7 @@ const getHospitalIdAndDoctorId = ({ colProps }) => {
getHospitalId({
colProps,
onChange: ({ formActionType, formModel, e }) => {
console.log('onChange', e);
const { updateSchema } = formActionType;
updateSchema([
{ field: 'doctorId', componentProps: { params: { hospitalId: e.value } } },
......
......@@ -21,15 +21,16 @@
</Select>
</template>
<script lang="ts">
import { defineComponent, PropType, ref, watchEffect, computed, unref, watch } from 'vue';
import { defineComponent, PropType, ref, watchEffect, computed, unref, watch, reactive } from 'vue';
import { Select } from 'ant-design-vue';
import { isFunction } from '/@/utils/is';
import { useRuleFormItem } from '/@/hooks/component/useFormItem';
import { useAttrs } from '/@/hooks/core/useAttrs';
import { get, omit } from 'lodash-es';
import { cloneDeep, get, omit } from 'lodash-es';
import { LoadingOutlined } from '@ant-design/icons-vue';
import { useI18n } from '/@/hooks/web/useI18n';
import { propTypes } from '/@/utils/propTypes';
import { deepMerge } from '/@/utils';
type OptionsItem = { label: string; value: string; disabled?: boolean };
......@@ -67,7 +68,7 @@
const emitData = ref<any[]>([]);
const attrs = useAttrs();
const { t } = useI18n();
let oldParams = reactive({});
// Embedded in the form, just use the hook binding to perform form verification
const [state] = useRuleFormItem(props, 'value', 'change', emitData);
......@@ -88,27 +89,29 @@
});
watchEffect(() => {
props.immediate && !props.alwaysLoad && fetch();
props.immediate && !props.alwaysLoad && isFirstLoad.value && fetch();
isFirstLoad.value = false;
});
watch(
() => props.params,
() => {
console.log('aaaa');
console.log('props.params', props.params);
console.log('oldParams', oldParams);
if (JSON.stringify(oldParams) !== JSON.stringify(props.params)) {
!unref(isFirstLoad) && fetch();
}
},
{ deep: true },
);
async function fetch() {
if (!isFirstLoad.value) {
isFirstLoad.value = false;
}
const api = props.api;
if (!api || !isFunction(api)) return;
options.value = [];
try {
loading.value = true;
oldParams = cloneDeep(props.params);
const res = await api(props.params);
if (Array.isArray(res)) {
options.value = res;
......@@ -129,9 +132,12 @@
async function handleFetch(visible) {
if (visible) {
if (props.alwaysLoad) {
console.log('handleFetc alwaysLoadh');
await fetch();
} else if (!props.immediate && unref(isFirstLoad)) {
console.log('handleFetch immediate');
await fetch();
isFirstLoad.value = false;
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论