|
|
@@ -4,7 +4,7 @@
|
|
4
|
4
|
<view class="content">
|
|
5
|
5
|
<view class="tip-card">
|
|
6
|
6
|
<u-icon name="setting" size="18" color="#108cff"></u-icon>
|
|
7
|
|
- <text class="tip-text">为指定角色配置仓库各字段的「可查看」「可编辑」权限,保存后该角色用户将按此配置在列表/详情中看到并可编辑对应字段。</text>
|
|
|
7
|
+ <text class="tip-text">为指定角色配置仓库各字段的「可查看」「可编辑」权限,以及「编辑」「删除」按钮权限。保存后该角色用户将按此配置在列表/详情中看到并可编辑对应字段、使用对应按钮。</text>
|
|
8
|
8
|
</view>
|
|
9
|
9
|
|
|
10
|
10
|
<!-- 选择角色 -->
|
|
|
@@ -77,6 +77,27 @@
|
|
77
|
77
|
</view>
|
|
78
|
78
|
</scroll-view>
|
|
79
|
79
|
</view>
|
|
|
80
|
+
|
|
|
81
|
+ <!-- 按钮权限 -->
|
|
|
82
|
+ <view class="section">
|
|
|
83
|
+ <view class="section-head">
|
|
|
84
|
+ <text class="section-title">按钮权限</text>
|
|
|
85
|
+ <view class="btn-group">
|
|
|
86
|
+ <u-button type="primary" size="mini" :loading="saveLoading"
|
|
|
87
|
+ :disabled="!currentRoleId || !buttonPermissionList.length" @click="saveButtonConfig">保存配置</u-button>
|
|
|
88
|
+ </view>
|
|
|
89
|
+ </view>
|
|
|
90
|
+ <view class="button-list">
|
|
|
91
|
+ <view class="field-item" v-for="item in buttonPermissionList" :key="item.buttonKey">
|
|
|
92
|
+ <view class="field-name-wrap">
|
|
|
93
|
+ <text class="field-name">{{ item.label }}</text>
|
|
|
94
|
+ </view>
|
|
|
95
|
+ <view class="field-switches">
|
|
|
96
|
+ <u-switch v-model="item.enabled" size="20" active-color="#09bb07"></u-switch>
|
|
|
97
|
+ </view>
|
|
|
98
|
+ </view>
|
|
|
99
|
+ </view>
|
|
|
100
|
+ </view>
|
|
80
|
101
|
</view>
|
|
81
|
102
|
</view>
|
|
82
|
103
|
</template>
|
|
|
@@ -106,6 +127,11 @@ export default {
|
|
106
|
127
|
loadConfigLoading: false,
|
|
107
|
128
|
saveLoading: false,
|
|
108
|
129
|
permissionList: [],
|
|
|
130
|
+ // 按钮权限:编辑、删除,与后端 buttonKey 一致
|
|
|
131
|
+ buttonPermissionList: [
|
|
|
132
|
+ { buttonKey: 'edit', label: '编辑', enabled: false },
|
|
|
133
|
+ { buttonKey: 'delete', label: '删除', enabled: false },
|
|
|
134
|
+ ],
|
|
109
|
135
|
};
|
|
110
|
136
|
},
|
|
111
|
137
|
computed: {
|
|
|
@@ -162,10 +188,13 @@ export default {
|
|
162
|
188
|
return;
|
|
163
|
189
|
}
|
|
164
|
190
|
this.loadConfigLoading = true;
|
|
165
|
|
- uni.$u.api.wareHouseFieldPermissionsConfigGet({ roleId })
|
|
166
|
|
- .then((res) => {
|
|
167
|
|
- if (res && res.data && Array.isArray(res.data)) {
|
|
168
|
|
- this.permissionList = res.data.map((p) => ({
|
|
|
191
|
+ Promise.all([
|
|
|
192
|
+ uni.$u.api.wareHouseFieldPermissionsConfigGet({ roleId }),
|
|
|
193
|
+ uni.$u.api.wareHouseButtonPermissionsConfigGet({ roleId }),
|
|
|
194
|
+ ])
|
|
|
195
|
+ .then(([fieldRes, buttonRes]) => {
|
|
|
196
|
+ if (fieldRes && fieldRes.data && Array.isArray(fieldRes.data)) {
|
|
|
197
|
+ this.permissionList = fieldRes.data.map((p) => ({
|
|
169
|
198
|
fieldName: p.fieldName,
|
|
170
|
199
|
read: !!p.read,
|
|
171
|
200
|
edit: !!p.edit,
|
|
|
@@ -173,6 +202,14 @@ export default {
|
|
173
|
202
|
} else {
|
|
174
|
203
|
this.permissionList = [];
|
|
175
|
204
|
}
|
|
|
205
|
+ if (buttonRes && buttonRes.data && Array.isArray(buttonRes.data)) {
|
|
|
206
|
+ const map = {};
|
|
|
207
|
+ buttonRes.data.forEach((b) => { map[b.buttonKey] = !!b.enabled; });
|
|
|
208
|
+ this.buttonPermissionList = [
|
|
|
209
|
+ { buttonKey: 'edit', label: '编辑', enabled: !!map['edit'] },
|
|
|
210
|
+ { buttonKey: 'delete', label: '删除', enabled: !!map['delete'] },
|
|
|
211
|
+ ];
|
|
|
212
|
+ }
|
|
176
|
213
|
})
|
|
177
|
214
|
.catch(() => {
|
|
178
|
215
|
this.permissionList = [];
|
|
|
@@ -209,16 +246,43 @@ export default {
|
|
209
|
246
|
this.saveLoading = false;
|
|
210
|
247
|
});
|
|
211
|
248
|
},
|
|
|
249
|
+ saveButtonConfig() {
|
|
|
250
|
+ const roleId = this.currentRoleId;
|
|
|
251
|
+ const roleKey = this.currentRoleKey;
|
|
|
252
|
+ if (roleId == null) {
|
|
|
253
|
+ uni.$u.toast('请选择或填写角色');
|
|
|
254
|
+ return;
|
|
|
255
|
+ }
|
|
|
256
|
+ this.saveLoading = true;
|
|
|
257
|
+ uni.$u.api.wareHouseButtonPermissionsConfigSave({
|
|
|
258
|
+ roleId,
|
|
|
259
|
+ roleKey,
|
|
|
260
|
+ permissions: this.buttonPermissionList.map((p) => ({ buttonKey: p.buttonKey, enabled: p.enabled })),
|
|
|
261
|
+ })
|
|
|
262
|
+ .then(() => {
|
|
|
263
|
+ uni.$u.toast('按钮权限保存成功');
|
|
|
264
|
+ })
|
|
|
265
|
+ .catch(() => {
|
|
|
266
|
+ uni.$u.toast('保存失败');
|
|
|
267
|
+ })
|
|
|
268
|
+ .finally(() => {
|
|
|
269
|
+ this.saveLoading = false;
|
|
|
270
|
+ });
|
|
|
271
|
+ },
|
|
212
|
272
|
clearConfig() {
|
|
213
|
273
|
if (!this.currentRoleId) return;
|
|
214
|
274
|
uni.showModal({
|
|
215
|
275
|
title: '确认清空',
|
|
216
|
|
- content: '将删除该角色下所有字段权限配置,确定吗?',
|
|
|
276
|
+ content: '将删除该角色下所有字段权限与按钮权限配置,确定吗?',
|
|
217
|
277
|
success: (res) => {
|
|
218
|
278
|
if (res.confirm) {
|
|
219
|
279
|
uni.$u.api.wareHouseFieldPermissionsConfigDeleteByRole(this.currentRoleId).then(() => {
|
|
220
|
280
|
uni.$u.toast('已清空');
|
|
221
|
281
|
this.permissionList = [];
|
|
|
282
|
+ this.buttonPermissionList = [
|
|
|
283
|
+ { buttonKey: 'edit', label: '编辑', enabled: false },
|
|
|
284
|
+ { buttonKey: 'delete', label: '删除', enabled: false },
|
|
|
285
|
+ ];
|
|
222
|
286
|
}).catch(() => uni.$u.toast('清空失败'));
|
|
223
|
287
|
}
|
|
224
|
288
|
},
|
|
|
@@ -436,4 +500,10 @@ export default {
|
|
436
|
500
|
.empty-wrap {
|
|
437
|
501
|
padding: 60rpx 0;
|
|
438
|
502
|
}
|
|
|
503
|
+
|
|
|
504
|
+.button-list {
|
|
|
505
|
+ display: flex;
|
|
|
506
|
+ flex-direction: column;
|
|
|
507
|
+ gap: 12rpx;
|
|
|
508
|
+}
|
|
439
|
509
|
</style>
|