| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520 |
- "use strict";
- var _xeUtils = _interopRequireDefault(require("xe-utils"));
- var _ui = require("../../ui");
- var _util = require("../src/util");
- var _utils = require("../../ui/src/utils");
- var _vn = require("../../ui/src/vn");
- var _log = require("../../ui/src/log");
- function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
- const {
- getConfig,
- renderer,
- getI18n,
- getComponent
- } = _ui.VxeUI;
- const componentDefaultModelProp = 'value';
- const defaultCompProps = {};
- function handleDefaultValue(value, defaultVal, initVal) {
- return _xeUtils.default.eqNull(value) ? _xeUtils.default.eqNull(defaultVal) ? initVal : defaultVal : value;
- }
- function parseDate(value, props) {
- return value && props.valueFormat ? _xeUtils.default.toStringDate(value, props.valueFormat) : value;
- }
- function getFormatDate(value, props, defaultFormat) {
- const {
- dateConfig = {}
- } = props;
- return _xeUtils.default.toDateString(parseDate(value, props), dateConfig.labelFormat || defaultFormat);
- }
- function getLabelFormatDate(value, props) {
- return getFormatDate(value, props, getI18n(`vxe.input.date.labelFormat.${props.type || 'date'}`));
- }
- /**
- * 已废弃
- * @deprecated
- */
- function getOldComponentName(name) {
- return `vxe-${name.replace('$', '')}`;
- }
- /**
- * 已废弃
- * @deprecated
- */
- function getOldComponent({
- name
- }) {
- return getOldComponentName(name);
- }
- function getDefaultComponent({
- name
- }) {
- return getComponent(name) || name;
- }
- function updateFilterChangeOption(params, checked, option) {
- const {
- $table
- } = params;
- $table.updateFilterOptionStatus(option, checked);
- }
- function saveFilterEvent(params) {
- const {
- $table,
- column
- } = params;
- $table.saveFilterByEvent(new Event('change'), column);
- }
- function getNativeAttrs(renderOpts) {
- let {
- name,
- attrs
- } = renderOpts;
- if (name === 'input') {
- attrs = Object.assign({
- type: 'text'
- }, attrs);
- }
- return attrs;
- }
- function getInputImmediateModel(renderOpts) {
- const {
- name,
- immediate,
- props
- } = renderOpts;
- if (!immediate) {
- if (name === 'VxeInput' || name === '$input') {
- const {
- type
- } = props || {};
- return !(!type || type === 'text' || type === 'number' || type === 'integer' || type === 'float');
- }
- if (name === 'input' || name === 'textarea' || name === '$textarea') {
- return false;
- }
- return true;
- }
- return immediate;
- }
- function getCellEditProps(renderOpts, params, value, defaultProps) {
- return _xeUtils.default.assign({
- immediate: getInputImmediateModel(renderOpts)
- }, defaultCompProps, defaultProps, renderOpts.props, {
- [componentDefaultModelProp]: value
- });
- }
- function getCellEditFilterProps(renderOpts, params, value, defaultProps) {
- return _xeUtils.default.assign({}, defaultCompProps, defaultProps, renderOpts.props, {
- [componentDefaultModelProp]: value
- });
- }
- function isImmediateCell(renderOpts, params) {
- return params.$type === 'cell' || getInputImmediateModel(renderOpts);
- }
- function getCellLabelVNs(h, renderOpts, params, cellLabel, opts) {
- const {
- placeholder
- } = renderOpts;
- return [h('span', {
- class: ['vxe-cell--label', opts ? opts.class : '']
- }, placeholder && (0, _utils.isEmptyValue)(cellLabel) ? [h('span', {
- class: 'vxe-cell--placeholder'
- }, (0, _utils.formatText)((0, _utils.getFuncText)(placeholder), 1))] : (0, _utils.formatText)(cellLabel, 1))];
- }
- /**
- * 原生事件处理
- * @param renderOpts
- * @param params
- * @param modelFunc
- * @param changeFunc
- */
- function getNativeElementOns(renderOpts, params, eFns) {
- const {
- events
- } = renderOpts;
- const modelEvent = (0, _vn.getModelEvent)(renderOpts);
- const changeEvent = (0, _vn.getChangeEvent)(renderOpts);
- const {
- model: modelFunc,
- change: changeFunc,
- blur: blurFunc
- } = eFns || {};
- const isSameEvent = changeEvent === modelEvent;
- const ons = {};
- if (events) {
- _xeUtils.default.objectEach(events, (func, key) => {
- ons[(0, _vn.getOnName)(key)] = function (...args) {
- func(params, ...args);
- };
- });
- }
- if (modelFunc) {
- ons[(0, _vn.getOnName)(modelEvent)] = function (targetEvnt) {
- modelFunc(targetEvnt);
- if (isSameEvent && changeFunc) {
- changeFunc(targetEvnt);
- }
- if (events && events[modelEvent]) {
- events[modelEvent](params, targetEvnt);
- }
- };
- }
- if (!isSameEvent && changeFunc) {
- ons[(0, _vn.getOnName)(changeEvent)] = function (evnt) {
- changeFunc(evnt);
- if (events && events[changeEvent]) {
- events[changeEvent](params, evnt);
- }
- };
- }
- if (blurFunc) {
- ons[(0, _vn.getOnName)(blurEvent)] = function (evnt) {
- blurFunc(evnt);
- if (events && events[blurEvent]) {
- events[blurEvent](params, evnt);
- }
- };
- }
- return ons;
- }
- const blurEvent = 'blur';
- const clearEvent = 'clear';
- /**
- * 组件事件处理
- * @param renderOpts
- * @param params
- * @param modelFunc
- * @param changeFunc
- */
- function getComponentOns(renderOpts, params, eFns, eventOns) {
- const {
- events
- } = renderOpts;
- const modelEvent = (0, _vn.getModelEvent)(renderOpts);
- const changeEvent = (0, _vn.getChangeEvent)(renderOpts);
- const {
- model: modelFunc,
- change: changeFunc,
- blur: blurFunc,
- clear: clearFunc
- } = eFns || {};
- const ons = {};
- _xeUtils.default.objectEach(events, (func, key) => {
- ons[(0, _vn.getOnName)(key)] = function (...args) {
- if (!_xeUtils.default.isFunction(func)) {
- (0, _log.errLog)('vxe.error.errFunc', [func]);
- }
- func(params, ...args);
- };
- });
- if (modelFunc) {
- ons[(0, _vn.getOnName)(modelEvent)] = function (targetEvnt) {
- modelFunc(targetEvnt);
- if (events && events[modelEvent]) {
- events[modelEvent](params, targetEvnt);
- }
- };
- }
- if (changeFunc) {
- ons[(0, _vn.getOnName)(changeEvent)] = function (...args) {
- changeFunc(...args);
- if (events && events[changeEvent]) {
- events[changeEvent](params, ...args);
- }
- };
- }
- if (blurFunc) {
- ons[(0, _vn.getOnName)(blurEvent)] = function (...args) {
- blurFunc(...args);
- if (events && events[blurEvent]) {
- events[blurEvent](params, ...args);
- }
- };
- }
- if (clearFunc) {
- ons[(0, _vn.getOnName)(clearEvent)] = function (...args) {
- clearFunc(...args);
- if (events && events[clearEvent]) {
- events[clearEvent](params, ...args);
- }
- };
- }
- return eventOns ? Object.assign(ons, eventOns) : ons;
- }
- function getEditOns(renderOpts, params) {
- const {
- $table,
- row,
- column
- } = params;
- const {
- name
- } = renderOpts;
- const {
- model
- } = column;
- const isImmediate = isImmediateCell(renderOpts, params);
- return getComponentOns(renderOpts, params, {
- model(cellValue) {
- // 处理 model 值双向绑定
- model.update = true;
- model.value = cellValue;
- if (isImmediate) {
- (0, _util.setCellValue)(row, column, cellValue);
- }
- },
- change(eventParams) {
- // 处理 change 事件相关逻辑
- if (!isImmediate && name && ['VxeInput', 'VxeNumberInput', 'VxeTextarea', '$input', '$textarea'].includes(name)) {
- const cellValue = eventParams.value;
- model.update = true;
- model.value = cellValue;
- $table.updateStatus(params, cellValue);
- } else {
- $table.updateStatus(params);
- }
- },
- blur() {
- if (isImmediate) {
- $table.handleCellRuleUpdateStatus('blur', params);
- } else {
- $table.handleCellRuleUpdateStatus('blur', params, model.value);
- }
- }
- });
- }
- function getFilterOns(renderOpts, params, option) {
- return getComponentOns(renderOpts, params, {
- model(value) {
- // 处理 model 值双向绑定
- option.data = value;
- },
- change() {
- updateFilterChangeOption(params, !(0, _utils.isEmptyValue)(option.data), option);
- },
- blur() {
- updateFilterChangeOption(params, !(0, _utils.isEmptyValue)(option.data), option);
- }
- });
- }
- function getFloatingFilterOns(renderOpts, params, option) {
- const {
- $table,
- column
- } = params;
- if ((0, _vn.hasInputType)(renderOpts)) {
- return getComponentOns(renderOpts, params, {
- model(value) {
- // 处理 model 值双向绑定
- option.data = value;
- },
- change() {
- updateFilterChangeOption(params, !(0, _utils.isEmptyValue)(option.data), option);
- },
- clear() {
- updateFilterChangeOption(params, !(0, _utils.isEmptyValue)(option.data), option);
- saveFilterEvent(params);
- },
- blur() {
- $table.saveFilterByEvent(new Event('change'), column);
- }
- }, renderOpts.name === 'VxeNumberInput' ? {
- [(0, _vn.getOnName)('plus-number')]() {
- updateFilterChangeOption(params, !(0, _utils.isEmptyValue)(option.data), option);
- saveFilterEvent(params);
- },
- [(0, _vn.getOnName)('minus-number')]() {
- updateFilterChangeOption(params, !(0, _utils.isEmptyValue)(option.data), option);
- saveFilterEvent(params);
- }
- } : {});
- }
- return getComponentOns(renderOpts, params, {
- model(value) {
- // 处理 model 值双向绑定
- option.data = value;
- },
- clear() {
- updateFilterChangeOption(params, !(0, _utils.isEmptyValue)(option.data), option);
- $table.saveFilterByEvent(new Event('change'), column);
- },
- change() {
- updateFilterChangeOption(params, !(0, _utils.isEmptyValue)(option.data), option);
- $table.saveFilterByEvent(new Event('change'), column);
- }
- });
- }
- function getNativeEditOns(renderOpts, params) {
- const {
- $table,
- row,
- column
- } = params;
- const {
- model
- } = column;
- return getNativeElementOns(renderOpts, params, {
- model(evnt) {
- // 处理 model 值双向绑定
- const targetEl = evnt.target;
- if (targetEl) {
- const cellValue = targetEl.value;
- if (isImmediateCell(renderOpts, params)) {
- (0, _util.setCellValue)(row, column, cellValue);
- } else {
- model.update = true;
- model.value = cellValue;
- }
- }
- },
- change(evnt) {
- // 处理 change 事件相关逻辑
- const targetEl = evnt.target;
- if (targetEl) {
- const cellValue = targetEl.value;
- $table.updateStatus(params, cellValue);
- }
- },
- blur(evnt) {
- const targetEl = evnt.target;
- if (targetEl) {
- const cellValue = targetEl.value;
- $table.updateStatus(params, cellValue);
- }
- }
- });
- }
- function getNativeFilterOns(renderOpts, params, option) {
- return getNativeElementOns(renderOpts, params, {
- model(evnt) {
- // 处理 model 值双向绑定
- const targetEl = evnt.target;
- if (targetEl) {
- option.data = targetEl.value;
- }
- },
- change() {
- updateFilterChangeOption(params, !_xeUtils.default.eqNull(option.data), option);
- },
- blur() {
- updateFilterChangeOption(params, !_xeUtils.default.eqNull(option.data), option);
- }
- });
- }
- /**
- * 单元格可编辑渲染-原生的标签
- * input、textarea、select
- */
- function nativeEditRender(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const {
- name
- } = renderOpts;
- const cellValue = isImmediateCell(renderOpts, params) ? (0, _util.getCellValue)(row, column) : column.model.value;
- return [h(`${name}`, {
- class: `vxe-default-${name}`,
- attrs: getNativeAttrs(renderOpts),
- domProps: {
- value: cellValue
- },
- on: getNativeEditOns(renderOpts, params)
- })];
- }
- function buttonCellRender(h, renderOpts, params) {
- return [h(getDefaultComponent(renderOpts), {
- props: getCellEditProps(renderOpts, params, null),
- on: getComponentOns(renderOpts, params)
- })];
- }
- function defaultEditRender(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: getCellEditProps(renderOpts, params, cellValue),
- on: getEditOns(renderOpts, params)
- })];
- }
- function checkboxEditRender(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: getCellEditProps(renderOpts, params, cellValue),
- on: getEditOns(renderOpts, params)
- })];
- }
- function radioAndCheckboxGroupEditRender(h, renderOpts, params) {
- const {
- options
- } = renderOpts;
- const {
- row,
- column
- } = params;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: Object.assign({
- options
- }, getCellEditProps(renderOpts, params, cellValue)),
- on: getEditOns(renderOpts, params)
- })];
- }
- /**
- * 已废弃
- * @deprecated
- */
- function oldEditRender(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getOldComponent(renderOpts), {
- props: getCellEditProps(renderOpts, params, cellValue),
- on: getEditOns(renderOpts, params)
- })];
- }
- /**
- * 已废弃
- * @deprecated
- */
- function oldButtonEditRender(h, renderOpts, params) {
- return [h('vxe-button', {
- props: getCellEditProps(renderOpts, params, null),
- on: getComponentOns(renderOpts, params)
- })];
- }
- /**
- * 已废弃
- * @deprecated
- */
- function oldButtonsEditRender(h, renderOpts, params) {
- const {
- children
- } = renderOpts;
- return children ? children.map(childRenderOpts => oldButtonEditRender(h, childRenderOpts, params)[0]) : [];
- }
- function renderNativeOptgroups(h, renderOpts, params, renderOptionsMethods) {
- const {
- optionGroups,
- optionGroupProps = {}
- } = renderOpts;
- const groupOptions = optionGroupProps.options || 'options';
- const groupLabel = optionGroupProps.label || 'label';
- if (optionGroups) {
- return optionGroups.map((group, gIndex) => {
- return h('optgroup', {
- key: gIndex,
- attrs: {
- label: group[groupLabel]
- }
- }, renderOptionsMethods(h, group[groupOptions], renderOpts, params));
- });
- }
- return [];
- }
- /**
- * 渲染原生的 option 标签
- */
- function renderNativeOptions(h, options, renderOpts, params) {
- const {
- optionProps = {}
- } = renderOpts;
- const {
- row,
- column
- } = params;
- const labelProp = optionProps.label || 'label';
- const valueProp = optionProps.value || 'value';
- const disabledProp = optionProps.disabled || 'disabled';
- const cellValue = isImmediateCell(renderOpts, params) ? (0, _util.getCellValue)(row, column) : column.model.value;
- if (options) {
- return options.map((option, oIndex) => {
- return h('option', {
- key: oIndex,
- attrs: {
- value: option[valueProp],
- disabled: option[disabledProp]
- },
- domProps: {
- /* eslint-disable eqeqeq */
- selected: option[valueProp] == cellValue
- }
- }, option[labelProp]);
- });
- }
- return [];
- }
- function nativeFilterRender(h, renderOpts, params) {
- const {
- column
- } = params;
- const {
- name
- } = renderOpts;
- const attrs = getNativeAttrs(renderOpts);
- return column.filters.map((option, oIndex) => {
- return h(`${name}`, {
- key: oIndex,
- class: `vxe-default-${name}`,
- attrs,
- domProps: {
- value: option.data
- },
- on: getNativeFilterOns(renderOpts, params, option)
- });
- });
- }
- function defaultFilterRender(h, renderOpts, params) {
- const {
- column
- } = params;
- return column.filters.map((option, oIndex) => {
- const optionValue = option.data;
- return h(getDefaultComponent(renderOpts), {
- key: oIndex,
- props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
- on: getFilterOns(renderOpts, params, option)
- });
- });
- }
- function defaultFloatingFilterRender(h, renderOpts, params) {
- const {
- option
- } = params;
- const optionValue = option.data;
- return [h(getDefaultComponent(renderOpts), {
- props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
- on: getFloatingFilterOns(renderOpts, params, option)
- })];
- }
- function defaultFilterOptions() {
- return [{
- data: null
- }];
- }
- /**
- * 已废弃
- * @deprecated
- */
- function oldFilterRender(h, renderOpts, params) {
- const {
- column
- } = params;
- return column.filters.map((option, oIndex) => {
- const optionValue = option.data;
- return h(getOldComponent(renderOpts), {
- key: oIndex,
- props: getCellEditFilterProps(renderOpts, renderOpts, optionValue),
- on: getFilterOns(renderOpts, params, option)
- });
- });
- }
- function handleFilterMethod({
- option,
- row,
- column
- }) {
- const {
- data
- } = option;
- const cellValue = _xeUtils.default.get(row, column.field);
- /* eslint-disable eqeqeq */
- return cellValue == data;
- }
- function handleInputFilterMethod({
- option,
- row,
- column
- }) {
- const {
- data
- } = option;
- const cellValue = _xeUtils.default.get(row, column.field);
- /* eslint-disable eqeqeq */
- return _xeUtils.default.toValueString(cellValue).indexOf(data) > -1;
- }
- function nativeSelectEditRender(h, renderOpts, params) {
- return [h('select', {
- class: 'vxe-default-select',
- attrs: getNativeAttrs(renderOpts),
- on: getNativeEditOns(renderOpts, params)
- }, renderOpts.optionGroups ? renderNativeOptgroups(h, renderOpts, params, renderNativeOptions) : renderNativeOptions(h, renderOpts.options, renderOpts, params))];
- }
- function defaultSelectEditRender(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const {
- options,
- optionProps,
- optionGroups,
- optionGroupProps
- } = renderOpts;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: getCellEditProps(renderOpts, params, cellValue, {
- options,
- optionProps,
- optionGroups,
- optionGroupProps
- }),
- on: getEditOns(renderOpts, params)
- })];
- }
- function defaultTableOrTreeSelectEditRender(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const {
- options,
- optionProps
- } = renderOpts;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: getCellEditProps(renderOpts, params, cellValue, {
- options,
- optionProps
- }),
- on: getEditOns(renderOpts, params)
- })];
- }
- /**
- * 已废弃
- * @deprecated
- */
- function oldSelectEditRender(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const {
- options,
- optionProps,
- optionGroups,
- optionGroupProps
- } = renderOpts;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getOldComponent(renderOpts), {
- props: getCellEditProps(renderOpts, params, cellValue, {
- options,
- optionProps,
- optionGroups,
- optionGroupProps
- }),
- on: getEditOns(renderOpts, params)
- })];
- }
- function getSelectCellValue(renderOpts, {
- row,
- column
- }) {
- const {
- options,
- optionGroups,
- optionProps = {},
- optionGroupProps = {},
- props = {}
- } = renderOpts;
- const cellValue = _xeUtils.default.get(row, column.field);
- let selectItem;
- const labelProp = optionProps.label || 'label';
- const valueProp = optionProps.value || 'value';
- if (!(cellValue === null || cellValue === undefined)) {
- let vals = [];
- if (_xeUtils.default.isArray(cellValue)) {
- vals = cellValue;
- } else {
- if (props.multiple && `${cellValue}`.indexOf(',') > -1) {
- vals = `${cellValue}`.split(',');
- } else {
- vals = [cellValue];
- }
- }
- return _xeUtils.default.map(vals, optionGroups ? value => {
- const groupOptions = optionGroupProps.options || 'options';
- for (let index = 0; index < optionGroups.length; index++) {
- /* eslint-disable eqeqeq */
- selectItem = _xeUtils.default.find(optionGroups[index][groupOptions], item => item[valueProp] == value);
- if (selectItem) {
- break;
- }
- }
- return selectItem ? selectItem[labelProp] : value;
- } : value => {
- /* eslint-disable eqeqeq */
- selectItem = _xeUtils.default.find(options, item => item[valueProp] == value);
- return selectItem ? selectItem[labelProp] : value;
- }).join(', ');
- }
- return '';
- }
- function handleExportSelectMethod(params) {
- const {
- row,
- column,
- options
- } = params;
- return options.original ? (0, _util.getCellValue)(row, column) : getSelectCellValue(column.editRender || column.cellRender, params);
- }
- function getTreeSelectCellValue(renderOpts, {
- row,
- column
- }) {
- const {
- options,
- optionProps = {}
- } = renderOpts;
- const cellValue = _xeUtils.default.get(row, column.field);
- const labelProp = optionProps.label || 'label';
- const valueProp = optionProps.value || 'value';
- const childrenProp = optionProps.children || 'children';
- if (!(cellValue === null || cellValue === undefined)) {
- const keyMaps = {};
- _xeUtils.default.eachTree(options, item => {
- keyMaps[_xeUtils.default.get(item, valueProp)] = item;
- }, {
- children: childrenProp
- });
- return _xeUtils.default.map(_xeUtils.default.isArray(cellValue) ? cellValue : [cellValue], value => {
- const item = keyMaps[value];
- return item ? _xeUtils.default.get(item, labelProp) : item;
- }).join(', ');
- }
- return '';
- }
- function handleExportTreeSelectMethod(params) {
- const {
- row,
- column,
- options
- } = params;
- return options.original ? (0, _util.getCellValue)(row, column) : getTreeSelectCellValue(column.editRender || column.cellRender, params);
- }
- function handleNumberCell(h, renderOpts, params) {
- const {
- props = {},
- showNegativeStatus
- } = renderOpts;
- const {
- row,
- column
- } = params;
- const {
- type
- } = props;
- let cellValue = _xeUtils.default.get(row, column.field);
- let isNegative = false;
- if (!(0, _utils.isEmptyValue)(cellValue)) {
- const numberInputConfig = getConfig().numberInput || {};
- if (type === 'float') {
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true);
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1);
- cellValue = _xeUtils.default.toFixed(_xeUtils.default.floor(cellValue, digits), digits);
- if (!autoFill) {
- cellValue = _xeUtils.default.toNumber(cellValue);
- }
- if (showNegativeStatus) {
- if (cellValue < 0) {
- isNegative = true;
- }
- }
- } else if (type === 'amount') {
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true);
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2);
- const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false);
- cellValue = _xeUtils.default.toNumber(cellValue);
- if (showNegativeStatus) {
- if (cellValue < 0) {
- isNegative = true;
- }
- }
- cellValue = _xeUtils.default.commafy(cellValue, {
- digits
- });
- if (!autoFill) {
- const [iStr, dStr] = cellValue.split('.');
- if (dStr) {
- const dRest = dStr.replace(/0+$/, '');
- cellValue = dRest ? [iStr, '.', dRest].join('') : iStr;
- }
- }
- if (showCurrency) {
- cellValue = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${cellValue}`;
- }
- } else {
- if (showNegativeStatus) {
- if (_xeUtils.default.toNumber(cellValue) < 0) {
- isNegative = true;
- }
- }
- }
- }
- return getCellLabelVNs(h, renderOpts, params, cellValue, isNegative ? {
- class: 'is--negative'
- } : {});
- }
- /**
- * 表格 - 渲染器
- */
- renderer.mixin({
- input: {
- tableAutoFocus: 'input',
- renderTableEdit: nativeEditRender,
- renderTableDefault: nativeEditRender,
- renderTableFilter: nativeFilterRender,
- tableFilterDefaultMethod: handleInputFilterMethod
- },
- textarea: {
- tableAutoFocus: 'textarea',
- renderTableEdit: nativeEditRender
- },
- select: {
- renderTableEdit: nativeSelectEditRender,
- renderTableDefault: nativeSelectEditRender,
- renderTableCell(h, renderOpts, params) {
- return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params));
- },
- renderTableFilter(h, renderOpts, params) {
- const {
- column
- } = params;
- return column.filters.map((option, oIndex) => {
- return h('select', {
- key: oIndex,
- class: 'vxe-default-select',
- attrs: getNativeAttrs(renderOpts),
- on: getNativeFilterOns(renderOpts, params, option)
- }, renderOpts.optionGroups ? renderNativeOptgroups(h, renderOpts, params, renderNativeOptions) : renderNativeOptions(h, renderOpts.options, renderOpts, params));
- });
- },
- tableFilterDefaultMethod: handleFilterMethod,
- tableExportMethod: handleExportSelectMethod
- },
- VxeInput: {
- tableAutoFocus: 'input',
- renderTableEdit: defaultEditRender,
- renderTableCell(h, renderOpts, params) {
- const {
- props = {}
- } = renderOpts;
- const {
- row,
- column
- } = params;
- const inputConfig = getConfig().input || {};
- const digits = props.digits || inputConfig.digits || 2;
- let cellValue = _xeUtils.default.get(row, column.field);
- if (cellValue) {
- switch (props.type) {
- case 'date':
- case 'week':
- case 'month':
- case 'quarter':
- case 'year':
- cellValue = getLabelFormatDate(cellValue, props);
- break;
- case 'float':
- cellValue = _xeUtils.default.toFixed(_xeUtils.default.floor(cellValue, digits), digits);
- break;
- }
- }
- return getCellLabelVNs(h, renderOpts, params, cellValue);
- },
- renderTableDefault: defaultEditRender,
- createTableFilterOptions: defaultFilterOptions,
- renderTableFilter: defaultFilterRender,
- renderTableFloatingFilter: defaultFloatingFilterRender,
- tableFilterDefaultMethod: handleInputFilterMethod
- },
- FormatNumberInput: {
- renderTableDefault: handleNumberCell,
- tableFilterDefaultMethod: handleInputFilterMethod,
- tableExportMethod(params) {
- const {
- row,
- column
- } = params;
- const cellValue = _xeUtils.default.get(row, column.field);
- return cellValue;
- }
- },
- VxeNumberInput: {
- tableAutoFocus: 'input',
- renderTableEdit: defaultEditRender,
- renderTableCell: handleNumberCell,
- renderTableFooter(h, renderOpts, params) {
- const {
- props = {}
- } = renderOpts;
- const {
- row,
- column,
- _columnIndex
- } = params;
- const {
- type
- } = props;
- // 兼容老模式
- const itemValue = _xeUtils.default.isArray(row) ? row[_columnIndex] : _xeUtils.default.get(row, column.field);
- if (_xeUtils.default.isNumber(itemValue)) {
- const numberInputConfig = getConfig().numberInput || {};
- if (type === 'float') {
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true);
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 1);
- let amountLabel = _xeUtils.default.toFixed(_xeUtils.default.floor(itemValue, digits), digits);
- if (!autoFill) {
- amountLabel = _xeUtils.default.toNumber(amountLabel);
- }
- return amountLabel;
- } else if (type === 'amount') {
- const autoFill = handleDefaultValue(props.autoFill, numberInputConfig.autoFill, true);
- const digits = handleDefaultValue(props.digits, numberInputConfig.digits, 2);
- const showCurrency = handleDefaultValue(props.showCurrency, numberInputConfig.showCurrency, false);
- let amountLabel = _xeUtils.default.commafy(_xeUtils.default.toNumber(itemValue), {
- digits
- });
- if (!autoFill) {
- const [iStr, dStr] = amountLabel.split('.');
- if (dStr) {
- const dRest = dStr.replace(/0+$/, '');
- amountLabel = dRest ? [iStr, '.', dRest].join('') : iStr;
- }
- }
- if (showCurrency) {
- amountLabel = `${props.currencySymbol || numberInputConfig.currencySymbol || getI18n('vxe.numberInput.currencySymbol') || ''}${amountLabel}`;
- }
- return amountLabel;
- }
- }
- return (0, _utils.getFuncText)(itemValue, 1);
- },
- renderTableDefault: defaultEditRender,
- createTableFilterOptions: defaultFilterOptions,
- renderTableFilter: defaultFilterRender,
- renderTableFloatingFilter: defaultFloatingFilterRender,
- tableFilterDefaultMethod: handleInputFilterMethod,
- tableExportMethod(params) {
- const {
- row,
- column
- } = params;
- const cellValue = _xeUtils.default.get(row, column.field);
- return cellValue;
- }
- },
- VxeDatePicker: {
- tableAutoFocus: 'input',
- renderTableEdit: defaultEditRender,
- renderTableCell(h, renderOpts, params) {
- const {
- props = {}
- } = renderOpts;
- const {
- row,
- column
- } = params;
- let cellValue = _xeUtils.default.get(row, column.field);
- if (cellValue) {
- if (props.type !== 'time') {
- cellValue = getLabelFormatDate(cellValue, props);
- }
- }
- return getCellLabelVNs(h, renderOpts, params, cellValue);
- },
- renderTableDefault: defaultEditRender,
- createTableFilterOptions: defaultFilterOptions,
- renderTableFilter: defaultFilterRender,
- renderTableFloatingFilter: defaultFloatingFilterRender,
- tableFilterDefaultMethod: handleFilterMethod
- },
- VxeDateRangePicker: {
- tableAutoFocus: 'input',
- renderTableEdit(h, renderOpts, params) {
- const {
- startField,
- endField
- } = renderOpts;
- const {
- $table,
- row,
- column
- } = params;
- const {
- model
- } = column;
- const cellValue = (0, _util.getCellValue)(row, column);
- const seProps = {};
- const seOs = {};
- if (startField && endField) {
- seProps.startValue = _xeUtils.default.get(row, startField);
- seProps.endValue = _xeUtils.default.get(row, endField);
- seOs['update:startValue'] = value => {
- if (startField) {
- _xeUtils.default.set(row, startField, value);
- }
- };
- seOs['update:endValue'] = value => {
- if (endField) {
- _xeUtils.default.set(row, endField, value);
- }
- };
- }
- return [h(getDefaultComponent(renderOpts), {
- props: getCellEditProps(renderOpts, params, cellValue, seProps),
- on: getComponentOns(renderOpts, params, {
- model(cellValue) {
- model.update = true;
- model.value = cellValue;
- (0, _util.setCellValue)(row, column, cellValue);
- },
- change() {
- $table.updateStatus(params);
- },
- blur() {
- $table.handleCellRuleUpdateStatus('blur', params);
- }
- }, seOs)
- })];
- },
- renderTableCell(h, renderOpts, params) {
- const {
- startField,
- endField
- } = renderOpts;
- const {
- row,
- column
- } = params;
- let startValue = '';
- let endValue = '';
- if (startField && endField) {
- startValue = _xeUtils.default.get(row, startField);
- endValue = _xeUtils.default.get(row, endField);
- } else {
- const cellValue = _xeUtils.default.get(row, column.field);
- if (cellValue) {
- if (_xeUtils.default.isArray(cellValue)) {
- startValue = cellValue[0];
- endValue = cellValue[1];
- } else {
- const strs = `${cellValue}`.split(',');
- startValue = strs[0];
- endValue = strs[1];
- }
- }
- }
- let cellLabel = '';
- if (startValue && endValue) {
- cellLabel = `${startValue} ~ ${endValue}`;
- }
- return getCellLabelVNs(h, renderOpts, params, cellLabel);
- }
- },
- VxeTextarea: {
- tableAutoFocus: 'textarea',
- renderTableEdit: defaultEditRender
- },
- VxeButton: {
- renderTableDefault: buttonCellRender
- },
- VxeButtonGroup: {
- renderTableDefault(h, renderOpts, params) {
- const {
- options
- } = renderOpts;
- return [h(getDefaultComponent(renderOpts), {
- props: Object.assign({
- options
- }, getCellEditProps(renderOpts, params, null)),
- on: getComponentOns(renderOpts, params)
- })];
- }
- },
- VxeSelect: {
- tableAutoFocus: 'input',
- renderTableEdit: defaultSelectEditRender,
- renderTableDefault: defaultSelectEditRender,
- renderTableCell(h, renderOpts, params) {
- return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params));
- },
- createTableFilterOptions: defaultFilterOptions,
- renderTableFilter(h, renderOpts, params) {
- const {
- column
- } = params;
- const {
- options,
- optionProps,
- optionGroups,
- optionGroupProps
- } = renderOpts;
- return column.filters.map((option, oIndex) => {
- const optionValue = option.data;
- return h(getDefaultComponent(renderOpts), {
- key: oIndex,
- props: getCellEditFilterProps(renderOpts, params, optionValue, {
- options,
- optionProps,
- optionGroups,
- optionGroupProps
- }),
- on: getFilterOns(renderOpts, params, option)
- });
- });
- },
- renderTableFloatingFilter(h, renderOpts, params) {
- const {
- option
- } = params;
- const {
- options,
- optionProps,
- optionGroups,
- optionGroupProps
- } = renderOpts;
- const optionValue = option.data;
- return h(getDefaultComponent(renderOpts), {
- props: getCellEditFilterProps(renderOpts, params, optionValue, {
- options,
- optionProps,
- optionGroups,
- optionGroupProps
- }),
- on: getFloatingFilterOns(renderOpts, params, option)
- });
- },
- tableFilterDefaultMethod: handleFilterMethod,
- tableExportMethod: handleExportSelectMethod
- },
- VxeText: {
- renderTableDefault(h, renderOpts, params) {
- const {
- $table,
- row,
- column
- } = params;
- const {
- props
- } = renderOpts;
- const cellLabel = $table.getCellLabel(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: Object.assign(Object.assign({}, props || {}), {
- content: cellLabel
- }),
- on: getComponentOns(renderOpts, params)
- })];
- }
- },
- VxeLink: {
- renderTableDefault(h, renderOpts, params) {
- const {
- $table,
- row,
- column
- } = params;
- const {
- props
- } = renderOpts;
- const {
- href
- } = props || {};
- const cellLabel = $table.getCellLabel(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: Object.assign(Object.assign({}, props || {}), {
- content: cellLabel,
- href: _xeUtils.default.toFormatString(href, params)
- }),
- on: getComponentOns(renderOpts, params)
- })];
- }
- },
- /**
- * 已废弃,被 FormatSelect 替换
- * @deprecated
- */
- formatOption: {
- renderTableDefault(h, renderOpts, params) {
- return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params));
- }
- },
- FormatSelect: {
- renderTableDefault(h, renderOpts, params) {
- return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params));
- },
- tableFilterDefaultMethod: handleFilterMethod,
- tableExportMethod: handleExportSelectMethod
- },
- VxeTreeSelect: {
- tableAutoFocus: 'input',
- renderTableEdit: defaultTableOrTreeSelectEditRender,
- renderTableCell(h, renderOpts, params) {
- return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params));
- },
- tableExportMethod: handleExportTreeSelectMethod
- },
- VxeTableSelect: {
- tableAutoFocus: 'input',
- renderTableEdit: defaultTableOrTreeSelectEditRender,
- renderTableCell(h, renderOpts, params) {
- return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params));
- },
- tableExportMethod: handleExportTreeSelectMethod
- },
- /**
- * 已废弃,被 FormatTreeSelect 替换
- * @deprecated
- */
- formatTree: {
- renderTableDefault(h, renderOpts, params) {
- return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params));
- }
- },
- FormatTreeSelect: {
- renderTableDefault(h, renderOpts, params) {
- return getCellLabelVNs(h, renderOpts, params, getTreeSelectCellValue(renderOpts, params));
- },
- tableExportMethod: handleExportTreeSelectMethod
- },
- VxeColorPicker: {
- tableAutoFocus: 'input',
- renderTableEdit(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const {
- options
- } = renderOpts;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: getCellEditProps(renderOpts, params, cellValue, {
- colors: options
- }),
- on: getEditOns(renderOpts, params)
- })];
- },
- renderTableCell(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const cellValue = _xeUtils.default.get(row, column.field);
- return h('span', {
- class: 'vxe-color-picker--readonly'
- }, [h('div', {
- class: 'vxe-color-picker--readonly-color',
- style: {
- backgroundColor: cellValue
- }
- })]);
- }
- },
- VxeIconPicker: {
- tableAutoFocus: 'input',
- renderTableEdit(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const {
- options
- } = renderOpts;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: getCellEditProps(renderOpts, params, cellValue, {
- icons: options
- }),
- on: getEditOns(renderOpts, params)
- })];
- },
- renderTableCell(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const cellValue = _xeUtils.default.get(row, column.field);
- return h('i', {
- class: cellValue
- });
- }
- },
- VxeRadioGroup: {
- renderTableDefault: radioAndCheckboxGroupEditRender
- },
- VxeCheckbox: {
- renderTableDefault: checkboxEditRender
- },
- VxeCheckboxGroup: {
- renderTableDefault: radioAndCheckboxGroupEditRender
- },
- VxeSwitch: {
- tableAutoFocus: 'button',
- renderTableEdit: defaultEditRender,
- renderTableDefault: defaultEditRender
- },
- VxeUpload: {
- renderTableEdit: defaultEditRender,
- renderTableCell: defaultEditRender,
- renderTableDefault: defaultEditRender
- },
- VxeImage: {
- renderTableDefault(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const {
- props
- } = renderOpts;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: Object.assign(Object.assign({}, props), {
- src: cellValue
- }),
- on: getEditOns(renderOpts, params)
- })];
- }
- },
- VxeImageGroup: {
- renderTableDefault(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const {
- props
- } = renderOpts;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: Object.assign(Object.assign({}, props), {
- urlList: cellValue
- }),
- on: getEditOns(renderOpts, params)
- })];
- }
- },
- VxeTextEllipsis: {
- renderTableDefault(h, renderOpts, params) {
- const {
- row,
- column
- } = params;
- const {
- props
- } = renderOpts;
- const cellValue = (0, _util.getCellValue)(row, column);
- return [h(getDefaultComponent(renderOpts), {
- props: Object.assign(Object.assign({}, props), {
- content: cellValue
- }),
- on: getEditOns(renderOpts, params)
- })];
- }
- },
- VxeRate: {
- renderTableDefault: defaultEditRender
- },
- VxeSlider: {
- renderTableDefault: defaultEditRender
- },
- // 以下已废弃
- $input: {
- tableAutoFocus: '.vxe-input--inner',
- renderTableEdit: oldEditRender,
- renderTableCell(h, renderOpts, params) {
- var _a;
- const {
- props = {}
- } = renderOpts;
- const {
- row,
- column
- } = params;
- const digits = props.digits || ((_a = getConfig().input) === null || _a === void 0 ? void 0 : _a.digits) || 2;
- let cellValue = _xeUtils.default.get(row, column.field);
- if (cellValue) {
- switch (props.type) {
- case 'date':
- case 'week':
- case 'month':
- case 'year':
- cellValue = getLabelFormatDate(cellValue, props);
- break;
- case 'float':
- cellValue = _xeUtils.default.toFixed(_xeUtils.default.floor(cellValue, digits), digits);
- break;
- }
- }
- return getCellLabelVNs(h, renderOpts, params, cellValue);
- },
- renderTableDefault: oldEditRender,
- renderTableFilter: oldFilterRender,
- tableFilterDefaultMethod: handleInputFilterMethod
- },
- $textarea: {
- tableAutoFocus: '.vxe-textarea--inner'
- },
- $button: {
- renderTableDefault: oldButtonEditRender
- },
- $buttons: {
- renderTableDefault: oldButtonsEditRender
- },
- $select: {
- tableAutoFocus: '.vxe-input--inner',
- renderTableEdit: oldSelectEditRender,
- renderTableDefault: oldSelectEditRender,
- renderTableCell(h, renderOpts, params) {
- return getCellLabelVNs(h, renderOpts, params, getSelectCellValue(renderOpts, params));
- },
- renderTableFilter(h, renderOpts, params) {
- const {
- column
- } = params;
- const {
- options,
- optionProps,
- optionGroups,
- optionGroupProps
- } = renderOpts;
- return column.filters.map((option, oIndex) => {
- const optionValue = option.data;
- return h(getOldComponent(renderOpts), {
- key: oIndex,
- props: getCellEditFilterProps(renderOpts, params, optionValue, {
- options,
- optionProps,
- optionGroups,
- optionGroupProps
- }),
- on: getFilterOns(renderOpts, params, option)
- });
- });
- },
- tableFilterDefaultMethod: handleFilterMethod,
- tableExportMethod: handleExportSelectMethod
- },
- $radio: {
- tableAutoFocus: '.vxe-radio--input'
- },
- $checkbox: {
- tableAutoFocus: '.vxe-checkbox--input'
- },
- $switch: {
- tableAutoFocus: '.vxe-switch--button',
- renderTableEdit: oldEditRender,
- renderTableDefault: oldEditRender
- }
- // 以上已废弃
- });
|