set layouts

This commit is contained in:
Qiuxia Fan 2022-03-14 22:45:50 +08:00
parent 71c629b83a
commit bcbb3456b2
9 changed files with 158 additions and 119 deletions

View File

@ -15,7 +15,6 @@ limitations under the License. -->
<template> <template>
<router-view :key="$route.fullPath" /> <router-view :key="$route.fullPath" />
</template> </template>
<style> <style>
#app { #app {
color: #2c3e50; color: #2c3e50;

View File

@ -17,7 +17,10 @@
export const AllLayout = { export const AllLayout = {
id: "0", id: "0",
configuration: { configuration: {
name: "Global", name: "All Layout",
layer: "GENERAL",
entity: "All",
date: new Date().getTime(),
isRoot: true, isRoot: true,
children: [ children: [
{ {
@ -172,7 +175,10 @@ export const AllLayout = {
export const ServiceLayout = { export const ServiceLayout = {
id: "1", id: "1",
configuration: { configuration: {
name: "Service", name: "Service Layout",
layer: "GENERAL",
entity: "Service",
date: new Date().getTime(),
isRoot: true, isRoot: true,
children: [ children: [
{ {
@ -556,7 +562,10 @@ export const ServiceLayout = {
export const EndpointLayout = { export const EndpointLayout = {
id: "2", id: "2",
configuration: { configuration: {
name: "Endpoint", name: "Endpoint Layout",
layer: "GENERAL",
entity: "Endpoint",
date: new Date().getTime(),
isRoot: true, isRoot: true,
children: [ children: [
{ {
@ -731,7 +740,10 @@ export const EndpointLayout = {
export const InstanceLayout = { export const InstanceLayout = {
id: "3", id: "3",
configuration: { configuration: {
name: "Instance", name: "Instance Layout",
layer: "GENERAL",
entity: "ServiceInstance",
date: new Date().getTime(),
isRoot: true, isRoot: true,
children: [ children: [
{ {
@ -882,6 +894,9 @@ export const ServiceRelationLayout = {
id: "4", id: "4",
configuration: { configuration: {
name: "Service Relation Layout", name: "Service Relation Layout",
layer: "GENERAL",
entity: "ServiceRelation",
date: new Date().getTime(),
isRoot: true, isRoot: true,
children: [ children: [
{ {
@ -957,6 +972,9 @@ export const InstanceRelationLayout = {
id: "5", id: "5",
configuration: { configuration: {
name: "Service Instance Relation Layout", name: "Service Instance Relation Layout",
layer: "GENERAL",
entity: "ServiceInstanceRelation",
date: new Date().getTime(),
isRoot: true, isRoot: true,
children: [ children: [
{ {
@ -987,6 +1005,9 @@ export const EndpointRelationLayout = {
id: "5", id: "5",
configuration: { configuration: {
name: "Endpoint Relation Layout", name: "Endpoint Relation Layout",
layer: "GENERAL",
entity: "EndpointRelation",
date: new Date().getTime(),
isRoot: true, isRoot: true,
children: [ children: [
{ {

View File

@ -21,24 +21,6 @@ limitations under the License. -->
</router-view> </router-view>
</section> </section>
</template> </template>
<script lang="ts" setup>
import { ElMessage } from "element-plus";
import { useAppStoreWithOut } from "@/store/modules/app";
const appStore = useAppStoreWithOut();
appStore.queryOAPTimeInfo();
fetchTemplates();
async function fetchTemplates() {
const res = await appStore.getAllTemplates();
if (res.errors) {
ElMessage.error(res.errors);
return;
}
// sessionStorage.setItem("templates", "[]");
}
</script>
<style lang="scss" scoped> <style lang="scss" scoped>
.app-main { .app-main {
height: calc(100% - 40px); height: calc(100% - 40px);

View File

@ -23,11 +23,15 @@ import i18n from "./locales";
import "element-plus/dist/index.css"; import "element-plus/dist/index.css";
import "./styles/index.scss"; import "./styles/index.scss";
import ElementPlus from "element-plus"; import ElementPlus from "element-plus";
import { useAppStoreWithOut } from "@/store/modules/app";
const appStore = useAppStoreWithOut();
const app = createApp(App); const app = createApp(App);
app.use(ElementPlus, { size: "small", zIndex: 3000 }); app.use(ElementPlus, { size: "small", zIndex: 3000 });
app.use(components); app.use(components);
app.use(i18n); app.use(i18n);
app.use(store); app.use(store);
app.use(router).mount("#app"); appStore.queryOAPTimeInfo().then(() => {
app.use(router).mount("#app");
});

View File

@ -57,4 +57,5 @@ router.beforeEach((to, from, next) => {
next(); next();
} }
}); });
export default router; export default router;

View File

@ -22,7 +22,6 @@ import getLocalTime from "@/utils/localtime";
import { AxiosResponse } from "axios"; import { AxiosResponse } from "axios";
import dateFormatStep, { dateFormatTime } from "@/utils/dateFormat"; import dateFormatStep, { dateFormatTime } from "@/utils/dateFormat";
import { TimeType } from "@/constants/data"; import { TimeType } from "@/constants/data";
import { getAllTemplates } from "@/graphql/fragments/app";
/*global Nullable*/ /*global Nullable*/
interface AppState { interface AppState {
durationRow: any; durationRow: any;
@ -156,14 +155,6 @@ export const appStore = defineStore({
return res.data; return res.data;
}, },
async getAllTemplates() {
const res: AxiosResponse = await graphql.query("getTemplates").params({});
if (res.data.errors) {
return res.data;
}
return res.data;
},
}, },
}); });
export function useAppStoreWithOut(): any { export function useAppStoreWithOut(): any {

View File

@ -229,28 +229,6 @@ export const dashboardStore = defineStore({
}, },
setEntity(type: string) { setEntity(type: string) {
this.entity = type; this.entity = type;
// todo
if (type === "ServiceInstance") {
this.layout = InstanceLayout.configuration.children;
}
if (type === "Endpoint") {
this.layout = EndpointLayout.configuration.children;
}
if (type == "All") {
this.layout = AllLayout.configuration.children;
}
if (type == "Service") {
this.layout = ServiceLayout.configuration.children;
}
if (type == "ServiceRelation") {
this.layout = ServiceRelationLayout.configuration.children;
}
if (type == "ServiceInstanceRelation") {
this.layout = InstanceRelationLayout.configuration.children;
}
if (type == "EndpointRelation") {
this.layout = EndpointRelationLayout.configuration.children;
}
}, },
setTopology(show: boolean) { setTopology(show: boolean) {
this.showTopology = show; this.showTopology = show;
@ -303,6 +281,50 @@ export const dashboardStore = defineStore({
const res: AxiosResponse = await query(param); const res: AxiosResponse = await query(param);
return res.data; return res.data;
}, },
async getAllTemplates() {
const res: AxiosResponse = await graphql.query("getTemplates").params({});
if (res.data.errors) {
return res.data;
}
return res.data;
},
async fetchTemplates() {
const res = await this.getAllTemplates();
if (res.errors) {
return res;
}
const data = [
ServiceLayout,
AllLayout,
EndpointLayout,
InstanceLayout,
ServiceRelationLayout,
InstanceRelationLayout,
EndpointRelationLayout,
].map((t: any) => {
t.configuration = JSON.stringify(t.configuration);
return t;
});
const list = [];
for (const t of data) {
const c = JSON.parse(t.configuration);
const key = [c.layer, c.entity, c.name.split(" ").join("-")].join("_");
list.push({
id: t.id,
layer: c.layer,
entity: c.entity,
name: c.name,
date: c.date,
});
console.log(key);
sessionStorage.setItem(key, JSON.stringify(t));
}
sessionStorage.setItem("dashboards", JSON.stringify(list));
return res;
},
}, },
}); });

View File

@ -39,6 +39,7 @@ limitations under the License. -->
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useRoute } from "vue-router";
import GridLayout from "./panel/Layout.vue"; import GridLayout from "./panel/Layout.vue";
// import { LayoutConfig } from "@/types/dashboard"; // import { LayoutConfig } from "@/types/dashboard";
import Tool from "./panel/Tool.vue"; import Tool from "./panel/Tool.vue";
@ -47,30 +48,32 @@ import TopologyConfig from "./configuration/Topology.vue";
import Topology from "./related/topology/Index.vue"; import Topology from "./related/topology/Index.vue";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
import { ElMessage } from "element-plus";
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const { t } = useI18n(); const { t } = useI18n();
// fetch layout data from serve side const p = useRoute().params;
// const layout: any[] = [ const layoutKey = `${p.layerId}_${p.entity}_${p.name}`;
// { x: 0, y: 0, w: 4, h: 12, i: "0" },
// { x: 4, y: 0, w: 4, h: 12, i: "1" },
// { x: 8, y: 0, w: 4, h: 15, i: "2" },
// { x: 12, y: 0, w: 4, h: 9, i: "3" },
// { x: 16, y: 0, w: 4, h: 9, i: "4" },
// { x: 20, y: 0, w: 4, h: 9, i: "5" },
// { x: 0, y: 12, w: 4, h: 15, i: "7" },
// { x: 4, y: 12, w: 4, h: 15, i: "8" },
// { x: 8, y: 15, w: 4, h: 12, i: "9" },
// { x: 12, y: 9, w: 4, h: 12, i: "10" },
// { x: 16, y: 9, w: 4, h: 12, i: "11" },
// { x: 20, y: 9, w: 4, h: 15, i: "12" },
// { x: 0, y: 27, w: 4, h: 12, i: "14" },
// { x: 4, y: 27, w: 4, h: 12, i: "15" },
// { x: 8, y: 27, w: 4, h: 15, i: "16" },
// ];
// dashboardStore.setLayout(layout);
appStore.setPageTitle("Dashboard Name"); appStore.setPageTitle("Dashboard Name");
setTemplate();
async function setTemplate() {
if (!sessionStorage.getItem("dashboards")) {
const res = await dashboardStore.fetchTemplates();
if (res.errors) {
dashboardStore.setLayout([]);
ElMessage.error(res.errors);
return;
}
}
const c: { configuration: string; id: string } = JSON.parse(
sessionStorage.getItem(layoutKey) || "{}"
);
const layout = JSON.parse(c.configuration || "") || {};
dashboardStore.setLayout(layout.children || []);
}
function handleClick(e: any) { function handleClick(e: any) {
e.stopPropagation(); e.stopPropagation();
if (e.target.className === "ds-main") { if (e.target.className === "ds-main") {

View File

@ -23,7 +23,7 @@ limitations under the License. -->
> >
<template #append> <template #append>
<el-button size="small"> <el-button size="small">
<Icon size="lg" iconName="search" /> <Icon size="sm" iconName="search" />
</el-button> </el-button>
</template> </template>
</el-input> </el-input>
@ -33,28 +33,42 @@ limitations under the License. -->
</el-button> </el-button>
</router-link> </router-link>
</div> </div>
<el-table :data="tableData" style="width: 100%" max-height="550"> <div class="table">
<el-table-column fixed prop="name" label="Name" /> <el-table
<el-table-column prop="type" label="Type" /> :border="true"
<el-table-column prop="date" label="Date" /> :data="dashboards"
<el-table-column label="Operations"> :style="{ width: '100%' }"
<template #default="scope"> max-height="550"
<el-button size="small" @click="handleEdit(scope.$index, scope.row)"> >
{{ t("view") }} <el-table-column fixed prop="name" label="Name" />
</el-button> <el-table-column prop="layer" label="Layer" />
<el-button size="small" @click="handleEdit(scope.$index, scope.row)"> <el-table-column prop="entity" label="Entity" />
{{ t("edit") }} <el-table-column prop="date" label="Date" />
</el-button> <el-table-column label="Operations">
<el-button <template #default="scope">
size="small" <el-button
type="danger" size="small"
@click="handleDelete(scope.$index, scope.row)" @click="handleEdit(scope.$index, scope.row)"
> >
{{ t("delete") }} {{ t("view") }}
</el-button> </el-button>
</template> <!-- <el-button
</el-table-column> size="small"
</el-table> @click="handleEdit(scope.$index, scope.row)"
>
{{ t("edit") }}
</el-button> -->
<el-button
size="small"
type="danger"
@click="handleDelete(scope.$index, scope.row)"
>
{{ t("delete") }}
</el-button>
</template>
</el-table-column>
</el-table>
</div>
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
@ -62,8 +76,11 @@ import { ref } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { ElTable, ElTableColumn, ElButton, ElInput } from "element-plus"; import { ElTable, ElTableColumn, ElButton, ElInput } from "element-plus";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
import { useDashboardStore } from "@/store/modules/dashboard";
import { ElMessage } from "element-plus";
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const dashboardStore = useDashboardStore();
appStore.setPageTitle("Dashboard List"); appStore.setPageTitle("Dashboard List");
// # - os-linux // # - os-linux
// # - k8s // # - k8s
@ -77,29 +94,22 @@ appStore.setPageTitle("Dashboard List");
// # - browser // # - browser
// # - skywalking // # - skywalking
const { t } = useI18n(); const { t } = useI18n();
const dashboards = ref<any[]>([]);
const searchText = ref<string>(""); const searchText = ref<string>("");
const tableData = [
{ setList();
date: "2016-05-03",
name: "xxx", async function setList() {
type: "general", if (!sessionStorage.getItem("dashboards")) {
}, const res = await dashboardStore.fetchTemplates();
{ if (res.errors) {
date: "2016-05-02", dashboards.value = [];
name: "xxx", ElMessage.error(res.errors);
type: "k8s", return;
}, }
{ }
date: "2016-05-04", dashboards.value = JSON.parse(sessionStorage.getItem("dashboards") || "");
name: "xxx", }
type: "database",
},
{
date: "2016-05-01",
name: "xxx",
type: "mesh",
},
];
const handleEdit = (index: number, row: any) => { const handleEdit = (index: number, row: any) => {
console.log(index, row); console.log(index, row);
}; };
@ -120,4 +130,10 @@ const handleDelete = (index: number, row: any) => {
width: 300px; width: 300px;
margin-left: 20px; margin-left: 20px;
} }
.table {
padding: 20px;
background-color: #fff;
border-radius: 3px;
}
</style> </style>