main.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import App from './App'
  2. import uvUI from '@/uni_modules/uv-ui-tools'
  3. import {
  4. Request
  5. } from '@/util/request/index'
  6. import $mUtil from '@/util/index.js';
  7. import config from '@/config/global.config.js'
  8. import throttle from '@/uni_modules/uv-ui-tools/libs/function/throttle.js';
  9. import initialize from "@/util/initialize.ts";
  10. import { handleImageUrl } from "@/util/index.js"
  11. // #ifndef VUE3
  12. import Vue from 'vue'
  13. Vue.config.productionTip = false;
  14. App.mpType = 'app'
  15. try {
  16. function isPromise(obj) {
  17. return (!!obj && (typeof obj === "object" || typeof obj === "function") && typeof obj.then === "function");
  18. }
  19. // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  20. uni.addInterceptor({
  21. returnValue(res) {
  22. if (!isPromise(res)) {
  23. return res;
  24. }
  25. return new Promise((resolve, reject) => {
  26. res.then((res) => {
  27. if (res[0]) {
  28. reject(res[0]);
  29. } else {
  30. resolve(res[1]);
  31. }
  32. });
  33. });
  34. },
  35. });
  36. } catch (error) {}
  37. const app = new Vue({
  38. ...App
  39. })
  40. // #ifndef VUE3
  41. Vue.use(uvUI);
  42. Vue.use(initialize)
  43. // #endif
  44. // #ifdef VUE3
  45. app.use(uvUI);
  46. // #endif
  47. app.$mount()
  48. // 引入请求封装
  49. Request(app)
  50. // #endif
  51. // #ifdef VUE3
  52. import {
  53. createSSRApp
  54. } from 'vue'
  55. export function createApp() {
  56. const app = createSSRApp(App)
  57. // 注册全局工具函数
  58. app.config.globalProperties.$mUtil = $mUtil;
  59. app.config.globalProperties.$mConfig = config;
  60. app.config.globalProperties.$throttle = throttle;
  61. app.config.globalProperties.$defaultAvatar = config.staticUrl + '/czd/default-avatar.jpg';
  62. app.config.globalProperties.$handleImageUrl = handleImageUrl;
  63. app.use(initialize)
  64. // 引入请求封装
  65. Request(app)
  66. return {
  67. app
  68. }
  69. }
  70. // #endif