main.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. import Vue from 'vue'
  2. import App from './App'
  3. import * as Api from './config/api.js'
  4. import * as Common from './config/common.js'
  5. import * as Db from './config/db.js'
  6. import * as Config from './config/config.js'
  7. // import share from "@/common/share.js"
  8. import store from './store';
  9. import util from "@/common/util.js"
  10. import ElementUI from 'element-ui';
  11. import 'element-ui/lib/theme-chalk/index.css';
  12. import Print from 'vue-print-nb'
  13. const logic = {
  14. systemInfo: null,
  15. /**
  16. * 显示消息提示
  17. *
  18. * @param {Object} text
  19. * @param {Object} icon
  20. */
  21. showToast(text, icon) {
  22. return uni.showToast({
  23. title: text || '加载中',
  24. icon: icon || 'none',
  25. mask: true,
  26. duration: 2000
  27. });
  28. },
  29. /**
  30. * 全局方法 - px2rpx
  31. *
  32. * @param {Object} px
  33. */
  34. px2rpx(px) {
  35. if (this.systemInfo === null) {
  36. this.systemInfo = uni.getSystemInfoSync()
  37. }
  38. // 官方规定屏幕宽为750rpx
  39. return px / this.systemInfo.windowWidth * 750;
  40. },
  41. /**
  42. * 全局方法 - rpx2px
  43. *
  44. * @param {Object} rpx
  45. */
  46. rpx2px(rpx) {
  47. if (this.systemInfo === null) {
  48. this.systemInfo = uni.getSystemInfoSync()
  49. }
  50. // 官方规定屏幕宽为750rpx
  51. return rpx / 750 * this.systemInfo.windowWidth;
  52. },
  53. }
  54. // import {
  55. // createSSRApp
  56. // } from 'vue'
  57. // export function createApp() {
  58. // const app = createSSRApp(App)
  59. // app.use(store)
  60. // app.config.globalProperties.$logic = logic
  61. // return {
  62. // app
  63. // }
  64. // }
  65. function isPromise(obj) {
  66. return (!!obj &&
  67. (typeof obj === "object" || typeof obj === "function") &&
  68. typeof obj.then === "function"
  69. );
  70. }
  71. // uni方法转then数组
  72. uni.addInterceptor({
  73. returnValue(res) {
  74. if (!isPromise(res)) {
  75. return res;
  76. }
  77. const returnValue = [undefined, undefined];
  78. return res
  79. .then((res) => {
  80. returnValue[1] = res;
  81. })
  82. .catch((err) => {
  83. returnValue[0] = err;
  84. })
  85. .then(() => returnValue);
  86. },
  87. });
  88. /*
  89. 有报错我先注释掉了
  90. 105行 还有config.js 5-7行
  91. Vue.component('cu-custom',cuCustom) */
  92. import uView from '@/uni_modules/uview-ui'
  93. Vue.use(uView)
  94. Vue.use(Print)
  95. Vue.prototype.$api = Api;
  96. Vue.prototype.$common = Common;
  97. Vue.prototype.$db = Db;
  98. Vue.prototype.$config = Config;
  99. Vue.prototype.$logic = logic;
  100. Vue.prototype.$util = util;
  101. Vue.prototype.vuex_theme = {
  102. value: {
  103. color: "#fff",
  104. bgColor: "#c7a772"
  105. }
  106. }
  107. Vue.prototype.vuex_parse_style = {
  108. h1: 'padding:20rpx 0;',
  109. h2: 'padding:10rpx 0;',
  110. h3: 'padding:10rpx 0;',
  111. h4: 'padding:10rpx 0;',
  112. h5: 'padding:5rpx 0;',
  113. h6: 'padding:5rpx 0;',
  114. ul: 'margin-bottom:20rpx;padding-left:30rpx;',
  115. ol: 'margin-bottom:20rpx;padding-left:30rpx;',
  116. code: 'background-color: #f6f6f6;margin: 0 5rpx;padding: 6rpx 8rpx;border-radius: 6rpx;text-align:center;',
  117. pre: 'white-space: pre;overflow: auto;background: #f6f6f6;border-radius: 8rpx;border: none;color: #1a1a1a;margin-bottom: 20rpx;padding:20rpx;',
  118. 'pre code': 'margin:0;padding:0;',
  119. blockquote: 'padding: 15rpx;margin:0 0 20rpx 0;border-radius: 6rpx;',
  120. p: 'margin-bottom:20rpx',
  121. table: 'width:100%;margin-bottom:20rpx;border-collapse: collapse;',
  122. th: 'background-color: whitesmoke;border: 1px solid #e6e6e6;padding:10rpx;',
  123. td: 'border: 1px solid #e6e6e6;padding:10rpx;'
  124. }
  125. Vue.prototype.vuex_config = {}
  126. Vue.config.productionTip = false
  127. // Vue.mixin(share)
  128. App.mpType = 'app'
  129. Vue.use(ElementUI);
  130. const app = new Vue({
  131. ...App,
  132. store
  133. })
  134. app.$mount()