mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat: 测试代码生成
This commit is contained in:
28
src/components/custom/dict-radio.vue
Normal file
28
src/components/custom/dict-radio.vue
Normal file
@ -0,0 +1,28 @@
|
||||
<script setup lang="ts">
|
||||
import { useDict } from '@/hooks/business/dict';
|
||||
|
||||
defineOptions({ name: 'DictRadio' });
|
||||
|
||||
interface Props {
|
||||
dictCode: string;
|
||||
immediate?: boolean;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
immediate: true
|
||||
});
|
||||
|
||||
const value = defineModel<string | null>('value', { required: false });
|
||||
|
||||
const { options } = useDict(props.dictCode, props.immediate);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NRadioGroup v-model:value="value">
|
||||
<NSpace>
|
||||
<NRadio v-for="option in options" :key="option.value" :value="option.value" :label="option.label" />
|
||||
</NSpace>
|
||||
</NRadioGroup>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
@ -1,46 +1,30 @@
|
||||
<script setup lang="tsx">
|
||||
import { ref, useAttrs } from 'vue';
|
||||
import { useLoading } from '@sa/hooks';
|
||||
import type { SelectOption, SelectProps } from 'naive-ui';
|
||||
import { fetchGetDictTypeOption } from '@/service/api/system';
|
||||
<script setup lang="ts">
|
||||
import { useAttrs } from 'vue';
|
||||
import type { SelectProps } from 'naive-ui';
|
||||
import { useDict } from '@/hooks/business/dict';
|
||||
|
||||
defineOptions({ name: 'DictSelect' });
|
||||
|
||||
interface Props {
|
||||
dictCode: string;
|
||||
immediate?: boolean;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
immediate: true
|
||||
});
|
||||
|
||||
const value = defineModel<string>('value', { required: true });
|
||||
const value = defineModel<string | null>('value', { required: true });
|
||||
|
||||
const attrs: SelectProps = useAttrs();
|
||||
const options = ref<SelectOption[]>([]);
|
||||
const { loading, startLoading, endLoading } = useLoading();
|
||||
|
||||
async function getDeptOptions() {
|
||||
startLoading();
|
||||
const { error, data } = await fetchGetDictTypeOption();
|
||||
if (error) return;
|
||||
options.value = data.map(dict => ({
|
||||
value: dict.dictType!,
|
||||
label: () => (
|
||||
<div class="w-520px flex justify-between">
|
||||
<span>{dict.dictType}</span>
|
||||
<span>{dict.dictName}</span>
|
||||
</div>
|
||||
)
|
||||
}));
|
||||
endLoading();
|
||||
}
|
||||
|
||||
getDeptOptions();
|
||||
const { options } = useDict(props.dictCode, props.immediate);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NSelect
|
||||
v-model:value="value"
|
||||
:loading="loading"
|
||||
:loading="!options.length"
|
||||
:options="options"
|
||||
:clear-filter-after-select="false"
|
||||
v-bind="attrs"
|
||||
|
Reference in New Issue
Block a user