fieldPermissions.vue 10 KB

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