main.js 2.5 KB

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