init.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import carhelp from '@/apis/utils/mixin.js'
  2. import * as API_WeiXin from '@/apis/weixin.js'
  3. var openId = carhelp.getOpenId();
  4. var app = {
  5. init: function() {
  6. // #ifdef H5
  7. console.log("SIMPLE_RUN 模式,取配置固定openId 可修改SIMPLE_RUN ")
  8. carhelp.setOpenId(process.car.openId)
  9. // #endif
  10. // #ifdef MP-WEIXIN
  11. if(process.car.SIMPLE_RUN&& process.env.NODE_ENV === "development" ){
  12. console.log("SIMPLE_RUN 模式,取配置固定openId 可修改SIMPLE_RUN ")
  13. carhelp.setOpenId(process.car.openId)
  14. }else{
  15. if (!openId) {
  16. this.getOpenId()
  17. }
  18. }
  19. // #endif
  20. },
  21. getOpenId() {
  22. var openId = carhelp.getOpenId()
  23. if (!openId) {
  24. uni.login({
  25. provider: 'weixin',
  26. success: loginRes => {
  27. API_WeiXin.findAppletUserInfo(loginRes.code).then(response => {
  28. carhelp.setOpenId(response.data)
  29. //user_info 等属性 ,头像,名称,可通过授权获得 uniapp方法申请
  30. //carhelp.set("xpgj_wx_user_info",response.data)
  31. if(this.onload){
  32. this.onload();
  33. }
  34. }).catch(error => {
  35. console.log(error);
  36. });
  37. }
  38. });
  39. }
  40. }
  41. }
  42. module.exports = app