index.vue 3.2 KB

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