main.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. import Vue from 'vue'
  2. import App from './App'
  3. // 引入全局存储
  4. import store from './store'
  5. // 引入全局配置
  6. import $mAssetsPath from '@/config/assets.config.js';
  7. import $mConfig from '@/config/global.config.js';
  8. import commonMixin from '@/common/commonMixin'
  9. // // 注册公用渲染方法
  10. // import '@/utils/registerBaseStyle.js'
  11. // 引入全局方法
  12. import {
  13. http
  14. } from '@/common/request';
  15. import {
  16. yghttp
  17. } from '@/common/request/index-yg.js';
  18. import $mUtil from '@/common/util.js';
  19. // 全局组件
  20. import navbar from '@/components/hx-navbar/hx-navbar.nvue';
  21. import ldLoading from '@/components/ld-loading/index.vue';
  22. import nodata from '@/components/noData/nodata.vue';
  23. import loadMore from '@/components/uni-load-more/uni-load-more.vue';
  24. import Directives from './directives/index.js';
  25. import welfareGoods from '@/components/welfare-goods/index.vue';
  26. import donationNews from '@/components/donation-news/index.vue';
  27. import entrepreneurshipZoneTabbar from '@/components/entrepreneurship-zone-tabbar/index.vue';
  28. import initialize from "@/utils/initialize"
  29. // 网络状态监听
  30. // uni.getNetworkType({
  31. // success: res => {
  32. // console.log(res)
  33. // store.dispatch('networkStateChange', res.networkType);
  34. // }
  35. // });
  36. // uni.onNetworkStatusChange(function (res) {
  37. // console.log(res+'onNetworkStatusChange')
  38. // store.dispatch('networkStateChange', res.networkType);
  39. // });
  40. if (process.env.NODE_ENV === 'production') {
  41. Vue.config.productionTip = false;
  42. }
  43. // 挂载全局自定义方法
  44. Vue.prototype.$store = store
  45. Vue.prototype.$adpid = ""
  46. Vue.prototype.$http = http;
  47. Vue.prototype.$yghttp = yghttp;
  48. Vue.prototype.$mConfig = $mConfig;
  49. Vue.prototype.$mAssetsPath = $mAssetsPath;
  50. Vue.prototype.$mUtil = $mUtil;
  51. Vue.component('navbar', navbar);
  52. Vue.component('ldLoading', ldLoading);
  53. Vue.component('nodata', nodata);
  54. Vue.component('loadMore', loadMore);
  55. Vue.component('welfareGoods', welfareGoods);
  56. Vue.component('donationNews', donationNews);
  57. Vue.component('entrepreneurshipZoneTabbar', entrepreneurshipZoneTabbar);
  58. App.mpType = 'app'
  59. Vue.use(Directives);
  60. // 保留小数点后两位
  61. Vue.filter('keepTwo', value => {
  62. return (Math.floor((value || 0) * 100) / 100).toFixed(2);
  63. });
  64. // 整数,获取数字整数部分
  65. Vue.filter('integer', value => {
  66. if (value) {
  67. return Math.trunc(value)
  68. };
  69. return 0
  70. });
  71. // 整数,获取数字整数部分
  72. Vue.filter('integer', value => {
  73. if (value) {
  74. return Math.trunc(value)
  75. };
  76. return 0
  77. });
  78. // 整数,获取数字整数部分
  79. Vue.filter('decimals', value => {
  80. if (value) {
  81. try {
  82. value += "";
  83. return value.split('.')[1] || '00'
  84. } catch {
  85. return "00"
  86. }
  87. };
  88. return '00'
  89. });
  90. // integral(){
  91. // integral(num) {
  92. // //判断数字是否有小数
  93. // }
  94. // }
  95. // 添加小数
  96. Vue.prototype.$addDecimals = (num = 0, length = 8, type = true) => {
  97. // length 小数的长度,type 是否需要处理
  98. try {
  99. if (!type) {
  100. return num
  101. }
  102. num += '';
  103. if (num.indexOf('.') === -1) {
  104. num = `${num}.`
  105. for (let i = 1; i <= length; i++) {
  106. num += '0';
  107. }
  108. return num
  109. }
  110. const numArr = num.split('.');
  111. let integerNum = numArr[0],
  112. decimals = numArr[1];
  113. if (decimals.length === length) {
  114. return num
  115. }
  116. const addLength = length - decimals.length;
  117. for (let i = 1; i <= addLength > 0 ? addLength : 0; i++) {
  118. decimals += '0'
  119. }
  120. return `${integerNum}.${decimals}`
  121. } catch (err) {
  122. return num
  123. }
  124. }
  125. // import Vue from 'vue'
  126. /**
  127. * 注册指令
  128. */
  129. //引入 u-view 1.x
  130. import uView from 'uview-ui'
  131. Vue.use(uView)
  132. //全局组件混入mixin
  133. Vue.use(commonMixin);
  134. Vue.use(initialize)
  135. const app = new Vue({
  136. store,
  137. ...App
  138. })
  139. app.$mount()