App.vue 3.0 KB

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