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