index.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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. console.log(roles);
  75. let roleOptions = [];
  76. const hasAdminRole = roles.some(role => role.includes('admin'));
  77. const hasCrmRole = roles.some(role => role.includes('CRM'));
  78. const hasWAREandSALE = roles.some(role => role.includes('WAREandSALE'));
  79. if(hasAdminRole || (hasCrmRole && hasWAREandSALE) ){//管理员、crm+仓库、crm+销售、仓库+销售
  80. roleOptions.push(
  81. { label: 'CRM权限', value: 'CRM' },
  82. { label: '仓库和销售权限', value: 'WAREandSALE' },
  83. );
  84. }else if(hasCrmRole){//只有crm
  85. roleOptions.push(
  86. { label: 'CRM权限', value: 'CRM' },
  87. );
  88. }else if(hasWarehouser || hasSalesman){//只有仓库或销售
  89. roleOptions.push(
  90. { label: '仓库和销售权限', value: 'WAREandSALE' },
  91. );
  92. }
  93. this.columns = [roleOptions];
  94. this.showSwitchRole = true;
  95. },
  96. handleEditPassword(){
  97. uni.navigateTo({
  98. url : "/pages/changePw/index"
  99. });
  100. },
  101. toPersonal(){
  102. uni.navigateTo({
  103. url : "/pages/profile/index"
  104. })
  105. },
  106. handleShowModal() {
  107. this.showModal = true;
  108. },
  109. confirm() {
  110. // 停止电话监听
  111. //#ifdef APP-PLUS
  112. this.$store.dispatch("call/stopPhoneListener", null, { root: true }).catch(error => {
  113. console.error('退出登录时停止电话监听失败:', error);
  114. });
  115. //#endif
  116. this.$store.dispatch("user/logout").then(()=>{
  117. uni.$u.toast("退出成功");
  118. setTimeout(()=>{
  119. this.showModal = false;
  120. uni.reLaunch({
  121. url: "/pages/login/index"
  122. })
  123. },1000)
  124. })
  125. },
  126. confirmSwitchRole(e) {
  127. uni.navigateBack({
  128. delta: 1
  129. }).then(()=>{
  130. this.showSwitchRole = false;
  131. this.$store.commit('user/SET_CURRENT_ROLE_INDEX', e.indexs[0]);
  132. setTimeout(()=>{
  133. this.$store.commit('user/SWITCH_ROLE', e.value[0]);
  134. },50)
  135. })
  136. }
  137. }
  138. }
  139. </script>
  140. <style lang="scss" scoped>
  141. .modal_box{
  142. line-height: 100rpx;
  143. color: #aaa;
  144. }
  145. .logout_btn {
  146. width: 100%;
  147. position: absolute;
  148. left: 50%;
  149. transform: translate(-50%, 0%);
  150. bottom: 10%;
  151. ::v-deep .u-button {
  152. border: none;
  153. }
  154. }
  155. .option_list {
  156. .option_item {
  157. display: flex;
  158. justify-content: space-between;
  159. align-items: center;
  160. height: 100rpx;
  161. border-bottom: 2rpx solid #dfdfdf;
  162. background-color: #fff;
  163. padding: 0 30rpx;
  164. &:last-child {
  165. border: none;
  166. }
  167. .item_left {
  168. display: flex;
  169. align-items: center;
  170. image {
  171. width: 32rpx;
  172. height: 32rpx;
  173. margin-right: 20rpx;
  174. }
  175. .label {
  176. font-size: 28rpx;
  177. color: #202020;
  178. }
  179. }
  180. .item-right {
  181. display: flex;
  182. justify-content: space-between;
  183. align-items: center;
  184. ::v-deep .u-icon__icon {
  185. font-size: 30rpx !important;
  186. }
  187. text {
  188. font-size: 24rpx;
  189. color: #999999;
  190. margin-right: 20rpx;
  191. }
  192. .copy_btn {
  193. display: flex;
  194. font-size: 24rpx;
  195. color: #108CFF;
  196. margin-right: 30rpx;
  197. }
  198. }
  199. }
  200. }
  201. </style>