add widget id

This commit is contained in:
Qiuxia Fan 2022-06-28 18:35:26 +08:00
parent 5b1637b9ec
commit ec9749b90c
7 changed files with 69 additions and 14 deletions

View File

@ -143,6 +143,7 @@ const msg = {
pause: "Pause", pause: "Pause",
begin: "Start", begin: "Start",
associateOptions: "Association Options", associateOptions: "Association Options",
widget: "Widget",
seconds: "Seconds", seconds: "Seconds",
hourTip: "Select Hour", hourTip: "Select Hour",
minuteTip: "Select Minute", minuteTip: "Select Minute",

View File

@ -143,6 +143,7 @@ const msg = {
pause: "Pausa", pause: "Pausa",
begin: "Inicio", begin: "Inicio",
associateOptions: "Opciones de asociación", associateOptions: "Opciones de asociación",
widget: "Dispositivo pequeño",
seconds: "Segundos", seconds: "Segundos",
hourTip: "Seleccione Hora", hourTip: "Seleccione Hora",
minuteTip: "Seleccione Minuto", minuteTip: "Seleccione Minuto",

View File

@ -141,6 +141,7 @@ const msg = {
pause: "暂停", pause: "暂停",
begin: "开始", begin: "开始",
associateOptions: "关联选项", associateOptions: "关联选项",
widget: "部件",
seconds: "秒", seconds: "秒",
hourTip: "选择小时", hourTip: "选择小时",
minuteTip: "选择分钟", minuteTip: "选择分钟",

View File

@ -66,7 +66,8 @@ export default defineComponent({
sessionStorage.getItem(layoutKey.value) || "{}" sessionStorage.getItem(layoutKey.value) || "{}"
); );
const layout: any = c.configuration || {}; const layout: any = c.configuration || {};
dashboardStore.setLayout(layout.children || []);
dashboardStore.setLayout(setWidgetsID(layout.children || []));
appStore.setPageTitle(layout.name); appStore.setPageTitle(layout.name);
if (p.entity) { if (p.entity) {
dashboardStore.setCurrentDashboard({ dashboardStore.setCurrentDashboard({
@ -78,6 +79,24 @@ export default defineComponent({
}); });
} }
} }
function setWidgetsID(widgets: any[]) {
for (const item of widgets) {
item.id = item.i;
if (item.type === "Tab") {
if (item.children && item.children.length) {
for (const [index, child] of item.children.entries()) {
if (child.children && child.children.length) {
child.children.map((d: { i: string; index: string } | any) => {
d.id = `${item.i}-${index}-${d.i}`;
return d;
});
}
}
}
}
}
return widgets;
}
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

@ -232,12 +232,17 @@ function exportTemplates() {
}, 2000); }, 2000);
} }
function optimizeTemplate( function optimizeTemplate(
children: (LayoutConfig & { moved?: boolean; standard?: unknown })[] children: (LayoutConfig & {
moved?: boolean;
standard?: unknown;
id?: string;
})[]
) { ) {
for (const child of children || []) { for (const child of children || []) {
delete child.moved; delete child.moved;
delete child.activedTabIndex; delete child.activedTabIndex;
delete child.standard; delete child.standard;
delete child.id;
if (isEmptyObject(child.graph)) { if (isEmptyObject(child.graph)) {
delete child.graph; delete child.graph;
} }

View File

@ -14,26 +14,52 @@ See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<div class="item"> <div class="item">
<span class="label">{{ t("title") }}</span> <span class="label">{{ t("widget") }}</span>
<el-input <Selector
class="input" :value="widgetId"
v-model="title" :options="widgets"
size="small" size="small"
placeholder="Please input title" placeholder="Select a metric"
@change="updateWidgetConfig({ title: encodeURIComponent(title) })" @change="updateWidgetConfig({ associateWidget: $event[0].value })"
class="selectors"
/> />
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { ref } from "vue"; import { ref, computed } from "vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
const { t } = useI18n(); const { t } = useI18n();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const widget = dashboardStore.selectedGrid.widget || {}; const associate = dashboardStore.selectedGrid.associate || {};
const title = ref<string>(widget.title || ""); const widgetId = ref<string>(associate.widgetId || "");
const widgets = computed(() => {
const all = [];
for (const item of dashboardStore.layout) {
if (item.type === "Tab") {
if (item.children && item.children.length) {
for (const child of item.children) {
if (child.children && child.children.length) {
const items = child.children.map(
(d: { i: string; index: string } | any) => {
d.value = d.id;
d.label = (d.widget && d.widget.title) || d.type || "";
return d;
}
);
all.push(...items);
}
}
}
} else {
item.value = item.id;
item.label = (item.widget && item.widget.title) || item.type || "";
all.push(item);
}
}
return all;
});
function updateWidgetConfig(param: { [key: string]: string }) { function updateWidgetConfig(param: { [key: string]: string }) {
const key = Object.keys(param)[0]; const key = Object.keys(param)[0];
if (!key) { if (!key) {

View File

@ -22,7 +22,9 @@ limitations under the License. -->
size="small" size="small"
placeholder="Please input unit" placeholder="Please input unit"
@change=" @change="
updateConfig(index, { unit: encodeURIComponent(currentMetric.unit) }) updateConfig(index, {
unit: encodeURIComponent(currentMetric.unit || ''),
})
" "
/> />
</div> </div>
@ -35,7 +37,7 @@ limitations under the License. -->
placeholder="Please input a name" placeholder="Please input a name"
@change=" @change="
updateConfig(index, { updateConfig(index, {
label: encodeURIComponent(currentMetric.label), label: encodeURIComponent(currentMetric.label || ''),
}) })
" "
/> />