人民医院前端

main.js 3.1KB

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