App.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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_base&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. if (!token||!userId) {
  58. this.globalData.userId = userId;
  59. this.regist();
  60. } else {
  61. this.globalData.token = token;
  62. this.globalData.userId = userId;
  63. }
  64. document.body.style.setProperty("background-color",this.globalData.color4)
  65. },
  66. onHide: function() {
  67. },
  68. methods: {
  69. getThemeInfo() {
  70. },
  71. getQueryString(name){
  72. var reg = new RegExp("(^|\\?|&)"+ name +"=([^&]*)(\\s|&|$)", "i");
  73. return reg.test(location.href) ? unescape(RegExp.$2.replace(/\+/g, " ")) : ""
  74. },
  75. async regist() {
  76. let code = this.getQueryString('code');
  77. let shareToken = this.getQueryString('shareToken');
  78. let projectId = this.getQueryString('projectId');
  79. let ret = await this.$myRequest({
  80. url: "/regist",
  81. data: {
  82. "code": code,
  83. "shareToken":shareToken||"",
  84. "projectId":projectId||"",
  85. }
  86. });
  87. if (ret.data.success) {
  88. let userId = ret.data.single.userId;
  89. this.$cache.set("_user_id",userId,0);
  90. this.globalData.userId = userId;
  91. if (ret.data.single.authed == 1) {
  92. let token = ret.data.single.token;
  93. this.$cache.set('_token_owner_union', token);
  94. this.globalData.token = token
  95. }
  96. }
  97. },
  98. },
  99. globalData: {
  100. token: "",
  101. userId:"",
  102. color1: "#F07423",
  103. color2: "#FD8F3C",
  104. color3: "#FFC444",
  105. color4: "#F5F5F7",
  106. color5: "#F7A98E",
  107. color6: "#FFF4EB",
  108. color7:"#F8BA91",
  109. color8:"#FFF4EB",
  110. color9:"#8B654D",
  111. color10:"#FCF6F1",
  112. BASE_URL:"https://dm-api.elab-plus.cn",//默认环境
  113. }
  114. }
  115. </script>
  116. <style>
  117. </style>