This commit is contained in:
Qiuxia Fan 2022-03-16 15:16:25 +08:00
parent 3985856f97
commit 1af4adcb96
3 changed files with 25 additions and 57 deletions

View File

@ -19,6 +19,7 @@ import { store } from "@/store";
import { LayoutConfig } from "@/types/dashboard"; import { LayoutConfig } from "@/types/dashboard";
import graphql from "@/graphql"; import graphql from "@/graphql";
import query from "@/graphql/fetch"; import query from "@/graphql/fetch";
import { DashboardItem } from "@/types/dashboard";
// import { // import {
// ServiceLayout, // ServiceLayout,
// AllLayout, // AllLayout,
@ -45,13 +46,8 @@ interface DashboardState {
selectorStore: any; selectorStore: any;
showTopology: boolean; showTopology: boolean;
currentTabItems: LayoutConfig[]; currentTabItems: LayoutConfig[];
dashboards: { name: string; layer: string; entity: string; id: string }[]; dashboards: DashboardItem[];
currentDashboard: Nullable<{ currentDashboard: Nullable<DashboardItem>;
name: string;
layer: string;
entity: string;
id: string;
}>;
} }
export const dashboardStore = defineStore({ export const dashboardStore = defineStore({
@ -74,24 +70,11 @@ export const dashboardStore = defineStore({
setLayout(data: LayoutConfig[]) { setLayout(data: LayoutConfig[]) {
this.layout = data; this.layout = data;
}, },
resetDashboards( resetDashboards(list: DashboardItem[]) {
list: {
name: string;
layer: string;
entity: string;
id: string;
isRoot: boolean;
}[]
) {
this.dashboards = list; this.dashboards = list;
sessionStorage.setItem("dashboards", JSON.stringify(list)); sessionStorage.setItem("dashboards", JSON.stringify(list));
}, },
setCurrentDashboard(item: { setCurrentDashboard(item: DashboardItem) {
name: string;
layer: string;
entity: string;
id: string;
}) {
this.currentDashboard = item; this.currentDashboard = item;
}, },
addControl(type: string) { addControl(type: string) {
@ -402,7 +385,7 @@ export const dashboardStore = defineStore({
json = res.data.changeTemplate; json = res.data.changeTemplate;
} else { } else {
const index = this.dashboards.findIndex( const index = this.dashboards.findIndex(
(d: { name: string; entity: string; layer: string; id: string }) => (d: DashboardItem) =>
d.name === this.currentDashboard.name && d.name === this.currentDashboard.name &&
d.entity === this.currentDashboard.entity && d.entity === this.currentDashboard.entity &&
d.layer === this.currentDashboard.layerId d.layer === this.currentDashboard.layerId

View File

@ -14,6 +14,14 @@
* 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.
*/ */
export type DashboardItem = {
id: string;
entity: string;
layer: string;
isRoot: string;
name: string;
};
export interface LayoutConfig { export interface LayoutConfig {
x: number; x: number;
y: number; y: number;

View File

@ -38,7 +38,7 @@ limitations under the License. -->
<el-table <el-table
:border="true" :border="true"
:data="dashboards" :data="dashboards"
:style="{ width: '100%' }" :style="{ width: '100%', fontSize: '13px' }"
max-height="550" max-height="550"
v-loading="loading" v-loading="loading"
> >
@ -83,11 +83,12 @@ limitations under the License. -->
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue"; import { ref } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { ElTable, ElTableColumn, ElButton, ElInput } from "element-plus"; import { ElMessageBox, ElMessage } from "element-plus";
import type { ElTable } from "element-plus";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import router from "@/router"; import router from "@/router";
import { ElMessageBox, ElMessage } from "element-plus"; import { DashboardItem } from "@/types/dashboard";
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
@ -104,9 +105,10 @@ appStore.setPageTitle("Dashboard List");
// # - browser // # - browser
// # - skywalking // # - skywalking
const { t } = useI18n(); const { t } = useI18n();
const dashboards = ref<{ name: string; layer: string; entity: string }[]>([]); const dashboards = ref<DashboardItem[]>([]);
const searchText = ref<string>(""); const searchText = ref<string>("");
const loading = ref<boolean>(false); const loading = ref<boolean>(false);
const multipleTableRef = ref<InstanceType<typeof ElTable>>();
setList(); setList();
@ -114,25 +116,13 @@ async function setList() {
await dashboardStore.setDashboards(); await dashboardStore.setDashboards();
dashboards.value = dashboardStore.dashboards; dashboards.value = dashboardStore.dashboards;
} }
const handleView = (row: { const handleView = (row: DashboardItem) => {
entity: string;
layer: string;
name: string;
id: string;
isRoot: boolean;
}) => {
dashboardStore.setCurrentDashboard(row); dashboardStore.setCurrentDashboard(row);
router.push( router.push(
`/dashboard/${row.layer}/${row.entity}/${row.name.split(" ").join("-")}` `/dashboard/${row.layer}/${row.entity}/${row.name.split(" ").join("-")}`
); );
}; };
async function setRoot(row: { async function setRoot(row: DashboardItem) {
entity: string;
layer: string;
name: string;
id: string;
isRoot: boolean;
}) {
const items: any[] = []; const items: any[] = [];
loading.value = true; loading.value = true;
for (const d of dashboardStore.dashboards) { for (const d of dashboardStore.dashboards) {
@ -195,12 +185,7 @@ async function setRoot(row: {
searchDashboards(); searchDashboards();
loading.value = false; loading.value = false;
} }
function handleEdit(row: { function handleEdit(row: DashboardItem) {
entity: string;
layer: string;
name: string;
id: string;
}) {
ElMessageBox.prompt("Please input dashboard name", "Edit", { ElMessageBox.prompt("Please input dashboard name", "Edit", {
confirmButtonText: "OK", confirmButtonText: "OK",
cancelButtonText: "Cancel", cancelButtonText: "Cancel",
@ -216,10 +201,7 @@ function handleEdit(row: {
}); });
}); });
} }
async function updateName( async function updateName(d: DashboardItem, value: string) {
d: { entity: string; layer: string; name: string; id: string },
value: string
) {
const key = [d.layer, d.entity, d.name.split(" ").join("-")].join("_"); const key = [d.layer, d.entity, d.name.split(" ").join("-")].join("_");
const layout = sessionStorage.getItem(key) || "{}"; const layout = sessionStorage.getItem(key) || "{}";
const c = { const c = {
@ -265,12 +247,7 @@ async function updateName(
); );
searchText.value = ""; searchText.value = "";
} }
async function handleDelete(row: { async function handleDelete(row: DashboardItem) {
entity: string;
layer: string;
name: string;
id: string;
}) {
dashboardStore.setCurrentDashboard(row); dashboardStore.setCurrentDashboard(row);
loading.value = true; loading.value = true;
await dashboardStore.deleteDashboard(); await dashboardStore.deleteDashboard();