fieldPermissions.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408
  1. <template>
  2. <view class="page">
  3. <u-navbar class="nav-bar" title="字段权限配置" :autoBack="true" :placeholder="true" v-hideNav></u-navbar>
  4. <view class="content">
  5. <view class="tip-card">
  6. <u-icon name="setting" size="18" color="#108cff"></u-icon>
  7. <text class="tip-text">为指定角色配置仓库各字段的「可读」「可编辑」权限,保存后该角色用户将按此配置在列表/详情中看到并可编辑对应字段。</text>
  8. </view>
  9. <!-- 选择角色 -->
  10. <view class="section role-section">
  11. <view class="section-title">选择角色</view>
  12. <view v-if="roleList.length > 0" class="role-select-wrap">
  13. <picker :value="roleIndex" :range="roleList" range-key="roleName" @change="onRoleChange">
  14. <view class="picker-inner">
  15. <text class="picker-text">{{ currentRoleName }}</text>
  16. <u-icon name="arrow-down" size="14" color="#999"></u-icon>
  17. </view>
  18. </picker>
  19. </view>
  20. <view v-else class="role-input-wrap">
  21. <view class="input-row">
  22. <text class="input-label">角色ID</text>
  23. <u--input v-model="formRoleId" type="number" placeholder="请输入角色ID" border="surround"></u--input>
  24. </view>
  25. <view class="input-row">
  26. <text class="input-label">角色Key</text>
  27. <u--input v-model="formRoleKey" placeholder="如 WAREHOUSER" border="surround"></u--input>
  28. </view>
  29. </view>
  30. <view class="btn-row">
  31. <u-button type="primary" size="small" :loading="loadConfigLoading" @click="loadConfig">加载配置</u-button>
  32. <u-button type="error" plain size="small" :disabled="!currentRoleId" @click="clearConfig">清空该角色配置</u-button>
  33. </view>
  34. </view>
  35. <!-- 字段权限列表(可编辑) -->
  36. <view class="section">
  37. <view class="section-head">
  38. <text class="section-title">字段权限</text>
  39. <u-button type="primary" size="mini" :loading="saveLoading" :disabled="!currentRoleId || permissionList.length === 0" @click="saveConfig">保存配置</u-button>
  40. </view>
  41. <view v-if="loadConfigLoading" class="loading-wrap">
  42. <u-loading-icon mode="circle" size="36"></u-loading-icon>
  43. <text class="loading-text">加载中...</text>
  44. </view>
  45. <scroll-view v-else class="list-wrap" scroll-y enable-back-to-top>
  46. <view class="field-list">
  47. <view v-for="(item, index) in permissionList" :key="item.fieldName" class="field-item">
  48. <view class="field-name-wrap">
  49. <text class="field-name">{{ fieldLabel(item.fieldName) }}</text>
  50. <text class="field-key">{{ item.fieldName }}</text>
  51. </view>
  52. <view class="field-switches">
  53. <view class="switch-cell">
  54. <text class="switch-label">读</text>
  55. <u-switch v-model="item.read" size="20" active-color="#108cff"></u-switch>
  56. </view>
  57. <view class="switch-cell">
  58. <text class="switch-label">编辑</text>
  59. <u-switch v-model="item.edit" size="20" active-color="#09bb07"></u-switch>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. <view v-if="permissionList.length === 0 && !loadConfigLoading" class="empty-wrap">
  65. <u-empty text="请先选择角色并点击「加载配置」" mode="list"></u-empty>
  66. </view>
  67. </scroll-view>
  68. </view>
  69. </view>
  70. </view>
  71. </template>
  72. <script>
  73. const FIELD_LABELS = {
  74. dictLabel: '品牌/商品名', dictValue: '品牌ID', model: '型号', code: '独立编码', warehouseDate: '入库日期',
  75. payType: '付款方式', note: '备注', originalCost: '原始成本', additionalCost: '附加成本', agentPrice: '代理价格',
  76. suggestedPrice: '建议价格', costPrice: '成本价', salesPrice: '销售价', peerPrice: '同行价', actualPrice: '实价',
  77. stock: '库存数量', location: '商品位置', recyclePerson: '回收人员', recyclePersonId: '回收人员ID',
  78. identifyingPerson: '鉴定人员', identifyingPersonId: '鉴定人员ID', lockStatus: '锁单状态', downStatus: '下架状态',
  79. imgsUrl: '图片', goodPicFileList: '商品主图', goodPicHash: '主图哈希', category: '品类', recycleTime: '回收时间',
  80. productAttribute: '产品属性', desc: '描述', series: '系列', dialType: '机芯类型', caseMaterial: '表壳材质',
  81. dialDiameter: '表盘直径', material: '材质', size: '尺寸', yardage: '尺码', price: '官方指导价',
  82. productCondition: '商品成色', detailPicFileList: '细节图', title: '商品标题', productNo: '商品货号', watchYear: '手表年份',
  83. recycleType: '回收类型', recycleSituation: '回收情况', recycleBottomDesc: '回收留底描述', recycleBottomFileList: '回收留底图',
  84. targetAudience: '适用人群', productCard: '商品保卡', cardYear: '保卡年份', cardDate: '保卡日期',
  85. productCardPicFileList: '保卡图片', productTag: '商品标签', productAttachment: '商品附件', productDesc: '商品备注',
  86. productDescPicFileList: '备注图片', continuousWarehousing: '连续入库', label: '标签', stockStatus: '库存状态',
  87. origin: '来源', delFlag: '删除标志',
  88. };
  89. export default {
  90. data() {
  91. return {
  92. roleList: [],
  93. roleIndex: 0,
  94. formRoleId: '',
  95. formRoleKey: '',
  96. loadConfigLoading: false,
  97. saveLoading: false,
  98. permissionList: [],
  99. };
  100. },
  101. computed: {
  102. currentRoleId() {
  103. if (this.roleList.length > 0) {
  104. const r = this.roleList[this.roleIndex];
  105. return r ? r.roleId : null;
  106. }
  107. const id = parseInt(this.formRoleId, 10);
  108. return isNaN(id) ? null : id;
  109. },
  110. currentRoleKey() {
  111. if (this.roleList.length > 0) {
  112. const r = this.roleList[this.roleIndex];
  113. return r ? r.roleKey || '' : '';
  114. }
  115. return this.formRoleKey || '';
  116. },
  117. currentRoleName() {
  118. if (this.roleList.length > 0) {
  119. const r = this.roleList[this.roleIndex];
  120. return r ? (r.roleName || '请选择角色') : '请选择角色';
  121. }
  122. return this.currentRoleId ? `角色ID: ${this.currentRoleId}` : '请填写角色ID并加载';
  123. },
  124. },
  125. onLoad() {},
  126. onShow() {
  127. this.fetchRoleList();
  128. },
  129. methods: {
  130. fieldLabel(name) {
  131. return FIELD_LABELS[name] || name;
  132. },
  133. fetchRoleList() {
  134. uni.$u.api.getRoleOptionSelect({ custom: { loading: false } })
  135. .then((res) => {
  136. const list = (res && res.data) ? (Array.isArray(res.data) ? res.data : []) : [];
  137. this.roleList = list.map((r) => ({ roleId: r.roleId, roleName: r.roleName || r.roleKey || '', roleKey: r.roleKey || '' }));
  138. this.roleIndex = 0;
  139. })
  140. .catch(() => {
  141. this.roleList = [];
  142. });
  143. },
  144. onRoleChange(e) {
  145. this.roleIndex = e.detail.value;
  146. this.permissionList = [];
  147. },
  148. loadConfig() {
  149. const roleId = this.currentRoleId;
  150. if (roleId == null) {
  151. uni.$u.toast('请选择或填写角色');
  152. return;
  153. }
  154. this.loadConfigLoading = true;
  155. uni.$u.api.wareHouseFieldPermissionsConfigGet({ roleId })
  156. .then((res) => {
  157. if (res && res.data && Array.isArray(res.data)) {
  158. this.permissionList = res.data.map((p) => ({
  159. fieldName: p.fieldName,
  160. read: !!p.read,
  161. edit: !!p.edit,
  162. }));
  163. } else {
  164. this.permissionList = [];
  165. }
  166. })
  167. .catch(() => {
  168. this.permissionList = [];
  169. uni.$u.toast('加载失败');
  170. })
  171. .finally(() => {
  172. this.loadConfigLoading = false;
  173. });
  174. },
  175. saveConfig() {
  176. const roleId = this.currentRoleId;
  177. const roleKey = this.currentRoleKey;
  178. if (roleId == null) {
  179. uni.$u.toast('请选择或填写角色');
  180. return;
  181. }
  182. if (!this.permissionList.length) {
  183. uni.$u.toast('请先加载配置');
  184. return;
  185. }
  186. this.saveLoading = true;
  187. uni.$u.api.wareHouseFieldPermissionsConfigSave({
  188. roleId,
  189. roleKey,
  190. permissions: this.permissionList.map((p) => ({ fieldName: p.fieldName, read: p.read, edit: p.edit })),
  191. })
  192. .then(() => {
  193. uni.$u.toast('保存成功');
  194. })
  195. .catch(() => {
  196. uni.$u.toast('保存失败');
  197. })
  198. .finally(() => {
  199. this.saveLoading = false;
  200. });
  201. },
  202. clearConfig() {
  203. if (!this.currentRoleId) return;
  204. uni.showModal({
  205. title: '确认清空',
  206. content: '将删除该角色下所有字段权限配置,确定吗?',
  207. success: (res) => {
  208. if (res.confirm) {
  209. uni.$u.api.wareHouseFieldPermissionsConfigDeleteByRole(this.currentRoleId).then(() => {
  210. uni.$u.toast('已清空');
  211. this.permissionList = [];
  212. }).catch(() => uni.$u.toast('清空失败'));
  213. }
  214. },
  215. });
  216. },
  217. },
  218. };
  219. </script>
  220. <style lang="scss" scoped>
  221. .page {
  222. min-height: 100vh;
  223. background: #f5f6f8;
  224. display: flex;
  225. flex-direction: column;
  226. }
  227. .nav-bar {
  228. border-bottom: 1px solid #eee;
  229. }
  230. .content {
  231. flex: 1;
  232. display: flex;
  233. flex-direction: column;
  234. padding: 24rpx;
  235. box-sizing: border-box;
  236. }
  237. .tip-card {
  238. display: flex;
  239. align-items: flex-start;
  240. gap: 12rpx;
  241. background: #e8f4ff;
  242. border-radius: 16rpx;
  243. padding: 20rpx 24rpx;
  244. margin-bottom: 24rpx;
  245. border: 1px solid rgba(16, 140, 255, 0.2);
  246. .tip-text {
  247. font-size: 26rpx;
  248. color: #333;
  249. line-height: 1.5;
  250. flex: 1;
  251. }
  252. }
  253. .section {
  254. background: #fff;
  255. border-radius: 16rpx;
  256. padding: 24rpx;
  257. margin-bottom: 24rpx;
  258. box-shadow: 0 2rpx 12rpx rgba(0, 0, 0, 0.04);
  259. }
  260. .section-title {
  261. font-size: 30rpx;
  262. font-weight: 600;
  263. color: #333;
  264. margin-bottom: 20rpx;
  265. }
  266. .section-head {
  267. display: flex;
  268. align-items: center;
  269. justify-content: space-between;
  270. margin-bottom: 20rpx;
  271. .section-title {
  272. margin-bottom: 0;
  273. }
  274. }
  275. .role-section {
  276. .role-select-wrap {
  277. margin-bottom: 20rpx;
  278. }
  279. .picker-inner {
  280. display: flex;
  281. align-items: center;
  282. justify-content: space-between;
  283. padding: 20rpx 24rpx;
  284. background: #f9fafb;
  285. border-radius: 12rpx;
  286. border: 1px solid #eee;
  287. .picker-text {
  288. font-size: 28rpx;
  289. color: #333;
  290. }
  291. }
  292. .role-input-wrap {
  293. margin-bottom: 20rpx;
  294. .input-row {
  295. display: flex;
  296. align-items: center;
  297. margin-bottom: 16rpx;
  298. .input-label {
  299. width: 140rpx;
  300. font-size: 28rpx;
  301. color: #666;
  302. }
  303. }
  304. }
  305. .btn-row {
  306. display: flex;
  307. gap: 20rpx;
  308. flex-wrap: wrap;
  309. }
  310. }
  311. .list-wrap {
  312. max-height: 60vh;
  313. }
  314. .loading-wrap {
  315. display: flex;
  316. flex-direction: column;
  317. align-items: center;
  318. justify-content: center;
  319. padding: 60rpx 0;
  320. .loading-text {
  321. margin-top: 16rpx;
  322. font-size: 26rpx;
  323. color: #999;
  324. }
  325. }
  326. .field-list {
  327. display: flex;
  328. flex-direction: column;
  329. gap: 12rpx;
  330. padding-bottom: 24rpx;
  331. }
  332. .field-item {
  333. display: flex;
  334. align-items: center;
  335. justify-content: space-between;
  336. padding: 20rpx 24rpx;
  337. background: #fafafa;
  338. border-radius: 12rpx;
  339. border: 1px solid #f0f0f0;
  340. }
  341. .field-name-wrap {
  342. flex: 1;
  343. min-width: 0;
  344. display: flex;
  345. flex-direction: column;
  346. gap: 4rpx;
  347. }
  348. .field-name {
  349. font-size: 28rpx;
  350. font-weight: 600;
  351. color: #333;
  352. }
  353. .field-key {
  354. font-size: 22rpx;
  355. color: #999;
  356. }
  357. .field-switches {
  358. display: flex;
  359. align-items: center;
  360. gap: 32rpx;
  361. flex-shrink: 0;
  362. }
  363. .switch-cell {
  364. display: flex;
  365. align-items: center;
  366. gap: 12rpx;
  367. .switch-label {
  368. font-size: 24rpx;
  369. color: #666;
  370. }
  371. }
  372. .empty-wrap {
  373. padding: 60rpx 0;
  374. }
  375. </style>