index.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. <template>
  2. <view>
  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" @click="login($store.state.vuex_hasLogin)">
  5. <u-avatar :src="userInfo.headImgUrl || userInfo.avatar||pic" size="140"></u-avatar>
  6. </view>
  7. <view class="u-flex-1" @click="login($store.state.vuex_hasLogin)">
  8. <view class="u-font-18 u-p-b-20">{{ userInfo.nickname || userInfo.userName || '请登录' }}</view>
  9. <view class="u-font-14 u-tips-color">手机号:{{ userInfo.mobile || '暂无' }}</view>
  10. </view>
  11. <view class="u-m-l-10 u-p-10">
  12. <u-icon name="arrow-right" color="#969799" size="28"></u-icon>
  13. </view>
  14. </view>
  15. <view class="u-m-t-20">
  16. <u-cell-group>
  17. <u-cell-item icon="car" title="我的车辆" @click="openPage('pages/myCars/myCars')"></u-cell-item>
  18. <u-cell-item icon="order" title="停车记录" @click="openPage('pages/center/order/order')"></u-cell-item>
  19. </u-cell-group>
  20. </view>
  21. <view class="u-m-t-20">
  22. <u-cell-group>
  23. <u-cell-item icon="phone" title="手机号登录" @click="openPage('/pages/center/phoneLogin/phoneLogin')"></u-cell-item>
  24. <!-- <u-cell-item icon="star" title="微信支付" @click="handlewxpay"></u-cell-item> -->
  25. </u-cell-group>
  26. </view>
  27. <u-toast ref="uToast" />
  28. </view>
  29. </template>
  30. <script>
  31. import getUrlParams from "../../utils/getUrlParams.js";
  32. export default {
  33. data() {
  34. return {
  35. pic:'https://uviewui.com/common/logo.png',
  36. userInfo:[],
  37. code:null,
  38. }
  39. },
  40. onLoad() {
  41. if(this.$store.state.vuex_hasLogin){
  42. this.userInfo = this.$store.state.vuex_user;
  43. if(this.$store.state.vuex_wxinfo){
  44. this.userInfo = Object.assign(this.userInfo,this.$store.state.vuex_wxinfo);
  45. }
  46. }else{
  47. this.userInfo = [];
  48. };
  49. let locationLocaturl = window.location.search;
  50. this.code = getUrlParams(locationLocaturl,"code");
  51. if(this.code&&!this.$store.state.vuex_wxinfo.openId){this.handleGetWXInfo(this.code)};
  52. },
  53. methods: {
  54. openPage(path) {
  55. console.log('path',path);
  56. this.$u.route({
  57. url: path
  58. })
  59. },
  60. //登录判断
  61. login(status){
  62. if(!status){
  63. console.log('config',this.config);
  64. window.location.replace(this.config.loginUrl)
  65. }
  66. },
  67. // getCode () {
  68. // var local = window.location.href // 获取页面url
  69. // let locationLocaturl = window.location.search;
  70. // this.code = getUrlParams(locationLocaturl,"code"); // 截取code
  71. // if (this.code == null || this.code === '') { // 如果没有code,则去请求
  72. // window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${this.config.wxAppid}&redirect_uri=${encodeURIComponent(local)}&response_type=code&scope=snsapi_userinfo&#wechat_redirect`
  73. // } else {
  74. // this.handleGetWXInfo(this.code) //把code传给后台获取用户信息
  75. // }
  76. // },
  77. // handleGetWXInfo (code) { // 通过code获取 openId等用户信息,/api/user/wechat/login 为后台接口
  78. // let _this = this
  79. // this.$u.api.getWXInfo(code).then((res) => {
  80. // if (res.code === 200 ) {
  81. // this.$u.vuex('vuex_wxinfo',res.data);
  82. // // 继续支付
  83. // }
  84. // }).catch((err) => {
  85. // this.$refs.uToast.show({
  86. // title: err.msg,
  87. // type: 'error',
  88. // });
  89. // })
  90. // },
  91. // handlewxpay(){
  92. // if(!this.$store.state.vuex_wxinfo.openId){ // 如果微信openId,则需用code去后台获取
  93. // this.$refs.uToast.show({
  94. // title: '请登录后重试!',
  95. // type: 'info',
  96. // // url: '/pages/user/index'
  97. // });
  98. // this.getCode();
  99. // } else {
  100. // // 别的业务逻辑
  101. // this.getWXPay();
  102. // }
  103. // },
  104. // async getWXPay(id){
  105. // let params = {
  106. // orderId:id||new Date().getTime(),
  107. // openid:this.$store.state.vuex_wxinfo.openId,
  108. // tradeType:"test"
  109. // };
  110. // await this.$wxApi.config();
  111. // this.$pay.wxPay(params).then(res =>{
  112. // console.log('wxPay',res.code);
  113. // if(res.code == 0){
  114. // // 成功
  115. // // uni.reLaunch({
  116. // // url: '/pages/buySuccess/buySuccess?orderId=' + params.orderId
  117. // // })
  118. // }else if(res.code == 1){
  119. // // 取消
  120. // // uni.redirectTo({
  121. // // url: '/pages/userCenter/myOrder/myOrder'
  122. // // })
  123. // }else if(res.code == 2){
  124. // this.$refs.uToast.show({
  125. // title: '支付失败,请检查!',
  126. // type: 'error',
  127. // // url: '/pages/user/index'
  128. // });
  129. // }
  130. // });
  131. // },
  132. }
  133. }
  134. </script>
  135. <style lang="scss" scoped>
  136. page{background-color: $my-page-bg-color;}
  137. .user-box{background-color: #fff;}
  138. </style>