人民医院前端

main.js 3.0KB

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