index.js 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // 看到此报错,是因为没有配置vue.config.js的【transpileDependencies】,详见:https://www.uviewui.com/components/npmSetting.html#_5-cli模式额外配置
  2. const pleaseSetTranspileDependencies = {}, babelTest = pleaseSetTranspileDependencies?.test
  3. // 引入全局mixin
  4. import mixin from './libs/mixin/mixin.js'
  5. // 小程序特有的mixin
  6. import mpMixin from './libs/mixin/mpMixin.js'
  7. // 全局挂载引入http相关请求拦截插件
  8. import Request from './libs/luch-request'
  9. // 路由封装
  10. import route from './libs/util/route.js'
  11. // 颜色渐变相关,colorGradient-颜色渐变,hexToRgb-十六进制颜色转rgb颜色,rgbToHex-rgb转十六进制
  12. import colorGradient from './libs/function/colorGradient.js'
  13. // 规则检验
  14. import test from './libs/function/test.js'
  15. // 防抖方法
  16. import debounce from './libs/function/debounce.js'
  17. // 节流方法
  18. import throttle from './libs/function/throttle.js'
  19. // 公共文件写入的方法
  20. import index from './libs/function/index.js'
  21. // 配置信息
  22. import config from './libs/config/config.js'
  23. // props配置信息
  24. import props from './libs/config/props.js'
  25. // 各个需要fixed的地方的z-index配置文件
  26. import zIndex from './libs/config/zIndex.js'
  27. // 关于颜色的配置,特殊场景使用
  28. import color from './libs/config/color.js'
  29. // 平台
  30. import platform from './libs/function/platform'
  31. const $u = {
  32. route,
  33. date: index.timeFormat, // 另名date
  34. colorGradient: colorGradient.colorGradient,
  35. hexToRgb: colorGradient.hexToRgb,
  36. rgbToHex: colorGradient.rgbToHex,
  37. colorToRgba: colorGradient.colorToRgba,
  38. test,
  39. type: ['primary', 'success', 'error', 'warning', 'info'],
  40. http: new Request(),
  41. config, // uView配置信息相关,比如版本号
  42. zIndex,
  43. debounce,
  44. throttle,
  45. mixin,
  46. mpMixin,
  47. props,
  48. ...index,
  49. color,
  50. platform
  51. }
  52. // $u挂载到uni对象上
  53. uni.$u = $u
  54. const install = (Vue) => {
  55. // 时间格式化,同时两个名称,date和timeFormat
  56. // Vue.filter('timeFormat', (timestamp, format) => uni.$u.timeFormat(timestamp, format))
  57. // Vue.filter('date', (timestamp, format) => uni.$u.timeFormat(timestamp, format))
  58. // // 将多久以前的方法,注入到全局过滤器
  59. // Vue.filter('timeFrom', (timestamp, format) => uni.$u.timeFrom(timestamp, format))
  60. // 同时挂载到uni和Vue.prototype中
  61. // #ifndef APP-NVUE
  62. // 只有vue,挂载到Vue.prototype才有意义,因为nvue中全局Vue.prototype和Vue.mixin是无效的
  63. Vue.config.globalProperties.$u = $u
  64. // 暂时兼容vue2的$nextTick写法
  65. Vue.config.globalProperties.$nextTick = (cb) => {
  66. cb();
  67. }
  68. Vue.mixin(mixin)
  69. // #endif
  70. }
  71. export default {
  72. install
  73. }