profile.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. <template>
  2. <view class="wrap">
  3. <view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30">
  4. <view class="u-m-r-10">
  5. <u-avatar :src="vuex_avatar" size="140"></u-avatar>
  6. </view>
  7. <view class="u-flex-1">
  8. <view class="u-font-18 u-p-b-20">{{vuex_user.nickName}}</view>
  9. <view class="u-font-14 u-tips-color" v-if="vuex_user.nickName !== '未登录'">小铺ID:{{vuex_user.mobile}}</view>
  10. <view class="u-font-14 u-tips-color" v-if="vuex_user.nickName == '未登录'" @click="toLogin">点击登录邻家小铺账号</view>
  11. </view>
  12. <!-- <view class="u-m-l-10 u-p-10">
  13. <u-icon name="scan" color="#969799" size="28"></u-icon>
  14. </view> -->
  15. <!-- <view class="u-m-l-10 u-p-10">
  16. <u-icon name="arrow-right" color="#969799" size="28"></u-icon>
  17. </view> -->
  18. </view>
  19. <view class="u-m-t-20">
  20. <u-cell-group>
  21. <u-cell-item icon="list" title="我的订单" @click="openPage('/pages/order/list')"></u-cell-item>
  22. </u-cell-group>
  23. </view>
  24. <view class="u-m-t-20">
  25. <u-cell-group>
  26. <u-cell-item icon="map" title="收货地址" @click="openPage('/pages/address/list')"></u-cell-item>
  27. <u-cell-item icon="star" @click="openPage('/pages/favorite/favorite')" title="喜欢的商品"></u-cell-item>
  28. <u-cell-item icon="integral" @click="todo" title="我的积分"></u-cell-item>
  29. <u-cell-item icon="coupon" @click="todo" title="我的优惠券"></u-cell-item>
  30. </u-cell-group>
  31. </view>
  32. <view class="u-m-t-20">
  33. <u-cell-group>
  34. <u-cell-item icon="setting" title="设置" @click="openPage('/pages/setting/setting')"></u-cell-item>
  35. <!-- #ifdef H5 -->
  36. <u-cell-item icon="download" title="下载APP" @click="openPage('/pages/setting/app')"></u-cell-item>
  37. <!-- #endif -->
  38. </u-cell-group>
  39. </view>
  40. </view>
  41. </template>
  42. <script>
  43. export default {
  44. data() {
  45. return {
  46. show: true
  47. }
  48. },
  49. onLoad() {
  50. console.log('load.......')
  51. },
  52. onShow() {
  53. // #ifdef H5
  54. this.initH5()
  55. // #endif
  56. },
  57. methods: {
  58. initH5() {
  59. if (this.vuex_user.nickName !=='未登录' && this.vuex_user.refreshWechatInfo === true) {
  60. const url = window.location.href
  61. if (url.indexOf('localhost') > -1 || url.indexOf('127.0.0.1') > -1) {
  62. } else {
  63. const userAgent = window.navigator.userAgent.toLowerCase()
  64. //使用微信访问本系统的时候获取微信openid,否则不获取
  65. if (userAgent.indexOf('micromessenger') > -1) {
  66. this.processOpenid()
  67. }
  68. }
  69. }
  70. },
  71. openPage(url) {
  72. this.$u.route({
  73. url: url
  74. })
  75. },
  76. toLogin() {
  77. this.$u.route({
  78. url: '/pages/login/login'
  79. })
  80. },
  81. todo() {
  82. this.$u.toast('开发中')
  83. },
  84. processOpenid() {
  85. let url = window.location.href;
  86. if (url.indexOf('code') > -1) {
  87. const code = url.split('code=')[1].split("&")[0];
  88. this.$u.post('wechat/getWxOpenId?code='+code).then(res => {
  89. this.$u.vuex('vuex_token', res.token)
  90. this.$u.vuex('vuex_user', res.user)
  91. //优先展示手动上传的头像
  92. if (res.user.avatar && res.user.avatar !== '') {
  93. this.$u.vuex('vuex_avatar', this.baseApi + '/file/getImgStream?idFile=' + res.user.avatar);
  94. } else {
  95. if (res.user.wechatHeadImgUrl && res.user.wechatHeadImgUrl !== '') {
  96. //如果拉取到用户微信头像,则展示微信头像
  97. this.$u.vuex('vuex_avatar', res.user.wechatHeadImgUrl)
  98. }
  99. }
  100. })
  101. } else {
  102. this.redirectForCode()
  103. }
  104. },
  105. redirectForCode() {
  106. this.$u.post('wechat/getWxSign?url='+window.location.href).then(res => {
  107. const rr = res;
  108. const redirectUrl = window.location.href;
  109. let param = 'appid=' + rr.appId
  110. param += '&response_type=code'
  111. param += '&scope=snsapi_base'
  112. param += '&redirect_uri=' + encodeURIComponent(redirectUrl)
  113. param += '&state=linjiashop#wechat_redirect'
  114. console.log('url:', 'https://open.weixin.qq.com/connect/oauth2/authorize?' + param)
  115. window.location.href = 'https://open.weixin.qq.com/connect/oauth2/authorize?' + param
  116. })
  117. }
  118. }
  119. }
  120. </script>
  121. <style>
  122. page {
  123. background-color: #ededed;
  124. }
  125. </style>
  126. <style lang="scss" scoped>
  127. .camera {
  128. width: 54px;
  129. height: 44px;
  130. &:active {
  131. background-color: #ededed;
  132. }
  133. }
  134. .user-box {
  135. background-color: #fff;
  136. }
  137. </style>