main.js 2.3 KB

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