main.js 2.5 KB

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