diff --git a/src/hooks/useDashboardsSession.ts b/src/hooks/useDashboardsSession.ts index b2ae9c2e..e7c332b8 100644 --- a/src/hooks/useDashboardsSession.ts +++ b/src/hooks/useDashboardsSession.ts @@ -14,12 +14,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - +import { useDashboardStore } from "@/store/modules/dashboard"; export default function getDashboard(param: { name: string; layer: string; entity: string; }) { + const dashboardStore = useDashboardStore(); const list = JSON.parse(sessionStorage.getItem("dashboards") || "[]"); const dashboard = list.find( (d: { name: string; layer: string; entity: string }) => @@ -27,8 +28,9 @@ export default function getDashboard(param: { d.entity === param.entity && d.layer === param.layer ); + const all = dashboardStore.layout; const widgets = []; - for (const item of dashboard) { + for (const item of all) { if (item.type === "Tab") { if (item.children && item.children.length) { for (const child of item.children) { diff --git a/src/views/dashboard/configuration/widget/AssociateOptions.vue b/src/views/dashboard/configuration/widget/AssociateOptions.vue index 47668622..6bd7c423 100644 --- a/src/views/dashboard/configuration/widget/AssociateOptions.vue +++ b/src/views/dashboard/configuration/widget/AssociateOptions.vue @@ -43,18 +43,18 @@ const widgets = computed(() => { const isRank = ["TopList"].includes( dashboardStore.selectedGrid.graph && dashboardStore.selectedGrid.graph.type ); - const w = getDashboard(dashboardStore.currentDashboard).widgets; - const items = w.filter( + const { widgets } = getDashboard(dashboardStore.currentDashboard); + const items = widgets.filter( (d: { value: string; label: string } & LayoutConfig) => { if (dashboardStore.selectedGrid.id !== d.id) { - if (isLinear) { + if (isLinear && d.widget) { d.value = d.id || ""; - d.label = (d.widget && d.widget.title) || d.type || ""; + d.label = d.widget.name || d.id || ""; return d; } - if (isRank && d.type !== "Widget") { + if (isRank && d.type !== "Widget" && d.widget) { d.value = d.id || ""; - d.label = (d.widget && d.widget.title) || d.type || ""; + d.label = d.widget.name || d.id || ""; return d; } } diff --git a/src/views/dashboard/configuration/widget/WidgetOptions.vue b/src/views/dashboard/configuration/widget/WidgetOptions.vue index f6ef40f1..6d8b8aa3 100644 --- a/src/views/dashboard/configuration/widget/WidgetOptions.vue +++ b/src/views/dashboard/configuration/widget/WidgetOptions.vue @@ -74,7 +74,14 @@ function updateWidgetConfig(param: { [key: string]: string }) { function updateWidgetName(param: { [key: string]: string }) { const key = Object.keys(param)[0]; const n = decodeURIComponent(param[key]); - const widgets = getDashboard(dashboardStore.currentDashboard).widgets; + const pattern = /^[A-Za-z0-9-_\u4e00-\u9fa5]{4,30}$/; + if (!pattern.test(n)) { + ElMessage.warning( + "The name only supports Chinese and English, horizontal lines and underscores" + ); + return; + } + const { widgets } = getDashboard(dashboardStore.currentDashboard); const item = widgets.find( (d: LayoutConfig) => d.widget && d.widget.name === n );