main.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. import Vue from 'vue'
  2. import App from './App'
  3. Vue.config.productionTip = false
  4. // import uView from "uview-ui";
  5. // Vue.use(uView);
  6. import md5 from 'js-md5';
  7. Vue.prototype.$md5 = md5;
  8. import dayjs from 'dayjs';
  9. Vue.prototype.$day = dayjs;
  10. import cof from '@/static/config/in';
  11. Vue.prototype.$cof = cof;
  12. // 微信全局分享
  13. import share from '@/utils/share.js'
  14. Vue.mixin(share)
  15. // js高精度计算
  16. import highPrecision from "@/utils/highPrecision";
  17. Vue.prototype.$h = highPrecision;
  18. Vue.prototype.tidyTpye = (da) => {
  19. switch(da) {
  20. case '1': return "零售专区";
  21. case '2': return "批发专区";
  22. case '3': return "精品专区";
  23. case '4': return "今日值得买";
  24. case '5': return "茶宝兑换";
  25. case '6': return "天天捡漏";
  26. default: return ""
  27. }
  28. }
  29. Number.prototype.toFixed = function (n) {
  30. if (n > 20 || n < 0) {
  31. throw new RangeError('toFixed() digits argument must be between 0 and 20');
  32. }
  33. const number = this;
  34. if (isNaN(number) || number >= Math.pow(10, 21)) {
  35. return number.toString();
  36. }
  37. if (typeof (n) == 'undefined' || n == 0) {
  38. return (Math.round(number)).toString();
  39. }
  40. let result = number.toString();
  41. const arr = result.split('.');
  42. // 整数的情况
  43. if (arr.length < 2) {
  44. result += '.';
  45. for (let i = 0; i < n; i += 1) {
  46. result += '0';
  47. }
  48. return result;
  49. }
  50. const integer = arr[0];
  51. const decimal = arr[1];
  52. if (decimal.length == n) {
  53. return result;
  54. }
  55. if (decimal.length < n) {
  56. for (let i = 0; i < n - decimal.length; i += 1) {
  57. result += '0';
  58. }
  59. return result;
  60. }
  61. result = integer + '.' + decimal.substr(0, n);
  62. const last = decimal.substr(n, 1);
  63. // 四舍五入,转换为整数再处理,避免浮点数精度的损失
  64. if (parseInt(last, 10) >= 5) {
  65. const x = Math.pow(10, n);
  66. result = (Math.round((parseFloat(result) * x)) + 1) / x;
  67. result = result.toFixed(n);
  68. }
  69. return result;
  70. }
  71. // 自动适配接口域名
  72. import hosts from "@/request/config";
  73. Vue.prototype.$hosts = hosts;
  74. // 上传
  75. import { up } from "@/utils/up";
  76. Vue.prototype.$up = up;
  77. // 页面跳转
  78. import { goto } from '@/utils/myfun.js';
  79. Vue.prototype.goto = goto;
  80. App.mpType = 'app'
  81. const app = new Vue({
  82. ...App
  83. })
  84. app.$mount()
  85. Array.prototype.indexOf = function (val) {
  86. for (var i = 0; i < this.length; i++) {
  87. if (this[i] == val) return i;
  88. }
  89. return -1;
  90. };
  91. Array.prototype.remove = function (val) {
  92. var index = this.indexOf(val);
  93. if (index > -1) {
  94. this.splice(index, 1);
  95. }
  96. };
  97. Vue.directive('focus', {
  98. inserted: (el, binding) => {
  99. if (binding.value == true || binding.value == undefined) {
  100. el.focus()
  101. }
  102. }
  103. });