人民医院前端

main.js 3.0KB

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