index.ts 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330
  1. import { CreateElement } from 'vue'
  2. import XEUtils from 'xe-utils'
  3. import { VxeUI } from '../../ui'
  4. import { getCellValue, setCellValue } from '../src/util'
  5. import { getFuncText, formatText, isEmptyValue } from '../../ui/src/utils'
  6. import { getOnName, getModelEvent, getChangeEvent, hasInputType } from '../../ui/src/vn'
  7. import { errLog } from '../../ui/src/log'
  8. import type { VxeGlobalRendererHandles, VxeColumnPropTypes, VxeTableConstructor, VxeTablePrivateMethods, VxeTableDefines } from '../../../types'
  9. const { getConfig, renderer, getI18n, getComponent } = VxeUI
  10. const componentDefaultModelProp = 'value'
  11. const defaultCompProps = {}
  12. function handleDefaultValue (value: any, defaultVal: any, initVal: any) {
  13. return XEUtils.eqNull(value) ? (XEUtils.eqNull(defaultVal) ? initVal : defaultVal) : value
  14. }
  15. function parseDate (value: any, props: any) {
  16. return value && props.valueFormat ? XEUtils.toStringDate(value, props.valueFormat) : value
  17. }
  18. function getFormatDate (value: any, props: any, defaultFormat: string) {
  19. const { dateConfig = {} } = props
  20. return XEUtils.toDateString(parseDate(value, props), dateConfig.labelFormat || defaultFormat)
  21. }
  22. function getLabelFormatDate (value: any, props: any) {
  23. return getFormatDate(value, props, getI18n(`vxe.input.date.labelFormat.${props.type || 'date'}`))
  24. }
  25. /**
  26. * 已废弃
  27. * @deprecated
  28. */
  29. function getOldComponentName (name: string) {
  30. return `vxe-${name.replace('$', '')}`
  31. }
  32. /**
  33. * 已废弃
  34. * @deprecated
  35. */
  36. function getOldComponent ({ name }: any) {
  37. return getOldComponentName(name)
  38. }
  39. function getDefaultComponent ({ name }: any) {
  40. return getComponent(name) || name
  41. }
  42. function updateFilterChangeOption (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams, checked: boolean, option: VxeTableDefines.FilterOption) {
  43. const { $table } = params
  44. $table.updateFilterOptionStatus(option, checked)
  45. }
  46. function saveFilterEvent (params: VxeGlobalRendererHandles.RenderTableFilterParams | VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
  47. const { $table, column } = params
  48. $table.saveFilterByEvent(new Event('change'), column)
  49. }
  50. function getNativeAttrs (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions) {
  51. let { name, attrs } = renderOpts
  52. if (name === 'input') {
  53. attrs = Object.assign({ type: 'text' }, attrs)
  54. }
  55. return attrs
  56. }
  57. function getInputImmediateModel (renderOpts: VxeColumnPropTypes.EditRender) {
  58. const { name, immediate, props } = renderOpts
  59. if (!immediate) {
  60. if (name === 'VxeInput' || name === '$input') {
  61. const { type } = props || {}
  62. return !(!type || type === 'text' || type === 'number' || type === 'integer' || type === 'float')
  63. }
  64. if (name === 'input' || name === 'textarea' || name === '$textarea') {
  65. return false
  66. }
  67. return true
  68. }
  69. return immediate
  70. }
  71. function getCellEditProps (renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderEditParams, value: any, defaultProps?: any) {
  72. return XEUtils.assign({ immediate: getInputImmediateModel(renderOpts) }, defaultCompProps, defaultProps, renderOpts.props, { [componentDefaultModelProp]: value })
  73. }
  74. function getCellEditFilterProps (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, value: any, defaultProps?: any) {
  75. return XEUtils.assign({}, defaultCompProps, defaultProps, renderOpts.props, { [componentDefaultModelProp]: value })
  76. }
  77. function isImmediateCell (renderOpts: VxeColumnPropTypes.EditRender, params: any) {
  78. return params.$type === 'cell' || getInputImmediateModel(renderOpts)
  79. }
  80. function getCellLabelVNs (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any, cellLabel: any, opts?: {
  81. class?: string
  82. }) {
  83. const { placeholder } = renderOpts
  84. return [
  85. h('span', {
  86. class: ['vxe-cell--label', opts ? opts.class : '']
  87. }, placeholder && isEmptyValue(cellLabel)
  88. ? [
  89. h('span', {
  90. class: 'vxe-cell--placeholder'
  91. }, formatText(getFuncText(placeholder), 1))
  92. ]
  93. : formatText(cellLabel, 1))
  94. ]
  95. }
  96. /**
  97. * 原生事件处理
  98. * @param renderOpts
  99. * @param params
  100. * @param modelFunc
  101. * @param changeFunc
  102. */
  103. function getNativeElementOns (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, eFns?: {
  104. model: (evnt: Event) => void
  105. change?: (evnt: Event) => void
  106. blur?: (evnt: Event) => void
  107. }) {
  108. const { events } = renderOpts
  109. const modelEvent = getModelEvent(renderOpts)
  110. const changeEvent = getChangeEvent(renderOpts)
  111. const { model: modelFunc, change: changeFunc, blur: blurFunc } = eFns || {}
  112. const isSameEvent = changeEvent === modelEvent
  113. const ons: any = {}
  114. if (events) {
  115. XEUtils.objectEach(events, (func, key: any) => {
  116. ons[getOnName(key)] = function (...args: any[]) {
  117. func(params, ...args)
  118. }
  119. })
  120. }
  121. if (modelFunc) {
  122. ons[getOnName(modelEvent)] = function (targetEvnt: any) {
  123. modelFunc(targetEvnt)
  124. if (isSameEvent && changeFunc) {
  125. changeFunc(targetEvnt)
  126. }
  127. if (events && events[modelEvent]) {
  128. events[modelEvent](params, targetEvnt)
  129. }
  130. }
  131. }
  132. if (!isSameEvent && changeFunc) {
  133. ons[getOnName(changeEvent)] = function (evnt: Event) {
  134. changeFunc(evnt)
  135. if (events && events[changeEvent]) {
  136. events[changeEvent](params, evnt)
  137. }
  138. }
  139. }
  140. if (blurFunc) {
  141. ons[getOnName(blurEvent)] = function (evnt: Event) {
  142. blurFunc(evnt)
  143. if (events && events[blurEvent]) {
  144. events[blurEvent](params, evnt)
  145. }
  146. }
  147. }
  148. return ons
  149. }
  150. const blurEvent = 'blur'
  151. const clearEvent = 'clear'
  152. /**
  153. * 组件事件处理
  154. * @param renderOpts
  155. * @param params
  156. * @param modelFunc
  157. * @param changeFunc
  158. */
  159. function getComponentOns (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions | VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, eFns?: {
  160. model: (cellValue: any) => void
  161. change?: (...args: any[]) => void
  162. blur?: (...args: any[]) => void
  163. clear?: (...args: any[]) => void
  164. }, eventOns?: Record<string, any>) {
  165. const { events } = renderOpts
  166. const modelEvent = getModelEvent(renderOpts)
  167. const changeEvent = getChangeEvent(renderOpts)
  168. const { model: modelFunc, change: changeFunc, blur: blurFunc, clear: clearFunc } = eFns || {}
  169. const ons: any = {}
  170. XEUtils.objectEach(events, (func, key: any) => {
  171. ons[getOnName(key)] = function (...args: any[]) {
  172. if (!XEUtils.isFunction(func)) {
  173. errLog('vxe.error.errFunc', [func])
  174. }
  175. func(params, ...args)
  176. }
  177. })
  178. if (modelFunc) {
  179. ons[getOnName(modelEvent)] = function (targetEvnt: any) {
  180. modelFunc(targetEvnt)
  181. if (events && events[modelEvent]) {
  182. events[modelEvent](params, targetEvnt)
  183. }
  184. }
  185. }
  186. if (changeFunc) {
  187. ons[getOnName(changeEvent)] = function (...args: any[]) {
  188. changeFunc(...args)
  189. if (events && events[changeEvent]) {
  190. events[changeEvent](params, ...args)
  191. }
  192. }
  193. }
  194. if (blurFunc) {
  195. ons[getOnName(blurEvent)] = function (...args: any[]) {
  196. blurFunc(...args)
  197. if (events && events[blurEvent]) {
  198. events[blurEvent](params, ...args)
  199. }
  200. }
  201. }
  202. if (clearFunc) {
  203. ons[getOnName(clearEvent)] = function (...args: any[]) {
  204. clearFunc(...args)
  205. if (events && events[clearEvent]) {
  206. events[clearEvent](params, ...args)
  207. }
  208. }
  209. }
  210. return eventOns ? Object.assign(ons, eventOns) : ons
  211. }
  212. function getEditOns (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
  213. const { $table, row, column } = params
  214. const { name } = renderOpts
  215. const { model } = column
  216. const isImmediate = isImmediateCell(renderOpts, params)
  217. return getComponentOns(renderOpts, params, {
  218. model (cellValue) {
  219. // 处理 model 值双向绑定
  220. model.update = true
  221. model.value = cellValue
  222. if (isImmediate) {
  223. setCellValue(row, column, cellValue)
  224. }
  225. },
  226. change (eventParams) {
  227. // 处理 change 事件相关逻辑
  228. if (!isImmediate && name && (['VxeInput', 'VxeNumberInput', 'VxeTextarea', '$input', '$textarea'].includes(name))) {
  229. const cellValue = eventParams.value
  230. model.update = true
  231. model.value = cellValue
  232. $table.updateStatus(params, cellValue)
  233. } else {
  234. $table.updateStatus(params)
  235. }
  236. },
  237. blur () {
  238. if (isImmediate) {
  239. $table.handleCellRuleUpdateStatus('blur', params)
  240. } else {
  241. $table.handleCellRuleUpdateStatus('blur', params, model.value)
  242. }
  243. }
  244. })
  245. }
  246. function getFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams, option: VxeTableDefines.FilterOption) {
  247. return getComponentOns(renderOpts, params, {
  248. model (value) {
  249. // 处理 model 值双向绑定
  250. option.data = value
  251. },
  252. change () {
  253. updateFilterChangeOption(params, !isEmptyValue(option.data), option)
  254. },
  255. blur () {
  256. updateFilterChangeOption(params, !isEmptyValue(option.data), option)
  257. }
  258. })
  259. }
  260. function getFloatingFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams, option: VxeTableDefines.FilterOption) {
  261. const { $table, column } = params
  262. if (hasInputType(renderOpts)) {
  263. return getComponentOns(renderOpts, params, {
  264. model (value: any) {
  265. // 处理 model 值双向绑定
  266. option.data = value
  267. },
  268. change () {
  269. updateFilterChangeOption(params, !isEmptyValue(option.data), option)
  270. },
  271. clear () {
  272. updateFilterChangeOption(params, !isEmptyValue(option.data), option)
  273. saveFilterEvent(params)
  274. },
  275. blur () {
  276. $table.saveFilterByEvent(new Event('change'), column)
  277. }
  278. }, renderOpts.name === 'VxeNumberInput'
  279. ? {
  280. [getOnName('plus-number')] () {
  281. updateFilterChangeOption(params, !isEmptyValue(option.data), option)
  282. saveFilterEvent(params)
  283. },
  284. [getOnName('minus-number')] () {
  285. updateFilterChangeOption(params, !isEmptyValue(option.data), option)
  286. saveFilterEvent(params)
  287. }
  288. }
  289. : {})
  290. }
  291. return getComponentOns(renderOpts, params, {
  292. model (value: any) {
  293. // 处理 model 值双向绑定
  294. option.data = value
  295. },
  296. clear () {
  297. updateFilterChangeOption(params, !isEmptyValue(option.data), option)
  298. $table.saveFilterByEvent(new Event('change'), column)
  299. },
  300. change () {
  301. updateFilterChangeOption(params, !isEmptyValue(option.data), option)
  302. $table.saveFilterByEvent(new Event('change'), column)
  303. }
  304. })
  305. }
  306. function getNativeEditOns (renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
  307. const { $table, row, column } = params
  308. const { model } = column
  309. return getNativeElementOns(renderOpts, params, {
  310. model (evnt) {
  311. // 处理 model 值双向绑定
  312. const targetEl = evnt.target as HTMLInputElement
  313. if (targetEl) {
  314. const cellValue = targetEl.value
  315. if (isImmediateCell(renderOpts, params)) {
  316. setCellValue(row, column, cellValue)
  317. } else {
  318. model.update = true
  319. model.value = cellValue
  320. }
  321. }
  322. },
  323. change (evnt) {
  324. // 处理 change 事件相关逻辑
  325. const targetEl = evnt.target as HTMLInputElement
  326. if (targetEl) {
  327. const cellValue = targetEl.value
  328. $table.updateStatus(params, cellValue)
  329. }
  330. },
  331. blur (evnt) {
  332. const targetEl = evnt.target as HTMLInputElement
  333. if (targetEl) {
  334. const cellValue = targetEl.value
  335. $table.updateStatus(params, cellValue)
  336. }
  337. }
  338. })
  339. }
  340. function getNativeFilterOns (renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any, option: any) {
  341. return getNativeElementOns(renderOpts, params, {
  342. model (evnt) {
  343. // 处理 model 值双向绑定
  344. const targetEl = evnt.target as HTMLInputElement
  345. if (targetEl) {
  346. option.data = targetEl.value
  347. }
  348. },
  349. change () {
  350. updateFilterChangeOption(params, !XEUtils.eqNull(option.data), option)
  351. },
  352. blur () {
  353. updateFilterChangeOption(params, !XEUtils.eqNull(option.data), option)
  354. }
  355. })
  356. }
  357. /**
  358. * 单元格可编辑渲染-原生的标签
  359. * input、textarea、select
  360. */
  361. function nativeEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
  362. const { row, column } = params
  363. const { name } = renderOpts
  364. const cellValue = isImmediateCell(renderOpts, params) ? getCellValue(row, column) : column.model.value
  365. return [
  366. h(`${name}`, {
  367. class: `vxe-default-${name}`,
  368. attrs: getNativeAttrs(renderOpts),
  369. domProps: {
  370. value: cellValue
  371. },
  372. on: getNativeEditOns(renderOpts, params)
  373. })
  374. ]
  375. }
  376. function buttonCellRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, params: any) {
  377. return [
  378. h(getDefaultComponent(renderOpts), {
  379. props: getCellEditProps(renderOpts, params, null),
  380. on: getComponentOns(renderOpts, params)
  381. })
  382. ]
  383. }
  384. function defaultEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
  385. const { row, column } = params
  386. const cellValue = getCellValue(row, column)
  387. return [
  388. h(getDefaultComponent(renderOpts), {
  389. props: getCellEditProps(renderOpts, params, cellValue),
  390. on: getEditOns(renderOpts, params)
  391. })
  392. ]
  393. }
  394. function checkboxEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
  395. const { row, column } = params
  396. const cellValue = getCellValue(row, column)
  397. return [
  398. h(getDefaultComponent(renderOpts), {
  399. props: getCellEditProps(renderOpts, params, cellValue),
  400. on: getEditOns(renderOpts, params)
  401. })
  402. ]
  403. }
  404. function radioAndCheckboxGroupEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
  405. const { options } = renderOpts
  406. const { row, column } = params
  407. const cellValue = getCellValue(row, column)
  408. return [
  409. h(getDefaultComponent(renderOpts), {
  410. props: {
  411. options,
  412. ...getCellEditProps(renderOpts, params, cellValue)
  413. },
  414. on: getEditOns(renderOpts, params)
  415. })
  416. ]
  417. }
  418. /**
  419. * 已废弃
  420. * @deprecated
  421. */
  422. function oldEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
  423. const { row, column } = params
  424. const cellValue = getCellValue(row, column)
  425. return [
  426. h(getOldComponent(renderOpts), {
  427. props: getCellEditProps(renderOpts, params, cellValue),
  428. on: getEditOns(renderOpts, params)
  429. })
  430. ]
  431. }
  432. /**
  433. * 已废弃
  434. * @deprecated
  435. */
  436. function oldButtonEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
  437. return [
  438. h('vxe-button', {
  439. props: getCellEditProps(renderOpts, params, null),
  440. on: getComponentOns(renderOpts, params)
  441. })
  442. ]
  443. }
  444. /**
  445. * 已废弃
  446. * @deprecated
  447. */
  448. function oldButtonsEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: any) {
  449. const { children } = renderOpts
  450. return children ? children.map((childRenderOpts: any) => oldButtonEditRender(h, childRenderOpts, params)[0]) : []
  451. }
  452. function renderNativeOptgroups (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, params: any, renderOptionsMethods: any) {
  453. const { optionGroups, optionGroupProps = {} } = renderOpts
  454. const groupOptions = optionGroupProps.options || 'options'
  455. const groupLabel = optionGroupProps.label || 'label'
  456. if (optionGroups) {
  457. return optionGroups.map((group: any, gIndex: any) => {
  458. return h('optgroup', {
  459. key: gIndex,
  460. attrs: {
  461. label: group[groupLabel]
  462. }
  463. }, renderOptionsMethods(h, group[groupOptions], renderOpts, params))
  464. })
  465. }
  466. return []
  467. }
  468. /**
  469. * 渲染原生的 option 标签
  470. */
  471. function renderNativeOptions (h: CreateElement, options: any, renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: any) {
  472. const { optionProps = {} } = renderOpts
  473. const { row, column } = params
  474. const labelProp = optionProps.label || 'label'
  475. const valueProp = optionProps.value || 'value'
  476. const disabledProp = optionProps.disabled || 'disabled'
  477. const cellValue = isImmediateCell(renderOpts, params) ? getCellValue(row, column) : column.model.value
  478. if (options) {
  479. return options.map((option: any, oIndex: any) => {
  480. return h('option', {
  481. key: oIndex,
  482. attrs: {
  483. value: option[valueProp],
  484. disabled: option[disabledProp]
  485. },
  486. domProps: {
  487. /* eslint-disable eqeqeq */
  488. selected: option[valueProp] == cellValue
  489. }
  490. }, option[labelProp])
  491. })
  492. }
  493. return []
  494. }
  495. function nativeFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams) {
  496. const { column } = params
  497. const { name } = renderOpts
  498. const attrs = getNativeAttrs(renderOpts)
  499. return column.filters.map((option, oIndex) => {
  500. return h(`${name}`, {
  501. key: oIndex,
  502. class: `vxe-default-${name}`,
  503. attrs,
  504. domProps: {
  505. value: option.data
  506. },
  507. on: getNativeFilterOns(renderOpts, params, option)
  508. })
  509. })
  510. }
  511. function defaultFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: VxeGlobalRendererHandles.RenderTableFilterParams) {
  512. const { column } = params
  513. return column.filters.map((option, oIndex) => {
  514. const optionValue = option.data
  515. return h(getDefaultComponent(renderOpts), {
  516. key: oIndex,
  517. props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
  518. on: getFilterOns(renderOpts, params, option)
  519. })
  520. })
  521. }
  522. function defaultFloatingFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFloatingFilterOptions, params: VxeGlobalRendererHandles.RenderTableFloatingFilterParams) {
  523. const { option } = params
  524. const optionValue = option.data
  525. return [
  526. h(getDefaultComponent(renderOpts), {
  527. props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
  528. on: getFloatingFilterOns(renderOpts, params, option)
  529. })
  530. ]
  531. }
  532. function defaultFilterOptions () {
  533. return [
  534. { data: null }
  535. ]
  536. }
  537. /**
  538. * 已废弃
  539. * @deprecated
  540. */
  541. function oldFilterRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableFilterOptions, params: any) {
  542. const { column } = params
  543. return column.filters.map((option: any, oIndex: any) => {
  544. const optionValue = option.data
  545. return h(getOldComponent(renderOpts), {
  546. key: oIndex,
  547. props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
  548. on: getFilterOns(renderOpts, params, option)
  549. })
  550. })
  551. }
  552. function handleFilterMethod ({ option, row, column }: any) {
  553. const { data } = option
  554. const cellValue = XEUtils.get(row, column.field)
  555. /* eslint-disable eqeqeq */
  556. return cellValue == data
  557. }
  558. function handleInputFilterMethod ({ option, row, column }: any) {
  559. const { data } = option
  560. const cellValue = XEUtils.get(row, column.field)
  561. /* eslint-disable eqeqeq */
  562. return XEUtils.toValueString(cellValue).indexOf(data) > -1
  563. }
  564. function nativeSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
  565. return [
  566. h('select', {
  567. class: 'vxe-default-select',
  568. attrs: getNativeAttrs(renderOpts),
  569. on: getNativeEditOns(renderOpts, params)
  570. },
  571. renderOpts.optionGroups ? renderNativeOptgroups(h, renderOpts, params, renderNativeOptions) : renderNativeOptions(h, renderOpts.options, renderOpts, params))
  572. ]
  573. }
  574. function defaultSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
  575. const { row, column } = params
  576. const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
  577. const cellValue = getCellValue(row, column)
  578. return [
  579. h(getDefaultComponent(renderOpts), {
  580. props: getCellEditProps(renderOpts, params, cellValue, { options, optionProps, optionGroups, optionGroupProps }),
  581. on: getEditOns(renderOpts, params)
  582. })
  583. ]
  584. }
  585. function defaultTableOrTreeSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
  586. const { row, column } = params
  587. const { options, optionProps } = renderOpts
  588. const cellValue = getCellValue(row, column)
  589. return [
  590. h(getDefaultComponent(renderOpts), {
  591. props: getCellEditProps(renderOpts, params, cellValue, { options, optionProps }),
  592. on: getEditOns(renderOpts, params)
  593. })
  594. ]
  595. }
  596. /**
  597. * 已废弃
  598. * @deprecated
  599. */
  600. function oldSelectEditRender (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: any) {
  601. const { row, column } = params
  602. const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
  603. const cellValue = getCellValue(row, column)
  604. return [
  605. h(getOldComponent(renderOpts), {
  606. props: getCellEditProps(renderOpts, params, cellValue, { options, optionProps, optionGroups, optionGroupProps }),
  607. on: getEditOns(renderOpts, params)
  608. })
  609. ]
  610. }
  611. function getSelectCellValue (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, { row, column }: any) {
  612. const { options, optionGroups, optionProps = {}, optionGroupProps = {}, props = {} } = renderOpts
  613. const cellValue = XEUtils.get(row, column.field)
  614. let selectItem: any
  615. const labelProp = optionProps.label || 'label'
  616. const valueProp = optionProps.value || 'value'
  617. if (!(cellValue === null || cellValue === undefined)) {
  618. let vals = []
  619. if (XEUtils.isArray(cellValue)) {
  620. vals = cellValue
  621. } else {
  622. if (props.multiple && `${cellValue}`.indexOf(',') > -1) {
  623. vals = `${cellValue}`.split(',')
  624. } else {
  625. vals = [cellValue]
  626. }
  627. }
  628. return XEUtils.map(vals, optionGroups
  629. ? (value) => {
  630. const groupOptions = optionGroupProps.options || 'options'
  631. for (let index = 0; index < optionGroups.length; index++) {
  632. /* eslint-disable eqeqeq */
  633. selectItem = XEUtils.find(optionGroups[index][groupOptions], item => item[valueProp] == value)
  634. if (selectItem) {
  635. break
  636. }
  637. }
  638. return selectItem ? selectItem[labelProp] : value
  639. }
  640. : (value) => {
  641. /* eslint-disable eqeqeq */
  642. selectItem = XEUtils.find(options, item => item[valueProp] == value)
  643. return selectItem ? selectItem[labelProp] : value
  644. }
  645. ).join(', ')
  646. }
  647. return ''
  648. }
  649. function handleExportSelectMethod (params: any) {
  650. const { row, column, options } = params
  651. return options.original ? getCellValue(row, column) : getSelectCellValue(column.editRender || column.cellRender, params)
  652. }
  653. function getTreeSelectCellValue (renderOpts: VxeGlobalRendererHandles.RenderTableCellOptions, { row, column }: any) {
  654. const { options, optionProps = {} } = renderOpts
  655. const cellValue = XEUtils.get(row, column.field)
  656. const labelProp = optionProps.label || 'label'
  657. const valueProp = optionProps.value || 'value'
  658. const childrenProp = optionProps.children || 'children'
  659. if (!(cellValue === null || cellValue === undefined)) {
  660. const keyMaps: Record<string, any> = {}
  661. XEUtils.eachTree(options, item => {
  662. keyMaps[XEUtils.get(item, valueProp)] = item
  663. }, { children: childrenProp })
  664. return XEUtils.map(XEUtils.isArray(cellValue) ? cellValue : [cellValue], (value) => {
  665. const item = keyMaps[value]
  666. return item ? XEUtils.get(item, labelProp) : item
  667. }
  668. ).join(', ')
  669. }
  670. return ''
  671. }
  672. function handleExportTreeSelectMethod (params: any) {
  673. const { row, column, options } = params
  674. return options.original ? getCellValue(row, column) : getTreeSelectCellValue(column.editRender || column.cellRender, params)
  675. }
  676. function handleNumberCell (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableDefaultOptions, params: VxeGlobalRendererHandles.RenderTableDefaultParams) {
  677. const { props = {}, showNegativeStatus } = renderOpts
  678. const { row, column } = params
  679. const { type } = props
  680. let cellValue = XEUtils.get(row, column.field)
  681. let isNegative = false
  682. if (!isEmptyValue(cellValue)) {
  683. const numberInputConfig = getConfig().numberInput || {}
  684. if (type === 'float') {
  685. const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
  686. const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1)
  687. cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
  688. if (!autoFill) {
  689. cellValue = XEUtils.toNumber(cellValue)
  690. }
  691. if (showNegativeStatus) {
  692. if (cellValue < 0) {
  693. isNegative = true
  694. }
  695. }
  696. } else if (type === 'amount') {
  697. const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
  698. const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2)
  699. const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false)
  700. cellValue = XEUtils.toNumber(cellValue)
  701. if (showNegativeStatus) {
  702. if (cellValue < 0) {
  703. isNegative = true
  704. }
  705. }
  706. cellValue = XEUtils.commafy(cellValue, { digits })
  707. if (!autoFill) {
  708. const [iStr, dStr] = cellValue.split('.')
  709. if (dStr) {
  710. const dRest = dStr.replace(/0+$/, '')
  711. cellValue = dRest ? [iStr, '.', dRest].join('') : iStr
  712. }
  713. }
  714. if (showCurrency) {
  715. cellValue = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${cellValue}`
  716. }
  717. } else {
  718. if (showNegativeStatus) {
  719. if (XEUtils.toNumber(cellValue) < 0) {
  720. isNegative = true
  721. }
  722. }
  723. }
  724. }
  725. return getCellLabelVNs(h, renderOpts, params, cellValue, isNegative
  726. ? {
  727. class: 'is--negative'
  728. }
  729. : {})
  730. }
  731. /**
  732. * 表格 - 渲染器
  733. */
  734. renderer.mixin({
  735. input: {
  736. tableAutoFocus: 'input',
  737. renderTableEdit: nativeEditRender,
  738. renderTableDefault: nativeEditRender,
  739. renderTableFilter: nativeFilterRender,
  740. tableFilterDefaultMethod: handleInputFilterMethod
  741. },
  742. textarea: {
  743. tableAutoFocus: 'textarea',
  744. renderTableEdit: nativeEditRender
  745. },
  746. select: {
  747. renderTableEdit: nativeSelectEditRender,
  748. renderTableDefault: nativeSelectEditRender,
  749. renderTableCell (h, renderOpts, params) {
  750. return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
  751. },
  752. renderTableFilter (h, renderOpts, params) {
  753. const { column } = params
  754. return column.filters.map((option, oIndex) => {
  755. return h('select', {
  756. key: oIndex,
  757. class: 'vxe-default-select',
  758. attrs: getNativeAttrs(renderOpts),
  759. on: getNativeFilterOns(renderOpts, params, option)
  760. },
  761. renderOpts.optionGroups ? renderNativeOptgroups(h, renderOpts, params, renderNativeOptions) : renderNativeOptions(h, renderOpts.options, renderOpts, params))
  762. })
  763. },
  764. tableFilterDefaultMethod: handleFilterMethod,
  765. tableExportMethod: handleExportSelectMethod
  766. },
  767. VxeInput: {
  768. tableAutoFocus: 'input',
  769. renderTableEdit: defaultEditRender,
  770. renderTableCell (h, renderOpts, params) {
  771. const { props = {} } = renderOpts
  772. const { row, column } = params
  773. const inputConfig = getConfig().input || {}
  774. const digits = props.digits || inputConfig.digits || 2
  775. let cellValue = XEUtils.get(row, column.field)
  776. if (cellValue) {
  777. switch (props.type) {
  778. case 'date':
  779. case 'week':
  780. case 'month':
  781. case 'quarter':
  782. case 'year':
  783. cellValue = getLabelFormatDate(cellValue, props)
  784. break
  785. case 'float':
  786. cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
  787. break
  788. }
  789. }
  790. return getCellLabelVNs(h, renderOpts, params, cellValue)
  791. },
  792. renderTableDefault: defaultEditRender,
  793. createTableFilterOptions: defaultFilterOptions,
  794. renderTableFilter: defaultFilterRender,
  795. renderTableFloatingFilter: defaultFloatingFilterRender,
  796. tableFilterDefaultMethod: handleInputFilterMethod
  797. },
  798. FormatNumberInput: {
  799. renderTableDefault: handleNumberCell,
  800. tableFilterDefaultMethod: handleInputFilterMethod,
  801. tableExportMethod (params) {
  802. const { row, column } = params
  803. const cellValue = XEUtils.get(row, column.field)
  804. return cellValue
  805. }
  806. },
  807. VxeNumberInput: {
  808. tableAutoFocus: 'input',
  809. renderTableEdit: defaultEditRender,
  810. renderTableCell: handleNumberCell,
  811. renderTableFooter (h, renderOpts, params) {
  812. const { props = {} } = renderOpts
  813. const { row, column, _columnIndex } = params
  814. const { type } = props
  815. // 兼容老模式
  816. const itemValue = XEUtils.isArray(row) ? row[_columnIndex] : XEUtils.get(row, column.field)
  817. if (XEUtils.isNumber(itemValue)) {
  818. const numberInputConfig = getConfig().numberInput || {}
  819. if (type === 'float') {
  820. const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
  821. const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1)
  822. let amountLabel = XEUtils.toFixed(XEUtils.floor(itemValue, digits), digits)
  823. if (!autoFill) {
  824. amountLabel = XEUtils.toNumber(amountLabel)
  825. }
  826. return amountLabel
  827. } else if (type === 'amount') {
  828. const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true)
  829. const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2)
  830. const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false)
  831. let amountLabel = XEUtils.commafy(XEUtils.toNumber(itemValue), { digits })
  832. if (!autoFill) {
  833. const [iStr, dStr] = amountLabel.split('.')
  834. if (dStr) {
  835. const dRest = dStr.replace(/0+$/, '')
  836. amountLabel = dRest ? [iStr, '.', dRest].join('') : iStr
  837. }
  838. }
  839. if (showCurrency) {
  840. amountLabel = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${amountLabel}`
  841. }
  842. return amountLabel
  843. }
  844. }
  845. return getFuncText(itemValue, 1)
  846. },
  847. renderTableDefault: defaultEditRender,
  848. createTableFilterOptions: defaultFilterOptions,
  849. renderTableFilter: defaultFilterRender,
  850. renderTableFloatingFilter: defaultFloatingFilterRender,
  851. tableFilterDefaultMethod: handleInputFilterMethod,
  852. tableExportMethod (params) {
  853. const { row, column } = params
  854. const cellValue = XEUtils.get(row, column.field)
  855. return cellValue
  856. }
  857. },
  858. VxeDatePicker: {
  859. tableAutoFocus: 'input',
  860. renderTableEdit: defaultEditRender,
  861. renderTableCell (h, renderOpts, params) {
  862. const { props = {} } = renderOpts
  863. const { row, column } = params
  864. let cellValue = XEUtils.get(row, column.field)
  865. if (cellValue) {
  866. if (props.type !== 'time') {
  867. cellValue = getLabelFormatDate(cellValue, props)
  868. }
  869. }
  870. return getCellLabelVNs(h, renderOpts, params, cellValue)
  871. },
  872. renderTableDefault: defaultEditRender,
  873. createTableFilterOptions: defaultFilterOptions,
  874. renderTableFilter: defaultFilterRender,
  875. renderTableFloatingFilter: defaultFloatingFilterRender,
  876. tableFilterDefaultMethod: handleFilterMethod
  877. },
  878. VxeDateRangePicker: {
  879. tableAutoFocus: 'input',
  880. renderTableEdit (h: CreateElement, renderOpts: VxeGlobalRendererHandles.RenderTableEditOptions, params: VxeGlobalRendererHandles.RenderEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
  881. const { startField, endField } = renderOpts
  882. const { $table, row, column } = params
  883. const { model } = column
  884. const cellValue = getCellValue(row, column)
  885. const seProps: Record<string, any> = {}
  886. const seOs: Record<string, any> = {}
  887. if (startField && endField) {
  888. seProps.startValue = XEUtils.get(row, startField)
  889. seProps.endValue = XEUtils.get(row, endField)
  890. seOs['update:startValue'] = (value: any) => {
  891. if (startField) {
  892. XEUtils.set(row, startField, value)
  893. }
  894. }
  895. seOs['update:endValue'] = (value: any) => {
  896. if (endField) {
  897. XEUtils.set(row, endField, value)
  898. }
  899. }
  900. }
  901. return [
  902. h(getDefaultComponent(renderOpts), {
  903. props: getCellEditProps(renderOpts, params, cellValue, seProps),
  904. on: getComponentOns(renderOpts, params, {
  905. model (cellValue) {
  906. model.update = true
  907. model.value = cellValue
  908. setCellValue(row, column, cellValue)
  909. },
  910. change () {
  911. $table.updateStatus(params)
  912. },
  913. blur () {
  914. $table.handleCellRuleUpdateStatus('blur', params)
  915. }
  916. }, seOs)
  917. })
  918. ]
  919. },
  920. renderTableCell (h, renderOpts, params) {
  921. const { startField, endField } = renderOpts
  922. const { row, column } = params
  923. let startValue = ''
  924. let endValue = ''
  925. if (startField && endField) {
  926. startValue = XEUtils.get(row, startField)
  927. endValue = XEUtils.get(row, endField)
  928. } else {
  929. const cellValue = XEUtils.get(row, column.field)
  930. if (cellValue) {
  931. if (XEUtils.isArray(cellValue)) {
  932. startValue = cellValue[0]
  933. endValue = cellValue[1]
  934. } else {
  935. const strs = `${cellValue}`.split(',')
  936. startValue = strs[0]
  937. endValue = strs[1]
  938. }
  939. }
  940. }
  941. let cellLabel = ''
  942. if (startValue && endValue) {
  943. cellLabel = `${startValue} ~ ${endValue}`
  944. }
  945. return getCellLabelVNs(h, renderOpts, params, cellLabel)
  946. }
  947. },
  948. VxeTextarea: {
  949. tableAutoFocus: 'textarea',
  950. renderTableEdit: defaultEditRender
  951. },
  952. VxeButton: {
  953. renderTableDefault: buttonCellRender
  954. },
  955. VxeButtonGroup: {
  956. renderTableDefault (h, renderOpts, params) {
  957. const { options } = renderOpts
  958. return [
  959. h(getDefaultComponent(renderOpts), {
  960. props: {
  961. options,
  962. ...getCellEditProps(renderOpts, params, null)
  963. },
  964. on: getComponentOns(renderOpts, params)
  965. })
  966. ]
  967. }
  968. },
  969. VxeSelect: {
  970. tableAutoFocus: 'input',
  971. renderTableEdit: defaultSelectEditRender,
  972. renderTableDefault: defaultSelectEditRender,
  973. renderTableCell (h, renderOpts, params) {
  974. return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
  975. },
  976. createTableFilterOptions: defaultFilterOptions,
  977. renderTableFilter (h, renderOpts, params) {
  978. const { column } = params
  979. const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
  980. return column.filters.map((option, oIndex) => {
  981. const optionValue = option.data
  982. return h(getDefaultComponent(renderOpts), {
  983. key: oIndex,
  984. props: getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
  985. on: getFilterOns(renderOpts, params, option)
  986. })
  987. })
  988. },
  989. renderTableFloatingFilter (h, renderOpts, params) {
  990. const { option } = params
  991. const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
  992. const optionValue = option.data
  993. return h(getDefaultComponent(renderOpts), {
  994. props: getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
  995. on: getFloatingFilterOns(renderOpts, params, option)
  996. })
  997. },
  998. tableFilterDefaultMethod: handleFilterMethod,
  999. tableExportMethod: handleExportSelectMethod
  1000. },
  1001. VxeText: {
  1002. renderTableDefault (h, renderOpts, params) {
  1003. const { $table, row, column } = params
  1004. const { props } = renderOpts
  1005. const cellLabel = $table.getCellLabel(row, column)
  1006. return [
  1007. h(getDefaultComponent(renderOpts), {
  1008. props: {
  1009. ...(props || {}),
  1010. content: cellLabel
  1011. },
  1012. on: getComponentOns(renderOpts, params)
  1013. })
  1014. ]
  1015. }
  1016. },
  1017. VxeLink: {
  1018. renderTableDefault (h, renderOpts, params) {
  1019. const { $table, row, column } = params
  1020. const { props } = renderOpts
  1021. const { href } = props || {}
  1022. const cellLabel = $table.getCellLabel(row, column)
  1023. return [
  1024. h(getDefaultComponent(renderOpts), {
  1025. props: {
  1026. ...(props || {}),
  1027. content: cellLabel,
  1028. href: XEUtils.toFormatString(href, params)
  1029. },
  1030. on: getComponentOns(renderOpts, params)
  1031. })
  1032. ]
  1033. }
  1034. },
  1035. /**
  1036. * 已废弃,被 FormatSelect 替换
  1037. * @deprecated
  1038. */
  1039. formatOption: {
  1040. renderTableDefault (h, renderOpts, params) {
  1041. return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
  1042. }
  1043. },
  1044. FormatSelect: {
  1045. renderTableDefault (h, renderOpts, params) {
  1046. return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
  1047. },
  1048. tableFilterDefaultMethod: handleFilterMethod,
  1049. tableExportMethod: handleExportSelectMethod
  1050. },
  1051. VxeTreeSelect: {
  1052. tableAutoFocus: 'input',
  1053. renderTableEdit: defaultTableOrTreeSelectEditRender,
  1054. renderTableCell (h, renderOpts, params) {
  1055. return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
  1056. },
  1057. tableExportMethod: handleExportTreeSelectMethod
  1058. },
  1059. VxeTableSelect: {
  1060. tableAutoFocus: 'input',
  1061. renderTableEdit: defaultTableOrTreeSelectEditRender,
  1062. renderTableCell (h, renderOpts, params) {
  1063. return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
  1064. },
  1065. tableExportMethod: handleExportTreeSelectMethod
  1066. },
  1067. /**
  1068. * 已废弃,被 FormatTreeSelect 替换
  1069. * @deprecated
  1070. */
  1071. formatTree: {
  1072. renderTableDefault (h, renderOpts, params) {
  1073. return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
  1074. }
  1075. },
  1076. FormatTreeSelect: {
  1077. renderTableDefault (h, renderOpts, params) {
  1078. return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params))
  1079. },
  1080. tableExportMethod: handleExportTreeSelectMethod
  1081. },
  1082. VxeColorPicker: {
  1083. tableAutoFocus: 'input',
  1084. renderTableEdit (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
  1085. const { row, column } = params
  1086. const { options } = renderOpts
  1087. const cellValue = getCellValue(row, column)
  1088. return [
  1089. h(getDefaultComponent(renderOpts), {
  1090. props: getCellEditProps(renderOpts, params, cellValue, { colors: options }),
  1091. on: getEditOns(renderOpts, params)
  1092. })
  1093. ]
  1094. },
  1095. renderTableCell (h, renderOpts, params) {
  1096. const { row, column } = params
  1097. const cellValue = XEUtils.get(row, column.field)
  1098. return h('span', {
  1099. class: 'vxe-color-picker--readonly'
  1100. }, [
  1101. h('div', {
  1102. class: 'vxe-color-picker--readonly-color',
  1103. style: {
  1104. backgroundColor: cellValue
  1105. }
  1106. })
  1107. ])
  1108. }
  1109. },
  1110. VxeIconPicker: {
  1111. tableAutoFocus: 'input',
  1112. renderTableEdit (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableEditParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
  1113. const { row, column } = params
  1114. const { options } = renderOpts
  1115. const cellValue = getCellValue(row, column)
  1116. return [
  1117. h(getDefaultComponent(renderOpts), {
  1118. props: getCellEditProps(renderOpts, params, cellValue, { icons: options }),
  1119. on: getEditOns(renderOpts, params)
  1120. })
  1121. ]
  1122. },
  1123. renderTableCell (h, renderOpts, params) {
  1124. const { row, column } = params
  1125. const cellValue = XEUtils.get(row, column.field)
  1126. return h('i', {
  1127. class: cellValue
  1128. })
  1129. }
  1130. },
  1131. VxeRadioGroup: {
  1132. renderTableDefault: radioAndCheckboxGroupEditRender
  1133. },
  1134. VxeCheckbox: {
  1135. renderTableDefault: checkboxEditRender
  1136. },
  1137. VxeCheckboxGroup: {
  1138. renderTableDefault: radioAndCheckboxGroupEditRender
  1139. },
  1140. VxeSwitch: {
  1141. tableAutoFocus: 'button',
  1142. renderTableEdit: defaultEditRender,
  1143. renderTableDefault: defaultEditRender
  1144. },
  1145. VxeUpload: {
  1146. renderTableEdit: defaultEditRender,
  1147. renderTableCell: defaultEditRender,
  1148. renderTableDefault: defaultEditRender
  1149. },
  1150. VxeImage: {
  1151. renderTableDefault (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
  1152. const { row, column } = params
  1153. const { props } = renderOpts
  1154. const cellValue = getCellValue(row, column)
  1155. return [
  1156. h(getDefaultComponent(renderOpts), {
  1157. props: {
  1158. ...props,
  1159. src: cellValue
  1160. },
  1161. on: getEditOns(renderOpts, params)
  1162. })
  1163. ]
  1164. }
  1165. },
  1166. VxeImageGroup: {
  1167. renderTableDefault (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
  1168. const { row, column } = params
  1169. const { props } = renderOpts
  1170. const cellValue = getCellValue(row, column)
  1171. return [
  1172. h(getDefaultComponent(renderOpts), {
  1173. props: {
  1174. ...props,
  1175. urlList: cellValue
  1176. },
  1177. on: getEditOns(renderOpts, params)
  1178. })
  1179. ]
  1180. }
  1181. },
  1182. VxeTextEllipsis: {
  1183. renderTableDefault (h, renderOpts, params: VxeGlobalRendererHandles.RenderTableDefaultParams & { $table: VxeTableConstructor & VxeTablePrivateMethods }) {
  1184. const { row, column } = params
  1185. const { props } = renderOpts
  1186. const cellValue = getCellValue(row, column)
  1187. return [
  1188. h(getDefaultComponent(renderOpts), {
  1189. props: {
  1190. ...props,
  1191. content: cellValue
  1192. },
  1193. on: getEditOns(renderOpts, params)
  1194. })
  1195. ]
  1196. }
  1197. },
  1198. VxeRate: {
  1199. renderTableDefault: defaultEditRender
  1200. },
  1201. VxeSlider: {
  1202. renderTableDefault: defaultEditRender
  1203. },
  1204. // 以下已废弃
  1205. $input: {
  1206. tableAutoFocus: '.vxe-input--inner',
  1207. renderTableEdit: oldEditRender,
  1208. renderTableCell (h, renderOpts, params) {
  1209. const { props = {} } = renderOpts
  1210. const { row, column } = params
  1211. const digits = props.digits || getConfig().input?.digits || 2
  1212. let cellValue = XEUtils.get(row, column.field)
  1213. if (cellValue) {
  1214. switch (props.type) {
  1215. case 'date':
  1216. case 'week':
  1217. case 'month':
  1218. case 'year':
  1219. cellValue = getLabelFormatDate(cellValue, props)
  1220. break
  1221. case 'float':
  1222. cellValue = XEUtils.toFixed(XEUtils.floor(cellValue, digits), digits)
  1223. break
  1224. }
  1225. }
  1226. return getCellLabelVNs(h, renderOpts, params, cellValue)
  1227. },
  1228. renderTableDefault: oldEditRender,
  1229. renderTableFilter: oldFilterRender,
  1230. tableFilterDefaultMethod: handleInputFilterMethod
  1231. },
  1232. $textarea: {
  1233. tableAutoFocus: '.vxe-textarea--inner'
  1234. },
  1235. $button: {
  1236. renderTableDefault: oldButtonEditRender
  1237. },
  1238. $buttons: {
  1239. renderTableDefault: oldButtonsEditRender
  1240. },
  1241. $select: {
  1242. tableAutoFocus: '.vxe-input--inner',
  1243. renderTableEdit: oldSelectEditRender,
  1244. renderTableDefault: oldSelectEditRender,
  1245. renderTableCell (h, renderOpts, params) {
  1246. return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params))
  1247. },
  1248. renderTableFilter (h, renderOpts, params) {
  1249. const { column } = params
  1250. const { options, optionProps, optionGroups, optionGroupProps } = renderOpts
  1251. return column.filters.map((option, oIndex) => {
  1252. const optionValue = option.data
  1253. return h(getOldComponent(renderOpts), {
  1254. key: oIndex,
  1255. props: getCellEditFilterProps(renderOpts, params, optionValue, { options, optionProps, optionGroups, optionGroupProps }),
  1256. on: getFilterOns(renderOpts, params, option)
  1257. })
  1258. })
  1259. },
  1260. tableFilterDefaultMethod: handleFilterMethod,
  1261. tableExportMethod: handleExportSelectMethod
  1262. },
  1263. $radio: {
  1264. tableAutoFocus: '.vxe-radio--input'
  1265. },
  1266. $checkbox: {
  1267. tableAutoFocus: '.vxe-checkbox--input'
  1268. },
  1269. $switch: {
  1270. tableAutoFocus: '.vxe-switch--button',
  1271. renderTableEdit: oldEditRender,
  1272. renderTableDefault: oldEditRender
  1273. }
  1274. // 以上已废弃
  1275. })