init.js 1.2 KB

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