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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
| <template>
| <win :title="setting.title" @close="close" :width="'800px'" :loading="loading">
| <el-form :model="formData" class="demo-ruleForm" label-width="100px">
| <el-form-item label="角色配置" prop="roleSetting">
| <el-checkbox v-model="checkAll" @change="handleCheckAllChange">全选</el-checkbox>
| <div style="margin: 15px 0;"></div>
| <el-checkbox-group v-model="checkedList" @change="handleCheckedCitiesChange">
| <el-checkbox v-for="(r,i) in roleOptions" :label="r.role_id" :key="r.role_id">{{ r.role_name }}</el-checkbox>
| </el-checkbox-group>
| </el-form-item>
| </el-form>
| <div slot="footer" align="center" class="dialog-footer">
| <my-button name="取消" site="form" @click="close"/>
| <my-button name="保存" site="form" @click="save"/>
| </div>
| </win>
| </template>
|
| <script>
| import win from '@/components/win'
| import myButton from '@/components/myButton/myButton'
| import * as role from "@/api/system/role";
| import * as user from "@/api/user";
|
| export default {
| components: {win, myButton},
| props: {
| // setting 中须至少包含控制dialog显示或隐藏的属性,其余属性可拓展
| // 将添加/修改的大量数据及逻辑从列表页面中分离出来,避免列表页面代码过多,审查困难
| // 若此页面须回传数据至父页面,可在引用组件时添加事件,本页面使用this.$emit('事件名',参数1,参数2...)回传数据
| setting: {
| type: Object,
| default: () => {
| }
| }
| },
| data() {
| return {
| loading: true,
| data_scope: null,
| checkAll: false,
| checkedList: [],
| roleList: [
| {'id': 1, label: '王涵1'},
| {'id': 2, label: '王涵2'}
| ],
| // 查询参数
| queryParams: {
| pageNum: 1,
| pageSize: 10,
| roleName: undefined,
| roleKey: undefined,
| status: 0,
| orgId: 1
| },
| roleOptions: [],// 选择项
| roleCheckStrictly: true,
| defaultProps: {
| children: 'childList',
| label: 'name',
| },
| formData: {
| userName: '',
| userCode: '',
| userPhone: '',
| sex: 1,
| status: 1,
| remark: '',
| seq: null
| }
| }
| },
| async created() {
| this.title = this.setting.title
| if (this.setting.id != null) {
| await this.getInfo()
| }
| await this.getAllRole()
| this.loading = false
| },
| methods: {
| // 获取所有角色
| async getAllRole() {
| // const user = this.$store.getters.userInfo
| // this.data_scope = 1
| this.data_scope = this.$store.getters.userInfo ? this.$store.getters.userInfo.lv : ''
| await role.listRoleByDataScope({dataScope: this.setting.data_scope}).then(response => {
| if (response) {
| this.roleOptions = response;
| } else {
| this.roleOptions = [];
| }
| this.loading = false;
| }
| );
| },
| handleCheckAllChange(val) {
| if (val) {
| this.checkedList = this.roleOptions.map(x => {
| return x.role_id
| })
| } else {
| this.checkedList = []
| }
| },
| handleCheckedCitiesChange(value) {
| let checkedCount = value.length;
| this.checkAll = checkedCount === this.roleOptions.length;
| },
| async getInfo() {
| // 查询数据
| await user.getUser({id: this.setting.id}).then(res => {
| const data = res.data
| this.formData = Object.assign(this.formData, data)
| this.checkedList = res.list.map(x => {
| return x.role_id
| })
| if (res.list.length === this.roleOptions.length) {
| this.handleCheckedCitiesChange(res.list)
| }
| })
| },
| close() {
| this.formData = {
| userName: '',
| userCode: '',
| userPhone: '',
| sex: 1,
| status: 1,
| remark: '',
| seq: null
| }
| this.$emit('close')
| },
| save() {
| const params = Object.assign({}, this.formData)
| params.roleList = this.checkedList
| if (params.id) {
| if (this.loading) return;
| this.loading = true
| user.updRole(params).then(res => {
| this.loading = false
| if (res) {
| this.$message.success('保存成功!')
| this.close()
| this.$emit('search')
| } else {
| this.$message.error('保存失败')
| }
| }).catch(() => {
| this.loading = false
| })
| }
| }
| }
| }
| </script>
|
|