index.vue 6.8 KB

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