App.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <script>
  2. const config = require('./static/config.js');
  3. export default {
  4. onLaunch: function() {
  5. let href = location.href;
  6. let code = this.getQueryString('code');
  7. if(!code){
  8. let url = href.split('#')[0];
  9. url = encodeURIComponent(url);
  10. url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid="+config.appid+"&redirect_uri="+url+"&response_type=code&scope=snsapi_userinfo&state=123&connect_redirect=1#wechat_redirect"
  11. window.location.href = url;
  12. }
  13. let BASE_URL = "";
  14. var env ='';
  15. let res = "3"
  16. switch(res){
  17. case '1': //dev
  18. BASE_URL = 'http://192.168.4.212:8866' // 开发环境
  19. env = 'dev'
  20. break;
  21. case '2': //test
  22. BASE_URL = 'https://opentest1.elab.ink'
  23. env = 'test'
  24. break;
  25. case '3'://test2
  26. BASE_URL = 'https://opentest2.elab.ink'
  27. env = 'test2'
  28. break;
  29. case '4'://test3
  30. BASE_URL = 'https://gatewaytest3.skyforestcity.com'
  31. env = 'test3'
  32. break;
  33. case '5'://test4
  34. BASE_URL = 'https://gatewaytest4.skyforestcity.com'
  35. env = 'test4'
  36. break;
  37. case '6'://uat3
  38. BASE_URL = "https://api-uat3.elaber.cn"
  39. env = 'uat3'
  40. break;
  41. case '7': //uat
  42. BASE_URL = "https://api-uat.elaber.cn"
  43. env = 'uat'
  44. break;
  45. case '8': // 线上 product
  46. default:
  47. BASE_URL = "https://dm-api.elab-plus.cn"
  48. env = 'production'
  49. break;
  50. }
  51. this.globalData.BASE_URL = BASE_URL;
  52. this.globalData.env = env;
  53. },
  54. onShow: function() {
  55. let token = this.$cache.get('_token_owner_union');
  56. let userId = this.$cache.get('_user_id');
  57. let shareToken = this.getQueryString('shareToken');
  58. let projectId = this.getQueryString('projectId');
  59. this.globalData.projectId = projectId;
  60. this.globalData.shareToken = shareToken;
  61. if (!token||!userId) {
  62. this.globalData.userId = userId;
  63. this.regist();
  64. } else {
  65. this.globalData.token = token;
  66. this.globalData.userId = userId;
  67. }
  68. document.body.style.setProperty("background-color",this.globalData.color4)
  69. },
  70. onHide: function() {
  71. },
  72. methods: {
  73. getThemeInfo() {
  74. },
  75. getQueryString(name){
  76. var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
  77. return reg.test(location.href) ? unescape(RegExp.$2.replace(/\+/g, " ")) : ""
  78. },
  79. async regist() {
  80. let code = this.getQueryString('code');
  81. let ret = await this.$myRequest({
  82. url: "/regist",
  83. data: {
  84. "code": code,
  85. "shareToken":this.globalData.shareToken||"",
  86. "projectId":this.globalData.projectId||"",
  87. }
  88. });
  89. if (ret.data.success) {
  90. let userId = ret.data.single.userId;
  91. this.$cache.set("_user_id",userId,0);
  92. this.globalData.userId = userId;
  93. if (ret.data.single.authed == 1) {
  94. let token = ret.data.single.token;
  95. this.$cache.set('_token_owner_union', token);
  96. this.globalData.token = token
  97. }
  98. }
  99. },
  100. },
  101. globalData: {
  102. token: "",
  103. userId:"",
  104. projectId:"",
  105. shareToken:"",
  106. color1: "#F07423",
  107. color2: "#FD8F3C",
  108. color3: "#FFC444",
  109. color4: "#F5F5F7",
  110. color5: "#F7A98E",
  111. color6: "#FFF4EB",
  112. color7:"#F8BA91",
  113. color8:"#FFF4EB",
  114. color9:"#8B654D",
  115. color10:"#FCF6F1",
  116. BASE_URL:"https://dm-api.elab-plus.cn",//默认环境
  117. }
  118. }
  119. </script>
  120. <style>
  121. </style>