index.vue 3.3 KB

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