index.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  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. if(orgs){
  65. orgs.map(item => {
  66. item.text = item.orgName
  67. })
  68. }
  69. return orgs ? orgs.filter(item => item.orgSn != user.orgSn) : []
  70. },
  71. userData () {
  72. return this.$store.state.vuex_userData;
  73. }
  74. },
  75. onLoad() {
  76. uni.setNavigationBarColor({
  77. frontColor: '#ffffff',
  78. backgroundColor: this.$config('primaryColor')
  79. })
  80. this.isRemember = this.$store.state.vuex_isRemember;
  81. this.curVer = getApp().globalData.version;
  82. },
  83. methods:{
  84. // 过滤权限code
  85. fiterAuthCode(data) {
  86. data.permCodes = data.permCodes.filter(item => item.indexOf('_mobile') > 0);
  87. return data;
  88. },
  89. // 切换账户
  90. changeAcount(index){
  91. const _this = this
  92. const item = this.orglist[index]
  93. console.log(index,item)
  94. this.$store.state.vuex_changeOrg = item.orgSn
  95. this.$set(getApp().globalData,'changeOrg',item.orgSn)
  96. setTimeout(()=>{
  97. // 登录
  98. login({ username: '', password: '' }).then(res => {
  99. console.log(res)
  100. uni.hideLoading();
  101. if (res.status == 200) {
  102. _this.$u.vuex('vuex_userData', _this.fiterAuthCode(res.data.auth_user));
  103. _this.$u.vuex('vuex_token', res.data.access_token);
  104. _this.$u.vuex('vuex_authOrgs',res.data.auth_orgs);
  105. getApp().globalData.token = res.data.access_token;
  106. uni.setStorageSync('loginTimeOut', 'NO');
  107. this.toMain()
  108. uni.$emit("refreshSalesHomeBL")
  109. uni.showToast({ icon: 'none', title: '切换成功!' });
  110. }else{
  111. uni.showToast({ icon: 'none', title: res.message });
  112. }
  113. });
  114. },100)
  115. },
  116. // 跳转到首页
  117. toMain() {
  118. uni.switchTab({
  119. url: '/pages/sales/index'
  120. });
  121. },
  122. // 打开对应的页面
  123. toPage(index){
  124. let pageUrl=[
  125. '/pages/login/userAuthYs?fromPage=usercenter',
  126. '/pages/userCenter/changePwd',
  127. 'getVersion'
  128. ]
  129. if(index != 2){
  130. uni.navigateTo({
  131. url: pageUrl[index]
  132. })
  133. }else{
  134. this[pageUrl[index]]()
  135. }
  136. },
  137. // 退出登录确认弹框
  138. quitOutSys() {
  139. const _this = this;
  140. clzConfirm({
  141. title: '提示',
  142. content: '确定退出登录?',
  143. success: function(res) {
  144. if (res.confirm || res.index == 0) {
  145. _this.quitSys();
  146. }
  147. }
  148. });
  149. },
  150. // 退出登录,返回登录页
  151. quitSys() {
  152. logout().then(res => {
  153. console.log(res);
  154. if (res.status == 200) {
  155. // this.$store.commit("$closeWebsocket")
  156. this.$store.state.vuex_token = '';
  157. this.$store.state.vuex_userData = '';
  158. this.$u.vuex('vuex_authOrgs','');
  159. getApp().globalData.token = '';
  160. this.$set(getApp().globalData,'changeOrg','')
  161. uni.setStorageSync('setStatusIndexFunc', 0);
  162. setTimeout(function() {
  163. uni.reLaunch({
  164. url: '/pages/login/login'
  165. });
  166. }, 500);
  167. }
  168. });
  169. },
  170. // 获取最新版本信息
  171. getVersion() {
  172. let version = getApp().globalData.version
  173. console.log(version)
  174. getSysVersion({versionType:version.platform=='android'?'ANDROID':'IOS'}).then(ret => {
  175. console.log(JSON.stringify(ret))
  176. if(ret.status == 200){
  177. console.log(ret.data)
  178. this.$store.state.vuex_versionInfo = ret.data
  179. //进行版本型号的比对 以及下载更新请求
  180. checkVersionToLoadUpdate(ret.data, 1, market);
  181. }
  182. })
  183. }
  184. }
  185. }
  186. </script>
  187. <style lang="scss">
  188. .user-content{
  189. width: 100%;
  190. .user-head{
  191. display: flex;
  192. align-items: center;
  193. padding: 80rpx 35rpx;
  194. .user-photo{
  195. flex-shrink: 0;
  196. margin-right: 5rpx;
  197. }
  198. .user-org{
  199. color: #fff;
  200. }
  201. .user-info{
  202. flex-grow: 1;
  203. padding: 0 20rpx;
  204. color: #FFFFFF;
  205. .user-name{
  206. display: block;
  207. font-size: 36rpx;
  208. margin-bottom: 10rpx;
  209. }
  210. .user-phone{
  211. display: block;
  212. font-size: 28rpx;
  213. }
  214. }
  215. }
  216. .user-list{
  217. border-radius: 15upx;
  218. margin: 20upx;
  219. overflow: hidden;
  220. box-shadow: 0upx 3upx 6upx #eee;
  221. }
  222. .user-btn{
  223. padding: 85rpx 200rpx;
  224. }
  225. }
  226. </style>