mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
chore:字典组件优化,支持数组格式,其他模块代码优化
This commit is contained in:
@ -8,14 +8,16 @@ defineOptions({ name: 'DictSelect' });
|
||||
interface Props {
|
||||
dictCode: string;
|
||||
immediate?: boolean;
|
||||
multiple?: boolean;
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
const props = withDefaults(defineProps<Props>(), {
|
||||
immediate: false
|
||||
immediate: false,
|
||||
multiple: false
|
||||
});
|
||||
|
||||
const value = defineModel<string | null>('value', { required: false });
|
||||
const value = defineModel<string | string[] | null>('value', { required: false });
|
||||
|
||||
const attrs: SelectProps = useAttrs();
|
||||
const { options } = useDict(props.dictCode, props.immediate);
|
||||
@ -24,6 +26,7 @@ const { options } = useDict(props.dictCode, props.immediate);
|
||||
<template>
|
||||
<NSelect
|
||||
v-model:value="value"
|
||||
:multiple="multiple"
|
||||
:loading="!options.length"
|
||||
:options="options"
|
||||
:clear-filter-after-select="false"
|
||||
|
@ -7,10 +7,10 @@ import { isNotNull } from '@/utils/common';
|
||||
defineOptions({ name: 'DictTag' });
|
||||
|
||||
interface Props {
|
||||
value?: string | number;
|
||||
value?: string[] | number[] | string | number;
|
||||
dictCode?: string;
|
||||
immediate?: boolean;
|
||||
dictData?: Api.System.DictData;
|
||||
dictData?: Api.System.DictData[];
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
@ -18,29 +18,38 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
immediate: false,
|
||||
dictData: undefined,
|
||||
dictCode: '',
|
||||
value: ''
|
||||
value: () => []
|
||||
});
|
||||
|
||||
const attrs = useAttrs() as TagProps;
|
||||
|
||||
const dictTagData = computed(() => {
|
||||
const dictTagData = computed<Api.System.DictData[]>(() => {
|
||||
if (props.dictData) {
|
||||
return props.dictData;
|
||||
}
|
||||
// 避免 props.value 为 0 时,无法触发
|
||||
if (props.dictCode && isNotNull(props.value)) {
|
||||
const { transformDictData } = useDict(props.dictCode, props.immediate);
|
||||
return transformDictData(String(props.value));
|
||||
return transformDictData(props.value) || [];
|
||||
}
|
||||
|
||||
return null;
|
||||
return [];
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NTag v-if="dictTagData" :class="dictTagData.cssClass" :type="dictTagData.listClass" v-bind="attrs">
|
||||
{{ dictTagData.dictLabel }}
|
||||
</NTag>
|
||||
<div v-if="dictTagData.length">
|
||||
<NTag
|
||||
v-for="item in dictTagData"
|
||||
:key="item.dictValue"
|
||||
class="mb-2 mr-2"
|
||||
:class="[item.cssClass]"
|
||||
:type="item.listClass"
|
||||
v-bind="attrs"
|
||||
>
|
||||
{{ item.dictLabel }}
|
||||
</NTag>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
|
@ -51,20 +51,19 @@ const jsonData = computed(() => {
|
||||
|
||||
<template>
|
||||
<div class="json-preview">
|
||||
<template v-if="jsonData">
|
||||
<VueJsonPretty
|
||||
:data="jsonData"
|
||||
:deep="deep"
|
||||
:show-double-quotes="showDoubleQuotes"
|
||||
:show-length="showLength"
|
||||
:show-line="showLine"
|
||||
:show-line-number="showLineNumber"
|
||||
:show-icon="showIcon"
|
||||
:show-select-controller="showSelectController"
|
||||
:collapsed-level="collapsedLevel"
|
||||
:highlight-mouseover-node="highlightMouseoverNode"
|
||||
/>
|
||||
</template>
|
||||
<VueJsonPretty
|
||||
v-if="jsonData"
|
||||
:data="jsonData"
|
||||
:deep="deep"
|
||||
:show-double-quotes="showDoubleQuotes"
|
||||
:show-length="showLength"
|
||||
:show-line="showLine"
|
||||
:show-line-number="showLineNumber"
|
||||
:show-icon="showIcon"
|
||||
:show-select-controller="showSelectController"
|
||||
:collapsed-level="collapsedLevel"
|
||||
:highlight-mouseover-node="highlightMouseoverNode"
|
||||
/>
|
||||
<span v-else-if="props.data">{{ props.data }}</span>
|
||||
<div v-else class="empty-data">暂无数据</div>
|
||||
</div>
|
||||
|
Reference in New Issue
Block a user