user.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. <template>
  2. <view class="content">
  3. <view class="content_top">
  4. <view class="flexV">
  5. <image :src="userInfo.headimgurl"></image>
  6. <text>{{ userInfo.nickname }}</text>
  7. </view>
  8. </view>
  9. <view v-if="login" class="setList">
  10. <view v-for="(item, i) in setList" :key="i" class="setItem flexB" @click="getUrl(i)">
  11. <view class="setItem-left flexV">
  12. <image mode="widthFix" :src="`../../static/index/${item.icon}`" class="icon" />
  13. <view>{{ item.name }}</view>
  14. </view>
  15. <view class="setItem-right flexV">
  16. <image mode="widthFix" src="../../static/Buy_soap_tape/arrow.png" class="right" />
  17. </view>
  18. </view>
  19. </view>
  20. </view>
  21. </template>
  22. <script>
  23. import { logout } from '@/api/index.js'
  24. export default {
  25. data() {
  26. return {
  27. login: false,
  28. userInfo: {},
  29. openid: '',
  30. setList: [
  31. {
  32. name: '购买记录',
  33. icon: 'jilu.png'
  34. },
  35. {
  36. name: '退出登录',
  37. icon: 'logout.png'
  38. }
  39. ]
  40. }
  41. },
  42. onShow() {
  43. // 有token
  44. if (uni.getStorageSync('token') && uni.getStorageSync('userInfo')) {
  45. this.userInfo = uni.getStorageSync('userInfo')
  46. this.login = true
  47. this.openid = this.userInfo.openid
  48. }
  49. },
  50. methods: {
  51. // 跳转微信授权
  52. toWxchatLogin(url, state) {
  53. url = url || '/pages/index/index';
  54. state = state || 'cli';
  55. const redirect_uri = encodeURIComponent(`${this.$config.redirect_uri}/#${url}`);
  56. const auth = () =>
  57. (window.location.href = `${this.$config.wxURL}?appid=${
  58. this.$config.appid
  59. }&redirect_uri=${redirect_uri}&response_type=code&scope=snsapi_userinfo&state=${state}#wechat_redirect`);
  60. auth();
  61. },
  62. // 跳转页面
  63. getUrl(i) {
  64. if (i == 0) {
  65. uni.navigateTo({
  66. url: '../Buy_soap_tape/purchase_history'
  67. })
  68. } else {
  69. uni.showModal({
  70. content: '确定要退出登录么?',
  71. success: res => {
  72. if (res.confirm) {
  73. uni.showLoading({ title: '加载中', mask: true })
  74. logout().then(res => {
  75. uni.hideLoading()
  76. uni.removeStorageSync('token')
  77. uni.removeStorageSync('userInfo')
  78. uni.reLaunch({
  79. url: '../login/login?openid=' + this.openid
  80. })
  81. })
  82. }
  83. }
  84. });
  85. }
  86. }
  87. }
  88. }
  89. </script>
  90. <style lang="scss" scoped>
  91. .content {
  92. height: 100vh;
  93. &_top {
  94. padding: 80rpx 0 40rpx 24rpx;
  95. background: linear-gradient(88deg, #FF232C 0%, #FF571B 100%);
  96. image {
  97. width: 126rpx;
  98. height: 126rpx;
  99. border-radius: 50%;
  100. border: 2rpx solid #fff;
  101. background-color: #999;
  102. margin-right: 25rpx;
  103. }
  104. text {
  105. font-size: 44rpx;
  106. font-family: PingFang SC-Bold, PingFang SC;
  107. font-weight: bold;
  108. color: #FFFFFF;
  109. }
  110. }
  111. .setList {
  112. width: calc(100% - 60rpx);
  113. margin: 24rpx auto 0;
  114. padding: 0 16rpx 0 30rpx;
  115. box-sizing: border-box;
  116. background-color: #ffffff;
  117. margin-bottom: 30rpx;
  118. border-radius: 16rpx 16rpx 16rpx 16rpx;
  119. .setItem {
  120. width: 100%;
  121. height: 120rpx;
  122. border-bottom: 2rpx solid #eeeeee;
  123. color: #333333;
  124. font-size: 30rpx;
  125. &-left {
  126. font-size: 30rpx;
  127. font-weight: bold;
  128. }
  129. &-right {
  130. .right {
  131. width: 48rpx;
  132. height: 48rpx;
  133. }
  134. }
  135. .icon {
  136. width: 48rpx;
  137. max-height: 48rpx;
  138. display: block;
  139. margin-right: 20rpx;
  140. }
  141. &:nth-last-of-type(1) {
  142. border-bottom: 0;
  143. }
  144. }
  145. }
  146. }
  147. </style>