main.js 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import App from './App'
  2. import vueComposition from "@vue/composition-api"
  3. Vue.use(vueComposition)
  4. // #ifndef VUE3
  5. import Vue from 'vue'
  6. import {
  7. router,
  8. RouterMount
  9. } from "@/common/router";
  10. import store from "@/common/store";
  11. import common from "@/common";
  12. import uView from '@/uni_modules/uview-ui'
  13. // 引入uView对小程序分享的mixin封装
  14. let mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js');
  15. Vue.mixin(mpShare)
  16. Vue.config.productionTip = false
  17. App.mpType = 'app'
  18. // store处理
  19. Vue.prototype.$store = store
  20. //引入路由
  21. Vue.use(router);
  22. // 引入全局uView
  23. Vue.use(uView);
  24. // 加载common
  25. Vue.use(common);
  26. try {
  27. function isPromise(obj) {
  28. return (
  29. !!obj &&
  30. (typeof obj === "object" || typeof obj === "function") &&
  31. typeof obj.then === "function"
  32. );
  33. }
  34. // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  35. uni.addInterceptor({
  36. returnValue(res) {
  37. if (!isPromise(res)) {
  38. return res;
  39. }
  40. return new Promise((resolve, reject) => {
  41. res.then((res) => {
  42. if (res[0]) {
  43. reject(res[0]);
  44. } else {
  45. resolve(res[1]);
  46. }
  47. });
  48. });
  49. },
  50. });
  51. } catch (error) {}
  52. const app = new Vue({
  53. ...App
  54. })
  55. // 去除console
  56. if (process.env.NODE_ENV !== "development") {
  57. console.log = () => {}
  58. }
  59. // http拦截器,将此部分放在new Vue()和app.$mount()之间,才能App.vue中正常使用
  60. require('@/common/request/index.js')(app)
  61. // 引入公共方法
  62. import { downloadFile, goChat, openFile, setCache, exportWord, filterSize, countChar, textFormat, accMul, accDiv, accAdd, accSub, parseDate } from '@/common/js/public.js'
  63. // #ifdef APP
  64. // app文件分享
  65. // import {anyShareFile} from '@/common/js/appFileShare.js'
  66. // Vue.prototype.$anyShareFile = anyShareFile
  67. // #endif
  68. Vue.prototype.$downloadFile = downloadFile
  69. Vue.prototype.$openFile = openFile
  70. Vue.prototype.$filterSize = filterSize
  71. Vue.prototype.$goChat = goChat
  72. Vue.prototype.$setCache = setCache
  73. Vue.prototype.$exportWord = exportWord
  74. Vue.prototype.$countChar = countChar
  75. Vue.prototype.$textFormat = textFormat
  76. Vue.prototype.$accMul = accMul
  77. Vue.prototype.$accDiv = accDiv
  78. Vue.prototype.$accAdd = accAdd
  79. Vue.prototype.$accSub = accSub
  80. Vue.prototype.$parseDate = parseDate
  81. // #ifdef H5
  82. RouterMount(app, router, "#app");
  83. // #endif
  84. // #ifndef H5
  85. app.$mount();
  86. // #endif
  87. // #endif
  88. // #ifdef VUE3
  89. import {
  90. createSSRApp
  91. } from 'vue'
  92. export function createApp() {
  93. const app = createSSRApp(App)
  94. return {
  95. app
  96. }
  97. }
  98. // #endif