vxe-gantt
Version:
A vue based gantt component
1,397 lines (1,395 loc) • 99 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _vue = require("vue");
var _comp = require("../../ui/src/comp");
var _xeUtils = _interopRequireDefault(require("xe-utils"));
var _utils = require("../../ui/src/utils");
var _dom = require("../../ui/src/dom");
var _vn = require("../../ui/src/vn");
var _core = require("@vxe-ui/core");
var _emits = require("./emits");
var _util = require("./util");
var _tableEmits = require("./table-emits");
var _log = require("../../ui/src/log");
var _ganttView = _interopRequireDefault(require("./gantt-view"));
var _vxeTable = require("vxe-table");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const {
getConfig,
getIcon,
getI18n,
commands,
hooks,
useFns,
createEvent,
globalEvents,
GLOBAL_EVENT_KEYS,
renderEmptyElement
} = _core.VxeUI;
const tableProps = _vxeTable.VxeTable.props;
const tableComponentPropKeys = Object.keys(tableProps);
const tableComponentMethodKeys = ['clearAll', 'syncData', 'updateData', 'loadData', 'reloadData', 'reloadRow', 'loadColumn', 'reloadColumn', 'getRowNode', 'getColumnNode', 'getRowIndex', 'getVTRowIndex', 'getVMRowIndex', 'getColumnIndex', 'getVTColumnIndex', 'getVMColumnIndex', 'setRow', 'createData', 'createRow', 'revertData', 'clearData', 'isRemoveByRow', 'isInsertByRow', 'isUpdateByRow', 'getColumns', 'getColumnById', 'getColumnByField', 'getTableColumn', 'getFullColumns', 'getData', 'getCheckboxRecords', 'getParentRow', 'getTreeRowChildren', 'getTreeRowLevel', 'getTreeParentRow', 'getRowSeq', 'getRowById', 'getRowid', 'getTableData', 'getFullData', 'setColumnFixed', 'clearColumnFixed', 'setColumnWidth', 'getColumnWidth', 'recalcRowHeight', 'setRowHeightConf', 'getRowHeightConf', 'setRowHeight', 'getRowHeight', 'hideColumn', 'showColumn', 'resetColumn', 'refreshColumn', 'refreshScroll', 'recalculate', 'closeTooltip', 'isAllCheckboxChecked', 'isAllCheckboxIndeterminate', 'getCheckboxIndeterminateRecords', 'setCheckboxRow', 'setCheckboxRowKey', 'isCheckedByCheckboxRow', 'isCheckedByCheckboxRowKey', 'isIndeterminateByCheckboxRow', 'isIndeterminateByCheckboxRowKey', 'toggleCheckboxRow', 'setAllCheckboxRow', 'getRadioReserveRecord', 'clearRadioReserve', 'getCheckboxReserveRecords', 'clearCheckboxReserve', 'toggleAllCheckboxRow', 'clearCheckboxRow', 'setCurrentRow', 'isCheckedByRadioRow', 'isCheckedByRadioRowKey', 'setRadioRow', 'setRadioRowKey', 'clearCurrentRow', 'clearRadioRow', 'getCurrentRecord', 'getRadioRecord', 'getCurrentColumn', 'setCurrentColumn', 'clearCurrentColumn', 'setPendingRow', 'togglePendingRow', 'hasPendingByRow', 'isPendingByRow', 'getPendingRecords', 'clearPendingRow', 'setFilterByEvent', 'sort', 'setSort', 'setSortByEvent', 'clearSort', 'clearSortByEvent', 'isSort', 'getSortColumns', 'closeFilter', 'isFilter', 'clearFilterByEvent', 'isActiveFilterByColumn', 'isRowExpandLoaded', 'clearRowExpandLoaded', 'reloadRowExpand', 'reloadRowExpand', 'toggleRowExpand', 'setAllRowExpand', 'setRowExpand', 'isExpandByRow', 'isRowExpandByRow', 'clearRowExpand', 'clearRowExpandReserve', 'getRowExpandRecords', 'getTreeExpandRecords', 'isTreeExpandLoaded', 'clearTreeExpandLoaded', 'reloadTreeExpand', 'reloadTreeChilds', 'toggleTreeExpand', 'setAllTreeExpand', 'setTreeExpand', 'isTreeExpandByRow', 'clearTreeExpand', 'clearTreeExpandReserve', 'getScroll', 'scrollTo', 'scrollToStartRow', 'scrollToEndRow', 'scrollToRow', 'scrollToStartColumn', 'scrollToEndColumn', 'scrollToColumn', 'clearScroll', 'updateFooter', 'updateStatus', 'setMergeCells', 'removeInsertRow', 'removeMergeCells', 'getMergeCells', 'clearMergeCells', 'setMergeFooterItems', 'removeMergeFooterItems', 'getMergeFooterItems', 'clearMergeFooterItems', 'getCustomStoreData', 'setRowGroupExpand', 'setRowGroupExpandByField', 'setAllRowGroupExpand', 'clearRowGroupExpand', 'isRowGroupExpandByRow', 'isRowGroupRecord', 'isAggregateRecord', 'isAggregateExpandByRow', 'getAggregateContentByRow', 'getAggregateRowChildren', 'setRowGroups', 'clearRowGroups', 'openTooltip', 'moveColumnTo', 'moveRowTo', 'getCellLabel', 'undo', 'redo', 'getCellElement', 'focus', 'blur', 'connect'];
const defaultLayouts = [['Form'], ['Toolbar', 'Top', 'Gantt', 'Bottom', 'Pager']];
function createInternalData() {
return {
linkFromConfMaps: {},
linkToConfMaps: {},
linkUniqueMaps: {},
uFoot: false,
resizeTableWidth: 0,
// barTipTimeout: null,
// dragBarRow: null,
// dragLineRow: null,
dragLinkToStore: {
rowid: null,
type: 0
}
};
}
function createReactData() {
var _a;
return {
tableLoading: false,
proxyInited: false,
isZMax: false,
tableLinks: [],
tableData: [],
filterData: [],
formData: {},
sortData: [],
footerData: [],
tZindex: 0,
tablePage: {
total: 0,
pageSize: ((_a = getConfig().pager) === null || _a === void 0 ? void 0 : _a.pageSize) || 10,
currentPage: 1
},
showLeftView: true,
showRightView: true,
taskScaleList: [],
barTipStore: {
row: null,
content: '',
visible: false,
params: null
},
dragLinkFromStore: {
rowid: null,
type: 0
},
activeBarRowid: null,
activeLink: null,
isActiveCeLe: false,
linkList: [],
upLinkFlag: 0,
nowTime: 0,
currLeftSpacing: 0,
currRightSpacing: 0
};
}
const viewTypeLevelMaps = {
year: 19,
quarter: 17,
month: 15,
week: 13,
day: 11,
date: 9,
hour: 7,
minute: 5,
second: 3
};
function getViewTypeLevel(type) {
return viewTypeLevelMaps[type || 'date'] || viewTypeLevelMaps.date;
}
var _default = exports.default = (0, _comp.defineVxeComponent)({
name: 'VxeGantt',
mixins: [],
props: Object.assign(Object.assign({}, tableProps), {
columns: Array,
pagerConfig: Object,
proxyConfig: Object,
toolbarConfig: Object,
formConfig: Object,
zoomConfig: Object,
links: Array,
layouts: Array,
taskConfig: Object,
taskViewScaleConfig: Object,
taskNowLineConfig: Object,
taskViewConfig: Object,
taskLinkConfig: Object,
taskBarConfig: Object,
taskBarMilestoneConfig: Object,
taskBarSubviewConfig: Object,
taskBarTooltipConfig: Object,
taskSplitConfig: Object,
taskBarResizeConfig: Object,
taskBarMoveConfig: Object,
size: {
type: String,
default: () => getConfig().gantt.size || getConfig().size
}
}),
emits: _emits.ganttEmits,
setup(props, context) {
const {
slots,
emit
} = context;
const xID = _xeUtils.default.uniqueId();
// 使用已安装的组件,如果未安装则不渲染
const VxeUIFormComponent = _core.VxeUI.getComponent('VxeForm');
const VxeUIPagerComponent = _core.VxeUI.getComponent('VxePager');
const VxeTableComponent = _core.VxeUI.getComponent('VxeTable');
const VxeToolbarComponent = _core.VxeUI.getComponent('VxeToolbar');
const VxeUITooltipComponent = _core.VxeUI.getComponent('VxeTooltip');
const {
computeSize
} = useFns.useSize(props);
const reactData = (0, _vue.reactive)(createReactData());
const internalData = createInternalData();
const refElem = (0, _vue.ref)();
const refTable = (0, _vue.ref)();
const refForm = (0, _vue.ref)();
const refToolbar = (0, _vue.ref)();
const refPager = (0, _vue.ref)();
const refGanttContainerElem = (0, _vue.ref)();
const refClassifyWrapperElem = (0, _vue.ref)();
const refGanttView = (0, _vue.ref)();
const refPopupContainerElem = (0, _vue.ref)();
const refFormWrapper = (0, _vue.ref)();
const refToolbarWrapper = (0, _vue.ref)();
const refTopWrapper = (0, _vue.ref)();
const refBottomWrapper = (0, _vue.ref)();
const refPagerWrapper = (0, _vue.ref)();
const refTableWrapper = (0, _vue.ref)();
const refGanttWrapper = (0, _vue.ref)();
const refTooltip = (0, _vue.ref)();
const refResizableSplitTip = (0, _vue.ref)();
const extendTableMethods = methodKeys => {
const funcs = {};
methodKeys.forEach(name => {
funcs[name] = (...args) => {
const $xeTable = refTable.value;
if ($xeTable && $xeTable[name]) {
return $xeTable[name](...args);
}
};
});
return funcs;
};
const ganttExtendTableMethods = extendTableMethods(tableComponentMethodKeys);
tableComponentMethodKeys.forEach(name => {
ganttExtendTableMethods[name] = (...args) => {
const $xeTable = refTable.value;
if ($xeTable && $xeTable[name]) {
return $xeTable && $xeTable[name](...args);
}
};
});
const computeProxyOpts = (0, _vue.computed)(() => {
return _xeUtils.default.merge({}, _xeUtils.default.clone(getConfig().gantt.proxyConfig, true), props.proxyConfig);
});
const computeIsRespMsg = (0, _vue.computed)(() => {
const proxyOpts = computeProxyOpts.value;
return !!(_xeUtils.default.isBoolean(proxyOpts.message) ? proxyOpts.message : proxyOpts.showResponseMsg);
});
const computeIsActiveMsg = (0, _vue.computed)(() => {
const proxyOpts = computeProxyOpts.value;
return _xeUtils.default.isBoolean(proxyOpts.showActionMsg) ? proxyOpts.showActionMsg : !!proxyOpts.showActiveMsg;
});
const computePagerOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.pagerConfig, props.pagerConfig);
});
const computeFormOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.formConfig, props.formConfig);
});
const computeToolbarOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.toolbarConfig, props.toolbarConfig);
});
const computeZoomOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.zoomConfig, props.zoomConfig);
});
const computeTaskOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.taskConfig, props.taskConfig);
});
const computeTaskViewScaleOpts = (0, _vue.computed)(() => {
return _xeUtils.default.merge({}, getConfig().gantt.taskViewScaleConfig, props.taskViewScaleConfig);
});
const computeTaskNowLineOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.taskNowLineConfig, props.taskNowLineConfig);
});
const computeTaskViewOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.taskViewConfig, props.taskViewConfig);
});
const computeTaskBarOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.taskBarConfig, props.taskBarConfig);
});
const computeTaskBarMoveOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.taskBarMoveConfig, props.taskBarMoveConfig);
});
const computeTaskBarResizeOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.taskBarResizeConfig, props.taskBarResizeConfig);
});
const computeTaskSplitOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.taskSplitConfig, props.taskSplitConfig);
});
const computeTaskBarMilestoneOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.taskBarMilestoneConfig, props.taskBarMilestoneConfig);
});
const computeTaskBarSubviewOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.taskBarSubviewConfig, props.taskBarSubviewConfig);
});
const computeTaskBarTooltipOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.taskBarTooltipConfig, props.taskBarTooltipConfig);
});
const computeTaskLinkOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.taskLinkConfig, props.taskLinkConfig);
});
const computeScaleUnit = (0, _vue.computed)(() => {
const minScale = computeMinScale.value;
return minScale ? minScale.type : 'date';
});
const computeMinScale = (0, _vue.computed)(() => {
const {
taskScaleList
} = reactData;
return _xeUtils.default.last(taskScaleList);
});
const computeWeekScale = (0, _vue.computed)(() => {
const {
taskScaleList
} = reactData;
return taskScaleList.find(item => item.type === 'week');
});
const computeTaskViewScales = (0, _vue.computed)(() => {
const taskViewOpts = computeTaskViewOpts.value;
const {
scales
} = taskViewOpts;
return scales;
});
const computeTaskLinkStyle = (0, _vue.computed)(() => {
const {
lineType,
lineWidth,
lineStatus,
lineColor
} = computeTaskLinkOpts.value;
return `${lineType || ''}_${lineWidth || ''}_${lineStatus || ''}_${lineColor || ''}`;
});
const computeTitleField = (0, _vue.computed)(() => {
const taskOpts = computeTaskOpts.value;
return taskOpts.titleField || 'title';
});
const computeStartField = (0, _vue.computed)(() => {
const taskOpts = computeTaskOpts.value;
return taskOpts.startField || 'start';
});
const computeEndField = (0, _vue.computed)(() => {
const taskOpts = computeTaskOpts.value;
return taskOpts.endField || 'end';
});
const computeTypeField = (0, _vue.computed)(() => {
const taskOpts = computeTaskOpts.value;
return taskOpts.typeField || 'type';
});
const computeProgressField = (0, _vue.computed)(() => {
const taskOpts = computeTaskOpts.value;
return taskOpts.progressField || 'progress';
});
const computeScrollbarOpts = (0, _vue.computed)(() => {
return Object.assign({}, getConfig().gantt.scrollbarConfig, props.scrollbarConfig);
});
const computeScrollbarXToTop = (0, _vue.computed)(() => {
const scrollbarOpts = computeScrollbarOpts.value;
return !!(scrollbarOpts.x && scrollbarOpts.x.position === 'top');
});
const computeScrollbarYToLeft = (0, _vue.computed)(() => {
const scrollbarOpts = computeScrollbarOpts.value;
return !!(scrollbarOpts.y && scrollbarOpts.y.position === 'left');
});
const computeStyles = (0, _vue.computed)(() => {
const {
height,
maxHeight,
taskBarSubviewConfig
} = props;
const {
isZMax,
tZindex
} = reactData;
const taskViewOpts = computeTaskViewOpts.value;
const {
viewStyle,
tableStyle
} = taskViewOpts;
const taskBarOpts = computeTaskBarOpts.value;
const {
barStyle
} = taskBarOpts;
const taskBarSubviewOpts = computeTaskBarSubviewOpts.value;
const taskNowLineOpts = computeTaskNowLineOpts.value;
const {
fontColor: nlfColor,
bgColor: nlbgColor,
width: nlWidth
} = taskNowLineOpts;
const stys = {};
if (isZMax) {
stys.zIndex = tZindex;
} else {
if (height) {
stys.height = height === 'auto' || height === '100%' ? '100%' : (0, _dom.toCssUnit)(height);
}
if (maxHeight) {
stys.maxHeight = maxHeight === 'auto' || maxHeight === '100%' ? '100%' : (0, _dom.toCssUnit)(maxHeight);
}
}
if (barStyle && !_xeUtils.default.isFunction(barStyle)) {
const {
bgColor,
completedBgColor,
overviewBgColor
} = barStyle;
if (bgColor) {
stys['--vxe-ui-gantt-view-task-bar-background-color'] = bgColor;
}
if (completedBgColor) {
stys['--vxe-ui-gantt-view-task-bar-completed-background-color'] = completedBgColor;
}
if (overviewBgColor && (0, _utils.hasEnableConf)(taskBarSubviewConfig, taskBarSubviewOpts)) {
stys['--vxe-ui-gantt-view-task-bar-overview-background-color'] = overviewBgColor;
}
}
if (nlfColor) {
stys['--vxe-ui-gantt-view-task-now-line-color'] = nlfColor;
}
if (nlbgColor) {
stys['--vxe-ui-gantt-view-task-now-line-background-color'] = nlbgColor;
}
if (nlWidth) {
stys['--vxe-ui-gantt-view-task-now-line-width'] = nlWidth;
}
if (viewStyle) {
const {
cellWidth
} = viewStyle;
if (cellWidth) {
stys['--vxe-ui-gantt-view-default-cell-width'] = (0, _dom.toCssUnit)(cellWidth);
}
}
if (tableStyle) {
const {
width: defTbWidth
} = tableStyle;
if (defTbWidth) {
stys['--vxe-ui-gantt-view-table-default-width'] = (0, _dom.toCssUnit)(defTbWidth);
}
}
return stys;
});
const computeTableExtendProps = (0, _vue.computed)(() => {
const rest = {};
const ganttProps = props;
tableComponentPropKeys.forEach(key => {
if (ganttProps[key] !== undefined) {
rest[key] = ganttProps[key];
}
});
return rest;
});
const computeTableProps = (0, _vue.computed)(() => {
const {
showFooter,
seqConfig,
pagerConfig,
editConfig,
proxyConfig
} = props;
const {
isZMax,
tablePage,
footerData
} = reactData;
const taskViewOpts = computeTaskViewOpts.value;
const {
tableStyle
} = taskViewOpts;
const tableExtendProps = computeTableExtendProps.value;
const proxyOpts = computeProxyOpts.value;
const pagerOpts = computePagerOpts.value;
const isLoading = computeIsLoading.value;
const tProps = Object.assign({}, tableExtendProps, {
// 不支持修改的属性
showOverflow: true,
showHeaderOverflow: true,
showFooterOverflow: true
});
if (tableStyle) {
const {
border
} = tableStyle;
if (!_xeUtils.default.eqNull(border)) {
tProps.border = border;
}
}
if (showFooter && !tProps.footerData) {
// 如果未设置自己的标位数据,则使用代理的
tProps.footerData = footerData;
} else if (proxyOpts.footer && footerData.length) {
// 如果代理标为数据,且未请求到数据,则用自己的
tProps.footerData = footerData;
}
if (isZMax) {
if (tProps.maxHeight) {
tProps.maxHeight = '100%';
} else {
tProps.height = '100%';
}
}
if (proxyConfig && (0, _utils.isEnableConf)(proxyOpts)) {
tProps.loading = isLoading;
if (pagerConfig && proxyOpts.seq && (0, _utils.isEnableConf)(pagerOpts)) {
tProps.seqConfig = Object.assign({}, seqConfig, {
startIndex: (tablePage.currentPage - 1) * tablePage.pageSize
});
}
}
if (editConfig) {
tProps.editConfig = Object.assign({}, editConfig);
}
return tProps;
});
const computeCurrLayoutConf = (0, _vue.computed)(() => {
const {
layouts
} = props;
let confs = [];
if (layouts && layouts.length) {
confs = layouts;
} else {
confs = getConfig().gantt.layouts || defaultLayouts;
}
let headKeys = [];
let bodyKeys = [];
let footKeys = [];
if (confs.length) {
if (_xeUtils.default.isArray(confs[0])) {
headKeys = confs[0];
bodyKeys = confs[1] || [];
footKeys = confs[2] || [];
} else {
bodyKeys = confs;
}
}
return {
headKeys,
bodyKeys,
footKeys
};
});
const computeCustomCurrentPageFlag = (0, _vue.computed)(() => {
const pagerOpts = computePagerOpts.value;
return pagerOpts.currentPage;
});
const computeCustomPageSizeFlag = (0, _vue.computed)(() => {
const pagerOpts = computePagerOpts.value;
return pagerOpts.pageSize;
});
const computeCustomTotalFlag = (0, _vue.computed)(() => {
const pagerOpts = computePagerOpts.value;
return pagerOpts.total;
});
const computePageCount = (0, _vue.computed)(() => {
const {
tablePage
} = reactData;
return Math.max(Math.ceil(tablePage.total / tablePage.pageSize), 1);
});
const computeIsLoading = (0, _vue.computed)(() => {
const {
loading,
proxyConfig
} = props;
const {
tableLoading
} = reactData;
const proxyOpts = computeProxyOpts.value;
const {
showLoading
} = proxyOpts;
return loading || tableLoading && showLoading && proxyConfig && (0, _utils.isEnableConf)(proxyOpts);
});
const computeTableBorder = (0, _vue.computed)(() => {
let {
border
} = props;
const taskViewOpts = computeTaskViewOpts.value;
const {
viewStyle
} = taskViewOpts;
if (viewStyle) {
if (!_xeUtils.default.eqNull(viewStyle.border)) {
border = viewStyle.border;
}
}
if (border === true) {
return 'full';
}
if (border) {
return border;
}
return 'default';
});
const refMaps = {
refElem,
refTable,
refForm,
refToolbar,
refPager,
refGanttView,
refGanttContainerElem,
refClassifyWrapperElem,
refPopupContainerElem
};
const computeMaps = {
computeProxyOpts,
computePagerOpts,
computeFormOpts,
computeToolbarOpts,
computeZoomOpts,
computeTaskOpts,
computeTaskViewScaleOpts,
computeTaskNowLineOpts,
computeTaskViewOpts,
computeTaskBarOpts,
computeTaskBarMoveOpts,
computeTaskBarResizeOpts,
computeTaskSplitOpts,
computeTaskBarMilestoneOpts,
computeTaskBarSubviewOpts,
computeTaskBarTooltipOpts,
computeTaskLinkOpts,
computeTaskViewScales,
computeScaleUnit,
computeMinScale,
computeWeekScale,
computeTitleField,
computeStartField,
computeEndField,
computeTypeField,
computeProgressField,
computeScrollbarOpts,
computeScrollbarXToTop,
computeScrollbarYToLeft
};
computeMaps.computeTaskScaleConfs = computeTaskViewScales;
const $xeGantt = {
xID,
props: props,
context,
reactData,
internalData,
getRefMaps: () => refMaps,
getComputeMaps: () => computeMaps
};
const handleTaskScaleConfig = () => {
const taskScaleConfs = computeTaskViewScales.value;
const taskViewScaleOpts = computeTaskViewScaleOpts.value;
const scaleConfs = [];
const keyMaps = {};
const scaleList = taskScaleConfs && taskScaleConfs.length ? taskScaleConfs : ['month', 'date'];
scaleList.forEach(conf => {
const sConf = !conf || _xeUtils.default.isString(conf) ? {
type: conf
} : conf;
const type = sConf.type;
const step = sConf.step;
const level = getViewTypeLevel(type);
if (step) {
(0, _log.errLog)('vxe.error.errProp', [`step=${step}`, 'step=1']);
}
if (!type || !viewTypeLevelMaps[type]) {
(0, _log.errLog)('vxe.error.errProp', [`type=${type}`, _xeUtils.default.keys(viewTypeLevelMaps).join(',')]);
return;
}
if (keyMaps[type]) {
(0, _log.errLog)('vxe.error.repeatProp', ['type', type]);
return;
}
const scaleObj = Object.assign({}, type ? taskViewScaleOpts[type] || {} : {}, sConf, {
level
});
keyMaps[type] = true;
scaleConfs.push(scaleObj);
});
reactData.taskScaleList = _xeUtils.default.orderBy(scaleConfs, {
field: 'level',
order: 'desc'
});
};
const initToolbar = () => {
const toolbarOpts = computeToolbarOpts.value;
if (props.toolbarConfig && (0, _utils.isEnableConf)(toolbarOpts)) {
(0, _vue.nextTick)(() => {
const $xeTable = refTable.value;
const $xeToolbar = refToolbar.value;
if ($xeTable && $xeToolbar) {
$xeTable.connectToolbar($xeToolbar);
}
});
}
};
const initGanttView = () => {
const $xeTable = refTable.value;
const $ganttView = refGanttView.value;
if ($xeTable && $ganttView) {
$xeTable.handleConnectGanttView($ganttView);
}
};
const getFormData = () => {
const {
proxyConfig
} = props;
const {
formData
} = reactData;
const proxyOpts = computeProxyOpts.value;
const formOpts = computeFormOpts.value;
return proxyConfig && (0, _utils.isEnableConf)(proxyOpts) && proxyOpts.form ? formData : formOpts.data;
};
const initPages = propKey => {
const {
tablePage
} = reactData;
const {
pagerConfig
} = props;
const pagerOpts = computePagerOpts.value;
if (pagerConfig && (0, _utils.isEnableConf)(pagerOpts)) {
if (propKey) {
if (pagerOpts[propKey]) {
tablePage[propKey] = _xeUtils.default.toNumber(pagerOpts[propKey]);
}
} else {
const {
currentPage,
pageSize,
total
} = pagerOpts;
if (currentPage) {
tablePage.currentPage = currentPage;
}
if (pageSize) {
tablePage.pageSize = pageSize;
}
if (total) {
tablePage.total = total;
}
}
}
};
const triggerPendingEvent = code => {
const isActiveMsg = computeIsActiveMsg.value;
const $xeTable = refTable.value;
const selectRecords = $xeTable ? $xeTable.getCheckboxRecords() : [];
if (selectRecords.length) {
if ($xeTable) {
$xeTable.togglePendingRow(selectRecords);
}
$xeGantt.clearCheckboxRow();
} else {
if (isActiveMsg) {
if (_core.VxeUI.modal) {
_core.VxeUI.modal.message({
id: code,
content: getI18n('vxe.grid.selectOneRecord'),
status: 'warning'
});
}
}
}
};
const getRespMsg = (rest, defaultMsg) => {
const proxyOpts = computeProxyOpts.value;
const resConfigs = proxyOpts.response || proxyOpts.props || {};
const messageProp = resConfigs.message;
const $xeTable = refTable.value;
let msg;
if (rest && messageProp) {
msg = _xeUtils.default.isFunction(messageProp) ? messageProp({
data: rest,
$table: $xeTable,
$grid: null,
$gantt: $xeGantt
}) : _xeUtils.default.get(rest, messageProp);
}
return msg || getI18n(defaultMsg);
};
const handleDeleteRow = (code, alertKey, callback) => {
const isActiveMsg = computeIsActiveMsg.value;
const selectRecords = $xeGantt.getCheckboxRecords();
if (isActiveMsg) {
if (selectRecords.length) {
if (_core.VxeUI.modal) {
return _core.VxeUI.modal.confirm({
id: `cfm_${code}`,
content: getI18n(alertKey),
escClosable: true
}).then(type => {
if (type === 'confirm') {
return callback();
}
});
}
} else {
if (_core.VxeUI.modal) {
_core.VxeUI.modal.message({
id: `msg_${code}`,
content: getI18n('vxe.grid.selectOneRecord'),
status: 'warning'
});
}
}
} else {
if (selectRecords.length) {
callback();
}
}
return Promise.resolve();
};
const pageChangeEvent = params => {
const {
proxyConfig
} = props;
const {
tablePage
} = reactData;
const {
$event,
currentPage,
pageSize
} = params;
const proxyOpts = computeProxyOpts.value;
tablePage.currentPage = currentPage;
tablePage.pageSize = pageSize;
$xeGantt.dispatchEvent('page-change', params, $event);
if (proxyConfig && (0, _utils.isEnableConf)(proxyOpts)) {
$xeGantt.commitProxy('query').then(rest => {
$xeGantt.dispatchEvent('proxy-query', rest, $event);
});
}
};
const handleSortEvent = params => {
const $xeTable = refTable.value;
const {
proxyConfig
} = props;
if (!$xeTable) {
return;
}
const {
computeSortOpts
} = $xeTable.getComputeMaps();
const proxyOpts = computeProxyOpts.value;
const sortOpts = computeSortOpts.value;
// 如果是服务端排序
if (sortOpts.remote) {
reactData.sortData = params.sortList;
if (proxyConfig && (0, _utils.isEnableConf)(proxyOpts)) {
reactData.tablePage.currentPage = 1;
$xeGantt.commitProxy('query').then(rest => {
$xeGantt.dispatchEvent('proxy-query', rest, params.$event);
});
}
}
};
const sortChangeEvent = params => {
handleSortEvent(params);
$xeGantt.dispatchEvent('sort-change', params, params.$event);
};
const clearAllSortEvent = params => {
handleSortEvent(params);
$xeGantt.dispatchEvent('clear-all-sort', params, params.$event);
};
const handleFilterEvent = params => {
const $xeTable = refTable.value;
const {
proxyConfig
} = props;
if (!$xeTable) {
return;
}
const {
computeFilterOpts
} = $xeTable.getComputeMaps();
const proxyOpts = computeProxyOpts.value;
const filterOpts = computeFilterOpts.value;
// 如果是服务端过滤
if (filterOpts.remote) {
reactData.filterData = params.filterList;
if (proxyConfig && (0, _utils.isEnableConf)(proxyOpts)) {
reactData.tablePage.currentPage = 1;
internalData.uFoot = true;
$xeGantt.commitProxy('query').then(rest => {
$xeGantt.dispatchEvent('proxy-query', rest, params.$event);
});
internalData.uFoot = false;
updateQueryFooter();
}
}
};
const filterChangeEvent = params => {
handleFilterEvent(params);
$xeGantt.dispatchEvent('filter-change', params, params.$event);
};
const clearAllFilterEvent = params => {
handleFilterEvent(params);
$xeGantt.dispatchEvent('clear-all-filter', params, params.$event);
};
const submitFormEvent = params => {
const {
proxyConfig
} = props;
const proxyOpts = computeProxyOpts.value;
if (reactData.tableLoading) {
return;
}
if (proxyConfig && (0, _utils.isEnableConf)(proxyOpts)) {
internalData.uFoot = true;
$xeGantt.commitProxy('reload').then(rest => {
$xeGantt.dispatchEvent('proxy-query', Object.assign(Object.assign({}, rest), {
isReload: true
}), params.$event);
});
internalData.uFoot = false;
updateQueryFooter();
}
$xeGantt.dispatchEvent('form-submit', params, params.$event);
};
const resetFormEvent = params => {
const $xeTable = refTable.value;
const {
proxyConfig
} = props;
const {
$event
} = params;
const proxyOpts = computeProxyOpts.value;
if (proxyConfig && (0, _utils.isEnableConf)(proxyOpts)) {
if ($xeTable) {
$xeTable.clearScroll();
}
internalData.uFoot = true;
$xeGantt.commitProxy('reload').then(rest => {
$xeGantt.dispatchEvent('proxy-query', Object.assign(Object.assign({}, rest), {
isReload: true
}), $event);
});
internalData.uFoot = false;
updateQueryFooter();
}
$xeGantt.dispatchEvent('form-reset', params, $event);
};
const submitInvalidEvent = params => {
$xeGantt.dispatchEvent('form-submit-invalid', params, params.$event);
};
const collapseEvent = params => {
const {
$event
} = params;
$xeGantt.dispatchEvent('form-toggle-collapse', params, $event);
$xeGantt.dispatchEvent('form-collapse', params, $event);
};
const handleZoom = isMax => {
const {
isZMax
} = reactData;
if (isMax ? !isZMax : isZMax) {
reactData.isZMax = !isZMax;
if (reactData.tZindex < (0, _utils.getLastZIndex)()) {
reactData.tZindex = (0, _utils.nextZIndex)();
}
}
return (0, _vue.nextTick)().then(() => $xeGantt.recalculate(true)).then(() => {
setTimeout(() => $xeGantt.recalculate(true), 15);
return reactData.isZMax;
});
};
const getFuncSlot = (optSlots, slotKey) => {
const funcSlot = optSlots[slotKey];
if (funcSlot) {
if (_xeUtils.default.isString(funcSlot)) {
if (slots[funcSlot]) {
return slots[funcSlot];
} else {
(0, _log.errLog)('vxe.error.notSlot', [funcSlot]);
}
} else {
return funcSlot;
}
}
return null;
};
const getConfigSlot = slotConfigs => {
const slotConf = {};
_xeUtils.default.objectMap(slotConfigs, (slotFunc, slotKey) => {
if (slotFunc) {
if (_xeUtils.default.isString(slotFunc)) {
if (slots[slotFunc]) {
slotConf[slotKey] = slots[slotFunc];
} else {
(0, _log.errLog)('vxe.error.notSlot', [slotFunc]);
}
} else {
slotConf[slotKey] = slotFunc;
}
}
});
return slotConf;
};
const dragSplitEvent = evnt => {
const el = refElem.value;
if (!el) {
return;
}
const ganttContainerEl = refGanttContainerElem.value;
if (!ganttContainerEl) {
return;
}
const tableWrapperEl = refTableWrapper.value;
if (!tableWrapperEl) {
return;
}
const rsSplitLineEl = refResizableSplitTip.value;
if (!rsSplitLineEl) {
return;
}
const taskViewOpts = computeTaskViewOpts.value;
const containerRect = ganttContainerEl.getBoundingClientRect();
const rsSplitTipEl = rsSplitLineEl.children[0];
const disX = evnt.clientX;
const ganttWidth = ganttContainerEl.clientWidth;
const tableWidth = tableWrapperEl.clientWidth;
const tableMinWidth = taskViewOpts.tableStyle && _xeUtils.default.toNumber(taskViewOpts.tableStyle.minWidth) || 80;
let targetTableWidth = tableWidth;
let offsetLeft = -1;
(0, _dom.addClass)(el, 'is--split-drag');
const handleReStyle = evnt => {
const rsNumLeftEl = rsSplitTipEl.children[0];
const rsNumRightEl = rsSplitTipEl.children[1];
let tipHeight = 0;
if (rsNumLeftEl) {
if (offsetLeft < 0) {
rsNumLeftEl.style.display = 'none';
} else {
rsNumLeftEl.textContent = `${targetTableWidth}px`;
rsNumLeftEl.style.display = 'block';
tipHeight = rsNumLeftEl.offsetHeight;
}
}
if (rsNumRightEl) {
if (offsetLeft < 0) {
rsNumRightEl.textContent = `${Math.floor(containerRect.width - targetTableWidth)}px`;
rsNumRightEl.style.display = 'block';
tipHeight = rsNumRightEl.offsetHeight;
} else {
rsNumRightEl.style.display = 'none';
}
}
const tipTop = evnt.clientY - containerRect.top - tipHeight / 2;
rsSplitLineEl.style.left = `${targetTableWidth}px`;
rsSplitTipEl.style.top = `${Math.min(containerRect.height - tipHeight - 1, Math.max(1, tipTop))}px`;
};
document.onmousemove = evnt => {
evnt.preventDefault();
offsetLeft = evnt.clientX - disX;
targetTableWidth = Math.min(ganttWidth - 80, Math.max(tableMinWidth, tableWidth + offsetLeft));
handleReStyle(evnt);
};
document.onmouseup = () => {
document.onmousemove = null;
document.onmouseup = null;
rsSplitLineEl.style.display = '';
tableWrapperEl.style.width = `${targetTableWidth}px`;
(0, _dom.removeClass)(el, 'is--split-drag');
const $xeTable = refTable.value;
if ($xeTable) {
$xeTable.recalculate(true);
}
};
rsSplitLineEl.style.display = 'block';
handleReStyle(evnt);
};
const handleSplitLeftViewEvent = () => {
reactData.showLeftView = !reactData.showLeftView;
};
const handleSplitRightViewEvent = () => {
reactData.showRightView = !reactData.showRightView;
};
const tableCompEvents = {};
_tableEmits.tableEmits.forEach(name => {
const type = _xeUtils.default.camelCase(`on-${name}`);
tableCompEvents[type] = (...args) => emit(name, ...args);
});
const getDefaultFormData = () => {
const formOpts = computeFormOpts.value;
if (formOpts.items) {
const fData = {};
formOpts.items.forEach(item => {
const {
field,
itemRender
} = item;
if (field) {
let itemValue = null;
if (itemRender) {
const {
startField,
endField,
defaultValue
} = itemRender;
if (_xeUtils.default.isFunction(defaultValue)) {
itemValue = defaultValue({
item
});
} else if (!_xeUtils.default.isUndefined(defaultValue)) {
itemValue = defaultValue;
}
if (startField && endField) {
_xeUtils.default.set(fData, startField, null);
_xeUtils.default.set(fData, endField, null);
}
}
fData[field] = itemValue;
}
});
return fData;
}
return {};
};
const initProxy = () => {
const {
proxyConfig,
formConfig
} = props;
const {
proxyInited
} = reactData;
const proxyOpts = computeProxyOpts.value;
const formOpts = computeFormOpts.value;
if (proxyConfig && (0, _utils.isEnableConf)(proxyOpts)) {
if (formConfig && (0, _utils.isEnableConf)(formOpts) && proxyOpts.form && formOpts.items) {
reactData.formData = getDefaultFormData();
}
if (!proxyInited) {
reactData.proxyInited = true;
if (proxyOpts.autoLoad !== false) {
(0, _vue.nextTick)().then(() => {
internalData.uFoot = true;
const rest = $xeGantt.commitProxy('initial');
internalData.uFoot = false;
updateQueryFooter();
return rest;
}).then(rest => {
dispatchEvent('proxy-query', Object.assign(Object.assign({}, rest), {
isInited: true
}), new Event('initial'));
});
}
}
}
};
const updateQueryFooter = () => {
const proxyOpts = computeProxyOpts.value;
const {
ajax
} = proxyOpts;
if (ajax && ajax.queryFooter) {
return $xeGantt.commitProxy('queryFooter');
}
};
const handleGlobalKeydownEvent = evnt => {
const zoomOpts = computeZoomOpts.value;
const isEsc = globalEvents.hasKey(evnt, GLOBAL_EVENT_KEYS.ESCAPE);
if (isEsc && reactData.isZMax && zoomOpts.escRestore !== false) {
$xeGantt.triggerZoomEvent(evnt);
}
};
const dispatchEvent = (type, params, evnt) => {
emit(type, createEvent(evnt, {
$grid: null,
$gantt: $xeGantt
}, params));
};
const handleTargetEnterEvent = isClear => {
const $tooltip = refTooltip.value;
clearTimeout(internalData.barTipTimeout);
if (isClear) {
$xeGantt.closeTaskBarTooltip();
} else {
if ($tooltip && $tooltip.setActived) {
$tooltip.setActived(true);
}
}
};
const ganttMethods = {
dispatchEvent,
getEl() {
return refElem.value;
},
/**
* 提交指令,支持 code 或 button
* @param {String/Object} code 字符串或对象
*/
commitProxy(proxyTarget, ...args) {
const {
showFooter,
proxyConfig,
toolbarConfig,
pagerConfig,
editRules,
validConfig
} = props;
const {
tablePage
} = reactData;
const isActiveMsg = computeIsActiveMsg.value;
const isRespMsg = computeIsRespMsg.value;
const proxyOpts = computeProxyOpts.value;
const pagerOpts = computePagerOpts.value;
const toolbarOpts = computeToolbarOpts.value;
const {
beforeQuery,
afterQuery,
beforeQueryFooter,
afterQueryFooter,
beforeDelete,
afterDelete,
beforeSave,
afterSave,
ajax = {}
} = proxyOpts;
const resConfigs = proxyOpts.response || proxyOpts.props || {};
const $xeTable = refTable.value;
if (!$xeTable) {
return (0, _vue.nextTick)();
}
let formData = getFormData();
let button = null;
let code = null;
if (_xeUtils.default.isString(proxyTarget)) {
const {
buttons
} = toolbarOpts;
const matchObj = toolbarConfig && (0, _utils.isEnableConf)(toolbarOpts) && buttons ? _xeUtils.default.findTree(buttons, item => item.code === proxyTarget, {
children: 'dropdowns'
}) : null;
button = matchObj ? matchObj.item : null;
code = proxyTarget;
} else {
button = proxyTarget;
code = button.code;
}
const btnParams = button ? button.params : null;
switch (code) {
case 'insert':
return $xeTable.insert({});
case 'insert_edit':
return $xeTable.insert({}).then(({
row
}) => $xeTable.setEditRow(row, true));
// 已废弃
case 'insert_actived':
return $xeTable.insert({}).then(({
row
}) => $xeTable.setEditRow(row, true));
// 已废弃
case 'mark_cancel':
triggerPendingEvent(code);
break;
case 'remove':
return handleDeleteRow(code, 'vxe.grid.removeSelectRecord', () => $xeTable.removeCheckboxRow());
case 'import':
$xeTable.importData(btnParams);
break;
case 'open_import':
$xeTable.openImport(btnParams);
break;
case 'export':
$xeTable.exportData(btnParams);
break;
case 'open_export':
$xeTable.openExport(btnParams);
break;
case 'reset_custom':
return $xeTable.resetCustom(true);
case 'initial':
case 'reload':
case 'query':
{
const qMethods = ajax.query;
const qsMethods = ajax.querySuccess;
const qeMethods = ajax.queryError;
if (qMethods) {
const isInited = code === 'initial';
const isReload = code === 'reload';
if (!isInited && reactData.tableLoading) {
return (0, _vue.nextTick)();
}
let operPromise = null;
let sortList = [];
let filterList = [];
let pageParams = {};
if (pagerConfig) {
if (isInited || isReload) {
// 重置分页
tablePage.currentPage = 1;
}
if ((0, _utils.isEnableConf)(pagerOpts)) {
pageParams = Object.assign({}, tablePage);
}
}
if (isInited) {
// 重置代理表单数据
if (proxyConfig && (0, _utils.isEnableConf)(proxyOpts) && proxyOpts.form) {
formData = getDefaultFormData();
reactData.formData = formData;
}
if ($xeTable) {
const tableInternalData = $xeTable.internalData;
const {
tableFullColumn,
fullColumnFieldData
} = tableInternalData;
const {
computeSortOpts
} = $xeTable.getComputeMaps();
const sortOpts = computeSortOpts.value;
let defaultSort = sortOpts.defaultSort;
tableFullColumn.forEach(column => {
column.order = null;
});
// 如果使用默认排序
if (defaultSort) {
if (!_xeUtils.default.isArray(defaultSort)) {
defaultSort = [defaultSort];
}
sortList = defaultSort.map(item => {
const {
field,
order
} = item;
const colRest = fullColumnFieldData[field];
if (colRest) {
const column = colRest.column;
if (column) {
column.order = order;
}
}
return {
field,
property: field,
order
};
});
}
filterList = $xeTable.getCheckedFilters();
}
} else {
if ($xeTable) {
if (isReload) {
operPromise = $xeTable.clearAll();
} else {
sortList = $xeTable.getSortColumns();
filterList = $xeTable.getCheckedFilters();
}
}
}
const commitParams = {
$table: $xeTable,
$grid: null,
$gantt: $xeGantt,
code,
button,
isInited,
isReload,
page: pageParams,
sort: sortList.length ? sortList[0] : {},
sorts: sortList,
filters: filterList,
form: formData,
options: qMethods
};
reactData.sortData = sortList;
reactData.filterData = filterList;
reactData.tableLoading = true;
return Promise.all([Promise.resolve((beforeQuery || qMethods)(commitParams, ...args)), operPromise]).then(([rest]) => {
let tableData = [];
reactData.tableLoading = false;
if (rest) {
const reParams = {
data: rest,
$table: $xeTable,
$grid: null,
$gantt: $xeGantt
};
if (pagerConfig && (0, _utils.isEnableConf)(pagerOpts)) {
const totalProp = resConfigs.total;
const total = (_xeUtils.default.isFunction(totalProp) ? totalProp(reParams) : _xeUtils.default.get(rest, totalProp || 'page.total')) || 0;
tablePage.total = _xeUtils.default.toNumber(total);
const resultProp = resConfigs.result;
tableData = (_xeUtils.default.isFunction(resultProp) ? resultProp(reParams) : _xeUtils.default.get(rest, resultProp || 'result')) || [];
// 检验当前页码,不能超出当前最大页数
const pageCount = Math.max(Math.ceil(total / tablePage.pageSize), 1);
if (tablePage.currentPage > pageCount) {
tablePage.currentPage = pageCount;
}
} else {
const listProp = resConfigs.list;
if (_xeUtils.default.isArray(rest)) {
tableData = rest;
} else if (listProp) {
tableData = (_xeUtils.default.isFunction(listProp) ? listProp(reParams) : _xeUtils.default.get(rest, listProp)) || [];
}
}
if (showFooter) {
const fdProp = resConfigs.footerData;
const footerList = fdProp ? _xeUtils.default.isFunction(fdProp) ? fdProp(reParams) : _xeUtils.default.get(rest, fdProp) : [];
if (_xeUtils.default.isArray(footerList)) {
reactData.footerData = footerList;
}
}
}
if ($xeTable) {
$xeTable.loadData(tableData);
} else {
(0, _vue.nextTick)(() => {
const $xeTable = refTable.value;
if ($xeTable) {
$xeTable.loadData(tableData);
}
});
}
if (afterQuery) {
afterQuery(commitParams, ...args);
}
if (qsMethods) {
qsMethods(Object.assign(Object.assign({}, commitParams), {
response: rest
}));
}
return {
status: true
};
}).catch(rest => {
reactData.tableLoading = false;
if (qeMethods) {
qeMethods(Object.assign(Object.assign({}, commitParams), {
response: rest
}));
}