|
@@ -1,19 +1,103 @@
|
|
|
<template>
|
|
<template>
|
|
|
- <ApiSelect v-bind="$attrs" value-field="dictItemCode" label-field="dictItemName" :api="api" />
|
|
|
|
|
|
|
+ <Select
|
|
|
|
|
+ v-if="computedHasProvider"
|
|
|
|
|
+ v-bind="$attrs"
|
|
|
|
|
+ :options="computedOptions"
|
|
|
|
|
+ v-model:value="state"
|
|
|
|
|
+ @change="handleChange"
|
|
|
|
|
+ >
|
|
|
|
|
+ <template #[item]="data" v-for="item in Object.keys($slots)">
|
|
|
|
|
+ <slot :name="item" v-bind="data || {}"></slot>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ <template #suffixIcon v-if="loadingRef">
|
|
|
|
|
+ <LoadingOutlined spin />
|
|
|
|
|
+ </template>
|
|
|
|
|
+ <template #notFoundContent v-if="loadingRef">
|
|
|
|
|
+ <span>
|
|
|
|
|
+ <LoadingOutlined spin class="mr-1" />
|
|
|
|
|
+ {{ t('component.form.apiSelectNotFound') }}
|
|
|
|
|
+ </span>
|
|
|
|
|
+ </template>
|
|
|
|
|
+ </Select>
|
|
|
|
|
+ <ApiSelect
|
|
|
|
|
+ v-else
|
|
|
|
|
+ v-bind="$attrs"
|
|
|
|
|
+ value-field="dictItemCode"
|
|
|
|
|
+ label-field="dictItemName"
|
|
|
|
|
+ :api="api"
|
|
|
|
|
+ />
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
<script lang="ts" setup>
|
|
|
|
|
+ import { type PropType, ref, Ref, unref, watch } from 'vue';
|
|
|
|
|
+ import type { SelectValue } from 'ant-design-vue/es/select';
|
|
|
|
|
+
|
|
|
|
|
+ import { computed, inject } from 'vue';
|
|
|
|
|
+ import { Select } from 'ant-design-vue';
|
|
|
import ApiSelect from '../../components/ApiSelect.vue';
|
|
import ApiSelect from '../../components/ApiSelect.vue';
|
|
|
import { propTypes } from '@/utils/propTypes';
|
|
import { propTypes } from '@/utils/propTypes';
|
|
|
import { ApiServiceEnum, defHttp } from '@/utils/http/axios';
|
|
import { ApiServiceEnum, defHttp } from '@/utils/http/axios';
|
|
|
- import { type PropType } from 'vue';
|
|
|
|
|
- import type { SelectValue } from 'ant-design-vue/es/select';
|
|
|
|
|
|
|
+ import { SmartProviderConstants } from '@/components/SmartPageProvider';
|
|
|
|
|
+ import { LoadingOutlined } from '@ant-design/icons-vue';
|
|
|
|
|
+ import { useRuleFormItem } from '@/hooks/component/useFormItem';
|
|
|
|
|
+ import { useI18n } from '@/hooks/web/useI18n';
|
|
|
|
|
+
|
|
|
|
|
+ type OptionsItem = { label?: string; value?: string; disabled?: boolean; [name: string]: any };
|
|
|
|
|
|
|
|
const props = defineProps({
|
|
const props = defineProps({
|
|
|
dictCode: propTypes.string.isRequired,
|
|
dictCode: propTypes.string.isRequired,
|
|
|
value: { type: [Array, Object, String, Number] as PropType<SelectValue> },
|
|
value: { type: [Array, Object, String, Number] as PropType<SelectValue> },
|
|
|
|
|
+ numberToString: propTypes.bool,
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ const emit = defineEmits(['change', 'update:value']);
|
|
|
|
|
+
|
|
|
|
|
+ const { t } = useI18n();
|
|
|
|
|
+
|
|
|
|
|
+ const registerHandler = inject(SmartProviderConstants.dictRegisterKey) as Function | undefined;
|
|
|
|
|
+ if (registerHandler) {
|
|
|
|
|
+ registerHandler(props.dictCode);
|
|
|
|
|
+ }
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 加载状态
|
|
|
|
|
+ */
|
|
|
|
|
+ const loadingRef = inject(SmartProviderConstants.dictLoadingKey) as Ref<boolean> | undefined;
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 是否有注入
|
|
|
|
|
+ */
|
|
|
|
|
+ const computedHasProvider = computed(() => {
|
|
|
|
|
+ return registerHandler !== undefined;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 注入OPTIONS
|
|
|
|
|
+ */
|
|
|
|
|
+ const dictDataRef = inject(SmartProviderConstants.dictData) as Ref<Recordable<any[]>> | undefined;
|
|
|
|
|
+ const computedOptions = computed(() => {
|
|
|
|
|
+ if (!dictDataRef) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+ const dictData = unref(dictDataRef)?.[props.dictCode];
|
|
|
|
|
+ if (!dictData) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+ return dictData;
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ const emitData = ref<OptionsItem[]>([]);
|
|
|
|
|
+ const [state] = useRuleFormItem(props, 'value', 'change', emitData);
|
|
|
|
|
+
|
|
|
|
|
+ watch(
|
|
|
|
|
+ () => state.value,
|
|
|
|
|
+ (v) => {
|
|
|
|
|
+ emit('update:value', v);
|
|
|
|
|
+ },
|
|
|
|
|
+ );
|
|
|
|
|
+
|
|
|
|
|
+ function handleChange(_, ...args) {
|
|
|
|
|
+ emitData.value = args;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
const api = () => {
|
|
const api = () => {
|
|
|
return defHttp.post({
|
|
return defHttp.post({
|
|
|
service: ApiServiceEnum.SMART_SYSTEM,
|
|
service: ApiServiceEnum.SMART_SYSTEM,
|