role-switching.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="role-page">
  3. <view class="row-box">
  4. <view class="role-list" v-for="(item,index) in permissionList" :key="index">
  5. <text class="role-name">{{item.label}}</text>
  6. <view class="radio-item" @click="toggleSelect(item,index)">
  7. <image class="icon" :src="`/static/${item.isChecked ? 'check-radio' : 'check-no'}.png`"></image>
  8. </view>
  9. <text class="nowrole" v-show="item.isNowRole" >当前角色</text>
  10. <text class="task-msg">{{item.todoNum}}</text>
  11. </view>
  12. </view>
  13. <view class="btn-confirm" @click="saveChange">
  14. <text class="btn-text">确定</text>
  15. </view>
  16. </view>
  17. </template>
  18. /**
  19. * 角色切换
  20. */
  21. <script>
  22. export default {
  23. data() {
  24. return {
  25. permissionList:[],//权限列表
  26. nowPermission:'',//当前权限
  27. oldPermission:'',//初始化选中的权限
  28. roleList:[
  29. {permission: 1, name: '管理员'},
  30. {permission: 2, name: '查核组长'},
  31. {permission: 3, name: '查核组员'},
  32. {permission: 4, name: '单位负责人'},
  33. {permission: 5, name: '改善者'}
  34. ]
  35. }
  36. },
  37. created() {
  38. let permissions=uni.getStorageSync('permissions');
  39. this.nowPermission=uni.getStorageSync('nowPermission');
  40. this.permissionList=permissions.map((item,index)=>{
  41. let match=this.roleList.find(i => i.permission == item.permission);
  42. return {
  43. value:match.permission,
  44. label:match.name,
  45. todoNum:item.todoNum>0?item.todoNum+'个任务待处理':'暂无待处理',
  46. isNowRole:this.nowPermission==match.permission?true:false,
  47. isChecked:this.nowPermission==match.permission?true:false,
  48. }
  49. });
  50. let obj = this.permissionList.find((item)=>item.isChecked);
  51. this.oldPermission = obj ? obj.value : '';
  52. },
  53. methods: {
  54. toggleSelect(item,index) {
  55. this.permissionList.map((item,index)=>{
  56. item.isChecked=false;
  57. });
  58. this.permissionList[item.value-1].isChecked=true;
  59. },
  60. saveChange(){
  61. let obj = this.permissionList.find((item)=>item.isChecked);
  62. if(obj) {
  63. if(obj.value === this.oldPermission) {
  64. uni.navigateTo({url: '/pages/home/home'});
  65. return;
  66. };
  67. this.$store.dispatch({
  68. type: 'roleSwitching/commActions',
  69. payload: {
  70. key: 'updatePermission',
  71. data: {
  72. permission: obj.value,
  73. }
  74. }
  75. }).then((data)=>{
  76. if(data){
  77. uni.navigateTo({url: '/pages/home/home'});
  78. }
  79. });
  80. }
  81. }
  82. },
  83. }
  84. </script>
  85. <style lang="less">
  86. .role-page {
  87. height: 100%;
  88. .row-box {
  89. .role-list {
  90. height: 107.5rpx;
  91. width: 750rpx;
  92. background: #FFFFFF;
  93. border-bottom: 0.62rpx solid #DADEE6;
  94. position: relative;
  95. .role-name {
  96. font-size: 22.5rpx;
  97. font-family: SourceHanSansCN-Bold, SourceHanSansCN;
  98. font-weight: bold;
  99. color: #292C33;
  100. float: left;
  101. margin-left: 25rpx;
  102. margin-top: 25rpx;
  103. }
  104. .nowrole {
  105. float: right;
  106. font-size: 22.5rpx;
  107. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  108. font-weight: 400;
  109. color: #7A8599;
  110. margin-top: 42.5rpx;
  111. margin-right: 25rpx;
  112. }
  113. .radio-item {
  114. float: right;
  115. margin-right: 25rpx;
  116. margin-top: 41.25rpx;
  117. .icon {
  118. width: 25rpx;
  119. height: 25rpx;
  120. }
  121. }
  122. .task-msg {
  123. font-size: 20rpx;
  124. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  125. font-weight: 400;
  126. color: #7A8599;
  127. position: absolute;
  128. top: 62.5rpx;
  129. left: 25rpx;
  130. }
  131. }
  132. }
  133. .btn-confirm {
  134. width: 750rpx;
  135. height: 75rpx;
  136. background: #3377FF;
  137. position: absolute;
  138. bottom: 0rpx;
  139. .btn-text {
  140. font-size: 22.5rpx;
  141. font-family: SourceHanSansCN-Normal, SourceHanSansCN;
  142. font-weight: 400;
  143. color: #FFFFFF;
  144. line-height: 75rpx;
  145. margin-left: 352.5rpx;
  146. }
  147. }
  148. }
  149. </style>