main.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. import Vue from 'vue';
  2. import App from './App';
  3. import uView from 'uview-ui';
  4. Vue.use(uView);
  5. import { myRequest } from './util/api.js';
  6. Vue.prototype.$myRequest = myRequest;
  7. Vue.config.productionTip = false;
  8. App.mpType = 'app';
  9. import config from './util/neutral.js';
  10. Vue.prototype.$imageHost = config.imageHost;// 线上图片服务器路径常量 58003
  11. Vue.prototype.$imageURL = config.imageURL;
  12. console.log(Vue.prototype)
  13. import { QueryPermission } from './util/QueryPermission.js';
  14. // Vue.use(QueryPermission)
  15. Vue.prototype.$QueryPermission = QueryPermission;
  16. import customCard from './components/customCard/customCard.vue';
  17. Vue.component('customCard', customCard);
  18. Vue.filter('timeFormat', function (time,fmt = 'yyyy-MM-dd hh:mm:ss') {
  19. if(!time)return '';
  20. function fun(a) {
  21. return String(a).length == 1 ? '0' + a : a;
  22. }
  23. let $this = new Date(time*1000);
  24. let o = {
  25. 'M+': $this.getMonth() + 1,
  26. 'd+': $this.getDate(),
  27. 'h+': $this.getHours(),
  28. 'm+': $this.getMinutes(),
  29. 's+': $this.getSeconds(),
  30. 'q+': Math.floor(($this.getMonth() + 3) / 3),
  31. S: $this.getMilliseconds(),
  32. };
  33. if (/(y+)/.test(fmt)) {
  34. fmt = fmt.replace(
  35. RegExp.$1,
  36. ($this.getFullYear() + '').substr(4 - RegExp.$1.length)
  37. );
  38. }
  39. for (var k in o) {
  40. if (new RegExp('(' + k + ')').test(fmt)) {
  41. fmt = fmt.replace(
  42. RegExp.$1,
  43. RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
  44. );
  45. }
  46. }
  47. return fmt;
  48. });
  49. Vue.prototype.formatTime = function (thistime, fmt = 'yyyy-MM-dd hh:mm:ss') {
  50. let $this = new Date(thistime);
  51. let o = {
  52. 'M+': $this.getMonth() + 1,
  53. 'd+': $this.getDate(),
  54. 'h+': $this.getHours(),
  55. 'm+': $this.getMinutes(),
  56. 's+': $this.getSeconds(),
  57. 'q+': Math.floor(($this.getMonth() + 3) / 3),
  58. S: $this.getMilliseconds(),
  59. };
  60. if (/(y+)/.test(fmt)) {
  61. fmt = fmt.replace(
  62. RegExp.$1,
  63. ($this.getFullYear() + '').substr(4 - RegExp.$1.length)
  64. );
  65. }
  66. for (var k in o) {
  67. if (new RegExp('(' + k + ')').test(fmt)) {
  68. fmt = fmt.replace(
  69. RegExp.$1,
  70. RegExp.$1.length === 1 ? o[k] : ('00' + o[k]).substr(('' + o[k]).length)
  71. );
  72. }
  73. }
  74. return fmt;
  75. };
  76. Vue.mixin({
  77. data() {
  78. return {
  79. $imageURL: Vue.prototype.$imageURL,
  80. $imageHost: Vue.prototype.$imageHost,
  81. // 其他需要混入的全局变量
  82. shareTitle: '',
  83. sharePath: '',
  84. shareImage: '',
  85. timelineTitle: '',
  86. timelineQuery: '',
  87. timelineImage: ''
  88. };
  89. },
  90. onLoad() {
  91. // 开启分享功能
  92. uni.showShareMenu({
  93. withShareTicket: true,
  94. menus: ['shareAppMessage', 'shareTimeline']
  95. })
  96. },
  97. onShareAppMessage() {
  98. return {
  99. title: this.shareTitle || '云飞智控',
  100. path: this.sharePath || '/pages/index/index',
  101. imageUrl: this.shareImage || '/static/logo.png'
  102. }
  103. },
  104. onShareTimeline() {
  105. return {
  106. title: this.timelineTitle || '云飞智控',
  107. query: this.timelineQuery || '',
  108. imageUrl: this.timelineImage || '/static/logo.png'
  109. }
  110. },
  111. // 如果需要,也可以在created中赋值,但上面这样直接赋值也可以,因为mixin的data会在每个组件创建时合并
  112. // 但是注意,如果这些值在运行时改变,那么这种方式可能不会更新,因为data只初始化一次。如果需要在运行时响应变化,可以使用计算属性。
  113. // 另一种方式是用计算属性:
  114. // computed: {
  115. // $imageURL() {
  116. // return Vue.prototype.$imageURL;
  117. // },
  118. // $imageHost() {
  119. // return Vue.prototype.$imageHost;
  120. // }
  121. // }
  122. });
  123. const app = new Vue({
  124. ...App,
  125. });
  126. app.$mount();