mirror of
https://github.com/apache/skywalking-booster-ui.git
synced 2025-05-02 11:24:06 +00:00
feat: update layout
This commit is contained in:
parent
91abc20fef
commit
4992d1567d
@ -19,17 +19,17 @@ import { store } from "@/store";
|
|||||||
import { GridItemData } from "@/types/dashboard";
|
import { GridItemData } from "@/types/dashboard";
|
||||||
|
|
||||||
interface DashboardState {
|
interface DashboardState {
|
||||||
layouts: GridItemData[];
|
layout: GridItemData[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const dashboardStore = defineStore({
|
export const dashboardStore = defineStore({
|
||||||
id: "dashboard",
|
id: "dashboard",
|
||||||
state: (): DashboardState => ({
|
state: (): DashboardState => ({
|
||||||
layouts: [],
|
layout: [],
|
||||||
}),
|
}),
|
||||||
actions: {
|
actions: {
|
||||||
setLayouts(data: GridItemData[]) {
|
setLayout(data: GridItemData[]) {
|
||||||
this.layouts = data;
|
this.layout = data;
|
||||||
},
|
},
|
||||||
addWidget() {
|
addWidget() {
|
||||||
const newWidget: GridItemData = {
|
const newWidget: GridItemData = {
|
||||||
@ -37,13 +37,13 @@ export const dashboardStore = defineStore({
|
|||||||
y: 0,
|
y: 0,
|
||||||
w: 12,
|
w: 12,
|
||||||
h: 3,
|
h: 3,
|
||||||
i: String(this.layouts.length),
|
i: String(this.layout.length),
|
||||||
};
|
};
|
||||||
this.layouts = this.layouts.map((d: GridItemData) => {
|
this.layout = this.layout.map((d: GridItemData) => {
|
||||||
d.y = d.y + 3;
|
d.y = d.y + 3;
|
||||||
return d;
|
return d;
|
||||||
});
|
});
|
||||||
this.layouts.push(newWidget);
|
this.layout.push(newWidget);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -27,14 +27,13 @@ limitations under the License. -->
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { toRefs, defineComponent, reactive, ref } from "vue";
|
|
||||||
import { ElButton } from "element-plus";
|
import { ElButton } from "element-plus";
|
||||||
import GridLayout from "./widget/Layout.vue";
|
import GridLayout from "./panel/Layout.vue";
|
||||||
import { GridItemData } from "@/types/dashboard";
|
import { GridItemData } from "@/types/dashboard";
|
||||||
import { useDashboardStore } from "@/store/modules/dashboard";
|
import { useDashboardStore } from "@/store/modules/dashboard";
|
||||||
|
|
||||||
const dashboardStore = useDashboardStore();
|
const dashboardStore = useDashboardStore();
|
||||||
const layouts: GridItemData[] = [
|
const layout: GridItemData[] = [
|
||||||
{ x: 0, y: 0, w: 2, h: 2, i: "0" },
|
{ x: 0, y: 0, w: 2, h: 2, i: "0" },
|
||||||
{ x: 2, y: 0, w: 2, h: 4, i: "1" },
|
{ x: 2, y: 0, w: 2, h: 4, i: "1" },
|
||||||
{ x: 4, y: 0, w: 2, h: 5, i: "2" },
|
{ x: 4, y: 0, w: 2, h: 5, i: "2" },
|
||||||
@ -56,7 +55,7 @@ const layouts: GridItemData[] = [
|
|||||||
{ x: 0, y: 9, w: 2, h: 3, i: "18" },
|
{ x: 0, y: 9, w: 2, h: 3, i: "18" },
|
||||||
{ x: 2, y: 6, w: 2, h: 2, i: "19" },
|
{ x: 2, y: 6, w: 2, h: 2, i: "19" },
|
||||||
];
|
];
|
||||||
dashboardStore.setLayouts(layouts);
|
dashboardStore.setLayout(layout);
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.dashboard-tool {
|
.dashboard-tool {
|
||||||
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
|||||||
limitations under the License. -->
|
limitations under the License. -->
|
||||||
<template>
|
<template>
|
||||||
<grid-layout
|
<grid-layout
|
||||||
v-model:layout="dashboardStore.layouts"
|
v-model:layout="dashboardStore.layout"
|
||||||
:col-num="12"
|
:col-num="12"
|
||||||
:row-height="30"
|
:row-height="30"
|
||||||
:is-draggable="true"
|
:is-draggable="true"
|
||||||
@ -22,9 +22,10 @@ limitations under the License. -->
|
|||||||
:is-mirrored="false"
|
:is-mirrored="false"
|
||||||
:vertical-compact="true"
|
:vertical-compact="true"
|
||||||
:use-css-transforms="true"
|
:use-css-transforms="true"
|
||||||
|
@layout-updated="layoutUpdatedEvent"
|
||||||
>
|
>
|
||||||
<grid-item
|
<grid-item
|
||||||
v-for="item in dashboardStore.layouts"
|
v-for="item in dashboardStore.layout"
|
||||||
:x="item.x"
|
:x="item.x"
|
||||||
:y="item.y"
|
:y="item.y"
|
||||||
:w="item.w"
|
:w="item.w"
|
||||||
@ -32,14 +33,19 @@ limitations under the License. -->
|
|||||||
:i="item.i"
|
:i="item.i"
|
||||||
:key="item.i"
|
:key="item.i"
|
||||||
>
|
>
|
||||||
{{ item.i }}
|
<Widget :item="item" />
|
||||||
</grid-item>
|
</grid-item>
|
||||||
</grid-layout>
|
</grid-layout>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { useDashboardStore } from "@/store/modules/dashboard";
|
import { useDashboardStore } from "@/store/modules/dashboard";
|
||||||
|
import { GridItemData } from "@/types/dashboard";
|
||||||
|
import Widget from "./Widget.vue";
|
||||||
|
|
||||||
const dashboardStore = useDashboardStore();
|
const dashboardStore = useDashboardStore();
|
||||||
|
function layoutUpdatedEvent(newLayout: GridItemData) {
|
||||||
|
dashboardStore.setLayout(newLayout);
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.vue-grid-layout {
|
.vue-grid-layout {
|
||||||
@ -52,7 +58,6 @@ const dashboardStore = useDashboardStore();
|
|||||||
background: #fff;
|
background: #fff;
|
||||||
box-shadow: 0px 1px 4px 0px #00000029;
|
box-shadow: 0px 1px 4px 0px #00000029;
|
||||||
border-radius: 5px;
|
border-radius: 5px;
|
||||||
// border: 1px solid black;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.vue-grid-item .resizing {
|
.vue-grid-item .resizing {
|
@ -13,48 +13,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License. -->
|
limitations under the License. -->
|
||||||
<template>
|
<template>
|
||||||
<VueDragResize
|
<div class="header">title</div>
|
||||||
:isActive="item.static"
|
<div class="body">chart</div>
|
||||||
:w="item.w"
|
|
||||||
:h="item.h"
|
|
||||||
:x="item.x"
|
|
||||||
:y="item.y"
|
|
||||||
@resizing="resize"
|
|
||||||
@dragging="resize"
|
|
||||||
>
|
|
||||||
<h3>Hello World {{ item.i }}</h3>
|
|
||||||
</VueDragResize>
|
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { defineProps, defineEmits } from "vue";
|
import { defineProps } from "vue";
|
||||||
import type { PropType } from "vue";
|
import type { PropType } from "vue";
|
||||||
import VueDragResize from "vue-drag-resize";
|
import { GridItemData } from "@/types/dashboard";
|
||||||
interface GridItemData {
|
|
||||||
x: number;
|
|
||||||
y: number;
|
|
||||||
w: number;
|
|
||||||
h: number;
|
|
||||||
i: number;
|
|
||||||
static: boolean;
|
|
||||||
}
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
item: { type: Object as PropType<GridItemData> },
|
item: { type: Object as PropType<GridItemData> },
|
||||||
});
|
});
|
||||||
const emit = defineEmits(["move"]);
|
|
||||||
|
|
||||||
function resize(newRect: {
|
|
||||||
width: number;
|
|
||||||
height: number;
|
|
||||||
top: number;
|
|
||||||
left: number;
|
|
||||||
}) {
|
|
||||||
const m = {
|
|
||||||
...props.item,
|
|
||||||
x: newRect.left,
|
|
||||||
y: newRect.top,
|
|
||||||
w: newRect.width,
|
|
||||||
h: newRect.height,
|
|
||||||
};
|
|
||||||
emit("move", m);
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue
Block a user