App.vue 3.0 KB

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