Bez popisu

main.js 2.6KB

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