main.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. const goback = () =>{
  76. // let menuButtonInfo = uni.getMenuButtonBoundingClientRect();//胶囊按钮信息
  77. let pages = getCurrentPages();
  78. let prevPage = pages[pages.length - 2]; //上一个页面
  79. // console.log('pages',pages);
  80. // console.log('prevPage',prevPage.route);
  81. // console.log('pages[0].route',pages[0].route);
  82. if(prevPage.route == 'pages/use/useRouter'){
  83. // if(pages.length == '2'){
  84. uni.switchTab({
  85. url:'/pages/index/index',
  86. fail: (err) => {
  87. console.log('switchTab',err)
  88. }
  89. })
  90. return;
  91. };
  92. uni.navigateBack({})
  93. };
  94. Vue.prototype.$api = {msg,http,href,goback};
  95. Vue.prototype.$getimg = config.imgUrl;
  96. // Vue.prototype.$getInnerImg = config.innerImgUrl;
  97. Vue.prototype.$onlineImg = config.onlineImg;
  98. Vue.prototype.$placeImg = config.placeImg;
  99. // Vue.prototype.$qnyImg = config.qnyImg;
  100. Vue.prototype.$store = store;
  101. Vue.prototype.config = config;
  102. App.mpType = 'app'
  103. const app = new Vue({
  104. ...App
  105. })
  106. app.$mount()