fix: add controls

This commit is contained in:
Qiuxia Fan 2022-03-03 22:07:37 +08:00
parent f904792eca
commit f7c2c8549b
3 changed files with 14 additions and 22 deletions

View File

@ -207,9 +207,11 @@ export const dashboardStore = defineStore({
}, },
removeTabItem(item: LayoutConfig, index: number) { removeTabItem(item: LayoutConfig, index: number) {
const idx = this.layout.findIndex((d: LayoutConfig) => d.i === item.i); const idx = this.layout.findIndex((d: LayoutConfig) => d.i === item.i);
for (const item of this.layout[idx].children[index].children) { if (this.selectedGrid) {
if (this.selectedGrid.i === item.i) { for (const item of this.layout[idx].children[index].children) {
this.selectedGrid = null; if (this.selectedGrid.i === item.i) {
this.selectedGrid = null;
}
} }
} }
if (this.layout[idx].children) { if (this.layout[idx].children) {
@ -271,6 +273,7 @@ export const dashboardStore = defineStore({
}; };
this.selectedGrid = this.selectedGrid =
this.layout[index].children[tabIndex].children[itemIndex]; this.layout[index].children[tabIndex].children[itemIndex];
this.setCurrentTabItems(this.layout[index].children[tabIndex].children);
return; return;
} }
this.layout[index] = { this.layout[index] = {

View File

@ -56,9 +56,8 @@ limitations under the License. -->
:row-height="10" :row-height="10"
:is-draggable="true" :is-draggable="true"
:is-resizable="true" :is-resizable="true"
:vertical-compact="true"
:use-css-transforms="true"
:responsive="true" :responsive="true"
@layout-updated="layoutUpdatedEvent"
> >
<grid-item <grid-item
v-for="item in dashboardStore.currentTabItems" v-for="item in dashboardStore.currentTabItems"
@ -112,15 +111,12 @@ export default defineComponent({
.children .children
); );
function layoutUpdatedEvent(newLayout: LayoutConfig[]) {
dashboardStore.setCurrentTabItems(newLayout);
}
function clickTabs(e: Event, idx: number) { function clickTabs(e: Event, idx: number) {
e.stopPropagation(); e.stopPropagation();
activeTabIndex.value = idx; activeTabIndex.value = idx;
dashboardStore.activeGridItem( dashboardStore.activeGridItem(props.data.i);
`${props.data.i}-${activeTabIndex.value}-0` dashboardStore.selectWidget(props.data);
); dashboardStore.setActiveTabIndex(idx);
dashboardStore.setCurrentTabItems( dashboardStore.setCurrentTabItems(
dashboardStore.layout[props.data.i].children[activeTabIndex.value] dashboardStore.layout[props.data.i].children[activeTabIndex.value]
.children .children
@ -154,13 +150,8 @@ export default defineComponent({
`${props.data.i}-${activeTabIndex.value}-${item.i}` `${props.data.i}-${activeTabIndex.value}-${item.i}`
); );
} }
function breakpointChangedEvent(newBreakpoint: any, newLayout: any) { function layoutUpdatedEvent(newLayout: LayoutConfig[]) {
console.log( dashboardStore.setCurrentTabItems(newLayout);
"BREAKPOINT CHANGED breakpoint=",
newBreakpoint,
", layout: ",
newLayout
);
} }
document.body.addEventListener("click", handleClick, false); document.body.addEventListener("click", handleClick, false);
watch( watch(
@ -179,14 +170,13 @@ export default defineComponent({
} }
); );
return { return {
layoutUpdatedEvent,
clickTabGrid, clickTabGrid,
editTabName, editTabName,
addTabItem, addTabItem,
deleteTabItem, deleteTabItem,
removeTab, removeTab,
clickTabs, clickTabs,
layoutUpdatedEvent,
breakpointChangedEvent,
...toRefs(props), ...toRefs(props),
activeTabWidget, activeTabWidget,
dashboardStore, dashboardStore,
@ -203,7 +193,7 @@ export default defineComponent({
span { span {
display: inline-block; display: inline-block;
padding: 0 10px; padding: 0 20px;
margin: 0 10px; margin: 0 10px;
height: 40px; height: 40px;
line-height: 40px; line-height: 40px;

View File

@ -19,7 +19,6 @@ limitations under the License. -->
:row-height="10" :row-height="10"
:is-draggable="true" :is-draggable="true"
:is-resizable="true" :is-resizable="true"
:responsive="true"
@layout-updated="layoutUpdatedEvent" @layout-updated="layoutUpdatedEvent"
> >
<grid-item <grid-item