index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <view class="content">
  3. <image class="logo" src="/static/logo.png" @click="wxgologin"></image>
  4. <view >shopId:{{shopId}}</view>
  5. <view>
  6. url:{{url}}
  7. </view>
  8. <button type="default" open-type="getPhoneNumber" @getphonenumber="decryptPhoneNumber">获取手机号</button>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. data() {
  14. return {
  15. shopId: '',
  16. url:'',
  17. wxOpenData:'',
  18. code:'',
  19. }
  20. },
  21. onLoad() {
  22. var that=this;
  23. this.$common.getExtStoreId()
  24. var ext=this.$common.getExtStoreId();
  25. console.log(ext)
  26. this.shopId=ext.shopId;
  27. this.url=ext.url;
  28. uni.setStorage({
  29. key: 'extdata',
  30. data: {
  31. shopId:'E37BB296-5A08-4534-859D-B351BA611AF9',
  32. },
  33. success: function () {
  34. that.uniLogin()
  35. }
  36. });
  37. this.uniLogin()
  38. },
  39. methods: {
  40. decryptPhoneNumber: function(e) {
  41. console.log(e);
  42. this.code=e.detail.code
  43. this.wxPhoneLogin()
  44. },
  45. wxgologin(){
  46. var that=this;
  47. uni.getUserProfile({
  48. lang:'zh_CN',
  49. desc:'登录',
  50. success:(res)=>{
  51. console.log(res);
  52. that.wxdata=res;
  53. uni.setStorage({
  54. key: 'wxdata',
  55. data: res,
  56. success: function () {
  57. that.uniLogin()
  58. }
  59. });
  60. },
  61. fail:(res)=>{
  62. console.log(res)
  63. }
  64. });
  65. },
  66. uniLogin(){
  67. var that=this;
  68. uni.login({
  69. provider: 'weixin',
  70. success: function (loginRes) {
  71. console.log(loginRes);
  72. that.getWxOpenID(loginRes)
  73. }
  74. });
  75. },
  76. getWxOpenID(e){
  77. var that=this;
  78. // this.code=e.code;
  79. this.$http('miniApp2/sys/getWxOpenID', {
  80. code:e.code,
  81. shopId:'E37BB296-5A08-4534-859D-B351BA611AF9'
  82. },'GET').then(res => {
  83. this.wxOpenData=res.data;
  84. //that.wxPhoneLogin()
  85. uni.setStorage({
  86. key: 'wxOpenData',
  87. data: that.wxOpenData,
  88. success: function () {
  89. // that.uniLogin()
  90. }
  91. });
  92. if(this.wxOpenData.loginInfo){
  93. uni.setStorage({
  94. key: 'userInfo',
  95. data: that.wxOpenData.loginInfo.openUser,
  96. success: function () {
  97. // that.uniLogin()
  98. }
  99. });
  100. }
  101. })
  102. },
  103. wxPhoneLogin(){
  104. var that=this;
  105. this.$http('miniApp2/sys/wxPhoneLogin', {
  106. appId:'wx33053a645546ec31',
  107. shopId:'E37BB296-5A08-4534-859D-B351BA611AF9',
  108. code:this.code,
  109. openId:this.wxOpenData.openid
  110. },'POST').then(res => {
  111. var data = res.data;
  112. if(data.loginInfo){
  113. uni.setStorage({
  114. key: 'userInfo',
  115. data: data.loginInfo.openUser,
  116. success: function () {
  117. // that.uniLogin()
  118. }
  119. });
  120. }
  121. })
  122. }
  123. }
  124. }
  125. </script>
  126. <style>
  127. .logo {
  128. height: 200rpx;
  129. width: 200rpx;
  130. margin-top: 200rpx;
  131. margin-left: auto;
  132. margin-right: auto;
  133. margin-bottom: 50rpx;
  134. }
  135. </style>