Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
suyuan32 committed Jun 24, 2024
2 parents 6f1d686 + 0ebeb22 commit 524c97d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 55 deletions.
110 changes: 56 additions & 54 deletions src/components/Form/src/components/DictionarySelect.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,66 +15,68 @@
</Select>
</template>
<script lang="ts">
import { defineComponent, ref, watch, onMounted } from 'vue';
import { Select } from 'ant-design-vue';
import { useAttrs } from '@vben/hooks';
import { LoadingOutlined } from '@ant-design/icons-vue';
import { useI18n } from '@/hooks/web/useI18n';
import { propTypes } from '@/utils/propTypes';
import { useDictionaryStore } from '@/store/modules/dictionary';
import { DefaultOptionType } from 'ant-design-vue/lib/select';
import { useRuleFormItem } from '@/hooks/component/useFormItem';
import { defineComponent, ref, watch, onMounted } from 'vue';
import { Select } from 'ant-design-vue';
import { useAttrs } from '@vben/hooks';
import { LoadingOutlined } from '@ant-design/icons-vue';
import { useI18n } from '@/hooks/web/useI18n';
import { propTypes } from '@/utils/propTypes';
import { useDictionaryStore } from '@/store/modules/dictionary';
import { DefaultOptionType } from 'ant-design-vue/lib/select';
import { useRuleFormItem } from '@/hooks/component/useFormItem';
export default defineComponent({
name: 'DictionarySelect',
components: {
Select,
LoadingOutlined,
},
inheritAttrs: false,
props: {
dictionaryName: propTypes.string.def(''),
value: [String, Number],
cache: propTypes.bool.def(true),
},
emits: ['options-change', 'change', 'update:value'],
setup(props, { emit }) {
const loading = ref(false);
const emitData = ref<any[]>([]);
const attrs = useAttrs();
const { t } = useI18n();
const options = ref<DefaultOptionType[]>();
export default defineComponent({
name: 'DictionarySelect',
components: {
Select,
LoadingOutlined,
},
inheritAttrs: false,
props: {
dictionaryName: propTypes.string.def(''),
value: [String, Number],
cache: propTypes.bool.def(true),
},
emits: ['options-change', 'change', 'update:value'],
setup(props, { emit }) {
const loading = ref(false);
const emitData = ref<any[]>([]);
const attrs = useAttrs();
const { t } = useI18n();
const options = ref<DefaultOptionType[]>();
// Embedded in the form, just use the hook binding to perform form verification
const [state] = useRuleFormItem(props, 'value', 'change', emitData);
// Embedded in the form, just use the hook binding to perform form verification
const [state] = useRuleFormItem(props, 'value', 'change', emitData);
onMounted(() => {
handleFetch();
});
onMounted(() => {
handleFetch();
});
watch(
() => state.value,
(v) => {
emit('update:value', v);
},
);
watch(
() => state.value,
(v) => {
emit('update:value', v);
},
);
async function handleFetch() {
loading.value = true;
const dictStore = useDictionaryStore();
const dictData = await dictStore.getDictionary(props.dictionaryName, props.cache);
if (dictData != null) {
options.value = dictData.data;
}
loading.value = false;
async function handleFetch() {
loading.value = true;
const dictStore = useDictionaryStore();
const dictData = await dictStore.getDictionary(props.dictionaryName, props.cache);
if (dictData != null) {
options.value = dictData.data.filter(el => {
return el.status == 1
});
}
loading.value = false;
}
function handleChange(_, ...args) {
emitData.value = args;
emit('change', args);
}
function handleChange(_, ...args) {
emitData.value = args;
emit('change', args);
}
return { state, attrs, loading, t, options, handleFetch, handleChange };
},
});
return { state, attrs, loading, t, options, handleFetch, handleChange };
},
});
</script>
7 changes: 6 additions & 1 deletion src/store/modules/dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import { DefaultOptionType } from 'ant-design-vue/lib/select';
import { ref } from 'vue';
import { DICT_INFO_KEY } from '@/enums/cacheEnum';

interface DictionaryDataDefaultOptionType extends DefaultOptionType {
status?: string | number | null;
}

interface DictionaryData {
data: DefaultOptionType[];
data: DictionaryDataDefaultOptionType[];
}

const requestCache = new Map<
Expand Down Expand Up @@ -61,6 +65,7 @@ export const useDictionaryStore = defineStore({
dataConv.value.push({
label: result.data.data[i].title,
value: result.data.data[i].value,
status: result.data.data[i].status,
});
}

Expand Down

0 comments on commit 524c97d

Please sign in to comment.