You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

пре 2 година
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /**
  2. * 该文件截取自 "ant-design-vue/es/_util/props-util.js" 文件,并对其做出特殊修改
  3. */
  4. function classNames() {
  5. let classes = []
  6. for (let i = 0; i < arguments.length; i++) {
  7. let arg = arguments[i]
  8. if (!arg) continue
  9. let argType = typeof arg
  10. if (argType === 'string' || argType === 'number') {
  11. classes.push(arg)
  12. } else if (Array.isArray(arg) && arg.length) {
  13. let inner = classNames.apply(null, arg)
  14. if (inner) {
  15. classes.push(inner)
  16. }
  17. } else if (argType === 'object') {
  18. for (let key in arg) {
  19. if (arg.hasOwnProperty(key) && arg[key]) {
  20. classes.push(key)
  21. }
  22. }
  23. }
  24. }
  25. return classes.join(' ')
  26. }
  27. const camelizeRE = /-(\w)/g
  28. function camelize(str) {
  29. return str.replace(camelizeRE, (_, c) => (c ? c.toUpperCase() : ''))
  30. }
  31. function objectCamelize(obj) {
  32. let res = {}
  33. Object.keys(obj).forEach(k => (res[camelize(k)] = obj[k]))
  34. return res
  35. }
  36. function parseStyleText(cssText = '', camel) {
  37. const res = {}
  38. const listDelimiter = /;(?![^(]*\))/g
  39. const propertyDelimiter = /:(.+)/
  40. cssText.split(listDelimiter).forEach(function (item) {
  41. if (item) {
  42. const tmp = item.split(propertyDelimiter)
  43. if (tmp.length > 1) {
  44. const k = camel ? camelize(tmp[0].trim()) : tmp[0].trim()
  45. res[k] = tmp[1].trim()
  46. }
  47. }
  48. })
  49. return res
  50. }
  51. export function getClass(ele) {
  52. let data = {}
  53. if (ele.data) {
  54. data = ele.data
  55. } else if (ele.$vnode && ele.$vnode.data) {
  56. data = ele.$vnode.data
  57. }
  58. const tempCls = data.class || {}
  59. const staticClass = data.staticClass
  60. let cls = {}
  61. staticClass &&
  62. staticClass.split(' ').forEach(c => {
  63. cls[c.trim()] = true
  64. })
  65. if (typeof tempCls === 'string') {
  66. tempCls.split(' ').forEach(c => {
  67. cls[c.trim()] = true
  68. })
  69. } else if (Array.isArray(tempCls)) {
  70. classNames(tempCls)
  71. .split(' ')
  72. .forEach(c => {
  73. cls[c.trim()] = true
  74. })
  75. } else {
  76. cls = { ...cls, ...tempCls }
  77. }
  78. return cls
  79. }
  80. export function getStyle(ele, camel) {
  81. getClass(ele)
  82. let data = {}
  83. if (ele.data) {
  84. data = ele.data
  85. } else if (ele.$vnode && ele.$vnode.data) {
  86. data = ele.$vnode.data
  87. }
  88. // update-begin-author:sunjianlei date:20200303 for: style 和 staticStyle 可以共存
  89. let style = data.style || {}
  90. let staticStyle = data.staticStyle
  91. staticStyle = staticStyle ? objectCamelize(data.staticStyle) : {}
  92. // update-end-author:sunjianlei date:20200303 for: style 和 staticStyle 可以共存
  93. if (typeof style === 'string') {
  94. style = parseStyleText(style, camel)
  95. } else if (camel && style) {
  96. // 驼峰化
  97. style = objectCamelize(style)
  98. }
  99. return { ...staticStyle, ...style }
  100. }