1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<template>
<div class="app-content" style="height:180px;overflow:auto">
<a-spin :spinning="loading" style="width: 100%;height: 100%;">
<a-form-model ref="form" :model="formData" :rules="rules">
<a-form-model-item ref="name" label="角色名称" prop="name">
<a-input v-model="formData.name" style="width:280px;" />
</a-form-model-item>
<a-form-model-item ref="authority" label="角色权限" prop="authority" >
<a-input v-model="formData.authority" style="width:280px;" />
</a-form-model-item>
<a-row>
<a-col :span="24" style="text-align: center">
<a-button type="primary" @click="submit">提交</a-button>
</a-col>
</a-row>
</a-form-model>
</a-spin>
</div>
</template>
<script>
import { isEmptyParams } from '@/views/utils/common'
export default {
name: "roleEdit",
props: {
value: {
type: String,
default: () => {
return null
},
},
},
data () {
return {
formData: { id: null, name: null, authority: null },
rules: {
name: { required: true, message: '请填写角色名称', trigger: 'blur' },
authority: { required: true, message: '请填写角色权限', trigger: 'blur' },
},
loading: false
};
},
created () {
if (!!this.value) {
this.getRole()
}
},
computed: {
},
methods: {
getRole () {
this.loading = true
let pars = { id: this.value }
this.$api.systemManage.getRoleById(pars).then(({ data = {} }) => {
if (data) {
this.formData = data
}
this.loading = false
}).catch(() => { this.loading = false })
},
submit () {
this.$refs.form.validate(valid => {
if (valid) {
this.loading = true
if (!!!this.value) {
let pars = isEmptyParams(this.formData)
let par = { ...pars }
this.$api.systemManage.insertRole(par).then(({ data = {} }) => {
if (data) {
this.$message.success("添加成功!")
this.$emit('close')
}
this.loading = false
}).catch(() => { this.loading = false })
} else {
let pars = isEmptyParams(this.formData)
let par = { ...pars }
this.$api.systemManage.updateRole(par).then(({ data = {} }) => {
if (data) {
this.$message.success("修改成功!")
this.$emit('close')
}
this.loading = false
}).catch(() => { this.loading = false })
}
}
})
}
},
};
</script>
<style scoped lang="less">
.app-content {
.ant-form-item {
margin-bottom: 6px;
}
::v-deep .ant-row {
.ant-col {
display: inline-block;
}
.ant-form-item-label {
width: 90px;
}
.ant-form-item-control-wrapper {
width: calc(100% - 90px);
}
.ant-form-explain {
margin-left: 5px;
display: inline-block;
}
}
}
</style>