diff --git a/src/locales/lang/en.ts b/src/locales/lang/en.ts index 3c7740d1..35d65d50 100644 --- a/src/locales/lang/en.ts +++ b/src/locales/lang/en.ts @@ -100,6 +100,8 @@ const msg = { id: "ID", setRoot: "Set this to root", setNormal: "Set this to normal", + export: "Export Dashboard Templates", + import: "Import Dashboard Templates", hourTip: "Select Hour", minuteTip: "Select Minute", secondTip: "Select Second", diff --git a/src/locales/lang/zh.ts b/src/locales/lang/zh.ts index 9f950a96..ba53623b 100644 --- a/src/locales/lang/zh.ts +++ b/src/locales/lang/zh.ts @@ -100,6 +100,8 @@ const msg = { id: "编号", setRoot: "设置成为根", setNormal: "设置成为普通", + export: "导出仪表板模板", + import: "导入仪表板模板", hourTip: "选择小时", minuteTip: "选择分钟", secondTip: "选择秒数", diff --git a/src/store/modules/dashboard.ts b/src/store/modules/dashboard.ts index d00a43e3..19019a2d 100644 --- a/src/store/modules/dashboard.ts +++ b/src/store/modules/dashboard.ts @@ -413,8 +413,8 @@ export const dashboardStore = defineStore({ this.dashboards.push({ id: json.id, name: this.currentDashboard.name, - layer: this.layerId, - entity: this.entity, + layer: this.currentDashboard.layer, + entity: this.currentDashboard.entity, isRoot: true, }); const key = [ diff --git a/src/types/dashboard.ts b/src/types/dashboard.ts index b0104a75..1ade1404 100644 --- a/src/types/dashboard.ts +++ b/src/types/dashboard.ts @@ -16,7 +16,7 @@ */ export type DashboardItem = { - id: string; + id?: string; entity: string; layer: string; isRoot: string; diff --git a/src/utils/file.ts b/src/utils/file.ts new file mode 100644 index 00000000..0902bf8d --- /dev/null +++ b/src/utils/file.ts @@ -0,0 +1,44 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export const readFile = (event: any) => { + return new Promise((resolve) => { + const { files } = event.target; + if (files.length < 1) { + return; + } + const file = files[0]; + const reader: FileReader = new FileReader(); + reader.readAsText(file); + reader.onload = function () { + if (typeof this.result === "string") { + resolve(JSON.parse(this.result)); + } + }; + }); +}; +export const saveFile = (data: any, name: string) => { + const newData = JSON.stringify(data); + const tagA = document.createElement("a"); + tagA.download = name; + tagA.style.display = "none"; + const blob = new Blob([newData]); + tagA.href = URL.createObjectURL(blob); + document.body.appendChild(tagA); + tagA.click(); + document.body.removeChild(tagA); +}; diff --git a/src/views/dashboard/List.vue b/src/views/dashboard/List.vue index 6f7ce640..0f047482 100644 --- a/src/views/dashboard/List.vue +++ b/src/views/dashboard/List.vue @@ -36,12 +36,13 @@ limitations under the License. -->