index.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // 全局挂载引入http相关请求拦截插件
  2. import Request from './libs/luch-request'
  3. // 引入全局mixin
  4. import mixin from './libs/mixin/mixin.js'
  5. // 小程序特有的mixin
  6. import mpMixin from './libs/mixin/mpMixin.js'
  7. // #ifdef MP
  8. import mpShare from './libs/mixin/mpShare.js'
  9. // #endif
  10. // 路由封装
  11. import route from './libs/util/route.js'
  12. // 公共工具函数
  13. import * as index from './libs/function/index.js'
  14. // 防抖方法
  15. import debounce from './libs/function/debounce.js'
  16. // 节流方法
  17. import throttle from './libs/function/throttle.js'
  18. // 规则检验
  19. import * as test from './libs/function/test.js'
  20. // 颜色渐变相关,colorGradient-颜色渐变,hexToRgb-十六进制颜色转rgb颜色,rgbToHex-rgb转十六进制
  21. import * as colorGradient from './libs/function/colorGradient.js'
  22. // 配置信息
  23. import config from './libs/config/config.js'
  24. // 平台
  25. import platform from './libs/function/platform'
  26. const $uv = {
  27. route,
  28. config,
  29. test,
  30. date: index.timeFormat, // 另名date
  31. ...index,
  32. colorGradient: colorGradient.colorGradient,
  33. hexToRgb: colorGradient.hexToRgb,
  34. rgbToHex: colorGradient.rgbToHex,
  35. colorToRgba: colorGradient.colorToRgba,
  36. http: new Request(),
  37. debounce,
  38. throttle,
  39. platform,
  40. mixin,
  41. mpMixin
  42. }
  43. uni.$uv = $uv;
  44. const install = (Vue,options={}) => {
  45. // #ifndef APP-NVUE
  46. const cloneMixin = index.deepClone(mixin);
  47. delete cloneMixin?.props?.customClass;
  48. delete cloneMixin?.props?.customStyle;
  49. Vue.mixin(cloneMixin);
  50. // #ifdef MP
  51. if(options.mpShare){
  52. Vue.mixin(mpShare);
  53. }
  54. // #endif
  55. // #endif
  56. // #ifdef VUE2
  57. // 时间格式化,同时两个名称,date和timeFormat
  58. Vue.filter('timeFormat', (timestamp, format) => uni.$uv.timeFormat(timestamp, format));
  59. Vue.filter('date', (timestamp, format) => uni.$uv.timeFormat(timestamp, format));
  60. // 将多久以前的方法,注入到全局过滤器
  61. Vue.filter('timeFrom', (timestamp, format) => uni.$uv.timeFrom(timestamp, format));
  62. // 同时挂载到uni和Vue.prototype中
  63. // #ifndef APP-NVUE
  64. // 只有vue,挂载到Vue.prototype才有意义,因为nvue中全局Vue.prototype和Vue.mixin是无效的
  65. Vue.prototype.$uv = $uv;
  66. // #endif
  67. // #endif
  68. // #ifdef VUE3
  69. Vue.config.globalProperties.$uv = $uv;
  70. // #endif
  71. }
  72. export default {
  73. install
  74. }