main.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import App from './App'
  2. // #ifndef VUE3
  3. import Vue from 'vue'
  4. Vue.config.productionTip = false
  5. App.mpType = 'app'
  6. try {
  7. function isPromise(obj) {
  8. return (
  9. !!obj &&
  10. (typeof obj === "object" || typeof obj === "function") &&
  11. typeof obj.then === "function"
  12. );
  13. }
  14. // 统一 vue2 API Promise 化返回格式与 vue3 保持一致
  15. uni.addInterceptor({
  16. returnValue(res) {
  17. if (!isPromise(res)) {
  18. return res;
  19. }
  20. return new Promise((resolve, reject) => {
  21. res.then((res) => {
  22. if (res[0]) {
  23. reject(res[0]);
  24. } else {
  25. resolve(res[1]);
  26. }
  27. });
  28. });
  29. },
  30. });
  31. } catch (error) {}
  32. //import Permission from './directive/permission.js'
  33. //Vue.use(Permission)
  34. import system from '@/utils/system.js'
  35. Vue.mixin(system);
  36. import CusHeader from '@/components/CusHeader'
  37. Vue.component('CusHeader',CusHeader);
  38. //日期格式处理
  39. import dateFormat from '@/utils/dateFormat.js'
  40. Vue.use(dateFormat);
  41. import btnPermission from './directive/permission.js';
  42. import api from '@/http/index.js'
  43. Vue.prototype.$has = btnPermission;
  44. Vue.prototype.$api = api;
  45. Vue.prototype.$imgBase = "http://106.54.209.120:8666/image/";
  46. //重载uni.showToast,简化调用
  47. Vue.prototype.$showToast = function(title, duration = 2000, icon = "none") {
  48. return uni.showToast({
  49. title,
  50. duration,
  51. icon
  52. })
  53. }
  54. //重载uni.showModal,简化调用
  55. Vue.prototype.$showModal = function(content) {
  56. return uni.showModal({
  57. title:'温馨提示',
  58. content,
  59. showCancel:false,
  60. confirmText: '确定',
  61. confirmColor: '#007A69'
  62. })
  63. }
  64. // 引入全局uView
  65. import uView from '@/uni_modules/uview-ui'
  66. Vue.use(uView)
  67. uni.$u.config.unit = 'rpx'
  68. const app = new Vue({
  69. ...App
  70. })
  71. app.$mount()
  72. // #endif
  73. // #ifdef VUE3
  74. import {
  75. createSSRApp
  76. } from 'vue'
  77. export function createApp() {
  78. const app = createSSRApp(App)
  79. return {
  80. app
  81. }
  82. }
  83. // #endif