App.vue 3.1 KB

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