index.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. <template>
  2. <view class="setting_wrap">
  3. <u-navbar title="我的设置" :autoBack="true" :placeholder="true" v-hideNav></u-navbar>
  4. <view class="option_list">
  5. <!-- 只有当showRoleSwitch为true时才显示切换权限按钮 -->
  6. <view v-if="$store.state.user.showRoleSwitch" class="option_item" @click="handleSwitchRole">
  7. <view class="item_left" >
  8. <image src="@/static/parson/permission.png" mode=""></image>
  9. <text class="label">切换权限</text>
  10. </view>
  11. <view class="item-right">
  12. <u-icon name="arrow-right" color="#aaa"></u-icon>
  13. </view>
  14. </view>
  15. <view class="option_item" @click="toPersonal">
  16. <view class="item_left">
  17. <image src="@/static/parson/icon-gezl.png" mode=""></image>
  18. <text class="label">个人资料</text>
  19. </view>
  20. <view class="item-right">
  21. <u-icon name="arrow-right" color="#aaa"></u-icon>
  22. </view>
  23. </view>
  24. <view class="option_item" @click="handleEditPassword">
  25. <view class="item_left">
  26. <image src="@/static/parson/updatePass.png" mode=""></image>
  27. <text class="label">修改密码</text>
  28. </view>
  29. <view class="item-right">
  30. <u-icon name="arrow-right" color="#aaa"></u-icon>
  31. </view>
  32. </view>
  33. <option-list></option-list>
  34. </view>
  35. <view class="logout_btn">
  36. <u-button type="warning" :plain="true" text="退出账号" size="large" @click="handleShowModal"></u-button>
  37. </view>
  38. <u-picker :show="showSwitchRole" :columns="columns" keyName="label" :defaultIndex="defaultIndex" @confirm="confirmSwitchRole" @cancel="showSwitchRole = false"></u-picker>
  39. <u-modal :show="showModal"
  40. @confirm="confirm"
  41. ref="uModal"
  42. :asyncClose="true"
  43. showCancelButton
  44. @cancel="showModal = false"
  45. cancelColor="#409eff"
  46. :confirmText="'退出登录'" confirmColor="#f8836c">
  47. <view class="modal_box">
  48. 确定要退出当前账号
  49. </view>
  50. </u-modal>
  51. </view>
  52. </template>
  53. <script>
  54. import OptionList from '@/pages/person/option/index.vue'
  55. export default {
  56. components: {
  57. OptionList
  58. },
  59. data() {
  60. return {
  61. showModal: false,
  62. showSwitchRole: false,
  63. columns: [],
  64. defaultIndex: [this.$store.state.user.currentRoleIndex],
  65. isHaveCRM: false,
  66. isHaveSalesman: false,
  67. isHaveWarehouse: false,
  68. }
  69. },
  70. methods: {
  71. handleSwitchRole(){
  72. this.columns = [];
  73. let roles = this.$store.state.user.availableRoles;
  74. let roleOptions = [];
  75. const hasAdminRole = roles.some(role => role == 'admin');
  76. const hasCrmRole = roles.some(role => role.includes('CRM'));
  77. const hasWarehouser = roles.some(role => role == 'WAREHOUSER');
  78. const hasSalesman = roles.some(role => role == 'SALESMAN');
  79. if(hasAdminRole){
  80. roleOptions.push(
  81. { label: 'CRM权限', value: 'CRM' },
  82. { label: '仓库权限', value: 'WAREHOUSER' },
  83. { label: '销售权限', value: 'SALESMAN' },
  84. );
  85. }else if(hasWarehouser && hasSalesman && hasCrmRole){
  86. roleOptions.push(
  87. { label: 'CRM权限', value: 'CRM' },
  88. { label: '仓库权限', value: 'WAREHOUSER' },
  89. { label: '销售权限', value: 'SALESMAN' }
  90. );
  91. }else if(hasCrmRole && hasWarehouser){
  92. roleOptions.push(
  93. { label: 'CRM权限', value: 'CRM' },
  94. { label: '仓库权限', value: 'WAREHOUSER' }
  95. );
  96. }else if(hasCrmRole && hasSalesman){
  97. roleOptions.push(
  98. { label: 'CRM权限', value: 'CRM' },
  99. { label: '仓库权限', value: 'WAREHOUSER' },
  100. { label: '销售权限', value: 'SALESMAN' }
  101. );
  102. }else if(hasWarehouser && hasSalesman){
  103. roleOptions.push(
  104. { label: '仓库权限', value: 'WAREHOUSER' },
  105. { label: '销售权限', value: 'SALESMAN' }
  106. );
  107. }else if(hasCrmRole){
  108. roleOptions.push({ label: 'CRM权限', value: 'CRM' });
  109. }else if(hasWarehouser){
  110. roleOptions.push({ label: '仓库权限', value: 'WAREHOUSER' });
  111. }else if(hasSalesman){
  112. roleOptions.push({ label: '销售权限', value: 'SALESMAN' },{ label: '仓库权限', value: 'WAREHOUSER' });
  113. }
  114. this.columns = [roleOptions];
  115. this.showSwitchRole = true;
  116. },
  117. handleEditPassword(){
  118. uni.navigateTo({
  119. url : "/pages/changePw/index"
  120. });
  121. },
  122. toPersonal(){
  123. uni.navigateTo({
  124. url : "/pages/profile/index"
  125. })
  126. },
  127. handleShowModal() {
  128. this.showModal = true;
  129. },
  130. confirm() {
  131. // 停止电话监听
  132. //#ifdef APP-PLUS
  133. this.$store.dispatch("call/stopPhoneListener", null, { root: true }).catch(error => {
  134. console.error('退出登录时停止电话监听失败:', error);
  135. });
  136. //#endif
  137. this.$store.dispatch("user/logout").then(()=>{
  138. uni.$u.toast("退出成功");
  139. setTimeout(()=>{
  140. this.showModal = false;
  141. uni.reLaunch({
  142. url: "/pages/login/index"
  143. })
  144. },1000)
  145. })
  146. },
  147. confirmSwitchRole(e) {
  148. uni.navigateBack({
  149. delta: 1
  150. }).then(()=>{
  151. this.showSwitchRole = false;
  152. this.$store.commit('user/SET_CURRENT_ROLE_INDEX', e.indexs[0]);
  153. setTimeout(()=>{
  154. this.$store.commit('user/SWITCH_ROLE', e.value[0]);
  155. },50)
  156. })
  157. }
  158. }
  159. }
  160. </script>
  161. <style lang="scss" scoped>
  162. .modal_box{
  163. line-height: 100rpx;
  164. color: #aaa;
  165. }
  166. .logout_btn {
  167. width: 100%;
  168. position: absolute;
  169. left: 50%;
  170. transform: translate(-50%, 0%);
  171. bottom: 10%;
  172. ::v-deep .u-button {
  173. border: none;
  174. }
  175. }
  176. .option_list {
  177. .option_item {
  178. display: flex;
  179. justify-content: space-between;
  180. align-items: center;
  181. height: 100rpx;
  182. border-bottom: 2rpx solid #dfdfdf;
  183. background-color: #fff;
  184. padding: 0 30rpx;
  185. &:last-child {
  186. border: none;
  187. }
  188. .item_left {
  189. display: flex;
  190. align-items: center;
  191. image {
  192. width: 32rpx;
  193. height: 32rpx;
  194. margin-right: 20rpx;
  195. }
  196. .label {
  197. font-size: 28rpx;
  198. color: #202020;
  199. }
  200. }
  201. .item-right {
  202. display: flex;
  203. justify-content: space-between;
  204. align-items: center;
  205. ::v-deep .u-icon__icon {
  206. font-size: 30rpx !important;
  207. }
  208. text {
  209. font-size: 24rpx;
  210. color: #999999;
  211. margin-right: 20rpx;
  212. }
  213. .copy_btn {
  214. display: flex;
  215. font-size: 24rpx;
  216. color: #108CFF;
  217. margin-right: 30rpx;
  218. }
  219. }
  220. }
  221. }
  222. </style>