3
0

index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. // 看到此报错,是因为没有配置vite.config.js的【transpileDependencies】
  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. // 导出
  32. const http = new Request()
  33. let themeType = ['primary', 'success', 'error', 'warning', 'info'];
  34. export { route, http, debounce, throttle, platform, themeType, mixin, mpMixin, props, color, test, zIndex }
  35. export * from './libs/function/index.js'
  36. export * from './libs/function/colorGradient.js'
  37. /**
  38. * @description 修改uView内置属性值
  39. * @param {object} props 修改内置props属性
  40. * @param {object} config 修改内置config属性
  41. * @param {object} color 修改内置color属性
  42. * @param {object} zIndex 修改内置zIndex属性
  43. */
  44. export function setConfig(configs) {
  45. index.shallowMerge(config, configs.config || {})
  46. index.shallowMerge(props, configs.props || {})
  47. index.shallowMerge(color, configs.color || {})
  48. index.shallowMerge(zIndex, configs.zIndex || {})
  49. }
  50. index.setConfig = setConfig
  51. const $u = {
  52. route,
  53. date: index.timeFormat, // 另名date
  54. colorGradient: colorGradient.colorGradient,
  55. hexToRgb: colorGradient.hexToRgb,
  56. rgbToHex: colorGradient.rgbToHex,
  57. colorToRgba: colorGradient.colorToRgba,
  58. test,
  59. type: themeType,
  60. http,
  61. config, // uview-plus配置信息相关,比如版本号
  62. zIndex,
  63. debounce,
  64. throttle,
  65. mixin,
  66. mpMixin,
  67. props,
  68. ...index,
  69. color,
  70. platform
  71. }
  72. export const mount$u = function() {
  73. uni.$u = $u
  74. }
  75. // #ifdef H5
  76. const importFn = import.meta.glob('./components/u-*/u-*.vue', { eager: true })
  77. let components = [];
  78. // 批量注册全局组件
  79. for (const key in importFn) {
  80. let component = importFn[key].default;
  81. if (component.name && component.name.indexOf('u--') !== 0) {
  82. const name = component.name.replace(/u-([a-zA-Z0-9-_]+)/g, 'up-$1');
  83. component.install = function (Vue) {
  84. Vue.component(name, component);
  85. };
  86. // 导入组件
  87. components.push(component);
  88. }
  89. }
  90. // #endif
  91. function toCamelCase(str) {
  92. return str.replace(/-([a-z])/g, function(match, group1) {
  93. return group1.toUpperCase();
  94. }).replace(/^[a-z]/, function(match) {
  95. return match.toUpperCase();
  96. });
  97. }
  98. const install = (Vue) => {
  99. // #ifdef H5
  100. components.forEach(function(component) {
  101. Vue.component(component.name, component);
  102. });
  103. // #endif
  104. // 同时挂载到uni和Vue.prototype中
  105. // $u挂载到uni对象上
  106. uni.$u = $u
  107. // #ifndef APP-NVUE
  108. // 只有vue,挂载到Vue.prototype才有意义,因为nvue中全局Vue.prototype和Vue.mixin是无效的
  109. Vue.config.globalProperties.$u = $u
  110. Vue.mixin(mixin)
  111. // #endif
  112. }
  113. export default {
  114. install
  115. }