index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <view class="user-content">
  3. <view class="status_bar" :style="`background:${$config('primaryColor')}`">
  4. <!-- 这里是状态栏 -->
  5. </view>
  6. <!-- 头部 -->
  7. <view class="user-head" :style="`background:${$config('primaryColor')}`">
  8. <view class="user-photo">
  9. <u-avatar :src="userAvatarUrl" size="100" class="avatar"></u-avatar>
  10. </view>
  11. <view class="user-info">
  12. <text class="user-name">{{userData.orgName}}</text>
  13. <text class="user-phone">{{userData.username}}</text>
  14. </view>
  15. <view class="user-org" @click="show = true" v-if="orglist&&orglist.length">
  16. 切换 <u-icon name="arrow-right"></u-icon>
  17. </view>
  18. </view>
  19. <!-- 列表 -->
  20. <view class="user-list">
  21. <u-cell-group>
  22. <u-cell-item icon="file-text" icon-size="40" :icon-style="{color:'#ffaa00'}" index="0" @click="toPage(0)" title="服务协议及隐私政策"></u-cell-item>
  23. <!-- <u-cell-item icon="info-circle" icon-size="38" :icon-style="{color:'#55aa00'}" index="1" @click="toPage" title="关于我们"></u-cell-item> -->
  24. <u-cell-item icon="lock" icon-size="38" :icon-style="{color:'#00aaff'}" index="2" @click="toPage(1)" title="修改密码"></u-cell-item>
  25. <u-cell-item icon="info-circle" icon-size="38" :icon-style="{color:'#55aa00'}" index="1" @click="toPage(2)" :value="curVer.version" title="版本检查"></u-cell-item>
  26. </u-cell-group>
  27. </view>
  28. <!-- 退出 -->
  29. <view class="user-btn">
  30. <u-button type="success" :custom-style="{background:$config('primaryColor')}" hover-class="none" @click="quitOutSys" shape="circle">退出登录</u-button>
  31. </view>
  32. <u-action-sheet :list="orglist" v-model="show" @click="changeAcount" :tips="tips" :cancel-btn="true"></u-action-sheet>
  33. </view>
  34. </template>
  35. <script>
  36. import { getUserInfo, logout, login } from '@/api/user.js'
  37. import { getSysVersion } from '@/api/data.js'
  38. import { checkVersionToLoadUpdate, clzConfirm } from '@/libs/tools';
  39. import market from "@/js_sdk/dc-market/market.js"
  40. export default {
  41. data() {
  42. return {
  43. isRemember: false,
  44. show:false,
  45. tips: {
  46. text: '切换账户',
  47. color: '#999',
  48. fontSize: 32
  49. },
  50. userInfoData: null, // 用户信息
  51. userAvatarUrl: '' ,// 用户头像
  52. curVer: null
  53. };
  54. },
  55. onShow() {
  56. // this.getUserInfo()
  57. console.log(this.userData)
  58. },
  59. computed: {
  60. orglist() {
  61. // 当前连锁账户
  62. const orgs = this.$store.state.vuex_authOrgs;
  63. const user = this.$store.state.vuex_userData;
  64. orgs.map(item => {
  65. item.text = item.orgName
  66. })
  67. return orgs.filter(item => item.orgSn != user.orgSn)
  68. },
  69. userData () {
  70. return this.$store.state.vuex_userData;
  71. }
  72. },
  73. onLoad() {
  74. uni.setNavigationBarColor({
  75. frontColor: '#ffffff',
  76. backgroundColor: this.$config('primaryColor')
  77. })
  78. this.isRemember = this.$store.state.vuex_isRemember;
  79. this.curVer = getApp().globalData.version;
  80. },
  81. methods:{
  82. // 过滤权限code
  83. fiterAuthCode(data) {
  84. data.permCodes = data.permCodes.filter(item => item.indexOf('_mobile') > 0);
  85. return data;
  86. },
  87. // 切换账户
  88. changeAcount(index){
  89. const _this = this
  90. const item = this.orglist[index]
  91. console.log(index,item)
  92. this.$store.state.vuex_changeOrg = item.orgSn
  93. this.$set(getApp().globalData,'changeOrg',item.orgSn)
  94. setTimeout(()=>{
  95. // 登录
  96. login({ username: '', password: '' }).then(res => {
  97. console.log(res)
  98. uni.hideLoading();
  99. if (res.status == 200) {
  100. _this.$u.vuex('vuex_userData', _this.fiterAuthCode(res.data.auth_user));
  101. _this.$u.vuex('vuex_token', res.data.access_token);
  102. _this.$u.vuex('vuex_authOrgs',res.data.auth_orgs);
  103. getApp().globalData.token = res.data.access_token;
  104. uni.setStorageSync('loginTimeOut', 'NO');
  105. this.toMain()
  106. uni.$emit("refreshSalesBL")
  107. uni.showToast({ icon: 'none', title: '切换成功!' });
  108. }else{
  109. uni.showToast({ icon: 'none', title: res.message });
  110. }
  111. });
  112. },100)
  113. },
  114. // 跳转到首页
  115. toMain() {
  116. uni.switchTab({
  117. url: '/pages/sales/index'
  118. });
  119. },
  120. // 打开对应的页面
  121. toPage(index){
  122. let pageUrl=[
  123. '/pages/login/userAuthYs?fromPage=usercenter',
  124. '/pages/userCenter/changePwd',
  125. 'getVersion'
  126. ]
  127. if(index != 2){
  128. uni.navigateTo({
  129. url: pageUrl[index]
  130. })
  131. }else{
  132. this[pageUrl[index]]()
  133. }
  134. },
  135. // 退出登录确认弹框
  136. quitOutSys() {
  137. const _this = this;
  138. clzConfirm({
  139. title: '提示',
  140. content: '确定退出登录?',
  141. success: function(res) {
  142. if (res.confirm || res.index == 0) {
  143. _this.quitSys();
  144. }
  145. }
  146. });
  147. },
  148. // 退出登录,返回登录页
  149. quitSys() {
  150. logout().then(res => {
  151. console.log(res);
  152. if (res.status == 200) {
  153. // this.$store.commit("$closeWebsocket")
  154. this.$store.state.vuex_token = '';
  155. this.$store.state.vuex_userData = '';
  156. this.$u.vuex('vuex_authOrgs','');
  157. getApp().globalData.token = '';
  158. this.$set(getApp().globalData,'changeOrg','')
  159. uni.setStorageSync('setStatusIndexFunc', 0);
  160. setTimeout(function() {
  161. uni.reLaunch({
  162. url: '/pages/login/login'
  163. });
  164. }, 500);
  165. }
  166. });
  167. },
  168. // 获取最新版本信息
  169. getVersion() {
  170. let version = getApp().globalData.version
  171. console.log(version)
  172. getSysVersion({versionType:version.platform=='android'?'ANDROID':'IOS'}).then(ret => {
  173. console.log(JSON.stringify(ret))
  174. if(ret.status == 200){
  175. console.log(ret.data)
  176. this.$store.state.vuex_versionInfo = ret.data
  177. //进行版本型号的比对 以及下载更新请求
  178. checkVersionToLoadUpdate(ret.data, 1, market);
  179. }
  180. })
  181. }
  182. }
  183. }
  184. </script>
  185. <style lang="scss">
  186. .user-content{
  187. width: 100%;
  188. .user-head{
  189. display: flex;
  190. align-items: center;
  191. padding: 80rpx 35rpx;
  192. .user-photo{
  193. flex-shrink: 0;
  194. margin-right: 5rpx;
  195. }
  196. .user-org{
  197. color: #fff;
  198. }
  199. .user-info{
  200. flex-grow: 1;
  201. padding: 0 20rpx;
  202. color: #FFFFFF;
  203. .user-name{
  204. display: block;
  205. font-size: 36rpx;
  206. margin-bottom: 10rpx;
  207. }
  208. .user-phone{
  209. display: block;
  210. font-size: 28rpx;
  211. }
  212. }
  213. }
  214. .user-list{
  215. border-radius: 15upx;
  216. margin: 20upx;
  217. overflow: hidden;
  218. box-shadow: 0upx 3upx 6upx #eee;
  219. }
  220. .user-btn{
  221. padding: 85rpx 200rpx;
  222. }
  223. }
  224. </style>