Преглед на файлове

feat: add button permissions configuration to fieldPermissions.vue and update API for button permissions

Yannay преди 1 седмица
родител
ревизия
540329e26e
променени са 2 файла, в които са добавени 79 реда и са изтрити 6 реда
  1. 76 6
      pages/wareHouse/components/fieldPermissions.vue
  2. 3 0
      utils/api.js

+ 76 - 6
pages/wareHouse/components/fieldPermissions.vue

@@ -4,7 +4,7 @@
4
 		<view class="content">
4
 		<view class="content">
5
 			<view class="tip-card">
5
 			<view class="tip-card">
6
 				<u-icon name="setting" size="18" color="#108cff"></u-icon>
6
 				<u-icon name="setting" size="18" color="#108cff"></u-icon>
7
-				<text class="tip-text">为指定角色配置仓库各字段的「可查看」「可编辑」权限,保存后该角色用户将按此配置在列表/详情中看到并可编辑对应字段。</text>
7
+				<text class="tip-text">为指定角色配置仓库各字段的「可查看」「可编辑」权限,以及「编辑」「删除」按钮权限。保存后该角色用户将按此配置在列表/详情中看到并可编辑对应字段、使用对应按钮。</text>
8
 			</view>
8
 			</view>
9
 
9
 
10
 			<!-- 选择角色 -->
10
 			<!-- 选择角色 -->
@@ -77,6 +77,27 @@
77
 					</view>
77
 					</view>
78
 				</scroll-view>
78
 				</scroll-view>
79
 			</view>
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
 		</view>
101
 		</view>
81
 	</view>
102
 	</view>
82
 </template>
103
 </template>
@@ -106,6 +127,11 @@ export default {
106
 			loadConfigLoading: false,
127
 			loadConfigLoading: false,
107
 			saveLoading: false,
128
 			saveLoading: false,
108
 			permissionList: [],
129
 			permissionList: [],
130
+			// 按钮权限:编辑、删除,与后端 buttonKey 一致
131
+			buttonPermissionList: [
132
+				{ buttonKey: 'edit', label: '编辑', enabled: false },
133
+				{ buttonKey: 'delete', label: '删除', enabled: false },
134
+			],
109
 		};
135
 		};
110
 	},
136
 	},
111
 	computed: {
137
 	computed: {
@@ -162,10 +188,13 @@ export default {
162
 				return;
188
 				return;
163
 			}
189
 			}
164
 			this.loadConfigLoading = true;
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
 							fieldName: p.fieldName,
198
 							fieldName: p.fieldName,
170
 							read: !!p.read,
199
 							read: !!p.read,
171
 							edit: !!p.edit,
200
 							edit: !!p.edit,
@@ -173,6 +202,14 @@ export default {
173
 					} else {
202
 					} else {
174
 						this.permissionList = [];
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
 				.catch(() => {
214
 				.catch(() => {
178
 					this.permissionList = [];
215
 					this.permissionList = [];
@@ -209,16 +246,43 @@ export default {
209
 					this.saveLoading = false;
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
 		clearConfig() {
272
 		clearConfig() {
213
 			if (!this.currentRoleId) return;
273
 			if (!this.currentRoleId) return;
214
 			uni.showModal({
274
 			uni.showModal({
215
 				title: '确认清空',
275
 				title: '确认清空',
216
-				content: '将删除该角色下所有字段权限配置,确定吗?',
276
+				content: '将删除该角色下所有字段权限与按钮权限配置,确定吗?',
217
 				success: (res) => {
277
 				success: (res) => {
218
 					if (res.confirm) {
278
 					if (res.confirm) {
219
 						uni.$u.api.wareHouseFieldPermissionsConfigDeleteByRole(this.currentRoleId).then(() => {
279
 						uni.$u.api.wareHouseFieldPermissionsConfigDeleteByRole(this.currentRoleId).then(() => {
220
 							uni.$u.toast('已清空');
280
 							uni.$u.toast('已清空');
221
 							this.permissionList = [];
281
 							this.permissionList = [];
282
+							this.buttonPermissionList = [
283
+								{ buttonKey: 'edit', label: '编辑', enabled: false },
284
+								{ buttonKey: 'delete', label: '删除', enabled: false },
285
+							];
222
 						}).catch(() => uni.$u.toast('清空失败'));
286
 						}).catch(() => uni.$u.toast('清空失败'));
223
 					}
287
 					}
224
 				},
288
 				},
@@ -436,4 +500,10 @@ export default {
436
 .empty-wrap {
500
 .empty-wrap {
437
 	padding: 60rpx 0;
501
 	padding: 60rpx 0;
438
 }
502
 }
503
+
504
+.button-list {
505
+	display: flex;
506
+	flex-direction: column;
507
+	gap: 12rpx;
508
+}
439
 </style>
509
 </style>

+ 3 - 0
utils/api.js

@@ -136,6 +136,9 @@ const install = (Vue, vm) => {
136
 		wareHouseFieldPermissionsConfigGet:(params)=>http.get(store.state.user.path+'/warehouse/fieldPermissions/config',{ params }),
136
 		wareHouseFieldPermissionsConfigGet:(params)=>http.get(store.state.user.path+'/warehouse/fieldPermissions/config',{ params }),
137
 		wareHouseFieldPermissionsConfigSave:(data)=>http.post(store.state.user.path+'/warehouse/fieldPermissions/config', data),
137
 		wareHouseFieldPermissionsConfigSave:(data)=>http.post(store.state.user.path+'/warehouse/fieldPermissions/config', data),
138
 		wareHouseFieldPermissionsConfigDeleteByRole:(roleId)=>http.delete(store.state.user.path+'/warehouse/fieldPermissions/role/' + roleId),
138
 		wareHouseFieldPermissionsConfigDeleteByRole:(roleId)=>http.delete(store.state.user.path+'/warehouse/fieldPermissions/role/' + roleId),
139
+		/** 仓库按钮权限-配置:按角色查询/保存(管理端) */
140
+		wareHouseButtonPermissionsConfigGet:(params)=>http.get(store.state.user.path+'/warehouse/buttonPermissions/config',{ params }),
141
+		wareHouseButtonPermissionsConfigSave:(data)=>http.post(store.state.user.path+'/warehouse/buttonPermissions/config', data),
139
 		wareHouseLog:(params)=>http.get(store.state.user.path+'/warehouse/wareHouseLog',{ params }),//仓库中心-获取仓库操作日志
142
 		wareHouseLog:(params)=>http.get(store.state.user.path+'/warehouse/wareHouseLog',{ params }),//仓库中心-获取仓库操作日志
140
 		wareHouseUpdate:(data)=>http.post(store.state.user.path+'/warehouse/wareHouseUpdate',data),//仓库中心-编辑商品库存
143
 		wareHouseUpdate:(data)=>http.post(store.state.user.path+'/warehouse/wareHouseUpdate',data),//仓库中心-编辑商品库存
141
 		wareHouseLock:(data)=>http.post(store.state.user.path+'/warehouse/wareHouseLock',data),//仓库中心-锁单
144
 		wareHouseLock:(data)=>http.post(store.state.user.path+'/warehouse/wareHouseLock',data),//仓库中心-锁单