main.js 4.2 KB

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