main.js 4.0 KB

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