empower.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254
  1. <template>
  2. <view class="container" >
  3. <view ><!-- vsv-if="!wxOpendata&&isload" -->
  4. <view class="logoBox">
  5. <image src="../../static/img/euro.png" mode="" class="euroImg"></image>
  6. </view>
  7. <view class="title1">请完成微信授权以继续使用</view>
  8. <button class="wxlogin" @click="wxgologin">授权微信用户信息</button>
  9. <view class="title2" @click="goIndex">取消授权</view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. data() {
  16. return {
  17. wxdata:'',
  18. wxCode:'',
  19. openID:'',
  20. session_key:'',
  21. wxPhoneData:'',
  22. type:'',
  23. wxOpendata:'',
  24. isload:false,
  25. shopID:'',
  26. loginType:'',
  27. }
  28. },
  29. onLoad(opt) {
  30. this.type=opt.type;
  31. this.loginType=opt.loginType;
  32. this.wxOpendata=uni.getStorageSync("wxOpendata");
  33. var shopID=uni.getStorageSync("shopId");
  34. if(shopID){
  35. this.shopID=shopID;
  36. uni.removeStorageSync('shopId');
  37. }
  38. if(this.loginType==1){
  39. uni.clearStorage();
  40. }else{
  41. if( this.wxOpendata){
  42. /* uni.switchTab({
  43. url:'../index/index'
  44. }) */
  45. uni.navigateTo({
  46. url:'../index/index'
  47. })
  48. }else{
  49. this.isload=true;
  50. }
  51. }
  52. if(opt.shopId){
  53. this.shopID=opt.shopId
  54. }
  55. },
  56. methods: {
  57. goIndex(){
  58. /* uni.switchTab({
  59. url:'../index/index'
  60. }) */
  61. uni.reLaunch({
  62. url:'../index/index'
  63. })
  64. },
  65. getPhoneNumber: function(e) {
  66. console.log(e);
  67. this.wxPhoneData=e.detail;
  68. this.gologin()
  69. //this.wxgologin()
  70. },
  71. privacyClick(){
  72. this.privacyCk=!this.privacyCk
  73. },
  74. iphoneLogin(){
  75. uni.navigateTo({
  76. url:'iphoneLogin'
  77. })
  78. },
  79. wxgologin(){
  80. var that=this;
  81. uni.getUserProfile({
  82. lang:'zh_CN',
  83. desc:'登录',
  84. success:(res)=>{
  85. console.log(res);
  86. that.wxdata=res;
  87. uni.setStorage({
  88. key: 'wxdata',
  89. data: res,
  90. success: function () {
  91. that.ipLogin()
  92. }
  93. });
  94. },
  95. fail:(res)=>{
  96. console.log(res)
  97. }
  98. });
  99. },
  100. ipLogin(){
  101. var that=this;
  102. uni.showLoading({ title: '加载中'});
  103. uni.login({
  104. provider: 'weixin',
  105. success: function (loginRes) {
  106. console.log(loginRes)
  107. that.wxCode=loginRes.code
  108. that.getWxOpenID()
  109. //that.gologin()
  110. }
  111. });
  112. },
  113. gologin(){
  114. /* if(this.wxPhoneData&&this.wxCode){
  115. this.getWxOpenID()
  116. } */
  117. },
  118. getWxOpenID(){
  119. var that=this;
  120. this.$http('km66MiniApp/sys/getWxOpenID', {
  121. code:this.wxCode,
  122. shopID:this.shopID,
  123. nickName:this.wxdata.userInfo.nickName,
  124. headUrl:this.wxdata.userInfo.avatarUrl,
  125. },'GET').then(res => {
  126. console.log(res)
  127. this.openID=res.data.openid;
  128. this.session_key=res.data.session_key;
  129. this.shopID=res.data.shopID
  130. console.log(this.openID)
  131. uni.setStorage({
  132. key: 'wxOpendata',
  133. data: res.data,
  134. success: function (rrr) {
  135. // that.ipLogin()
  136. uni.hideLoading();
  137. if(that.shopID){
  138. uni.redirectTo({
  139. url:'login?shopId='+that.shopID
  140. })
  141. }else{
  142. uni.showToast({
  143. title: '请扫码店铺码',
  144. icon:'none',
  145. duration: 3000
  146. });
  147. /* uni.navigateTo({
  148. url:'../user/scanCode'
  149. }) */
  150. }
  151. /* if(!that.type){
  152. uni.switchTab({
  153. url:'../index/index'
  154. })
  155. }else{
  156. uni.redirectTo({
  157. url:'login'
  158. })
  159. } */
  160. }
  161. });
  162. //this.Login()
  163. })
  164. },
  165. Login(){
  166. var that=this;
  167. this.$http('miniApp/sys/wxLogin', {
  168. openID:this.openID,
  169. encrypData:this.wxPhoneData.encryptedData,
  170. iv:this.wxPhoneData.iv,
  171. sessionKey:this.session_key,
  172. nickName:this.wxdata.userInfo.nickName,
  173. headUrl:this.wxdata.userInfo.avatarUrl,
  174. },).then(res => {
  175. //console.log(res)
  176. uni.hideLoading();
  177. if(res.code==0){
  178. uni.setStorage({
  179. key: 'logodata',
  180. data: res.data,
  181. success: function () {
  182. }
  183. });
  184. uni.showToast({
  185. title: '登录成功',
  186. icon:'none',
  187. duration: 3000
  188. });
  189. uni.switchTab({
  190. url:'../index/index'
  191. })
  192. }else{
  193. uni.showToast({
  194. title: res.msg,
  195. icon:'none',
  196. duration: 3000
  197. });
  198. }
  199. })
  200. }
  201. }
  202. }
  203. </script>
  204. <style scoped>
  205. .euroImg{
  206. width: 290rpx;
  207. height: 361rpx;
  208. }
  209. .logoBox{
  210. text-align: center;
  211. padding-top: 160rpx;
  212. }
  213. .title1{
  214. font-size: 26rpx;
  215. text-align: center;
  216. color: #576B95;
  217. padding-top: 150rpx;
  218. }
  219. .wxlogin{
  220. width: 658rpx;
  221. height: 88rpx;
  222. background: linear-gradient(113deg, #FF630F 0%, #FF450F 100%);
  223. border-radius: 10rpx;
  224. line-height: 88rpx;
  225. text-align: center;
  226. color: #FFFFFF;
  227. font-size: 30rpx;
  228. margin-top: 20rpx;
  229. }
  230. .title2{
  231. width: 100vw;
  232. position: fixed;
  233. left: 0;
  234. bottom: 50rpx;
  235. font-size: 26rpx;
  236. text-align: center;
  237. color: #576B95;
  238. }
  239. </style>