main.js 2.3 KB

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