main.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. // #ifndef VUE3
  2. import Vue from 'vue'
  3. import App from './App'
  4. //导入网络请求包
  5. import {$http} from '@escook/request-miniprogram'
  6. //5.导入store的自定义模块
  7. import store from '@/store/store.js'
  8. //导入uView组件库
  9. import uView from '@/uni_modules/uview-ui'
  10. //导入公共方法
  11. import Common from './utils/Common.js'
  12. import APIHandler from './utils/APIHandler.js'
  13. //挂载公共方法实例
  14. Vue.prototype.$getRecentDateArray = Common.getRecentDateArray;
  15. Vue.prototype.$timestampToTime = Common.timestampToTime;
  16. //API数据获取与处理
  17. Vue.prototype.$initGrade = APIHandler.initGrade;
  18. Vue.prototype.$initHomework = APIHandler.initHomework;
  19. Vue.prototype.$initHome = APIHandler.initHome;
  20. Vue.prototype.$initApp = APIHandler.initApp;
  21. //格式化处理日期时间的方法
  22. Date.prototype.format = function(fmt) {
  23. let o = {
  24. "M+": this.getMonth() + 1, //月份
  25. "d+": this.getDate(), //日
  26. "h+": this.getHours(), //小时
  27. "m+": this.getMinutes(), //分
  28. "s+": this.getSeconds(), //秒
  29. "q+": Math.floor((this.getMonth() + 3) / 3), //季度
  30. "S": this.getMilliseconds() //毫秒
  31. };
  32. if (/(y+)/.test(fmt)) fmt = fmt.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
  33. for (let k in o)
  34. if (new RegExp("(" + k + ")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length == 1) ? (o[k]) :
  35. (("00" + o[k]).substr(("" + o[k]).length)));
  36. return fmt;
  37. }
  38. //挂载到uni.$http上方便调用
  39. uni.$http = $http
  40. //请求根路径
  41. // $http.baseUrl = 'https://www.uinav.com'
  42. //挂载请求拦截器
  43. $http.beforeRequest = function(options) {
  44. uni.showLoading({
  45. title: '数据加载中...'
  46. })
  47. //挂载请求头
  48. //判断当前请求的是否为有权限的接口
  49. // if(options.url.indexOf('/pages/login/login') !== -1){
  50. //为header中添加必要信息(权限字段)
  51. // options.header = {
  52. // }
  53. //}
  54. }
  55. //挂载响应拦截器
  56. $http.afterRequest = function() {
  57. uni.hideLoading()
  58. }
  59. //封装的展示消息提示方法
  60. uni.$showMsg = function(title = '请求失败', duration = 1500) {
  61. uni.showToast({
  62. title,
  63. duration,
  64. icon: 'none'
  65. })
  66. }
  67. Vue.config.productionTip = false
  68. App.mpType = 'app'
  69. //app实例对象
  70. const app = new Vue({
  71. ...App,
  72. //6.挂载到app实例对象里
  73. store
  74. })
  75. app.$mount()
  76. // #endif
  77. // #ifdef VUE3
  78. import {
  79. createSSRApp
  80. } from 'vue'
  81. import App from './App.vue'
  82. export function createApp() {
  83. const app = createSSRApp(App)
  84. return {
  85. app
  86. }
  87. }
  88. // #endif