Introducing new features. 部门管理增加i18n

This commit is contained in:
aeizzz 2023-02-07 10:08:08 +08:00
parent 619c08d2dd
commit bd489d6756
4 changed files with 93 additions and 67 deletions

View File

@ -1,32 +1,31 @@
<template>
<div class="system-dept-dialog-container">
<el-dialog :title="state.dialog.title" v-model="state.dialog.isShowDialog" width="769px">
<el-form ref="deptDialogFormRef" :model="state.form" size="default" label-width="90px">
<el-dialog :title="dataForm.deptId ? $t('common.editBtn') : $t('common.addBtn')" v-model="visible" width="769px">
<el-form ref="deptDialogFormRef" :model="dataForm" size="default" label-width="90px" :rules="dataRules">
<el-row :gutter="35">
<el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24" class="mb20">
<el-form-item label="上级部门">
<el-tree-select v-model="state.form.parentId" :data="state.parentData"
<el-form-item :label="$t('sysdept.parentId')" prop="parentId">
<el-tree-select v-model="dataForm.parentId" :data="parentData"
:props="{ value: 'id', label: 'name', children: 'children' }" class="w100" clearable check-strictly
placeholder="请选择上级部门">
</el-tree-select>
:placeholder="$t('sysdept.inputparentIdTip')"/>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
<el-form-item label="部门名称">
<el-input v-model="state.form.name" placeholder="请输入部门名称" clearable></el-input>
<el-form-item :label="$t('sysdept.name')" prop="name">
<el-input v-model="dataForm.name" :placeholder="$t('sysdept.inputnameTip')" clearable/>
</el-form-item>
</el-col>
<el-col :xs="24" :sm="12" :md="12" :lg="12" :xl="12" class="mb20">
<el-form-item label="排序">
<el-input-number v-model="state.form.sortOrder" placeholder="请输入部门名称" clearable></el-input-number>
<el-form-item :label="$t('sysdept.sortOrder')" prop="sortOrder">
<el-input-number v-model="dataForm.sortOrder" :placeholder="$t('sysdept.inputsortOrderTip')" clearable/>
</el-form-item>
</el-col>
</el-row>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="onCancel" size="default"> </el-button>
<el-button type="primary" @click="onSubmit" size="default">{{ state.dialog.submitTxt }}</el-button>
<el-button @click="onCancel" size="default">{{ $t('common.cancelButtonText') }}</el-button>
<el-button type="primary" @click="onSubmit" size="default">{{ $t('common.confirmButtonText') }}</el-button>
</span>
</template>
</el-dialog>
@ -42,51 +41,45 @@ const emit = defineEmits(['refresh']);
//
const deptDialogFormRef = ref();
const state = reactive({
form: {
const dataForm = reactive({
parentId: '',
deptId: '',
name: '',
sortOrder: 9999
},
parentData: [] as any[], //
dialog: {
isShowDialog: false,
type: '',
title: '',
submitTxt: '',
},
});
})
const parentData = ref<any[]>([])
const visible = ref(false)
const dataRules = ref({
parentId: [{ required: true, message: "上级部门不能为空", trigger: "blur" }],
name: [{ required: true, message: "部门名称不能为空", trigger: "blur" }],
sortOrder: [{ required: true, message: "排序不能为空", trigger: "blur" }],
})
//
const openDialog = (type: string, id: string) => {
if (type === 'edit') {
getObj(id).then(res => {
state.form = Object.assign({},res.data)
Object.assign(dataForm,res.data)
}).catch(err => {
useMessage().error(err.msg)
})
state.dialog.title = '修改部门';
state.dialog.submitTxt = '修 改';
} else {
state.dialog.title = '新增部门';
state.dialog.submitTxt = '新 增';
// 使
nextTick(() => {
deptDialogFormRef.value.resetFields();
state.form = Object.assign({
sortOrder: 9999
})
state.form.parentId = id
deptDialogFormRef?.value?.resetFields();
dataForm.parentId = id
});
}
state.dialog.isShowDialog = true;
visible.value = true
getDeptData()
};
//
const closeDialog = () => {
state.dialog.isShowDialog = false;
visible.value = false;
};
//
const onCancel = () => {
@ -94,32 +87,38 @@ const onCancel = () => {
};
//
const onSubmit = () => {
if (state.dialog.type === 'edit') {
putObj(state.form).then(() => {
closeDialog(); //
emit('refresh');
}).catch(err => {
useMessage().error(err.msg)
})
} else {
addObj(state.form).then(() => {
closeDialog(); //
emit('refresh');
}).catch(err => {
useMessage().error(err.msg)
})
}
deptDialogFormRef.value.validate((valid: boolean) => {
if (!valid) {
return false
}
if (dataForm.deptId) {
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 getDeptData = async () => {
depttree().then(res => {
state.parentData = []
parentData.value = []
const dept = {
id: '-1', name: '根部门', children: [] as any[]
};
dept.children = res.data;
state.parentData.push(dept)
parentData.value.push(dept)
})
};

View File

@ -0,0 +1,13 @@
export default {
sysdept: {
name: 'dept name',
parentId: 'parent dept',
createTime: 'createTime',
weight: 'weight',
sortOrder: 'sortOrder',
inputdeptNameTip: 'input deptName',
inputnameTip: 'input deptName',
inputparentIdTip: 'select deptName',
inputsortOrderTip: 'input sortOrder',
}
}

View File

@ -0,0 +1,15 @@
export default {
sysdept: {
name: '部门名称',
parentId: '上级部门',
createTime: '创建时间',
weight: '排序',
sortOrder: '排序',
inputdeptNameTip: '请输入部门名称',
inputnameTip: '请输入部门名称',
inputparentIdTip: '请选择上级部门',
inputsortOrderTip: '请输入排序',
},
}

View File

@ -2,12 +2,12 @@
<div class="system-dept-container layout-padding">
<el-card shadow="hover" class="layout-padding-auto">
<div class="mb15">
<el-input size="default" placeholder="请输入部门名称" style="max-width: 180px" v-model="state.queryForm.deptName"> </el-input>
<el-button size="default" icon="search" type="primary" class="ml10" @click="getDataList">
查询
<el-input :placeholder="$t('sysdept.inputdeptNameTip')" style="max-width: 180px" v-model="state.queryForm.deptName"> </el-input>
<el-button icon="search" type="primary" class="ml10" @click="getDataList">
{{ $t('common.queryBtn') }}
</el-button>
<el-button size="default" icon="folder-add" type="success" class="ml10" @click="deptDialogRef.openDialog('add');">
新增菜单
<el-button icon="folder-add" type="success" class="ml10" @click="deptDialogRef.openDialog('add');" v-auth="'sys_dept_add'">
{{ $t('common.addBtn') }}
</el-button>
</div>
<el-table
@ -18,15 +18,14 @@
default-expand-all
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
>
<el-table-column prop="name" label="部门名称" show-overflow-tooltip> </el-table-column>
<el-table-column prop="weight" label="排序" show-overflow-tooltip width="80">
</el-table-column>
<el-table-column prop="createTime" label="创建时间" show-overflow-tooltip></el-table-column>
<el-table-column label="操作" show-overflow-tooltip width="200">
<el-table-column :label="$t('sysdept.name')" prop="name" width="400" show-overflow-tooltip> </el-table-column>
<el-table-column :label="$t('sysdept.weight')" prop="weight" show-overflow-tooltip width="80"></el-table-column>
<el-table-column prop="createTime" :label="$t('sysdept.createTime')" show-overflow-tooltip></el-table-column>
<el-table-column :label="$t('common.action')" show-overflow-tooltip width="200">
<template #default="scope">
<el-button text type="primary" @click="onOpenAddDept('add',scope.row)">新增</el-button>
<el-button text type="primary" @click="onOpenEditDept('edit', scope.row)">修改</el-button>
<el-button text type="primary" @click="onTabelRowDel(scope.row)">删除</el-button>
<el-button text type="primary" @click="onOpenAddDept('add',scope.row)" v-auth="'sys_dept_add'"> {{ $t('common.addBtn') }}</el-button>
<el-button text type="primary" @click="onOpenEditDept('edit', scope.row)" v-auth="'sys_dept_edit'">{{$t('common.editBtn') }}</el-button>
<el-button text type="primary" @click="onTabelRowDel(scope.row)" v-auth="'sys_dept_del'"> {{ $t('common.delBtn') }}</el-button>
</template>
</el-table-column>
</el-table>
@ -49,7 +48,7 @@ const { t } = useI18n()
const deptDialogRef = ref();
const state: BasicTableProps = reactive<BasicTableProps>({
pageList: depttree, // H
pageList: depttree,
queryForm: {
deptName: ''
},