mine.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <view class="container">
  3. <view class="user">
  4. <view class="userInfo">
  5. <image class="userPhoto" src=""></image>
  6. <view class="info">
  7. <view class="name" v-if="hasLogin">
  8. {{userInfo.nickName}}
  9. </view>
  10. <view class="loginText" @click="wxLogin" v-else>
  11. 点击登录
  12. </view>
  13. <view class="id">
  14. ID: {{userId}}
  15. </view>
  16. </view>
  17. </view>
  18. <view class="row">
  19. <view class="box">
  20. <view class="value" style="color: #FF2C43;">
  21. 1000
  22. </view>
  23. <view class="label">
  24. 积分
  25. </view>
  26. </view>
  27. <view class="box">
  28. <view class="value">
  29. 2
  30. </view>
  31. <view class="label">
  32. 优惠卷
  33. </view>
  34. </view>
  35. </view>
  36. </view>
  37. <view class="menus">
  38. <view class="title">
  39. <image src="/static/img/mine/title.png" mode=""></image>
  40. </view>
  41. <view class="menuList">
  42. <view class="menu">
  43. <image src="/static/img/mine/menu1.png"></image>
  44. <span>地址管理</span>
  45. </view>
  46. <view class="menu">
  47. <image src="/static/img/mine/menu2.png"></image>
  48. <span>消费记录</span>
  49. </view>
  50. <view class="menu">
  51. <image src="/static/img/mine/menu3.png"></image>
  52. <span>加群交流</span>
  53. </view>
  54. <view class="menu">
  55. <image src="/static/img/mine/menu4.png"></image>
  56. <span>游戏规则</span>
  57. </view>
  58. <view class="menu">
  59. <image src="/static/img/mine/menu5.png"></image>
  60. <span>用户协议</span>
  61. </view>
  62. <view class="menu">
  63. <image src="/static/img/mine/menu6.png"></image>
  64. <span>联系客服</span>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import {
  72. loginByWeixinApi
  73. } from "@/api/user.js"
  74. export default {
  75. data() {
  76. return {
  77. isLogin: false,
  78. userInfo: null,
  79. userId: '-',
  80. hasLogin: false,
  81. }
  82. },
  83. onShow() {
  84. //获取用户的登录信息
  85. if (getApp().globalData.hasLogin) {
  86. let userInfo = wx.getStorageSync('userInfo');
  87. this.userInfo = userInfo
  88. this.hasLogin = true
  89. }
  90. },
  91. methods: {
  92. wxLogin: function(e) {
  93. console.log('111')
  94. let _this = this
  95. wx.getUserProfile({
  96. desc: '用于完善会员资料', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  97. success: (res1) => {
  98. console.log(res1, 'res111')
  99. wx.login({
  100. success: function(res2) {
  101. console.log(res2, 'res222')
  102. if (res2.code) {
  103. let params = {
  104. code: res2.code,
  105. userInfo: res1.userInfo
  106. }
  107. _this.executeLoginApi(params)
  108. }
  109. },
  110. fail: function(err) {
  111. reject(err);
  112. }
  113. });
  114. },
  115. fail: () => {
  116. console.log('微信登录失败')
  117. // util.showErrorToast('微信登录失败');
  118. }
  119. })
  120. },
  121. executeLoginApi(params) {
  122. let _this = this
  123. console.log(222)
  124. loginByWeixinApi(params).then(res => {
  125. console.log('调用登录api', res)
  126. //存储用户信息
  127. wx.setStorageSync('userInfo', res.data.userInfo);
  128. wx.setStorageSync('token', res.data.token);
  129. wx.setStorageSync('userId', res.data.userId);
  130. getApp().globalData.hasLogin = true;
  131. _this.userInfo = wx.getStorageSync('userInfo');
  132. _this.userId = wx.getStorageSync('userId');
  133. _this.hasLogin = true
  134. })
  135. }
  136. }
  137. }
  138. </script>
  139. <style scoped lang="scss">
  140. .container {
  141. background: #9EC8F9;
  142. padding: 0 10px;
  143. overflow: scroll;
  144. }
  145. .user {
  146. background: #fff;
  147. border-radius: 10px;
  148. padding: 0 10px;
  149. position: relative;
  150. margin-top: 10vw;
  151. .userInfo {
  152. display: flex;
  153. .userPhoto {
  154. width: 74px;
  155. height: 74px;
  156. border-radius: 50%;
  157. border: solid 3px #6BAFFF;
  158. position: relative;
  159. top: -20px;
  160. background: #dedede;
  161. }
  162. .info {
  163. padding: 10px;
  164. .name {
  165. font-weight: 600;
  166. }
  167. .loginText {
  168. font-weight: 600;
  169. }
  170. .id {
  171. margin-top: 5px;
  172. font-size: 13px;
  173. }
  174. }
  175. }
  176. .row {
  177. display: flex;
  178. justify-content: space-around;
  179. .box {
  180. display: flex;
  181. flex-direction: column;
  182. text-align: center;
  183. padding: 20px 10px;
  184. .label {
  185. margin-top: 5px;
  186. font-size: 15px;
  187. }
  188. .value {
  189. font-size: 20px;
  190. font-weight: 600;
  191. }
  192. }
  193. }
  194. }
  195. .menus {
  196. margin-top: 20px;
  197. background: #fff;
  198. border-radius: 10px;
  199. // padding: 0 10px;
  200. .title {
  201. position: relative;
  202. left: -10px;
  203. top: -10px;
  204. width: calc(100% + 10px);
  205. height: 55px;
  206. image {
  207. width: 100%;
  208. height: 100%;
  209. }
  210. }
  211. .menuList {
  212. display: grid;
  213. grid-template-columns: 1fr 1fr 1fr;
  214. padding: 20px 20px 0 20px;
  215. .menu {
  216. margin-bottom: 30px;
  217. display: flex;
  218. flex-direction: column;
  219. justify-content: center;
  220. align-items: center;
  221. image {
  222. width: 36px;
  223. height: 36px;
  224. }
  225. span {
  226. margin-top: 10px;
  227. font-size: 14px;
  228. }
  229. }
  230. }
  231. }
  232. </style>