main.js 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import Vue from 'vue'
  2. import App from './App'
  3. import { config } from './config/config'
  4. import store from './store'
  5. import Request from '@/js_sdk/luch-request/luch-request/index.js';
  6. const http = new Request();
  7. http.interceptors.response.use((response) => { /* 对响应成功做点什么 可使用async await 做异步操作*/
  8. if (response.data.code == 1) { // 服务端返回的状态码不等于200,则reject()
  9. uni.showToast({
  10. icon:'none',
  11. mask:false,
  12. title:`${response.data.msg}`,
  13. duration: 2000
  14. });
  15. return Promise.reject(response)
  16. };
  17. // console.log('response',response);
  18. if(response.data.code == 401){
  19. uni.showToast({
  20. title:response.data.message + " 即将跳转到登录页",
  21. icon:"none",
  22. duration:2000
  23. });
  24. uni.setStorage({
  25. key: "hasLogin",
  26. data: false
  27. });
  28. setTimeout(i=>{
  29. uni.navigateTo({
  30. url: '/pages/login/loginType',
  31. fail:function(err){
  32. console.log(err)
  33. }
  34. });
  35. },2000);
  36. return Promise.reject(response)
  37. };
  38. // return Promise.reject(response) // return Promise.reject 可使promise状态进入catch
  39. if (response.config.custom.verification) { // 演示自定义参数的作用
  40. return response.data
  41. }
  42. // console.log(response)
  43. return response
  44. }, (response) => { /* 对响应错误做点什么 (statusCode !== 200)*/
  45. console.log(response);
  46. return Promise.reject(response)
  47. });
  48. import './utils/filter'
  49. //统一提示方便全局修改
  50. const msg = (title, duration=1500, mask=false, icon='none')=>{
  51. if(Boolean(title) === false){
  52. return;
  53. }
  54. uni.showToast({
  55. title,
  56. duration,
  57. mask,
  58. icon
  59. });
  60. };
  61. // import $wxApi from "./wxapi.js";
  62. // Vue.prototype.$wxApi = $wxApi;
  63. // //微信支付封装
  64. // import $pay from "./pay.js";
  65. // Vue.prototype.$pay = $pay
  66. const href = (data,type = 1) =>{
  67. uni.navigateTo({
  68. url:data,
  69. fail:function(err){
  70. console.log('navigateTo fail',err)
  71. }
  72. })
  73. };
  74. Vue.config.productionTip = false;
  75. Vue.prototype.$api = {msg,http,href};
  76. Vue.prototype.$getimg = config.imgUrl;
  77. Vue.prototype.$getInnerImg = config.innerImgUrl;
  78. Vue.prototype.$onlineImg = config.onlineImg;
  79. Vue.prototype.$placeImg = config.placeImg;
  80. Vue.prototype.$qnyImg = config.qnyImg;
  81. Vue.prototype.$store = store;
  82. Vue.prototype.config = config;
  83. App.mpType = 'app'
  84. const app = new Vue({
  85. ...App
  86. })
  87. app.$mount()