index.vue 6.7 KB

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