feat:用dialog替换字典页面删除时原用的modal;menu/index中的adaptabilityOptions变量值改成从字典中获取

This commit is contained in:
wh 2025-07-18 00:50:38 +08:00
parent 0d9b6589c7
commit 29f516a337
5 changed files with 68 additions and 61 deletions

9
auto-imports.d.ts vendored
View File

@ -7,8 +7,6 @@
export {}
declare global {
const EffectScope: typeof import('vue')['EffectScope']
const addChildMenu: typeof import('./src/api/menu')['addChildMenu']
const addParentMenu: typeof import('./src/api/menu')['addParentMenu']
const addChildDict: typeof import('./src/api/dictApi')['addChildDict']
const addChildMenu: typeof import('./src/api/menu')['addChildMenu']
const addParentDict: typeof import('./src/api/dictApi')['addParentDict']
@ -18,9 +16,6 @@ declare global {
const customRef: typeof import('vue')['customRef']
const defineAsyncComponent: typeof import('vue')['defineAsyncComponent']
const defineComponent: typeof import('vue')['defineComponent']
const deleteMenu: typeof import('./src/api/menu')['deleteMenu']
const deleteUser: typeof import('./src/api/roleApi')['deleteUser']
const editParentMenu: typeof import('./src/api/menu')['editParentMenu']
const deleteChildDict: typeof import('./src/api/dictApi')['deleteChildDict']
const deleteMenu: typeof import('./src/api/menu')['deleteMenu']
const deleteParentDict: typeof import('./src/api/dictApi')['deleteParentDict']
@ -31,10 +26,6 @@ declare global {
const enable: typeof import('./src/api/roleApi')['enable']
const enableRole: typeof import('./src/api/roleApi')['enableRole']
const getAllMenu: typeof import('./src/api/menu')['getAllMenu']
const eidtChildMenu: typeof import('./src/api/menu')['eidtChildMenu']
const enable: typeof import('./src/api/roleApi')['enable']
const enableRole: typeof import('./src/api/roleApi')['enableRole']
const getAllMenu: typeof import('./src/api/menu')['getAllMenu']
const getCurrentInstance: typeof import('vue')['getCurrentInstance']
const getCurrentScope: typeof import('vue')['getCurrentScope']
const getDict: typeof import('./src/api/dictApi')['getDict']

View File

@ -79,7 +79,7 @@ export function addChildDict(data: DictRowQuery) {
* @param tag tags数组
* @returns
*/
export function getDict(value: string, tag: string): Promise<DictRowReturn[]> {
export function getDict(value: string, tag: string | null = null): Promise<DictRowReturn[]> {
return http({
url: DictChildURL,
method: 'GET',

View File

@ -10,8 +10,8 @@
<h1>{{ tableTitle }}</h1>
</div>
<div class="dict-main__search">
<n-input autosize v-model:value="mainSearch" placeholder="查询字典名称(中/英)" clearable
@keyup.enter="handleFindDatas" class="dict-main__search-input">
<n-input autosize v-model:value="mainSearch" placeholder="查询字典名称(中/英)或字典值" clearable
@keyup.enter="handleFindDatas" @input="handleInputSearch" class="dict-main__search-input" >
</n-input>
<n-button type="primary" @click="handleFindDatas" :focusable="false" class="dict-main__search-btn">
<template #icon>
@ -33,7 +33,7 @@
</div>
</main>
<n-modal v-model:show="showDataModal" title="新增字典数据" preset="dialog" :mask-closable="false">
<n-modal v-model:show="showDataModal" title="新增字典数据" preset="dialog" :mask-closable="false" :draggable="true">
<n-form ref="formRef" :model="formData" :rules="formRules">
<n-form-item label="字典中文名称" path="label">
<n-input v-model:value="formData.label" placeholder="输入字典中文名称" clearable />
@ -63,12 +63,6 @@
</n-space>
</template>
</n-modal>
<n-modal v-model:show="showDeleteModal" title="删除字典数据" preset="dialog" :mask-closable="false" content="确认删除该项字典数据?"
negative-text="取消" positive-text="确认" @negative-click="showDeleteModal = false"
@positive-click="hanldeDeleteSubmit">
</n-modal>
</template>
<script setup lang="ts">
@ -76,7 +70,7 @@ import { getDict } from '@/api/dictApi';
import LsEmpty from '@/components/Ls-UI/LsEmpty.vue';
import { deepClone } from '@/utils';
import { AddOutline, PencilOutline, SearchOutline, TrashOutline } from '@vicons/ionicons5';
import { DataTableColumns, FormInst, NButton, NIcon, NSpace, NTag, NTime, useMessage } from 'naive-ui';
import { DataTableColumns, FormInst, NButton, NIcon, NSpace, NTag, NTime, useDialog, useMessage } from 'naive-ui';
const parentProps = defineProps<{
uuid: string
@ -107,6 +101,9 @@ watch(parentProps, async (newValue) => {
}
});
const message = useMessage();
const dialog = useDialog();
interface DictRow {
uuid?: string
parentId?: string
@ -160,10 +157,6 @@ const getColumns = ({
return h(
NTag,
{
style: {
marginRight: '6px',
color: '#3D8EFF',
},
type: 'info',
bordered: false
},
@ -253,7 +246,7 @@ const getColumns = ({
const getDatas = async () => {
try {
console.log("父级字典:", parentProps);
const result = await getDict(parentProps.value, null);
const result = await getDict(parentProps.value);
tableData.value = result.map(item => {
const { tag, ...rest } = item;
return {
@ -268,11 +261,13 @@ const getDatas = async () => {
}
};
const handleFindDatas = () => {
currentData.value = tableData.value.filter(item => (item.label.includes(mainSearch.value) || item.labelEn.includes(mainSearch.value)) && item.value === parentProps.value)
};
const handleInputSearch = () => {
handleFindDatas(); //
}
const message = useMessage();
const handleFindDatas = () => {
currentData.value = tableData.value.filter(item => (item.label.includes(mainSearch.value) || item.labelEn.includes(mainSearch.value) || item.value.includes(mainSearch.value)))
};
const formRef = ref<FormInst | null>(null);
const currentMode = ref<'Add' | 'Modify'>('Add');
@ -389,19 +384,27 @@ const handleFormSubmit = async (e: MouseEvent) => {
}
//
const showDeleteModal = ref(false);
const deleteData = ref<DictRow | null>(null);
const handleDeleteDatas = (row: DictRow) => {
console.log("删除:", row);
deleteData.value = row;
showDeleteModal.value = true;
const handleDeleteDatas = async (row: DictRow) => {
dialog.warning({
title: '删除字典数据',
content: '确认删除?',
positiveText: '确认',
negativeText: '取消',
draggable: true,
onPositiveClick: async () => {
try {
await handleDeleteSubmit(row);
} catch (error) {
console.log('删除失败', error);
}
}
})
}
const hanldeDeleteSubmit = async () => {
const handleDeleteSubmit = async (deleteData: DictRow) => {
console.log('submit delete ', deleteData);
try {
await deleteChildDict(deleteData.value.uuid);
await deleteChildDict(deleteData.uuid);
message.success('删除成功');
try {
await getDatas();

View File

@ -39,7 +39,7 @@
</n-space>
</nav>
<n-modal v-model:show="showDataModal" title="新增父级字典" preset="dialog" :mask-closable="false">
<n-modal v-model:show="showDataModal" title="新增父级字典" preset="dialog" :mask-closable="false" :draggable="true">
<n-form ref="formRef" :model="formData" :rules="formRules">
<n-form-item label="父级字典名称" path="label">
<n-input v-model:value="formData.label" placeholder="输入父级字典名称" />
@ -55,18 +55,12 @@
</n-space>
</template>
</n-modal>
<n-modal v-model:show="showDeleteModal" title="删除父级字典数据" preset="dialog" :mask-closable="false"
content="确认删除该项字典数据?" negative-text="取消" positive-text="确认" @negative-click="showDeleteModal = false"
@positive-click="handleDeleteSubmit">
</n-modal>
</template>
<script setup lang="ts">
import { getParentDict } from '@/api/dictApi';
import { AddOutline, BookOutline, PencilOutline, SearchOutline, TrashOutline } from '@vicons/ionicons5';
import { FormInst, NButton, NIcon, useMessage } from 'naive-ui';
import { FormInst, NButton, NIcon, useDialog, useMessage } from 'naive-ui';
const parentProps = defineProps<{
parentUuid: string
@ -93,6 +87,8 @@ interface DictRow {
createUserId?: string
}
const message = useMessage();
const dialog = useDialog();
const parentDictDatas = ref<DictRow[]>([]);
//
@ -126,8 +122,6 @@ const handleUpdateParent = (dict: DictRow) => {
return;
}
const message = useMessage();
//
interface FormData {
label: string;
@ -206,21 +200,30 @@ const handleFormSubmit = async (e: MouseEvent) => {
}
//
const showDeleteModal = ref(false);
const deleteData = ref<DictRow | null>(null);
const handleDeleteParent = (e: MouseEvent, data: DictRow) => {
e.stopPropagation();
console.log('删除', data);
deleteData.value = data;
showDeleteModal.value = true;
dialog.warning({
title: '删除父级字典数据',
content: '确认删除?',
positiveText: '确认',
negativeText: '取消',
draggable: true,
onPositiveClick: async () => {
try {
await handleDeleteSubmit(data);
} catch (error) {
console.log('删除失败', error);
}
}
})
}
const handleDeleteSubmit = async () => {
const handleDeleteSubmit = async (deleteData: DictRow) => {
console.log('submit delete ', deleteData);
try {
await deleteParentDict(deleteData.value.uuid);
if (deleteData.value.uuid === parentProps.parentUuid) {
await deleteParentDict(deleteData.uuid);
if (deleteData.uuid === parentProps.parentUuid) {
emit('update:parentUuid', '');
emit('update:parentValue', '');
emit('update:parentTitle', '');

View File

@ -295,11 +295,21 @@ const isEditChild = ref(false)
const currentChildId = ref('')
//
const adaptabilityOptions = [
{ label: 'PC端', value: 'pc' },
{ label: '移动端', value: 'mobile' },
{ label: '响应式', value: 'responsive' }
]
const adaptabilityOptions = ref([]);
getDict("page_adaptability").then((res) => {
console.log('获取适配方式选项', res);
adaptabilityOptions.value = res.map(item => {
const {label, value, ...rest} = item;
return {
label: label,
value: value,
}
})
}).catch((errors) => {
console.log('获取适配方式选项失败', errors);
message.error('获取适配方式选项失败');
})
//
const parentModalTitle = computed(() => (isEditParent.value ? '编辑父级菜单' : '添加父级菜单'))