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

fix ApiSelect.vue 重复查询问题

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