main.js 3.8 KB

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