index.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 '@/uni_modules/uv-ui-tools/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. throttle,
  31. date: index.timeFormat, // 另名date
  32. ...index,
  33. colorGradient: colorGradient.colorGradient,
  34. hexToRgb: colorGradient.hexToRgb,
  35. rgbToHex: colorGradient.rgbToHex,
  36. colorToRgba: colorGradient.colorToRgba,
  37. http: new Request(),
  38. debounce,
  39. throttle,
  40. platform,
  41. mixin,
  42. mpMixin
  43. }
  44. uni.$uv = $uv;
  45. const install = (Vue,options={}) => {
  46. // #ifndef APP-NVUE
  47. Vue.mixin(mixin);
  48. // #ifdef MP
  49. if(options.mpShare){
  50. Vue.mixin(mpShare);
  51. }
  52. // #endif
  53. // #endif
  54. // #ifdef VUE2
  55. // 时间格式化,同时两个名称,date和timeFormat
  56. Vue.filter('timeFormat', (timestamp, format) => uni.$uv.timeFormat(timestamp, format));
  57. Vue.filter('date', (timestamp, format) => uni.$uv.timeFormat(timestamp, format));
  58. // 将多久以前的方法,注入到全局过滤器
  59. Vue.filter('timeFrom', (timestamp, format) => uni.$uv.timeFrom(timestamp, format));
  60. // 同时挂载到uni和Vue.prototype中
  61. // #ifndef APP-NVUE
  62. // 只有vue,挂载到Vue.prototype才有意义,因为nvue中全局Vue.prototype和Vue.mixin是无效的
  63. Vue.prototype.$uv = $uv;
  64. // #endif
  65. // #endif
  66. // #ifdef VUE3
  67. Vue.config.globalProperties.$uv = $uv;
  68. // #endif
  69. }
  70. export default {
  71. install
  72. }