人民医院前端

main.js 2.9KB

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