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:
@ -1,39 +1,50 @@
|
||||
<script setup lang="tsx">
|
||||
import { ref, useAttrs, watch } from 'vue';
|
||||
import { ref, useAttrs } from 'vue';
|
||||
import { useLoading } from '@sa/hooks';
|
||||
import type { SelectProps } from 'naive-ui';
|
||||
import { useDict } from '@/hooks/business/dict';
|
||||
import type { SelectOption, SelectProps } from 'naive-ui';
|
||||
import { fetchGetDictTypeOption } from '@/service/api';
|
||||
|
||||
defineOptions({ name: 'DictSelect' });
|
||||
|
||||
const dictType = defineModel<string>('value', { required: true });
|
||||
interface Props {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
|
||||
const value = defineModel<string>('value', { required: true });
|
||||
|
||||
const attrs: SelectProps = useAttrs();
|
||||
const { getDictOptions } = useDict();
|
||||
const options = ref<Array<CommonType.Option>>([]);
|
||||
const options = ref<SelectOption[]>([]);
|
||||
const { loading, startLoading, endLoading } = useLoading();
|
||||
|
||||
async function getDeptOptions() {
|
||||
if (!dictType.value) {
|
||||
return;
|
||||
}
|
||||
startLoading();
|
||||
const dictData = await getDictOptions(dictType.value);
|
||||
options.value = dictData[dictType.value];
|
||||
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();
|
||||
}
|
||||
|
||||
watch(
|
||||
() => dictType.value,
|
||||
() => {
|
||||
getDeptOptions();
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
getDeptOptions();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NSelect :loading="loading" :options="options" :clear-filter-after-select="false" v-bind="attrs" />
|
||||
<NSelect
|
||||
v-model:value="value"
|
||||
:loading="loading"
|
||||
:options="options"
|
||||
:clear-filter-after-select="false"
|
||||
v-bind="attrs"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
||||
|
63
src/components/custom/menu-tree-select.vue
Normal file
63
src/components/custom/menu-tree-select.vue
Normal file
@ -0,0 +1,63 @@
|
||||
<script setup lang="tsx">
|
||||
import { ref, useAttrs } from 'vue';
|
||||
import { useLoading } from '@sa/hooks';
|
||||
import type { TreeOption, TreeSelectProps } from 'naive-ui';
|
||||
import { fetchGetMenuList } from '@/service/api';
|
||||
import SvgIcon from '@/components/custom/svg-icon.vue';
|
||||
import { handleMenuTree } from '@/utils/ruoyi';
|
||||
|
||||
defineOptions({ name: 'MenuTreeSelect' });
|
||||
|
||||
interface Props {
|
||||
[key: string]: any;
|
||||
}
|
||||
|
||||
defineProps<Props>();
|
||||
|
||||
const value = defineModel<CommonType.IdType | null>('value', { required: true });
|
||||
|
||||
const attrs: TreeSelectProps = useAttrs();
|
||||
const options = ref<Api.System.MenuList>([]);
|
||||
const { loading, startLoading, endLoading } = useLoading();
|
||||
|
||||
async function getMenuList() {
|
||||
startLoading();
|
||||
const { error, data } = await fetchGetMenuList();
|
||||
if (error) return;
|
||||
options.value = [
|
||||
{
|
||||
menuId: 0,
|
||||
menuName: '根目录',
|
||||
icon: 'material-symbols:home-outline-rounded',
|
||||
children: handleMenuTree(data, 'menuId')
|
||||
}
|
||||
] as Api.System.Menu[];
|
||||
endLoading();
|
||||
}
|
||||
|
||||
getMenuList();
|
||||
|
||||
function renderPrefix({ option }: { option: TreeOption }) {
|
||||
const renderLocalIcon = String(option.icon).startsWith('icon-');
|
||||
const icon = renderLocalIcon ? undefined : String(option.icon);
|
||||
const localIcon = renderLocalIcon ? String(option.icon).replace('icon-', 'menu-') : undefined;
|
||||
return <SvgIcon icon={icon} localIcon={localIcon} />;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<NTreeSelect
|
||||
v-model:value="value"
|
||||
filterable
|
||||
class="h-full"
|
||||
:loading="loading"
|
||||
key-field="menuId"
|
||||
label-field="menuName"
|
||||
:options="options"
|
||||
:default-expanded-keys="[0]"
|
||||
:render-prefix="renderPrefix"
|
||||
v-bind="attrs"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<style scoped></style>
|
Reference in New Issue
Block a user