mirror of
https://gitee.com/log4j/pig-ui.git
synced 2024-12-22 21:22:33 +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({
|
||||
url: '/admin/menu',
|
||||
method: 'put',
|
||||
|
@ -84,13 +84,12 @@ const showSearch = ref(true);
|
||||
const selectObjs = ref([]) as any;
|
||||
const multiple = ref(true);
|
||||
|
||||
// table hook
|
||||
const state: BasicTableProps = reactive<BasicTableProps>({
|
||||
queryForm: {},
|
||||
pageList: fetchList,
|
||||
descs: ['create_time'],
|
||||
});
|
||||
|
||||
// table hook
|
||||
const { getDataList, currentChangeHandle, sizeChangeHandle, sortChangeHandle, downBlobFile } = useTable(state);
|
||||
|
||||
// 清空搜索条件
|
||||
|
@ -196,11 +196,8 @@ const dataRules = ref({
|
||||
const openDialog = (id: string) => {
|
||||
visible.value = true;
|
||||
form.id = '';
|
||||
|
||||
// 重置表单数据
|
||||
if (dataFormRef.value) {
|
||||
dataFormRef.value.resetFields();
|
||||
}
|
||||
dataFormRef.value?.resetFields();
|
||||
|
||||
// 获取sysOauthClientDetails信息
|
||||
if (id) {
|
||||
@ -210,35 +207,18 @@ const openDialog = (id: string) => {
|
||||
};
|
||||
|
||||
// 提交
|
||||
const onSubmit = () => {
|
||||
dataFormRef.value.validate((valid: boolean) => {
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
const onSubmit = async () => {
|
||||
const valid = await dataFormRef.value.validate().catch(() => {});
|
||||
if (!valid) return false;
|
||||
|
||||
// 更新
|
||||
if (form.id) {
|
||||
putObj(form)
|
||||
.then(() => {
|
||||
useMessage().success(t('common.editSuccessText'));
|
||||
visible.value = false; // 关闭弹窗
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
try {
|
||||
form.id ? await putObj(form) : await addObj(form);
|
||||
useMessage().success(t(form.id ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||
visible.value = false;
|
||||
emit('refresh');
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg);
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化表单数据
|
||||
|
@ -31,7 +31,7 @@
|
||||
</el-form>
|
||||
<template #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>
|
||||
</span>
|
||||
</template>
|
||||
@ -45,7 +45,6 @@ import { useMessage } from '/@/hooks/message';
|
||||
|
||||
// 定义子组件向父组件传值/事件
|
||||
const emit = defineEmits(['refresh']);
|
||||
|
||||
// 定义变量内容
|
||||
const deptDialogFormRef = ref();
|
||||
const dataForm = reactive({
|
||||
@ -65,6 +64,14 @@ const dataRules = ref({
|
||||
|
||||
// 打开弹窗
|
||||
const openDialog = (type: string, id: string) => {
|
||||
visible.value = true;
|
||||
dataForm.deptId = '';
|
||||
|
||||
nextTick(() => {
|
||||
deptDialogFormRef.value?.resetFields();
|
||||
dataForm.parentId = id;
|
||||
});
|
||||
|
||||
if (type === 'edit') {
|
||||
getObj(id)
|
||||
.then((res) => {
|
||||
@ -73,24 +80,11 @@ const openDialog = (type: string, id: string) => {
|
||||
.catch((err) => {
|
||||
useMessage().error(err.msg);
|
||||
});
|
||||
} else {
|
||||
// 清空表单,此项需加表单验证才能使用
|
||||
nextTick(() => {
|
||||
deptDialogFormRef?.value?.resetFields();
|
||||
dataForm.parentId = id;
|
||||
});
|
||||
}
|
||||
visible.value = true;
|
||||
|
||||
getDeptData();
|
||||
};
|
||||
// 关闭弹窗
|
||||
const closeDialog = () => {
|
||||
visible.value = false;
|
||||
};
|
||||
// 取消
|
||||
const onCancel = () => {
|
||||
closeDialog();
|
||||
};
|
||||
|
||||
// 提交
|
||||
const onSubmit = () => {
|
||||
deptDialogFormRef.value.validate((valid: boolean) => {
|
||||
@ -100,7 +94,7 @@ const onSubmit = () => {
|
||||
if (dataForm.deptId) {
|
||||
putObj(dataForm)
|
||||
.then(() => {
|
||||
closeDialog(); // 关闭弹窗
|
||||
visible.value = false; // 关闭弹窗
|
||||
emit('refresh');
|
||||
})
|
||||
.catch((err) => {
|
||||
@ -109,7 +103,7 @@ const onSubmit = () => {
|
||||
} else {
|
||||
addObj(dataForm)
|
||||
.then(() => {
|
||||
closeDialog(); // 关闭弹窗
|
||||
visible.value = false; // 关闭弹窗
|
||||
emit('refresh');
|
||||
})
|
||||
.catch((err) => {
|
||||
|
@ -37,7 +37,7 @@
|
||||
</el-form>
|
||||
<template #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>
|
||||
</span>
|
||||
</template>
|
||||
@ -46,11 +46,13 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts" name="dict-item-form">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { getItemObj, addItemObj, putItemObj, validateDictItemLabel } from '/@/api/admin/dict';
|
||||
import { useMessage } from '/@/hooks/message';
|
||||
|
||||
// 定义子组件向父组件传值/事件
|
||||
const emit = defineEmits(['refresh']);
|
||||
const { t } = useI18n();
|
||||
|
||||
// 定义变量内容
|
||||
const dicDialogFormRef = ref();
|
||||
@ -85,59 +87,38 @@ const dataRules = reactive({
|
||||
|
||||
// 打开弹窗
|
||||
const openDialog = (row: any, dictForm: any) => {
|
||||
visible.value = true;
|
||||
dataForm.id = '';
|
||||
if (dictForm) {
|
||||
dataForm.dictId = dictForm.dictId;
|
||||
dataForm.dictType = dictForm.dictType;
|
||||
}
|
||||
|
||||
nextTick(() => {
|
||||
dicDialogFormRef.value?.resetFields();
|
||||
});
|
||||
|
||||
if (row?.id) {
|
||||
getItemObj(row.id).then((res) => {
|
||||
Object.assign(dataForm, res.data);
|
||||
});
|
||||
} else {
|
||||
// 清空表单,此项需加表单验证才能使用
|
||||
nextTick(() => {
|
||||
dicDialogFormRef?.value?.resetFields();
|
||||
});
|
||||
} else if (dictForm) {
|
||||
dataForm.dictId = dictForm.dictId;
|
||||
dataForm.dictType = dictForm.dictType;
|
||||
}
|
||||
visible.value = true;
|
||||
};
|
||||
|
||||
// 关闭弹窗
|
||||
const closeDialog = () => {
|
||||
visible.value = false;
|
||||
};
|
||||
// 取消
|
||||
const onCancel = () => {
|
||||
closeDialog();
|
||||
};
|
||||
// 提交
|
||||
const onSubmit = () => {
|
||||
dicDialogFormRef.value.validate((valid: boolean) => {
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
if (dataForm.id) {
|
||||
putItemObj(dataForm)
|
||||
.then(() => {
|
||||
closeDialog(); // 关闭弹窗
|
||||
emit('refresh');
|
||||
})
|
||||
.catch((err) => {
|
||||
useMessage().error(err.msg);
|
||||
});
|
||||
} else {
|
||||
addItemObj(dataForm)
|
||||
.then(() => {
|
||||
closeDialog(); // 关闭弹窗
|
||||
emit('refresh');
|
||||
})
|
||||
.catch((err) => {
|
||||
useMessage().error(err.msg);
|
||||
});
|
||||
}
|
||||
});
|
||||
const onSubmit = async () => {
|
||||
const valid = await dicDialogFormRef.value.validate().catch(() => {});
|
||||
if (!valid) return false;
|
||||
|
||||
try {
|
||||
dataForm.id ? await putItemObj(dataForm) : await addItemObj(dataForm);
|
||||
useMessage().success(t(dataForm.id ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||
visible.value = false;
|
||||
emit('refresh');
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg);
|
||||
}
|
||||
};
|
||||
|
||||
// 暴露变量
|
||||
defineExpose({
|
||||
openDialog,
|
||||
|
@ -67,6 +67,7 @@ const handleDelete = (row: any) => {
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
const open = (row: any) => {
|
||||
state.queryForm.dictId = row.id;
|
||||
state.queryForm.dictType = row.dictType;
|
||||
|
@ -31,7 +31,7 @@
|
||||
</el-form>
|
||||
<template #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>
|
||||
</span>
|
||||
</template>
|
||||
@ -40,6 +40,7 @@
|
||||
</template>
|
||||
|
||||
<script lang="ts" name="systemDicDialog" setup>
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { addObj, getObj, putObj, validateDictType } from '/@/api/admin/dict';
|
||||
import { useDict } from '/@/hooks/dict';
|
||||
import { useMessage } from '/@/hooks/message';
|
||||
@ -48,7 +49,7 @@ import { rule } from '/@/utils/validate';
|
||||
// 定义子组件向父组件传值/事件
|
||||
const emit = defineEmits(['refresh']);
|
||||
const { dict_type } = useDict('dict_type');
|
||||
|
||||
const { t } = useI18n();
|
||||
// 定义变量内容
|
||||
const dicDialogFormRef = ref();
|
||||
|
||||
@ -78,55 +79,35 @@ const dataRules = reactive({
|
||||
});
|
||||
|
||||
// 打开弹窗
|
||||
const openDialog = (type: string, row: any) => {
|
||||
if (row?.id) {
|
||||
getObj(row.id).then((res) => {
|
||||
const openDialog = (id: string) => {
|
||||
visible.value = true;
|
||||
dataForm.id = '';
|
||||
nextTick(() => {
|
||||
dicDialogFormRef.value?.resetFields();
|
||||
});
|
||||
|
||||
if (id) {
|
||||
getObj(id).then((res) => {
|
||||
Object.assign(dataForm, res.data);
|
||||
});
|
||||
} else {
|
||||
// 清空表单,此项需加表单验证才能使用
|
||||
nextTick(() => {
|
||||
dicDialogFormRef?.value?.resetFields();
|
||||
});
|
||||
}
|
||||
visible.value = true;
|
||||
};
|
||||
|
||||
// 关闭弹窗
|
||||
const closeDialog = () => {
|
||||
visible.value = false;
|
||||
};
|
||||
// 取消
|
||||
const onCancel = () => {
|
||||
closeDialog();
|
||||
};
|
||||
// 提交
|
||||
const onSubmit = () => {
|
||||
dicDialogFormRef.value.validate((valid: boolean) => {
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
if (dataForm.id) {
|
||||
putObj(dataForm)
|
||||
.then(() => {
|
||||
closeDialog(); // 关闭弹窗
|
||||
emit('refresh');
|
||||
})
|
||||
.catch((err) => {
|
||||
useMessage().error(err.msg);
|
||||
});
|
||||
} else {
|
||||
addObj(dataForm)
|
||||
.then(() => {
|
||||
closeDialog(); // 关闭弹窗
|
||||
emit('refresh');
|
||||
})
|
||||
.catch((err) => {
|
||||
useMessage().error(err.msg);
|
||||
});
|
||||
}
|
||||
});
|
||||
const onSubmit = async () => {
|
||||
const valid = await dicDialogFormRef.value.validate().catch(() => {});
|
||||
if (!valid) return false;
|
||||
|
||||
try {
|
||||
dataForm.id ? await putObj(dataForm) : await addObj(dataForm);
|
||||
useMessage().success(t(dataForm.id ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||
visible.value = false;
|
||||
emit('refresh');
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg);
|
||||
}
|
||||
};
|
||||
|
||||
// 暴露变量
|
||||
defineExpose({
|
||||
openDialog,
|
||||
|
@ -46,7 +46,7 @@
|
||||
<el-table-column :label="$t('sysdict.index')" type="index" width="80" />
|
||||
<el-table-column :label="$t('sysdict.dictType')" show-overflow-tooltip>
|
||||
<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>
|
||||
</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('common.action')" width="200">
|
||||
<template #default="scope">
|
||||
<el-button @click="showDictITem(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="dictItemDialogRef.open(scope.row)" text type="primary">{{ $t('sysdict.dictItem') }} </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">
|
||||
<span style="margin-left: 12px">
|
||||
<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 onOpenEditDic = (type: string, row: any) => {
|
||||
dicDialogRef.value.openDialog(type, row);
|
||||
};
|
||||
|
||||
const showDictITem = (row: any) => {
|
||||
dictItemDialogRef.value.open(row);
|
||||
};
|
||||
|
||||
// 清空搜索条件
|
||||
const resetQuery = () => {
|
||||
queryRef.value.resetFields();
|
||||
@ -139,6 +130,7 @@ const handleSelectionChange = (objs: any) => {
|
||||
});
|
||||
multiple.value = !objs.length;
|
||||
};
|
||||
|
||||
//刷新缓存
|
||||
const handleRefreshCache = () => {
|
||||
refreshCache().then(() => {
|
||||
|
@ -34,16 +34,13 @@ import { useMessage } from '/@/hooks/message';
|
||||
import { addObj, getObj, putObj, validateName, validateZhCn, validateEn } from '/@/api/admin/i18n';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { rule } from '/@/utils/validate';
|
||||
import { validateTenantCode } from '/@/api/admin/tenant';
|
||||
|
||||
const emit = defineEmits(['refresh']);
|
||||
|
||||
const { t } = useI18n();
|
||||
|
||||
// 定义变量内容
|
||||
const dataFormRef = ref();
|
||||
const visible = ref(false);
|
||||
// 定义字典
|
||||
|
||||
// 提交表单数据
|
||||
const form = reactive({
|
||||
@ -90,11 +87,10 @@ const dataRules = ref({
|
||||
const openDialog = (id: string) => {
|
||||
visible.value = true;
|
||||
form.id = '';
|
||||
|
||||
// 重置表单数据
|
||||
if (dataFormRef.value) {
|
||||
dataFormRef.value.resetFields();
|
||||
}
|
||||
nextTick(() => {
|
||||
dataFormRef.value?.resetFields();
|
||||
});
|
||||
|
||||
// 获取sysI18n信息
|
||||
if (id) {
|
||||
@ -104,34 +100,18 @@ const openDialog = (id: string) => {
|
||||
};
|
||||
|
||||
// 提交
|
||||
const onSubmit = () => {
|
||||
dataFormRef.value.validate((valid: boolean) => {
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
// 更新
|
||||
if (form.id) {
|
||||
putObj(form)
|
||||
.then(() => {
|
||||
useMessage().success(t('common.editSuccessText'));
|
||||
visible.value = false; // 关闭弹窗
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
const onSubmit = async () => {
|
||||
const valid = await dataFormRef.value.validate().catch(() => {});
|
||||
if (!valid) return false;
|
||||
|
||||
try {
|
||||
form.id ? await putObj(form) : await addObj(form);
|
||||
useMessage().success(t(form.id ? 'common.editSuccessText' : '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.createTime')">{{ data.createTime }}</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.exception')">
|
||||
<highlightjs v-if="data.exception" autodetect :code="data.exception" />
|
||||
</el-descriptions-item>
|
||||
</el-descriptions>
|
||||
</el-drawer>
|
||||
</template>
|
||||
@ -29,5 +31,3 @@ defineExpose({
|
||||
openDialog,
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped></style>
|
||||
|
@ -3,7 +3,7 @@
|
||||
<el-form ref="menuDialogFormRef" :model="state.ruleForm" :rules="dataRules" label-width="90px" v-loading="loading">
|
||||
<el-row :gutter="20">
|
||||
<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-button label="0">菜单</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" />
|
||||
</el-form-item>
|
||||
</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-radio-group v-model="state.ruleForm.embedded">
|
||||
<el-radio-button label="0">否</el-radio-button>
|
||||
@ -86,17 +86,19 @@
|
||||
</template>
|
||||
|
||||
<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';
|
||||
|
||||
// 定义子组件向父组件传值/事件
|
||||
const emit = defineEmits(['refresh']);
|
||||
const { t } = useI18n();
|
||||
// 引入组件
|
||||
const IconSelector = defineAsyncComponent(() => import('/@/components/iconSelector/index.vue'));
|
||||
|
||||
// 定义变量内容
|
||||
const visible = ref(false);
|
||||
const loading = ref(false);
|
||||
// 定义变量内容
|
||||
const menuDialogFormRef = ref();
|
||||
// 定义需要的数据
|
||||
const state = reactive({
|
||||
@ -116,27 +118,54 @@ const state = reactive({
|
||||
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 = [];
|
||||
pageList({
|
||||
type: '0',
|
||||
}).then((res) => {
|
||||
let menu = {
|
||||
createBy: '',
|
||||
createTime: '',
|
||||
delFlag: '',
|
||||
icon: '',
|
||||
keepAlive: '',
|
||||
menuId: '',
|
||||
menuType: '',
|
||||
parentId: '',
|
||||
path: '',
|
||||
embedded: '0',
|
||||
sortOrder: 0,
|
||||
updateBy: '',
|
||||
updateTime: '',
|
||||
visible: '1',
|
||||
id: '-1',
|
||||
name: '根菜单',
|
||||
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 = () => {
|
||||
// 保存 调用刷新
|
||||
if (state.ruleForm.menuId) {
|
||||
loading.value = true;
|
||||
update(state.ruleForm)
|
||||
.then(() => {
|
||||
visible.value = false;
|
||||
emit('refresh');
|
||||
})
|
||||
.catch((err) => {
|
||||
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;
|
||||
});
|
||||
const onSubmit = async () => {
|
||||
const valid = await menuDialogFormRef.value.validate().catch(() => {});
|
||||
if (!valid) return false;
|
||||
|
||||
try {
|
||||
state.ruleForm.menuId ? await putObj(state.ruleForm) : await addObj(state.ruleForm);
|
||||
useMessage().success(t(state.ruleForm.menuId ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||
visible.value = false;
|
||||
emit('refresh');
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg);
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -123,9 +123,9 @@ const openDialog = (id: string) => {
|
||||
form.publicId = '';
|
||||
|
||||
// 重置表单数据
|
||||
if (dataFormRef.value) {
|
||||
dataFormRef.value.resetFields();
|
||||
}
|
||||
nextTick(() => {
|
||||
dataFormRef.value?.resetFields();
|
||||
});
|
||||
|
||||
// 获取sysPublicParam信息
|
||||
if (id) {
|
||||
@ -135,35 +135,18 @@ const openDialog = (id: string) => {
|
||||
};
|
||||
|
||||
// 提交
|
||||
const onSubmit = () => {
|
||||
dataFormRef.value.validate((valid: boolean) => {
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
const onSubmit = async () => {
|
||||
const valid = await dataFormRef.value.validate().catch(() => {});
|
||||
if (!valid) return false;
|
||||
|
||||
// 更新
|
||||
if (form.publicId) {
|
||||
putObj(form)
|
||||
.then(() => {
|
||||
useMessage().success(t('common.editSuccessText'));
|
||||
visible.value = false; // 关闭弹窗
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
try {
|
||||
form.publicId ? await putObj(form) : await addObj(form);
|
||||
useMessage().success(t(form.publicId ? 'common.editSuccessText' : 'common.addSuccessText'));
|
||||
visible.value = false;
|
||||
emit('refresh');
|
||||
} catch (err: any) {
|
||||
useMessage().error(err.msg);
|
||||
}
|
||||
};
|
||||
|
||||
// 初始化表单数据
|
||||
|
@ -91,9 +91,9 @@ const openDialog = (id: string) => {
|
||||
form.postId = '';
|
||||
|
||||
// 重置表单数据
|
||||
if (dataFormRef.value) {
|
||||
dataFormRef.value.resetFields();
|
||||
}
|
||||
nextTick(() => {
|
||||
dataFormRef.value?.resetFields();
|
||||
});
|
||||
|
||||
// 获取Post信息
|
||||
if (id) {
|
||||
@ -103,35 +103,18 @@ const openDialog = (id: string) => {
|
||||
};
|
||||
|
||||
// 提交
|
||||
const onSubmit = () => {
|
||||
dataFormRef.value.validate((valid: boolean) => {
|
||||
if (!valid) {
|
||||
return false;
|
||||
}
|
||||
const onSubmit = async () => {
|
||||
const valid = await dataFormRef.value.validate().catch(() => {});
|
||||
if (!valid) return false;
|
||||
|
||||
// 更新
|
||||
if (form.postId) {
|
||||
putObj(form)
|
||||
.then(() => {
|
||||
useMessage().success(t('common.editSuccessText'));
|
||||
visible.value = false; // 关闭弹窗
|
||||
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);
|
||||
});
|
||||
}
|
||||
});
|
||||
try {
|
||||
form.postId ? await putObj(form) : await addObj(form);
|
||||
useMessage().success(t(form.postId ? 'common.editSuccessText' : '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;
|
||||
form.roleId = '';
|
||||
|
||||
// 重置表单数据
|
||||
if (dataFormRef.value) {
|
||||
nextTick(() => {
|
||||
dataFormRef.value.resetFields();
|
||||
}
|
||||
});
|
||||
|
||||
// 获取角色信息
|
||||
if (id) {
|
||||
|
@ -17,7 +17,7 @@
|
||||
|
||||
<template #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>
|
||||
</span>
|
||||
</template>
|
||||
@ -76,14 +76,7 @@ const openDialog = (row: any) => {
|
||||
state.dialog.isShowDialog = true;
|
||||
};
|
||||
|
||||
// 关闭弹窗
|
||||
const closeDialog = () => {
|
||||
state.dialog.isShowDialog = false;
|
||||
};
|
||||
// 取消
|
||||
const onCancel = () => {
|
||||
closeDialog();
|
||||
};
|
||||
// 提交授权数据
|
||||
const onSubmit = () => {
|
||||
const menuIds = menuTree.value.getCheckedKeys().join(',').concat(',').concat(menuTree.value.getHalfCheckedKeys().join(','));
|
||||
loading.value = true;
|
||||
@ -97,6 +90,7 @@ const onSubmit = () => {
|
||||
});
|
||||
};
|
||||
|
||||
// 遍历节点
|
||||
const resolveAllEunuchNodeId = (json: any[], idArr: any[], temp: any[]) => {
|
||||
for (let i = 0; i < json.length; i++) {
|
||||
const item = json[i];
|
||||
|
@ -175,9 +175,9 @@ const openDialog = async (id: string) => {
|
||||
dataForm.userId = '';
|
||||
|
||||
// 重置表单数据
|
||||
if (dataFormRef.value) {
|
||||
dataFormRef.value.resetFields();
|
||||
}
|
||||
nextTick(() => {
|
||||
dataFormRef.value?.resetFields();
|
||||
});
|
||||
|
||||
// 修改获取用户信息
|
||||
if (id) {
|
||||
|
Loading…
Reference in New Issue
Block a user