feat: 代码优化

This commit is contained in:
lbw 2023-03-13 23:47:37 +08:00
parent a1e36c5028
commit 37113133ae
16 changed files with 196 additions and 363 deletions

View File

@ -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',

View File

@ -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);
//

View File

@ -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);
}
};
//

View File

@ -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) => {

View File

@ -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,

View File

@ -67,6 +67,7 @@ const handleDelete = (row: any) => {
});
});
};
const open = (row: any) => {
state.queryForm.dictId = row.id;
state.queryForm.dictType = row.dictType;

View File

@ -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,

View File

@ -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(() => {

View File

@ -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);
}
};
//

View File

@ -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>

View File

@ -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);
}
};

View File

@ -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);
}
};
//

View File

@ -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);
}
};
//

View File

@ -149,10 +149,9 @@ const openDialog = (id: string) => {
visible.value = true;
form.roleId = '';
//
if (dataFormRef.value) {
nextTick(() => {
dataFormRef.value.resetFields();
}
});
//
if (id) {

View File

@ -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];

View File

@ -175,9 +175,9 @@ const openDialog = async (id: string) => {
dataForm.userId = '';
//
if (dataFormRef.value) {
dataFormRef.value.resetFields();
}
nextTick(() => {
dataFormRef.value?.resetFields();
});
//
if (id) {