mirror of
https://github.com/FatttSnake/Pinnacle-OA.git
synced 2026-04-04 22:41:24 +08:00
Fixed form validation
This commit is contained in:
@@ -48,9 +48,15 @@
|
|||||||
@open="handleDialogOpen"
|
@open="handleDialogOpen"
|
||||||
>
|
>
|
||||||
<template #default>
|
<template #default>
|
||||||
<el-form label-width="80px" v-loading="dialogLoading" :rules="rules">
|
<el-form
|
||||||
<el-form-item label="角色名称" prop="name">
|
label-width="80px"
|
||||||
<el-input autocomplete="off" v-model="inputRoleName" />
|
v-loading="dialogLoading"
|
||||||
|
:rules="rules"
|
||||||
|
ref="formRef"
|
||||||
|
:model="roleForm"
|
||||||
|
>
|
||||||
|
<el-form-item label="角色名称" prop="inputRoleName">
|
||||||
|
<el-input autocomplete="off" v-model="roleForm.inputRoleName" />
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="角色权限">
|
<el-form-item label="角色权限">
|
||||||
<el-tree
|
<el-tree
|
||||||
@@ -78,7 +84,8 @@ import request from '@/services'
|
|||||||
import {
|
import {
|
||||||
DATABASE_DELETE_OK,
|
DATABASE_DELETE_OK,
|
||||||
DATABASE_SAVE_OK,
|
DATABASE_SAVE_OK,
|
||||||
DATABASE_SELECT_OK
|
DATABASE_SELECT_OK,
|
||||||
|
DATABASE_UPDATE_OK
|
||||||
} from '@/constants/Common.constants'
|
} from '@/constants/Common.constants'
|
||||||
import _ from 'lodash'
|
import _ from 'lodash'
|
||||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||||
@@ -96,16 +103,19 @@ export default {
|
|||||||
label: 'name',
|
label: 'name',
|
||||||
children: 'children'
|
children: 'children'
|
||||||
},
|
},
|
||||||
|
roleForm: {
|
||||||
inputRoleName: '',
|
inputRoleName: '',
|
||||||
selectedPower: new Set(),
|
selectedPower: new Set()
|
||||||
|
},
|
||||||
isAddNew: true,
|
isAddNew: true,
|
||||||
defaultSelectedPower: [],
|
defaultSelectedPower: [],
|
||||||
dialogTitle: '',
|
dialogTitle: '',
|
||||||
editRoleId: '',
|
editRoleId: '',
|
||||||
rules: {
|
rules: {
|
||||||
name: [
|
inputRoleName: [
|
||||||
{
|
{
|
||||||
required: true
|
required: true,
|
||||||
|
message: '角色名称为必填项'
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
@@ -159,8 +169,8 @@ export default {
|
|||||||
|
|
||||||
if (this.isAddNew) {
|
if (this.isAddNew) {
|
||||||
this.defaultSelectedPower = []
|
this.defaultSelectedPower = []
|
||||||
this.inputRoleName = ''
|
this.roleForm.inputRoleName = ''
|
||||||
this.selectedPower.clear()
|
this.roleForm.selectedPower.clear()
|
||||||
this.dialogTitle = '添加角色'
|
this.dialogTitle = '添加角色'
|
||||||
} else {
|
} else {
|
||||||
this.dialogTitle = '编辑角色'
|
this.dialogTitle = '编辑角色'
|
||||||
@@ -201,9 +211,9 @@ export default {
|
|||||||
},
|
},
|
||||||
handleSelectedPowerChange(data, checked, indeterminate) {
|
handleSelectedPowerChange(data, checked, indeterminate) {
|
||||||
if (checked || indeterminate) {
|
if (checked || indeterminate) {
|
||||||
this.selectedPower.add(data.powerId)
|
this.roleForm.selectedPower.add(data.powerId)
|
||||||
} else {
|
} else {
|
||||||
this.selectedPower.delete(data.powerId)
|
this.roleForm.selectedPower.delete(data.powerId)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
handleAddBtn() {
|
handleAddBtn() {
|
||||||
@@ -211,19 +221,19 @@ export default {
|
|||||||
this.dialogVisible = true
|
this.dialogVisible = true
|
||||||
},
|
},
|
||||||
handleEdit(index, row) {
|
handleEdit(index, row) {
|
||||||
this.inputRoleName = row.name
|
this.roleForm.inputRoleName = row.name
|
||||||
this.editRoleId = row.id
|
this.editRoleId = row.id
|
||||||
this.selectedPower.clear()
|
this.roleForm.selectedPower.clear()
|
||||||
this.defaultSelectedPower = []
|
this.defaultSelectedPower = []
|
||||||
for (const operation of row.operations) {
|
for (const operation of row.operations) {
|
||||||
this.defaultSelectedPower.push(operation.powerId)
|
this.defaultSelectedPower.push(operation.powerId)
|
||||||
this.selectedPower.add(operation.powerId)
|
this.roleForm.selectedPower.add(operation.powerId)
|
||||||
}
|
}
|
||||||
for (const element of row.elements) {
|
for (const element of row.elements) {
|
||||||
this.selectedPower.add(element.powerId)
|
this.roleForm.selectedPower.add(element.powerId)
|
||||||
}
|
}
|
||||||
for (const menu of row.menus) {
|
for (const menu of row.menus) {
|
||||||
this.selectedPower.add(menu.powerId)
|
this.roleForm.selectedPower.add(menu.powerId)
|
||||||
}
|
}
|
||||||
this.isAddNew = false
|
this.isAddNew = false
|
||||||
this.dialogVisible = true
|
this.dialogVisible = true
|
||||||
@@ -249,14 +259,16 @@ export default {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
handleSubmit() {
|
async handleSubmit() {
|
||||||
|
await this.$refs.formRef.validate((valid) => {
|
||||||
|
if (valid) {
|
||||||
this.dialogLoading = true
|
this.dialogLoading = true
|
||||||
const roleObject = {
|
const roleObject = {
|
||||||
name: this.inputRoleName,
|
name: this.roleForm.inputRoleName,
|
||||||
powers: [],
|
powers: [],
|
||||||
id: ''
|
id: ''
|
||||||
}
|
}
|
||||||
for (const powerId of this.selectedPower) {
|
for (const powerId of this.roleForm.selectedPower) {
|
||||||
const power = {
|
const power = {
|
||||||
id: powerId
|
id: powerId
|
||||||
}
|
}
|
||||||
@@ -284,7 +296,7 @@ export default {
|
|||||||
roleObject.id = this.editRoleId
|
roleObject.id = this.editRoleId
|
||||||
request.put('/role', roleObject).then((res) => {
|
request.put('/role', roleObject).then((res) => {
|
||||||
const response = res.data
|
const response = res.data
|
||||||
if (response.code === DATABASE_SAVE_OK) {
|
if (response.code === DATABASE_UPDATE_OK) {
|
||||||
ElMessage.success({
|
ElMessage.success({
|
||||||
dangerouslyUseHTMLString: true,
|
dangerouslyUseHTMLString: true,
|
||||||
message: '<strong>修改成功</strong>'
|
message: '<strong>修改成功</strong>'
|
||||||
@@ -300,6 +312,8 @@ export default {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
},
|
},
|
||||||
handleCancel() {
|
handleCancel() {
|
||||||
this.dialogVisible = false
|
this.dialogVisible = false
|
||||||
|
|||||||
Reference in New Issue
Block a user