index.js 42 KB

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