diff --git a/lib/kanban/README.md b/lib/kanban/README.md index e8881e2a70..66d74b9ada 100644 --- a/lib/kanban/README.md +++ b/lib/kanban/README.md @@ -3,5 +3,27 @@ ## 示例 ```html:example: bg-surface -
+
+
+
+
卡片1
+
+
+
卡片2
+
+
+
卡片3
+
+
+
卡片4
+
+
+
卡片5
+
+
+
卡片6
+
+
+
+
``` diff --git a/lib/kanban/dev.ts b/lib/kanban/dev.ts index 0db84656b2..d05f4dad46 100644 --- a/lib/kanban/dev.ts +++ b/lib/kanban/dev.ts @@ -12,7 +12,7 @@ import {$} from '@zui/core'; import {KanbanRegionProps, KanbanList, KanbanProps} from './src/main'; import {createKanbanData} from './dev/create-kanban-data'; -onPageLoad(() => { +onPageUpdate(() => { const kanban1Options: KanbanProps = { key: 'kanban1', data: { @@ -257,6 +257,14 @@ onPageLoad(() => { return dropInfo.col === 'assigned'; } }, + draggable: { + // 指定可以从哪个元素内部监听拖拽事件,可以为看板的或看板列表的父级元素,这样就可以实现从看板外部拖拽新的卡片到看板内部。 + dragContainer: '#kanbanExample', + }, + onDropNewItem: (info) => { + // 返回需要创建的新的卡片数据 + return {id: `new-${$.guid++}`, title: info.drag.element.innerText}; + }, }; const kanbanList = new KanbanList('#kanbanList', { items: [kanbanOptions, kanbanRegionOptions], diff --git a/lib/kanban/src/component/kanban.tsx b/lib/kanban/src/component/kanban.tsx index 5496f9ab6a..f2913228b3 100644 --- a/lib/kanban/src/component/kanban.tsx +++ b/lib/kanban/src/component/kanban.tsx @@ -266,6 +266,10 @@ export class Kanban

| undefined; + if (onDropNewItem) { + newItem = onDropNewItem.call(this, info); + } else { + newItem = $(drag.element).data(); + if (newItem?.item) { + newItem = newItem.item; + } + } + newItem = { + lane: drop.lane, + col: drop.col, + ...newItem, + }; + if (newItem) { + const colItems = data.items[drop.lane!][drop.col!]; + const newColItems = [...colItems]; + newColItems.push(newItem); + changes.items = newColItems; + changeData.list.push(newItem[itemKey] as string); + } } return {changes, data: changeData}; } @@ -376,12 +403,13 @@ export class Kanban

= { item: '.kanban-item', lane: '.kanban-lane-name', col: '.kanban-header-col', + newItem: '.kanban-new-item', }; const userOptions = typeof draggable === 'object' ? draggable : {}; const updateDropElementAttr = (dropElement: HTMLElement, info?: KanbanDropInfo) => { @@ -393,7 +421,7 @@ export class Kanban

dragTypeSelectors[x] || '').join(''), + selector: userOptions.selector || dragTypeList.map(x => dragTypeSelectors[x] || '').filter(Boolean).join(','), target: userOptions.target || ((dragElement: HTMLElement) => { const info = this._getElementInfo(dragElement); if (!info) { @@ -403,6 +431,7 @@ export class Kanban

boolean | void; onDragStart?: (info: KanbanDragInfo) => void | boolean; onDrop?: (changes: Partial, info: KanbanDropInfo, restore: () => void) => void | false; + onDropNewItem?: (info: KanbanDropInfo) => KanbanItem | undefined; /* Component lifecycle. */ beforeRender?: (options: KanbanProps) => void;