main.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. import Vue from 'vue';
  2. import App from './App.vue';
  3. import router from './router';
  4. import store from './store';
  5. import Vant from 'vant';
  6. import VueI18n from 'vue-i18n';
  7. import 'vant/lib/index.less';
  8. import '@vant/touch-emulator';
  9. import { push, replace, switchPage, getCurPage } from './utils/navigate'
  10. import tool from '../src/utils/tools'
  11. import Message from '@/components/jackToast/index';
  12. import './utils/rem.js';
  13. // Vue.prototype.$eventBus = new Vue();
  14. import VueAnimateNumber from 'vue-animate-number'
  15. import VueAwesomeSwiper from "vue-awesome-swiper";
  16. import "swiper/css/swiper.css";
  17. Vue.use(VueAwesomeSwiper);
  18. Vue.use(VueAnimateNumber)
  19. Vue.use(VueI18n);
  20. if (localStorage.getItem('language') == 'null') {
  21. localStorage.setItem('language', 'zh-cn')
  22. }
  23. const i18n = new VueI18n({
  24. locale: localStorage.getItem('language') || 'zh-cn', //切换语言
  25. messages: {
  26. 'zh-cn': require('./language/zh.json'),
  27. 'en': require('./language/en.json'),
  28. },
  29. });
  30. Vue.use(Vant);
  31. Vue.config.productionTip = false;
  32. Vue.use(tool);
  33. Vue.use(Message);
  34. // 路由跳转方法
  35. Vue.prototype.$Router = {
  36. pushPage(obj) {
  37. push(obj);
  38. },
  39. replacePage(obj) {
  40. replace(obj);
  41. },
  42. switchPage(obj) {
  43. switchPage(obj);
  44. }
  45. };
  46. Vue.prototype.$bus = new Vue()
  47. Number.prototype.toFixed = function (n) {
  48. if (n > 20 || n < 0) {
  49. throw new RangeError('toFixed() digits argument must be between 0 and 20');
  50. }
  51. const number = this;
  52. if (isNaN(number) || number >= Math.pow(10, 21)) {
  53. return number.toString();
  54. }
  55. if (typeof (n) == 'undefined' || n == 0) {
  56. return (Math.round(number)).toString();
  57. }
  58. let result = number.toString();
  59. const arr = result.split('.');
  60. // 整数的情况
  61. if (arr.length < 2) {
  62. result += '.';
  63. for (let i = 0; i < n; i += 1) {
  64. result += '0';
  65. }
  66. return result;
  67. }
  68. const integer = arr[0];
  69. const decimal = arr[1];
  70. if (decimal.length == n) {
  71. return result;
  72. }
  73. if (decimal.length < n) {
  74. for (let i = 0; i < n - decimal.length; i += 1) {
  75. result += '0';
  76. }
  77. return result;
  78. }
  79. result = integer + '.' + decimal.substr(0, n);
  80. const last = decimal.substr(n, 1);
  81. // 四舍五入,转换为整数再处理,避免浮点数精度的损失
  82. if (parseInt(last, 10) >= 5) {
  83. const x = Math.pow(10, n);
  84. result = (Math.round((parseFloat(result) * x)) + 1) / x;
  85. result = result.toFixed(n);
  86. }
  87. return result;
  88. }
  89. // 除开发环境,其它不输出日志
  90. if (process.env.NODE_ENV != "development") {
  91. console.log = () => { }
  92. }
  93. new Vue({
  94. router,
  95. store,
  96. i18n,
  97. render: h => h(App),
  98. }).$mount('#app');