main.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import Vue from 'vue'
  2. import App from './App'
  3. import store from './store/logion.js'
  4. // 定义全局提示title
  5. const baseURL = 'http://192.168.1.12:8082';
  6. const msg = (title, duration=1500, mask=false, icon='none')=>{
  7. //统一提示方便全局修改
  8. if(Boolean(title) === false){
  9. return;
  10. }
  11. uni.showToast({
  12. title,
  13. duration,
  14. mask,
  15. icon
  16. });
  17. }
  18. const request = function(options) {
  19. options.url = baseUrl + options.url;
  20. option.method = options.method;
  21. const token = uni.getStorageSync('sessionId');
  22. if (sessionId) { // 如果存在sessionId 配置请求头
  23. options.header = {
  24. 'Authorization' : sessionId,
  25. 'Content-Type' : 'application/json'
  26. }
  27. }else{ // 不存在token 跳转至登录
  28. }
  29. // 这里对response进行处理,
  30. options.complete = (response) => {
  31. if (response.statusCode == 401) {
  32. }
  33. }
  34. return uni.request(options);
  35. }
  36. // const request = (url, urlhead, sessIoid) => {
  37. // uni.request({
  38. // url: baseURL+url,
  39. // method: urlhead,
  40. // header = {
  41. // 'Authorization' : 'Bearer ' + sessIoid,
  42. // 'Content-Type' : 'application/json'
  43. // },
  44. // })
  45. // }
  46. Vue.prototype.$msg = msg
  47. Vue.prototype.request = request
  48. Vue.config.productionTip = false
  49. Vue.prototype.$store = store
  50. App.mpType = 'app'
  51. const app = new Vue({
  52. ...App
  53. })
  54. app.$mount()