main.js 2.6 KB

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