App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. let userId = this.$cache.get('_user_id')
  8. if(!(code&&userId)){
  9. href = encodeURIComponent(href);
  10. 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"
  11. window.location.href = url;
  12. }
  13. let BASE_URL = "";
  14. var env ='';
  15. let res = uni.getStorageSync('env')
  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) {
  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. uni.$emit('request')
  93. }else{
  94. uni.$emit('request')
  95. }
  96. },
  97. },
  98. globalData: {
  99. token: "",
  100. userId:"",
  101. color1: "#F07423",
  102. color2: "#FD8F3C",
  103. color3: "#FFC444",
  104. color4: "#F5F5F7",
  105. color5: "#F7A98E",
  106. color6: "#FFF4EB",
  107. color7:"#F8BA91",
  108. color8:"#FFF4EB",
  109. color9:"#8B654D",
  110. color10:"#FCF6F1",
  111. BASE_URL:"https://dm-api.elab-plus.cn",//默认环境
  112. }
  113. }
  114. </script>
  115. <style>
  116. </style>