index.vue 4.8 KB

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