main.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. import Vue from 'vue';
  2. import App from './App';
  3. //token前缀
  4. Vue.prototype.$preToken='Bearer';
  5. //更新提示红点
  6. Vue.prototype.$needUpdate = true;
  7. // 引入全局存储
  8. import store from '@/store';
  9. // 引入全局配置
  10. import $mAssetsPath from '@/config/assets.config.js';
  11. import $mConfig from '@/config/index.config.js';
  12. import $mRoutesConfig from '@/config/routes.config.js';
  13. import $mFormRule from '@/config/formRule.config.js';
  14. import $mConstDataConfig from '@/config/constData.config.js';
  15. // import $mWebsocketConfig from '@/config/websocket.config.js';
  16. import $mSettingConfig from '@/config/setting.config.js';
  17. // 引入全局方法
  18. import {
  19. http
  20. } from '@/utils/request';
  21. import $mGraceChecker from '@/utils/graceChecker';
  22. import $mHelper from '@/utils/helper';
  23. import $mRouter from '@/utils/router';
  24. import { getTabBarBadge } from '@/api/login.js'
  25. // import $mWebsocket from '@/utils/websocket';
  26. // 全局组件
  27. import rfImage from '@/components/oa-image/oa-image';
  28. import rfEmpty from '@/components/oa-empty';
  29. import rfLoading from '@/components/oa-loading';
  30. import rfLoadProgress from '@/components/oa-load-progress/oa-load-progress';
  31. import rfParser from '@/components/oa-parser';
  32. import rfBackTop from '@/components/oa-back-top';
  33. import rfTag from '@/components/oa-tag';
  34. import rfNavDetail from '@/components/oa-nav-detail';
  35. import cuCustom from '@/components/cu-custom';
  36. // 网络状态监听
  37. uni.getNetworkType({
  38. success: res => {
  39. store.dispatch('networkStateChange', res.networkType);
  40. }
  41. });
  42. uni.onNetworkStatusChange(function(res) {
  43. store.dispatch('networkStateChange', res.networkType);
  44. });
  45. // 挂载全局自定义方法
  46. Vue.prototype.$mStore = store;
  47. Vue.prototype.$http = http;
  48. Vue.prototype.$mConfig = $mConfig;
  49. Vue.prototype.$mAssetsPath = $mAssetsPath;
  50. Vue.prototype.$mFormRule = $mFormRule;
  51. Vue.prototype.$mRoutesConfig = $mRoutesConfig;
  52. Vue.prototype.$mConstDataConfig = $mConstDataConfig;
  53. Vue.prototype.$mSettingConfig = $mSettingConfig;
  54. Vue.prototype.$mGraceChecker = $mGraceChecker;
  55. Vue.prototype.$mHelper = $mHelper;
  56. Vue.prototype.$mRouter = $mRouter;
  57. Vue.component('rfImage', rfImage);
  58. Vue.component('rfEmpty', rfEmpty);
  59. Vue.component('rfLoading', rfLoading);
  60. Vue.component('rfLoadProgress', rfLoadProgress);
  61. Vue.component('rfParser', rfParser);
  62. Vue.component('rfBackTop', rfBackTop);
  63. Vue.component('rfTag', rfTag);
  64. Vue.component('rfNavDetail', rfNavDetail);
  65. Vue.component('cuCustom', cuCustom);
  66. if (process.env.NODE_ENV === 'production') {
  67. Vue.config.productionTip = false;
  68. }
  69. // 路由导航
  70. $mRouter.beforeEach((navType, to) => {
  71. var mRoutesConfig = $mRoutesConfig;
  72. var requiresAuth = false;
  73. if (to.route === undefined) {
  74. throw '路由钩子函数中没有找到to对象,路由信息:' + JSON.stringify(to);
  75. }
  76. if (to.route === mRoutesConfig.login.path && store.getters.hasLogin) {
  77. uni.reLaunch({
  78. url: $mHelper.objParseUrlAndParam(mRoutesConfig.main.path)
  79. });
  80. return;
  81. }
  82. // 过滤需要权限的页面
  83. for (var routeCfg in mRoutesConfig) {
  84. if (to.route === mRoutesConfig[routeCfg].path) {
  85. requiresAuth = false;
  86. }
  87. }
  88. if (requiresAuth) {
  89. if (store.getters.hasLogin) {
  90. // 已经登录
  91. uni[navType]({
  92. url: to.route
  93. });
  94. } else {
  95. uni.navigateTo({
  96. url: "/pages/public/login"
  97. });
  98. }
  99. } else {
  100. uni[navType]({
  101. url: to.route
  102. });
  103. }
  104. });
  105. App.mpType = 'app';
  106. Vue.mixin({
  107. computed: {
  108. themeColor: {
  109. get() {
  110. return store.getters.themeColor;
  111. },
  112. set(val) {
  113. store.state.themeColor = val;
  114. }
  115. }
  116. }
  117. });
  118. Vue.prototype.getTabBarBadge=getTabBarBadge;
  119. Vue.prototype.moneySymbol = $mConstDataConfig.moneySymbol;
  120. Vue.prototype.singleSkuText = $mConstDataConfig.singleSkuText;
  121. // 保留小数点后两位
  122. Vue.filter('keepTwoDecimal', value => {
  123. return (Math.floor((value || 0) * 100) / 100).toFixed(2);
  124. });
  125. const app = new Vue({
  126. ...App,
  127. store: store
  128. });
  129. app.$mount();