Ei kuvausta

main.js 2.5KB

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