main.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 !== 200) { // 服务端返回的状态码不等于200,则reject()
  9. uni.showToast({
  10. icon:'none',
  11. mask:false,
  12. title:`${response.data.message}`,
  13. duration: 2000
  14. });
  15. };
  16. if(response.data.code == 401){
  17. // console.log(response)
  18. };
  19. // return Promise.reject(response) // return Promise.reject 可使promise状态进入catch
  20. if (response.config.custom.verification) { // 演示自定义参数的作用
  21. return response.data
  22. }
  23. // console.log(response)
  24. return response
  25. }, (response) => { /* 对响应错误做点什么 (statusCode !== 200)*/
  26. console.log(response);
  27. return Promise.reject(response)
  28. });
  29. import './utils/filter'
  30. Vue.config.productionTip = false
  31. //栏目标题设置
  32. const setNavbarTitle = (title,defaultTitle) => {
  33. uni.setNavigationBarTitle({
  34. title:title || defaultTitle
  35. })
  36. }
  37. //统一提示方便全局修改
  38. const msg = (title, duration=1500, mask=false, icon='none')=>{
  39. if(Boolean(title) === false){
  40. return;
  41. }
  42. uni.showToast({
  43. title,
  44. duration,
  45. mask,
  46. icon
  47. });
  48. }
  49. //封装全局登录检查函数:backpage为登录后返回的页面;backtype为打开页面的类型[1 : redirectTo 2 : switchTab]
  50. //3种页面跳转方式:NavigationTo(直接打开新页面),RedirectTo(覆盖原页面后打开新页面),SwitchTo(切换顶部导航的方式来切换页面)
  51. Vue.prototype.checkLogin = function(backpage, backtype){
  52. var TOKEN = uni.getStorageSync('token');//本地持久化存储
  53. var TOKENHEAD = uni.getStorageSync('tokenhead');
  54. var USERINFO = uni.getStorageSync('userInfo');
  55. if(TOKEN == '' || TOKENHEAD == '' || USERINFO == ''){
  56. uni.redirectTo({url:'/pages/login/login?backpage='+backpage+'&backtype='+backtype});
  57. return false;
  58. }
  59. return [TOKEN,TOKENHEAD,USERINFO];//已经登录返回数组TOKEN等用户信息
  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. Vue.prototype.$api = {msg,http,setNavbarTitle}
  67. Vue.prototype.$getimg = config.imgUrl
  68. Vue.prototype.$placeImg = config.placeImg
  69. Vue.prototype.$store = store
  70. Vue.prototype.config = config
  71. App.mpType = 'app'
  72. const app = new Vue({
  73. ...App
  74. })
  75. app.$mount()