vue-ant-patterns
Version:
vue-ant-patterns
376 lines (321 loc) • 11.6 kB
JavaScript
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _toConsumableArray2 = require('babel-runtime/helpers/toConsumableArray');
var _toConsumableArray3 = _interopRequireDefault(_toConsumableArray2);
var _extends2 = require('babel-runtime/helpers/extends');
var _extends3 = _interopRequireDefault(_extends2);
var _slicedToArray2 = require('babel-runtime/helpers/slicedToArray');
var _slicedToArray3 = _interopRequireDefault(_slicedToArray2);
var _antDesignVue = require('ant-design-vue');
var _vueTypes = require('ant-design-vue/lib/_util/vue-types');
var _vueTypes2 = _interopRequireDefault(_vueTypes);
var _utils = require('../../lib/_utils');
var _components = require('../../lib/');
var _mixinBase = require('./mixinBase');
var _mixinBase2 = _interopRequireDefault(_mixinBase);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; }
var Horizontal = _components.DContainer.Horizontal;
exports['default'] = {
name: 'VmTable',
mixins: [_mixinBase2['default']],
props: {
panel: _vueTypes2['default'].object,
section: _vueTypes2['default'].object,
panelInfo: _vueTypes2['default'].array,
sectionInfo: _vueTypes2['default'].array,
fieldInfo: _vueTypes2['default'].array,
dataSource: _vueTypes2['default'].object,
vmStatus: _vueTypes2['default'].string.def('view'),
dateFormat: _vueTypes2['default'].string.def('YYYY-MM-DD'),
localeCode: _vueTypes2['default'].string.def('zh-cn'),
tableAction: _vueTypes2['default'].array,
tableRowKey: _vueTypes2['default'].string,
tableCustomConfig: _vueTypes2['default'].func
},
data: function data() {
var vmStatus = this.$props.vmStatus;
var isEdit = vmStatus === 'edit';
return {
isEdit: isEdit,
v_status: 'view'
};
},
watch: {
vmStatus: function vmStatus(val) {
this.isEdit = val === 'edit';
this.v_status = 'view';
}
},
methods: {
/**
* 操作列
*/
actionColumn: function actionColumn(columnArr) {
var _this = this;
var h = this.$createElement;
var _$props = this.$props,
section = _$props.section,
panel = _$props.panel,
panelInfo = _$props.panelInfo,
sectionInfo = _$props.sectionInfo,
localeCode = _$props.localeCode,
tableAction = _$props.tableAction;
var _panelInfo = (0, _slicedToArray3['default'])(panelInfo, 3),
vPanelKey = _panelInfo[0],
vPanelCodeKey = _panelInfo[1],
vPanelNameKey = _panelInfo[2];
var _sectionInfo = (0, _slicedToArray3['default'])(sectionInfo, 3),
vSectionKey = _sectionInfo[0],
vSectionCodeKey = _sectionInfo[1],
vSectionNameKey = _sectionInfo[2];
var isEdit = this.isEdit;
var key = panel[vPanelCodeKey] + '-' + section[vSectionCodeKey] + '-first-action';
var lang = this.langType[localeCode];
var action = lang.action;
var firstColObj = {
key: key,
title: action,
width: 60,
align: 'center',
customRender: function customRender(text, record, index) {
var buttonProps = {
props: {
size: 'small',
disabled: !isEdit
},
on: {
click: function click() {
_this.showConfirm({ text: text, panel: panel, section: section, record: record, index: index });
}
}
};
var editProps = {
on: {
click: function click() {
_this.$emit('tableEdit', { text: text, panel: panel, section: section, record: record, index: index });
}
}
};
var isEditAction = tableAction.includes('edit');
var isDeleteACtion = tableAction.includes('delete');
return !isEditAction && !isDeleteACtion ? null : h(Horizontal, [isDeleteACtion ? h(
_components.DIconButton,
buttonProps,
[h(_components.DIcon, {
attrs: { type: 'delete' }
})]
) : null, isEditAction ? h(
_components.DIconButton,
(0, _extends3['default'])({}, buttonProps, editProps),
[h(_components.DIcon, {
attrs: { type: 'edit' }
})]
) : null]);
}
};
columnArr.unshift(firstColObj);
},
/**
* 首列增加链接
*/
columnFirstHandler: function columnFirstHandler(_ref) {
var _this2 = this;
var panel = _ref.panel,
section = _ref.section,
columnArr = _ref.columnArr,
dataList = _ref.dataList;
var h = this.$createElement;
var _getFieldProperty = this.getFieldProperty({
panel: panel,
section: section,
field: dataList[0]
}),
fieldName = _getFieldProperty.fieldName,
isDisplayInGrid = _getFieldProperty.isDisplayInGrid,
controlType = _getFieldProperty.controlType;
if (!isDisplayInGrid) {}
columnArr[0].customRender = function (text, record, index) {
var linkProps = {
props: {},
on: {
click: function click(e) {
_this2.$emit('tableDetail', { text: text, panel: panel, section: section, record: record, index: index });
}
}
};
var value = void 0;
var isConstant = controlType === 'CONSTANT';
/**
* 表格类型的常数代码不使用常数代码组件, 通过字段直接取值
*/
if (isConstant) {
value = record[fieldName] ? record[fieldName].name : '';
} else {
value = _this2.getFieldValue(controlType, fieldName, record);
}
return h(
'a',
linkProps,
[value]
);
};
},
/**
* 根据模板数据, 生成 table 使用的 columns
*/
createColumn: function createColumn() {
var _this3 = this;
var _$props2 = this.$props,
section = _$props2.section,
panel = _$props2.panel;
var fieldsList = section.fieldsList;
var cloneFieldList = [].concat((0, _toConsumableArray3['default'])(fieldsList));
// 排序
(0, _utils.sortList)(cloneFieldList);
// 过滤掉无效的数据 或者 不需要显示的数据
cloneFieldList = cloneFieldList.map(function (item) {
var isDisplayInGrid = item.isDisplayInGrid;
if (!isDisplayInGrid) return;
return item;
}).filter(function (T) {
return T;
});
var columnArr = cloneFieldList.map(function (item) {
var _getFieldProperty2 = _this3.getFieldProperty({
panel: panel,
section: section,
field: item
}),
fieldName = _getFieldProperty2.fieldName,
nFieldName = _getFieldProperty2.nFieldName,
label = _getFieldProperty2.label,
controlType = _getFieldProperty2.controlType;
var colObj = {
key: nFieldName,
dataIndex: fieldName,
title: label,
customRender: function customRender(text, record, index) {
var isConstant = controlType === 'CONSTANT';
/**
* 表格类型的常数代码不使用常数代码组件, 通过字段直接取值
*/
if (isConstant) {
return record[fieldName] ? record[fieldName].name : '';
}
var v = _this3.getFieldValue(controlType, fieldName, record);
return v;
}
};
return colObj;
}).filter(function (T) {
return T;
});
this.columnFirstHandler({ section: section, panel: panel, columnArr: columnArr, dataList: cloneFieldList });
this.actionColumn(columnArr);
return columnArr;
},
showConfirm: function showConfirm(_ref2) {
var _this4 = this;
var text = _ref2.text,
panel = _ref2.panel,
section = _ref2.section,
record = _ref2.record,
index = _ref2.index;
var _$props3 = this.$props,
panelInfo = _$props3.panelInfo,
sectionInfo = _$props3.sectionInfo,
localeCode = _$props3.localeCode;
var _panelInfo2 = (0, _slicedToArray3['default'])(panelInfo, 3),
vPanelKey = _panelInfo2[0],
vPanelCodeKey = _panelInfo2[1],
vPanelNameKey = _panelInfo2[2];
var _sectionInfo2 = (0, _slicedToArray3['default'])(sectionInfo, 3),
vSectionKey = _sectionInfo2[0],
vSectionCodeKey = _sectionInfo2[1],
vSectionNameKey = _sectionInfo2[2];
var isEdit = this.isEdit;
var key = panel[vPanelCodeKey] + '-' + section[vSectionCodeKey] + '-first-action';
var lang = this.langType[localeCode];
var confirmDelete = lang.confirmDelete,
confirm = lang.confirm,
cancel = lang.cancel;
var setConfirmStatus = function setConfirmStatus(cfm, status) {
cfm.update({
cancelDisable: status,
confirmLoading: status,
maskClosable: !status,
cancelButtonProps: {
props: {
// disabled: status,
}
},
okButtonProps: {
props: {
loading: status
}
}
});
};
var confirmIns = this.$confirm({
disabled: !isEdit,
title: confirmDelete,
okText: confirm,
cancelText: cancel,
maskClosable: true,
confirmLoading: false,
key: key,
onOk: function onOk() {
setConfirmStatus(confirmIns, true);
return new Promise(function (resolve, reject) {
_this4.$emit('tableDelete', { text: text, panel: panel, section: section, record: record, index: index }, function (cb) {
resolve();
}, function (rejectCallback) {
confirmIns.update({
okButtonProps: {
props: {
loading: false
}
}
});
});
})['finally'](function () {
setConfirmStatus(confirmIns, false);
});
},
onCancel: function onCancel() {
// this.confirmLoading = false;
// this.cancelDisable = false;
// this.maskClosable = true;
}
});
}
},
render: function render() {
var h = arguments[0];
var _$props4 = this.$props,
section = _$props4.section,
dataSource = _$props4.dataSource,
sectionInfo = _$props4.sectionInfo,
tableRowKey = _$props4.tableRowKey,
tableCustomConfig = _$props4.tableCustomConfig,
panel = _$props4.panel;
var _sectionInfo3 = (0, _slicedToArray3['default'])(sectionInfo, 1),
sectionIdKey = _sectionInfo3[0];
// const { fieldsList } = section;
var cols = this.createColumn();
var tableConfig = tableCustomConfig ? tableCustomConfig({ panel: panel, section: section }) : null;
var source = (0, _utils.isEmptyObj)(dataSource) ? [] : dataSource[section[sectionIdKey]] || [];
var tableProps = tableConfig ? tableConfig : {
props: {
dataSource: source,
columns: [].concat((0, _toConsumableArray3['default'])(cols)),
pagination: false,
rowKey: tableRowKey,
size: 'small'
}
};
return h(_antDesignVue.Table, tableProps);
}
};