main.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. import Vue from 'vue'
  2. import App from './App'
  3. import store from './store'
  4. // +----------------------------------------------------------------------
  5. // | 组件引入
  6. // +----------------------------------------------------------------------
  7. // 引入全局TuniaoUI
  8. import TuniaoUI from 'tuniao-ui'
  9. Vue.use(TuniaoUI)
  10. // 底部导航栏组件
  11. import tabbar from '@/components/tabbar/tabbar.vue';
  12. Vue.component('tabbar', tabbar);
  13. // 登录框组件
  14. import login from '@/components/login/login.vue';
  15. Vue.component('login', login);
  16. // |______________________________________________________________________
  17. // +----------------------------------------------------------------------
  18. // | 函数引入
  19. // +----------------------------------------------------------------------
  20. // 工具函数
  21. import utils from './common/js/utils';
  22. Vue.prototype.utils = utils;
  23. // 广告函数
  24. import adUtils from './common/js/ad';
  25. Vue.prototype.adUtils = adUtils;
  26. // 应用配置
  27. const app_info = require("@/static/appInfo.js");
  28. Vue.prototype.appInfo = app_info
  29. Vue.config.productionTip = false
  30. // 全局登录事件
  31. Vue.prototype.login = function() {
  32. if (!this.utils.getData('token')) {
  33. this.$refs.login.modal = true
  34. return;
  35. }
  36. }
  37. let api_host = app_info.api_host;
  38. Vue.prototype.imgUrl = api_host
  39. // 统一请求函数
  40. Vue.prototype.http = function(path, data, method = 'post', showLoading = true) {
  41. return utils.http(this, path, data, method, showLoading)
  42. }
  43. // 获取当前页面路径
  44. Vue.prototype.currentPage = function () {
  45. var pages = getCurrentPages() // 获取栈实例
  46. let currentRoute = pages[pages.length-1].route; // 获取当前页面路由
  47. let currentPage = pages[pages.length-1]['$page']['fullPath'] //当前页面路径(带参数)
  48. return currentPage
  49. }
  50. // 正常格式的日期时间
  51. Vue.filter('format_date', function(time) {
  52. const dateTime = new Date(time * 1000);
  53. const YY = dateTime.getFullYear();
  54. const MM =
  55. dateTime.getMonth() + 1 < 10 ?
  56. '0' + (dateTime.getMonth() + 1) :
  57. dateTime.getMonth() + 1;
  58. const D =
  59. dateTime.getDate() < 10 ? '0' + dateTime.getDate() : dateTime.getDate();
  60. const hh =
  61. dateTime.getHours() < 10 ?
  62. '0' + dateTime.getHours() :
  63. dateTime.getHours();
  64. const mm =
  65. dateTime.getMinutes() < 10 ?
  66. '0' + dateTime.getMinutes() :
  67. dateTime.getMinutes();
  68. const ss =
  69. dateTime.getSeconds() < 10 ?
  70. '0' + dateTime.getSeconds() :
  71. dateTime.getSeconds();
  72. return `${YY}-${MM}-${D} ${hh}:${mm}`
  73. });
  74. // 秒转时分秒格式
  75. Vue.filter('format_second', function(second, tips = '不限时') {
  76. if (second == undefined) return ''
  77. if (second == 0) return tips
  78. let result = parseInt(second)
  79. let h = Math.floor(result / 3600) < 10 ? '0' + Math.floor(result / 3600) : Math.floor(result / 3600);
  80. let m = Math.floor((result / 60 % 60)) < 10 ? '0' + Math.floor((result / 60 % 60)) : Math.floor((result / 60 % 60));
  81. let s = Math.floor((result % 60)) < 10 ? '0' + Math.floor((result % 60)) : Math.floor((result % 60));
  82. let res = '';
  83. if(h !== '00') res += `${h}时`;
  84. if(m !== '00') res += `${m}分`;
  85. res += `${s}秒`;
  86. return res;
  87. });
  88. // |______________________________________________________________________
  89. // +----------------------------------------------------------------------
  90. // | 全局变量及函数
  91. // +----------------------------------------------------------------------
  92. // 引入TuniaoUI提供的vuex简写方法
  93. let vuexStore = require('@/store/$t.mixin.js')
  94. Vue.mixin(vuexStore)
  95. // 导入并挂载全局的分享方法
  96. import wxShare from '@/common/mixins/share.js'
  97. Vue.mixin(wxShare)
  98. // |______________________________________________________________________
  99. App.mpType = 'app'
  100. const app = new Vue({
  101. store,
  102. ...App
  103. })
  104. app.$mount()