main.js 4.0 KB

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