mirror of
https://gitee.com/log4j/pig-ui.git
synced 2024-12-23 05:40:20 +08:00
feat: 代码优化
This commit is contained in:
parent
a1e36c5028
commit
37113133ae
@ -23,7 +23,7 @@ export const save = (data: Object) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
export const update = (data: Object) => {
|
export const putObj = (data: Object) => {
|
||||||
return request({
|
return request({
|
||||||
url: '/admin/menu',
|
url: '/admin/menu',
|
||||||
method: 'put',
|
method: 'put',
|
||||||
|
@ -84,13 +84,12 @@ const showSearch = ref(true);
|
|||||||
const selectObjs = ref([]) as any;
|
const selectObjs = ref([]) as any;
|
||||||
const multiple = ref(true);
|
const multiple = ref(true);
|
||||||
|
|
||||||
|
// table hook
|
||||||
const state: BasicTableProps = reactive<BasicTableProps>({
|
const state: BasicTableProps = reactive<BasicTableProps>({
|
||||||
queryForm: {},
|
queryForm: {},
|
||||||
pageList: fetchList,
|
pageList: fetchList,
|
||||||
descs: ['create_time'],
|
descs: ['create_time'],
|
||||||
});
|
});
|
||||||
|
|
||||||
// table hook
|
|
||||||
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile } = useTable(state);
|
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile } = useTable(state);
|
||||||
|
|
||||||
// 清空搜索条件
|
// 清空搜索条件
|
||||||
|
@ -196,11 +196,8 @@ const dataRules = ref({
|
|||||||
const openDialog = (id: string) => {
|
const openDialog = (id: string) => {
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
form.id = '';
|
form.id = '';
|
||||||
|
|
||||||
// 重置表单数据
|
// 重置表单数据
|
||||||
if (dataFormRef.value) {
|
dataFormRef.value?.resetFields();
|
||||||
dataFormRef.value.resetFields();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取sysOauthClientDetails信息
|
// 获取sysOauthClientDetails信息
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -210,35 +207,18 @@ const openDialog = (id: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 提交
|
// 提交
|
||||||
const onSubmit = () => {
|
const onSubmit = async () => {
|
||||||
dataFormRef.value.validate((valid: boolean) => {
|
const valid = await dataFormRef.value.validate().catch(() => {});
|
||||||
if (!valid) {
|
if (!valid) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新
|
try {
|
||||||
if (form.id) {
|
form.id ? await putObj(form) : await addObj(form);
|
||||||
putObj(form)
|
useMessage().success(t(form.id ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||||
.then(() => {
|
visible.value = false;
|
||||||
useMessage().success(t('common.editSuccessText'));
|
emit('refresh');
|
||||||
visible.value = false; // 关闭弹窗
|
} catch (err: any) {
|
||||||
emit('refresh');
|
useMessage().error(err.msg);
|
||||||
})
|
}
|
||||||
.catch((err: any) => {
|
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
addObj(form)
|
|
||||||
.then(() => {
|
|
||||||
useMessage().success(t('common.addSuccessText'));
|
|
||||||
visible.value = false; // 关闭弹窗
|
|
||||||
emit('refresh');
|
|
||||||
})
|
|
||||||
.catch((err: any) => {
|
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 初始化表单数据
|
// 初始化表单数据
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class="dialog-footer">
|
<span class="dialog-footer">
|
||||||
<el-button @click="onCancel">{{ $t('common.cancelButtonText') }}</el-button>
|
<el-button @click="visible = false">{{ $t('common.cancelButtonText') }}</el-button>
|
||||||
<el-button type="primary" @click="onSubmit">{{ $t('common.confirmButtonText') }}</el-button>
|
<el-button type="primary" @click="onSubmit">{{ $t('common.confirmButtonText') }}</el-button>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
@ -45,7 +45,6 @@ import { useMessage } from '/@/hooks/message';
|
|||||||
|
|
||||||
// 定义子组件向父组件传值/事件
|
// 定义子组件向父组件传值/事件
|
||||||
const emit = defineEmits(['refresh']);
|
const emit = defineEmits(['refresh']);
|
||||||
|
|
||||||
// 定义变量内容
|
// 定义变量内容
|
||||||
const deptDialogFormRef = ref();
|
const deptDialogFormRef = ref();
|
||||||
const dataForm = reactive({
|
const dataForm = reactive({
|
||||||
@ -65,6 +64,14 @@ const dataRules = ref({
|
|||||||
|
|
||||||
// 打开弹窗
|
// 打开弹窗
|
||||||
const openDialog = (type: string, id: string) => {
|
const openDialog = (type: string, id: string) => {
|
||||||
|
visible.value = true;
|
||||||
|
dataForm.deptId = '';
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
deptDialogFormRef.value?.resetFields();
|
||||||
|
dataForm.parentId = id;
|
||||||
|
});
|
||||||
|
|
||||||
if (type === 'edit') {
|
if (type === 'edit') {
|
||||||
getObj(id)
|
getObj(id)
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
@ -73,24 +80,11 @@ const openDialog = (type: string, id: string) => {
|
|||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
useMessage().error(err.msg);
|
useMessage().error(err.msg);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
// 清空表单,此项需加表单验证才能使用
|
|
||||||
nextTick(() => {
|
|
||||||
deptDialogFormRef?.value?.resetFields();
|
|
||||||
dataForm.parentId = id;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
visible.value = true;
|
|
||||||
getDeptData();
|
getDeptData();
|
||||||
};
|
};
|
||||||
// 关闭弹窗
|
|
||||||
const closeDialog = () => {
|
|
||||||
visible.value = false;
|
|
||||||
};
|
|
||||||
// 取消
|
|
||||||
const onCancel = () => {
|
|
||||||
closeDialog();
|
|
||||||
};
|
|
||||||
// 提交
|
// 提交
|
||||||
const onSubmit = () => {
|
const onSubmit = () => {
|
||||||
deptDialogFormRef.value.validate((valid: boolean) => {
|
deptDialogFormRef.value.validate((valid: boolean) => {
|
||||||
@ -100,7 +94,7 @@ const onSubmit = () => {
|
|||||||
if (dataForm.deptId) {
|
if (dataForm.deptId) {
|
||||||
putObj(dataForm)
|
putObj(dataForm)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
closeDialog(); // 关闭弹窗
|
visible.value = false; // 关闭弹窗
|
||||||
emit('refresh');
|
emit('refresh');
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@ -109,7 +103,7 @@ const onSubmit = () => {
|
|||||||
} else {
|
} else {
|
||||||
addObj(dataForm)
|
addObj(dataForm)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
closeDialog(); // 关闭弹窗
|
visible.value = false; // 关闭弹窗
|
||||||
emit('refresh');
|
emit('refresh');
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class="dialog-footer">
|
<span class="dialog-footer">
|
||||||
<el-button @click="onCancel">{{ $t('common.cancelButtonText') }}</el-button>
|
<el-button @click="visible = false">{{ $t('common.cancelButtonText') }}</el-button>
|
||||||
<el-button type="primary" @click="onSubmit">{{ $t('common.confirmButtonText') }}</el-button>
|
<el-button type="primary" @click="onSubmit">{{ $t('common.confirmButtonText') }}</el-button>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
@ -46,11 +46,13 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts" name="dict-item-form">
|
<script setup lang="ts" name="dict-item-form">
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
import { getItemObj, addItemObj, putItemObj, validateDictItemLabel } from '/@/api/admin/dict';
|
import { getItemObj, addItemObj, putItemObj, validateDictItemLabel } from '/@/api/admin/dict';
|
||||||
import { useMessage } from '/@/hooks/message';
|
import { useMessage } from '/@/hooks/message';
|
||||||
|
|
||||||
// 定义子组件向父组件传值/事件
|
// 定义子组件向父组件传值/事件
|
||||||
const emit = defineEmits(['refresh']);
|
const emit = defineEmits(['refresh']);
|
||||||
|
const { t } = useI18n();
|
||||||
|
|
||||||
// 定义变量内容
|
// 定义变量内容
|
||||||
const dicDialogFormRef = ref();
|
const dicDialogFormRef = ref();
|
||||||
@ -85,59 +87,38 @@ const dataRules = reactive({
|
|||||||
|
|
||||||
// 打开弹窗
|
// 打开弹窗
|
||||||
const openDialog = (row: any, dictForm: any) => {
|
const openDialog = (row: any, dictForm: any) => {
|
||||||
|
visible.value = true;
|
||||||
dataForm.id = '';
|
dataForm.id = '';
|
||||||
if (dictForm) {
|
|
||||||
dataForm.dictId = dictForm.dictId;
|
nextTick(() => {
|
||||||
dataForm.dictType = dictForm.dictType;
|
dicDialogFormRef.value?.resetFields();
|
||||||
}
|
});
|
||||||
|
|
||||||
if (row?.id) {
|
if (row?.id) {
|
||||||
getItemObj(row.id).then((res) => {
|
getItemObj(row.id).then((res) => {
|
||||||
Object.assign(dataForm, res.data);
|
Object.assign(dataForm, res.data);
|
||||||
});
|
});
|
||||||
} else {
|
} else if (dictForm) {
|
||||||
// 清空表单,此项需加表单验证才能使用
|
dataForm.dictId = dictForm.dictId;
|
||||||
nextTick(() => {
|
dataForm.dictType = dictForm.dictType;
|
||||||
dicDialogFormRef?.value?.resetFields();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
visible.value = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 关闭弹窗
|
|
||||||
const closeDialog = () => {
|
|
||||||
visible.value = false;
|
|
||||||
};
|
|
||||||
// 取消
|
|
||||||
const onCancel = () => {
|
|
||||||
closeDialog();
|
|
||||||
};
|
|
||||||
// 提交
|
// 提交
|
||||||
const onSubmit = () => {
|
const onSubmit = async () => {
|
||||||
dicDialogFormRef.value.validate((valid: boolean) => {
|
const valid = await dicDialogFormRef.value.validate().catch(() => {});
|
||||||
if (!valid) {
|
if (!valid) return false;
|
||||||
return false;
|
|
||||||
}
|
try {
|
||||||
if (dataForm.id) {
|
dataForm.id ? await putItemObj(dataForm) : await addItemObj(dataForm);
|
||||||
putItemObj(dataForm)
|
useMessage().success(t(dataForm.id ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||||
.then(() => {
|
visible.value = false;
|
||||||
closeDialog(); // 关闭弹窗
|
emit('refresh');
|
||||||
emit('refresh');
|
} catch (err: any) {
|
||||||
})
|
useMessage().error(err.msg);
|
||||||
.catch((err) => {
|
}
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
addItemObj(dataForm)
|
|
||||||
.then(() => {
|
|
||||||
closeDialog(); // 关闭弹窗
|
|
||||||
emit('refresh');
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 暴露变量
|
// 暴露变量
|
||||||
defineExpose({
|
defineExpose({
|
||||||
openDialog,
|
openDialog,
|
||||||
|
@ -67,6 +67,7 @@ const handleDelete = (row: any) => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const open = (row: any) => {
|
const open = (row: any) => {
|
||||||
state.queryForm.dictId = row.id;
|
state.queryForm.dictId = row.id;
|
||||||
state.queryForm.dictType = row.dictType;
|
state.queryForm.dictType = row.dictType;
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
</el-form>
|
</el-form>
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class="dialog-footer">
|
<span class="dialog-footer">
|
||||||
<el-button @click="onCancel">{{ $t('common.cancelButtonText') }}</el-button>
|
<el-button @click="visible = false">{{ $t('common.cancelButtonText') }}</el-button>
|
||||||
<el-button @click="onSubmit" type="primary">{{ $t('common.confirmButtonText') }}</el-button>
|
<el-button @click="onSubmit" type="primary">{{ $t('common.confirmButtonText') }}</el-button>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
@ -40,6 +40,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" name="systemDicDialog" setup>
|
<script lang="ts" name="systemDicDialog" setup>
|
||||||
|
import { useI18n } from 'vue-i18n';
|
||||||
import { addObj, getObj, putObj, validateDictType } from '/@/api/admin/dict';
|
import { addObj, getObj, putObj, validateDictType } from '/@/api/admin/dict';
|
||||||
import { useDict } from '/@/hooks/dict';
|
import { useDict } from '/@/hooks/dict';
|
||||||
import { useMessage } from '/@/hooks/message';
|
import { useMessage } from '/@/hooks/message';
|
||||||
@ -48,7 +49,7 @@ import { rule } from '/@/utils/validate';
|
|||||||
// 定义子组件向父组件传值/事件
|
// 定义子组件向父组件传值/事件
|
||||||
const emit = defineEmits(['refresh']);
|
const emit = defineEmits(['refresh']);
|
||||||
const { dict_type } = useDict('dict_type');
|
const { dict_type } = useDict('dict_type');
|
||||||
|
const { t } = useI18n();
|
||||||
// 定义变量内容
|
// 定义变量内容
|
||||||
const dicDialogFormRef = ref();
|
const dicDialogFormRef = ref();
|
||||||
|
|
||||||
@ -78,55 +79,35 @@ const dataRules = reactive({
|
|||||||
});
|
});
|
||||||
|
|
||||||
// 打开弹窗
|
// 打开弹窗
|
||||||
const openDialog = (type: string, row: any) => {
|
const openDialog = (id: string) => {
|
||||||
if (row?.id) {
|
visible.value = true;
|
||||||
getObj(row.id).then((res) => {
|
dataForm.id = '';
|
||||||
|
nextTick(() => {
|
||||||
|
dicDialogFormRef.value?.resetFields();
|
||||||
|
});
|
||||||
|
|
||||||
|
if (id) {
|
||||||
|
getObj(id).then((res) => {
|
||||||
Object.assign(dataForm, res.data);
|
Object.assign(dataForm, res.data);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
// 清空表单,此项需加表单验证才能使用
|
|
||||||
nextTick(() => {
|
|
||||||
dicDialogFormRef?.value?.resetFields();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
visible.value = true;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 关闭弹窗
|
|
||||||
const closeDialog = () => {
|
|
||||||
visible.value = false;
|
|
||||||
};
|
|
||||||
// 取消
|
|
||||||
const onCancel = () => {
|
|
||||||
closeDialog();
|
|
||||||
};
|
|
||||||
// 提交
|
// 提交
|
||||||
const onSubmit = () => {
|
const onSubmit = async () => {
|
||||||
dicDialogFormRef.value.validate((valid: boolean) => {
|
const valid = await dicDialogFormRef.value.validate().catch(() => {});
|
||||||
if (!valid) {
|
if (!valid) return false;
|
||||||
return false;
|
|
||||||
}
|
try {
|
||||||
if (dataForm.id) {
|
dataForm.id ? await putObj(dataForm) : await addObj(dataForm);
|
||||||
putObj(dataForm)
|
useMessage().success(t(dataForm.id ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||||
.then(() => {
|
visible.value = false;
|
||||||
closeDialog(); // 关闭弹窗
|
emit('refresh');
|
||||||
emit('refresh');
|
} catch (err: any) {
|
||||||
})
|
useMessage().error(err.msg);
|
||||||
.catch((err) => {
|
}
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
addObj(dataForm)
|
|
||||||
.then(() => {
|
|
||||||
closeDialog(); // 关闭弹窗
|
|
||||||
emit('refresh');
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 暴露变量
|
// 暴露变量
|
||||||
defineExpose({
|
defineExpose({
|
||||||
openDialog,
|
openDialog,
|
||||||
|
@ -46,7 +46,7 @@
|
|||||||
<el-table-column :label="$t('sysdict.index')" type="index" width="80" />
|
<el-table-column :label="$t('sysdict.index')" type="index" width="80" />
|
||||||
<el-table-column :label="$t('sysdict.dictType')" show-overflow-tooltip>
|
<el-table-column :label="$t('sysdict.dictType')" show-overflow-tooltip>
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button @click="showDictITem(scope.row)" text type="primary">{{ scope.row.dictType }} </el-button>
|
<el-button @click="dictItemDialogRef.open(scope.row)" text type="primary">{{ scope.row.dictType }} </el-button>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column :label="$t('sysdict.description')" prop="description" show-overflow-tooltip sortable></el-table-column>
|
<el-table-column :label="$t('sysdict.description')" prop="description" show-overflow-tooltip sortable></el-table-column>
|
||||||
@ -59,8 +59,8 @@
|
|||||||
<el-table-column :label="$t('sysdict.createTime')" prop="createTime" show-overflow-tooltip sortable></el-table-column>
|
<el-table-column :label="$t('sysdict.createTime')" prop="createTime" show-overflow-tooltip sortable></el-table-column>
|
||||||
<el-table-column :label="$t('common.action')" width="200">
|
<el-table-column :label="$t('common.action')" width="200">
|
||||||
<template #default="scope">
|
<template #default="scope">
|
||||||
<el-button @click="showDictITem(scope.row)" text type="primary">{{ $t('sysdict.dictItem') }} </el-button>
|
<el-button @click="dictItemDialogRef.open(scope.row)" text type="primary">{{ $t('sysdict.dictItem') }} </el-button>
|
||||||
<el-button @click="onOpenEditDic('edit', scope.row)" text type="primary">{{ $t('common.editBtn') }} </el-button>
|
<el-button @click="dicDialogRef.openDialog(scope.row.id)" text type="primary">{{ $t('common.editBtn') }} </el-button>
|
||||||
<el-tooltip :content="$t('sysdict.deleteDisabledTip')" :disabled="scope.row.systemFlag === '0'" placement="top">
|
<el-tooltip :content="$t('sysdict.deleteDisabledTip')" :disabled="scope.row.systemFlag === '0'" placement="top">
|
||||||
<span style="margin-left: 12px">
|
<span style="margin-left: 12px">
|
||||||
<el-button :disabled="scope.row.systemFlag !== '0'" @click="handleDelete([scope.row.id])" text type="primary">
|
<el-button :disabled="scope.row.systemFlag !== '0'" @click="handleDelete([scope.row.id])" text type="primary">
|
||||||
@ -107,15 +107,6 @@ const state: BasicTableProps = reactive<BasicTableProps>({
|
|||||||
});
|
});
|
||||||
const { getDataList, currentChangeHandle, sizeChangeHandle } = useTable(state);
|
const { getDataList, currentChangeHandle, sizeChangeHandle } = useTable(state);
|
||||||
|
|
||||||
// 打开修改字典弹窗
|
|
||||||
const onOpenEditDic = (type: string, row: any) => {
|
|
||||||
dicDialogRef.value.openDialog(type, row);
|
|
||||||
};
|
|
||||||
|
|
||||||
const showDictITem = (row: any) => {
|
|
||||||
dictItemDialogRef.value.open(row);
|
|
||||||
};
|
|
||||||
|
|
||||||
// 清空搜索条件
|
// 清空搜索条件
|
||||||
const resetQuery = () => {
|
const resetQuery = () => {
|
||||||
queryRef.value.resetFields();
|
queryRef.value.resetFields();
|
||||||
@ -139,6 +130,7 @@ const handleSelectionChange = (objs: any) => {
|
|||||||
});
|
});
|
||||||
multiple.value = !objs.length;
|
multiple.value = !objs.length;
|
||||||
};
|
};
|
||||||
|
|
||||||
//刷新缓存
|
//刷新缓存
|
||||||
const handleRefreshCache = () => {
|
const handleRefreshCache = () => {
|
||||||
refreshCache().then(() => {
|
refreshCache().then(() => {
|
||||||
|
@ -34,16 +34,13 @@ import { useMessage } from '/@/hooks/message';
|
|||||||
import { addObj, getObj, putObj, validateName, validateZhCn, validateEn } from '/@/api/admin/i18n';
|
import { addObj, getObj, putObj, validateName, validateZhCn, validateEn } from '/@/api/admin/i18n';
|
||||||
import { useI18n } from 'vue-i18n';
|
import { useI18n } from 'vue-i18n';
|
||||||
import { rule } from '/@/utils/validate';
|
import { rule } from '/@/utils/validate';
|
||||||
import { validateTenantCode } from '/@/api/admin/tenant';
|
|
||||||
|
|
||||||
const emit = defineEmits(['refresh']);
|
const emit = defineEmits(['refresh']);
|
||||||
|
|
||||||
const { t } = useI18n();
|
const { t } = useI18n();
|
||||||
|
|
||||||
// 定义变量内容
|
// 定义变量内容
|
||||||
const dataFormRef = ref();
|
const dataFormRef = ref();
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
// 定义字典
|
|
||||||
|
|
||||||
// 提交表单数据
|
// 提交表单数据
|
||||||
const form = reactive({
|
const form = reactive({
|
||||||
@ -90,11 +87,10 @@ const dataRules = ref({
|
|||||||
const openDialog = (id: string) => {
|
const openDialog = (id: string) => {
|
||||||
visible.value = true;
|
visible.value = true;
|
||||||
form.id = '';
|
form.id = '';
|
||||||
|
|
||||||
// 重置表单数据
|
// 重置表单数据
|
||||||
if (dataFormRef.value) {
|
nextTick(() => {
|
||||||
dataFormRef.value.resetFields();
|
dataFormRef.value?.resetFields();
|
||||||
}
|
});
|
||||||
|
|
||||||
// 获取sysI18n信息
|
// 获取sysI18n信息
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -104,34 +100,18 @@ const openDialog = (id: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 提交
|
// 提交
|
||||||
const onSubmit = () => {
|
const onSubmit = async () => {
|
||||||
dataFormRef.value.validate((valid: boolean) => {
|
const valid = await dataFormRef.value.validate().catch(() => {});
|
||||||
if (!valid) {
|
if (!valid) return false;
|
||||||
return false;
|
|
||||||
}
|
try {
|
||||||
// 更新
|
form.id ? await putObj(form) : await addObj(form);
|
||||||
if (form.id) {
|
useMessage().success(t(form.id ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||||
putObj(form)
|
visible.value = false;
|
||||||
.then(() => {
|
emit('refresh');
|
||||||
useMessage().success(t('common.editSuccessText'));
|
} catch (err: any) {
|
||||||
visible.value = false; // 关闭弹窗
|
useMessage().error(err.msg);
|
||||||
emit('refresh');
|
}
|
||||||
})
|
|
||||||
.catch((err: any) => {
|
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
addObj(form)
|
|
||||||
.then(() => {
|
|
||||||
useMessage().success(t('common.addSuccessText'));
|
|
||||||
visible.value = false; // 关闭弹窗
|
|
||||||
emit('refresh');
|
|
||||||
})
|
|
||||||
.catch((err: any) => {
|
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 初始化表单数据
|
// 初始化表单数据
|
||||||
|
@ -8,8 +8,10 @@
|
|||||||
<el-descriptions-item :label="$t('syslog.time')">{{ data.time }}</el-descriptions-item>
|
<el-descriptions-item :label="$t('syslog.time')">{{ data.time }}</el-descriptions-item>
|
||||||
<el-descriptions-item :label="$t('syslog.createTime')">{{ data.createTime }}</el-descriptions-item>
|
<el-descriptions-item :label="$t('syslog.createTime')">{{ data.createTime }}</el-descriptions-item>
|
||||||
<el-descriptions-item :label="$t('syslog.requestUri')">{{ data.requestUri }}</el-descriptions-item>
|
<el-descriptions-item :label="$t('syslog.requestUri')">{{ data.requestUri }}</el-descriptions-item>
|
||||||
<el-descriptions-item :label="$t('syslog.exception')">{{ data.exception }}</el-descriptions-item>
|
|
||||||
<el-descriptions-item :label="$t('syslog.createBy')">{{ data.createBy }}</el-descriptions-item>
|
<el-descriptions-item :label="$t('syslog.createBy')">{{ data.createBy }}</el-descriptions-item>
|
||||||
|
<el-descriptions-item :label="$t('syslog.exception')">
|
||||||
|
<highlightjs v-if="data.exception" autodetect :code="data.exception" />
|
||||||
|
</el-descriptions-item>
|
||||||
</el-descriptions>
|
</el-descriptions>
|
||||||
</el-drawer>
|
</el-drawer>
|
||||||
</template>
|
</template>
|
||||||
@ -29,5 +31,3 @@ defineExpose({
|
|||||||
openDialog,
|
openDialog,
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style scoped></style>
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
<el-form ref="menuDialogFormRef" :model="state.ruleForm" :rules="dataRules" label-width="90px" v-loading="loading">
|
<el-form ref="menuDialogFormRef" :model="state.ruleForm" :rules="dataRules" label-width="90px" v-loading="loading">
|
||||||
<el-row :gutter="20">
|
<el-row :gutter="20">
|
||||||
<el-col :span="12" class="mb20">
|
<el-col :span="12" class="mb20">
|
||||||
<el-form-item :label="$t('sysmenu.menuType')" prop="menType">
|
<el-form-item :label="$t('sysmenu.menuType')" prop="menuType">
|
||||||
<el-radio-group v-model="state.ruleForm.menuType">
|
<el-radio-group v-model="state.ruleForm.menuType">
|
||||||
<el-radio-button label="0">菜单</el-radio-button>
|
<el-radio-button label="0">菜单</el-radio-button>
|
||||||
<el-radio-button label="1">按钮</el-radio-button>
|
<el-radio-button label="1">按钮</el-radio-button>
|
||||||
@ -50,7 +50,7 @@
|
|||||||
<IconSelector :placeholder="$t('sysmenu.inputIconTip')" v-model="state.ruleForm.icon" />
|
<IconSelector :placeholder="$t('sysmenu.inputIconTip')" v-model="state.ruleForm.icon" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
</el-col>
|
</el-col>
|
||||||
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '0' && showembedded">
|
<el-col :span="12" class="mb20" v-if="state.ruleForm.menuType === '0' && state.ruleForm.path.startsWith('http')">
|
||||||
<el-form-item :label="$t('sysmenu.embedded')" prop="embedded">
|
<el-form-item :label="$t('sysmenu.embedded')" prop="embedded">
|
||||||
<el-radio-group v-model="state.ruleForm.embedded">
|
<el-radio-group v-model="state.ruleForm.embedded">
|
||||||
<el-radio-button label="0">否</el-radio-button>
|
<el-radio-button label="0">否</el-radio-button>
|
||||||
@ -86,17 +86,19 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts" name="systemMenuDialog">
|
<script setup lang="ts" name="systemMenuDialog">
|
||||||
import { info, pageList, update, addObj } from '/@/api/admin/menu';
|
import { useI18n } from 'vue-i18n';
|
||||||
|
import { info, pageList, putObj, addObj } from '/@/api/admin/menu';
|
||||||
import { useMessage } from '/@/hooks/message';
|
import { useMessage } from '/@/hooks/message';
|
||||||
|
|
||||||
// 定义子组件向父组件传值/事件
|
// 定义子组件向父组件传值/事件
|
||||||
const emit = defineEmits(['refresh']);
|
const emit = defineEmits(['refresh']);
|
||||||
|
const { t } = useI18n();
|
||||||
// 引入组件
|
// 引入组件
|
||||||
const IconSelector = defineAsyncComponent(() => import('/@/components/iconSelector/index.vue'));
|
const IconSelector = defineAsyncComponent(() => import('/@/components/iconSelector/index.vue'));
|
||||||
|
|
||||||
|
// 定义变量内容
|
||||||
const visible = ref(false);
|
const visible = ref(false);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
// 定义变量内容
|
|
||||||
const menuDialogFormRef = ref();
|
const menuDialogFormRef = ref();
|
||||||
// 定义需要的数据
|
// 定义需要的数据
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
@ -116,27 +118,54 @@ const state = reactive({
|
|||||||
parentData: [] as any[], // 上级菜单数据
|
parentData: [] as any[], // 上级菜单数据
|
||||||
});
|
});
|
||||||
|
|
||||||
// 从后端获取菜单信息
|
// 表单校验规则
|
||||||
const getMenuData = () => {
|
const dataRules = reactive({
|
||||||
|
menType: [{ required: true, message: '菜单类型不能为空', trigger: 'blur' }],
|
||||||
|
parentId: [{ required: true, message: '上级菜单不能为空', trigger: 'blur' }],
|
||||||
|
name: [{ required: true, message: '菜单不能为空', trigger: 'blur' }],
|
||||||
|
path: [{ required: true, message: '路径不能为空', trigger: 'blur' }],
|
||||||
|
icon: [{ required: true, message: '图标不能为空', trigger: 'blur' }],
|
||||||
|
permission: [{ required: true, message: '权限代码不能为空', trigger: 'blur' }],
|
||||||
|
sortOrder: [{ required: true, message: '排序不能为空', trigger: 'blur' }],
|
||||||
|
});
|
||||||
|
|
||||||
|
// 打开弹窗
|
||||||
|
const openDialog = (type: string, row?: any) => {
|
||||||
|
state.ruleForm.menuId = '';
|
||||||
|
visible.value = true;
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
menuDialogFormRef.value?.resetFields();
|
||||||
|
state.ruleForm.parentId = row?.id || '-1';
|
||||||
|
});
|
||||||
|
|
||||||
|
if (row?.id && type === 'edit') {
|
||||||
|
state.ruleForm.menuId = row.id;
|
||||||
|
// 获取当前节点菜单信息
|
||||||
|
getMenuDetail(row.id);
|
||||||
|
}
|
||||||
|
// 渲染上级菜单列表树
|
||||||
|
getAllMenuData();
|
||||||
|
};
|
||||||
|
|
||||||
|
// 获取菜单节点的详细信息
|
||||||
|
const getMenuDetail = (id: string) => {
|
||||||
|
info(id)
|
||||||
|
.then((res) => {
|
||||||
|
Object.assign(state.ruleForm, res.data);
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
loading.value = false;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// 从后端获取菜单信息(含层级)
|
||||||
|
const getAllMenuData = () => {
|
||||||
state.parentData = [];
|
state.parentData = [];
|
||||||
pageList({
|
pageList({
|
||||||
type: '0',
|
type: '0',
|
||||||
}).then((res) => {
|
}).then((res) => {
|
||||||
let menu = {
|
let menu = {
|
||||||
createBy: '',
|
|
||||||
createTime: '',
|
|
||||||
delFlag: '',
|
|
||||||
icon: '',
|
|
||||||
keepAlive: '',
|
|
||||||
menuId: '',
|
|
||||||
menuType: '',
|
|
||||||
parentId: '',
|
|
||||||
path: '',
|
|
||||||
embedded: '0',
|
|
||||||
sortOrder: 0,
|
|
||||||
updateBy: '',
|
|
||||||
updateTime: '',
|
|
||||||
visible: '1',
|
|
||||||
id: '-1',
|
id: '-1',
|
||||||
name: '根菜单',
|
name: '根菜单',
|
||||||
children: [],
|
children: [],
|
||||||
@ -146,81 +175,18 @@ const getMenuData = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const showembedded = ref(false);
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => state.ruleForm.path,
|
|
||||||
(val) => {
|
|
||||||
if (val.startsWith('http')) {
|
|
||||||
showembedded.value = true;
|
|
||||||
} else {
|
|
||||||
showembedded.value = false;
|
|
||||||
state.ruleForm.embedded = '0';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
const dataRules = reactive({
|
|
||||||
menType: [{ required: true, message: '菜单类型不能为空', trigger: 'blur' }],
|
|
||||||
parentId: [{ required: true, message: '上级菜单不能为空', trigger: 'blur' }],
|
|
||||||
name: [{ required: true, message: '菜单不能为空', trigger: 'blur' }],
|
|
||||||
path: [{ required: true, message: '路径不能为空', trigger: 'blur' }],
|
|
||||||
permission: [{ required: true, message: '权限代码不能为空', trigger: 'blur' }],
|
|
||||||
sortOrder: [{ required: true, message: '排序不能为空', trigger: 'blur' }],
|
|
||||||
});
|
|
||||||
// 打开弹窗
|
|
||||||
const openDialog = (type: string, row?: any) => {
|
|
||||||
if (row?.id && type === 'edit') {
|
|
||||||
state.ruleForm.menuId = row.id;
|
|
||||||
// 模拟数据,实际请走接口
|
|
||||||
loading.value = true;
|
|
||||||
info(row.id)
|
|
||||||
.then((res) => {
|
|
||||||
Object.assign(state.ruleForm, res.data);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
loading.value = false;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
// 清空表单,此项需加表单验证才能使用
|
|
||||||
nextTick(() => {
|
|
||||||
menuDialogFormRef?.value?.resetFields();
|
|
||||||
state.ruleForm.parentId = row?.id || '-1';
|
|
||||||
});
|
|
||||||
}
|
|
||||||
visible.value = true;
|
|
||||||
getMenuData();
|
|
||||||
};
|
|
||||||
|
|
||||||
// 保存数据
|
// 保存数据
|
||||||
const onSubmit = () => {
|
const onSubmit = async () => {
|
||||||
// 保存 调用刷新
|
const valid = await menuDialogFormRef.value.validate().catch(() => {});
|
||||||
if (state.ruleForm.menuId) {
|
if (!valid) return false;
|
||||||
loading.value = true;
|
|
||||||
update(state.ruleForm)
|
try {
|
||||||
.then(() => {
|
state.ruleForm.menuId ? await putObj(state.ruleForm) : await addObj(state.ruleForm);
|
||||||
visible.value = false;
|
useMessage().success(t(state.ruleForm.menuId ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||||
emit('refresh');
|
visible.value = false;
|
||||||
})
|
emit('refresh');
|
||||||
.catch((err) => {
|
} catch (err: any) {
|
||||||
useMessage().error(err.msg);
|
useMessage().error(err.msg);
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
loading.value = false;
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
loading.value = true;
|
|
||||||
addObj(state.ruleForm)
|
|
||||||
.then(() => {
|
|
||||||
visible.value = false;
|
|
||||||
emit('refresh');
|
|
||||||
})
|
|
||||||
.catch((err) => {
|
|
||||||
useMessage().error(err.msg);
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
loading.value = false;
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -123,9 +123,9 @@ const openDialog = (id: string) => {
|
|||||||
form.publicId = '';
|
form.publicId = '';
|
||||||
|
|
||||||
// 重置表单数据
|
// 重置表单数据
|
||||||
if (dataFormRef.value) {
|
nextTick(() => {
|
||||||
dataFormRef.value.resetFields();
|
dataFormRef.value?.resetFields();
|
||||||
}
|
});
|
||||||
|
|
||||||
// 获取sysPublicParam信息
|
// 获取sysPublicParam信息
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -135,35 +135,18 @@ const openDialog = (id: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 提交
|
// 提交
|
||||||
const onSubmit = () => {
|
const onSubmit = async () => {
|
||||||
dataFormRef.value.validate((valid: boolean) => {
|
const valid = await dataFormRef.value.validate().catch(() => {});
|
||||||
if (!valid) {
|
if (!valid) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新
|
try {
|
||||||
if (form.publicId) {
|
form.publicId ? await putObj(form) : await addObj(form);
|
||||||
putObj(form)
|
useMessage().success(t(form.publicId ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||||
.then(() => {
|
visible.value = false;
|
||||||
useMessage().success(t('common.editSuccessText'));
|
emit('refresh');
|
||||||
visible.value = false; // 关闭弹窗
|
} catch (err: any) {
|
||||||
emit('refresh');
|
useMessage().error(err.msg);
|
||||||
})
|
}
|
||||||
.catch((err: any) => {
|
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
addObj(form)
|
|
||||||
.then(() => {
|
|
||||||
useMessage().success(t('common.addSuccessText'));
|
|
||||||
visible.value = false; // 关闭弹窗
|
|
||||||
emit('refresh');
|
|
||||||
})
|
|
||||||
.catch((err: any) => {
|
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 初始化表单数据
|
// 初始化表单数据
|
||||||
|
@ -91,9 +91,9 @@ const openDialog = (id: string) => {
|
|||||||
form.postId = '';
|
form.postId = '';
|
||||||
|
|
||||||
// 重置表单数据
|
// 重置表单数据
|
||||||
if (dataFormRef.value) {
|
nextTick(() => {
|
||||||
dataFormRef.value.resetFields();
|
dataFormRef.value?.resetFields();
|
||||||
}
|
});
|
||||||
|
|
||||||
// 获取Post信息
|
// 获取Post信息
|
||||||
if (id) {
|
if (id) {
|
||||||
@ -103,35 +103,18 @@ const openDialog = (id: string) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// 提交
|
// 提交
|
||||||
const onSubmit = () => {
|
const onSubmit = async () => {
|
||||||
dataFormRef.value.validate((valid: boolean) => {
|
const valid = await dataFormRef.value.validate().catch(() => {});
|
||||||
if (!valid) {
|
if (!valid) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 更新
|
try {
|
||||||
if (form.postId) {
|
form.postId ? await putObj(form) : await addObj(form);
|
||||||
putObj(form)
|
useMessage().success(t(form.postId ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||||
.then(() => {
|
visible.value = false;
|
||||||
useMessage().success(t('common.editSuccessText'));
|
emit('refresh');
|
||||||
visible.value = false; // 关闭弹窗
|
} catch (err: any) {
|
||||||
emit('refresh');
|
useMessage().error(err.msg);
|
||||||
})
|
}
|
||||||
.catch((err: any) => {
|
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
addObj(form)
|
|
||||||
.then(() => {
|
|
||||||
useMessage().success(t('common.addSuccessText'));
|
|
||||||
visible.value = false; // 关闭弹窗
|
|
||||||
emit('refresh');
|
|
||||||
})
|
|
||||||
.catch((err: any) => {
|
|
||||||
useMessage().error(err.msg);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// 初始化表格数据
|
// 初始化表格数据
|
||||||
|
@ -149,10 +149,9 @@ const openDialog = (id: string) => {
|
|||||||
visible.value = true;
|
visible.value = true;
|
||||||
form.roleId = '';
|
form.roleId = '';
|
||||||
|
|
||||||
// 重置表单数据
|
nextTick(() => {
|
||||||
if (dataFormRef.value) {
|
|
||||||
dataFormRef.value.resetFields();
|
dataFormRef.value.resetFields();
|
||||||
}
|
});
|
||||||
|
|
||||||
// 获取角色信息
|
// 获取角色信息
|
||||||
if (id) {
|
if (id) {
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
<template #footer>
|
<template #footer>
|
||||||
<span class="dialog-footer">
|
<span class="dialog-footer">
|
||||||
<el-button @click="onCancel">取 消</el-button>
|
<el-button @click="state.dialog.isShowDialog = false">取 消</el-button>
|
||||||
<el-button type="primary" @click="onSubmit">{{ state.dialog.submitTxt }}</el-button>
|
<el-button type="primary" @click="onSubmit">{{ state.dialog.submitTxt }}</el-button>
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
@ -76,14 +76,7 @@ const openDialog = (row: any) => {
|
|||||||
state.dialog.isShowDialog = true;
|
state.dialog.isShowDialog = true;
|
||||||
};
|
};
|
||||||
|
|
||||||
// 关闭弹窗
|
// 提交授权数据
|
||||||
const closeDialog = () => {
|
|
||||||
state.dialog.isShowDialog = false;
|
|
||||||
};
|
|
||||||
// 取消
|
|
||||||
const onCancel = () => {
|
|
||||||
closeDialog();
|
|
||||||
};
|
|
||||||
const onSubmit = () => {
|
const onSubmit = () => {
|
||||||
const menuIds = menuTree.value.getCheckedKeys().join(',').concat(',').concat(menuTree.value.getHalfCheckedKeys().join(','));
|
const menuIds = menuTree.value.getCheckedKeys().join(',').concat(',').concat(menuTree.value.getHalfCheckedKeys().join(','));
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
@ -97,6 +90,7 @@ const onSubmit = () => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 遍历节点
|
||||||
const resolveAllEunuchNodeId = (json: any[], idArr: any[], temp: any[]) => {
|
const resolveAllEunuchNodeId = (json: any[], idArr: any[], temp: any[]) => {
|
||||||
for (let i = 0; i < json.length; i++) {
|
for (let i = 0; i < json.length; i++) {
|
||||||
const item = json[i];
|
const item = json[i];
|
||||||
|
@ -175,9 +175,9 @@ const openDialog = async (id: string) => {
|
|||||||
dataForm.userId = '';
|
dataForm.userId = '';
|
||||||
|
|
||||||
// 重置表单数据
|
// 重置表单数据
|
||||||
if (dataFormRef.value) {
|
nextTick(() => {
|
||||||
dataFormRef.value.resetFields();
|
dataFormRef.value?.resetFields();
|
||||||
}
|
});
|
||||||
|
|
||||||
// 修改获取用户信息
|
// 修改获取用户信息
|
||||||
if (id) {
|
if (id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user