人民医院前端

main.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. import Vue from 'vue';
  2. import App from './App';
  3. // 引入全局存储
  4. import store from '@/store';
  5. // 引入全局配置
  6. import $mAssetsPath from '@/config/assets.config.js';
  7. import $mConfig from '@/config/index.config.js';
  8. import $mRoutesConfig from '@/config/routes.config.js';
  9. import $mConstDataConfig from '@/config/constData.config';
  10. import $mButtonConfig from '@/config/buttons.config'
  11. // 调试
  12. // import VConsole from 'vconsole'
  13. // const vConsole = new VConsole()
  14. // Vue.use(vConsole)
  15. // 引入全局方法
  16. import { http } from '@/utils/request';
  17. import $mGraceChecker from '@/utils/graceChecker';
  18. import $mHelper from '@/utils/helper';
  19. import $mRouter from '@/utils/router';
  20. // import * as dd from 'dingtalk-jsapi'; // 此方式为整体加载,也可按需进行加载
  21. import { debuggerModule } from 'uni_modules/imengyu-IMDebuggerWindow/common/debuggerExtern.js'
  22. //引入echarts
  23. // import echarts from './components/echarts/echarts.min.js'
  24. // import echarts from 'echarts'
  25. // Vue.prototype.$echarts = echarts
  26. const errorHandler = (err, vm, info) => {
  27. if(debuggerModule) debuggerModule.addVueError(err, vm, info);
  28. }
  29. // window.wx = {}//解决tooltip失效问题
  30. Vue.config.errorHandler = errorHandler;
  31. // 挂载全局自定义方法
  32. Vue.prototype.$mStore = store;
  33. Vue.prototype.$http = http;
  34. Vue.prototype.$mConfig = $mConfig
  35. Vue.prototype.$mAssetsPath = $mAssetsPath;
  36. Vue.prototype.$mRoutesConfig = $mRoutesConfig;
  37. Vue.prototype.$mConstDataConfig = $mConstDataConfig;
  38. Vue.prototype.$mButtonConfig = $mButtonConfig;
  39. Vue.prototype.$mGraceChecker = $mGraceChecker;
  40. Vue.prototype.$mHelper = $mHelper;
  41. Vue.prototype.$mRouter = $mRouter;
  42. if (process.env.NODE_ENV === 'production') {
  43. Vue.config.productionTip = false;
  44. }
  45. // 路由导航
  46. $mRouter.beforeEach((navType, to) => {
  47. if (to.route === undefined) {
  48. throw '路由钩子函数中没有找到to对象,路由信息:' + JSON.stringify(to);
  49. }
  50. if (to.route === $mRoutesConfig.login.path && store.getters.hasLogin) {
  51. uni.reLaunch({
  52. url: $mHelper.objParseUrlAndParam($mRoutesConfig.main.path)
  53. });
  54. return;
  55. }
  56. // 过滤需要权限的页面
  57. if (to.route.requiresAuth) {
  58. if (store.getters.hasLogin) {
  59. // 已经登录
  60. uni[navType]({
  61. url: $mHelper.objParseUrlAndParam(to.route.path, to.query)
  62. });
  63. } else {
  64. // 登录成功后的重定向地址和参数
  65. const query = {
  66. redirectUrl: to.route.path,
  67. ...to.query
  68. };
  69. // 没有登录 是否强制登录?
  70. if (store.state.forcedLogin) {
  71. uni.redirectTo({
  72. url: $mHelper.objParseUrlAndParam($mRoutesConfig.login.path, query)
  73. });
  74. } else {
  75. uni.navigateTo({
  76. url: $mHelper.objParseUrlAndParam($mRoutesConfig.login.path, query)
  77. });
  78. }
  79. }
  80. } else {
  81. uni[navType]({
  82. url: $mHelper.objParseUrlAndParam(to.route, to.query)
  83. });
  84. }
  85. });
  86. App.mpType = 'app';
  87. Vue.mixin({
  88. computed: {
  89. themeColor: {
  90. get () {
  91. return store.getters.themeColor;
  92. },
  93. set (val) {
  94. store.state.themeColor = val;
  95. }
  96. }
  97. }
  98. });
  99. Vue.prototype.moneySymbol = $mConstDataConfig.moneySymbol;
  100. Vue.prototype.singleSkuText = $mConstDataConfig.singleSkuText;
  101. // 保留小数点后两位
  102. Vue.filter('keepTwoDecimal', value => {
  103. return (Math.floor((value || 0) * 100) / 100).toFixed(2);
  104. });
  105. const app = new Vue({
  106. ...App,
  107. store: store
  108. });
  109. app.$mount();