App.vue 3.0 KB

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