fieldPermissions.vue 11 KB

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