main.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. import btnPermission from './directive/permission.js';
  39. import api from '@/http/index.js'
  40. Vue.prototype.$has = btnPermission;
  41. Vue.prototype.$api = api;
  42. Vue.prototype.$imgBase = "http://106.54.209.120:8666/image/";
  43. //重载uni.showToast,简化调用
  44. Vue.prototype.$showToast = function(title, duration = 2000, icon = "none") {
  45. return uni.showToast({
  46. title,
  47. duration,
  48. icon
  49. })
  50. }
  51. //重载uni.showModal,简化调用
  52. Vue.prototype.$showModal = function(content) {
  53. return uni.showModal({
  54. title:'温馨提示',
  55. content,
  56. showCancel:false,
  57. confirmText: '确定',
  58. confirmColor: '#007A69'
  59. })
  60. }
  61. // 引入全局uView
  62. import uView from '@/uni_modules/uview-ui'
  63. Vue.use(uView)
  64. uni.$u.config.unit = 'rpx'
  65. const app = new Vue({
  66. ...App
  67. })
  68. app.$mount()
  69. // #endif
  70. // #ifdef VUE3
  71. import {
  72. createSSRApp
  73. } from 'vue'
  74. export function createApp() {
  75. const app = createSSRApp(App)
  76. return {
  77. app
  78. }
  79. }
  80. // #endif