set config

This commit is contained in:
Qiuxia Fan 2022-07-08 10:48:19 +08:00
parent 6aa7c5fbae
commit ec0758af07
2 changed files with 22 additions and 10 deletions

View File

@ -279,22 +279,23 @@ export const dashboardStore = defineStore({
this.selectedGrid = this.layout[index]; this.selectedGrid = this.layout[index];
}, },
setWidget(param: LayoutConfig) { setWidget(param: LayoutConfig) {
for (let item of this.layout) { for (let i = 0; i < this.layout.length; i++) {
if (item.type === "Tab") { if (this.layout[i].type === "Tab") {
if (item.children && item.children.length) { if (this.layout[i].children && this.layout[i].children.length) {
for (const child of item.children) { for (const child of this.layout[i].children) {
if (child.children && child.children.length) { if (child.children && child.children.length) {
for (let c of child.children) { for (let c = 0; c < child.children.length; c++) {
if (c.id === param.id) { if (child.children[c].id === param.id) {
c = param; child.children.splice(c, 1, param);
return;
} }
} }
} }
} }
} }
} else { } else {
if (item.id === param.id) { if (this.layout[i].id === param.id) {
item = param; this.layout.splice(i, 1, param);
} }
} }
} }

View File

@ -51,7 +51,7 @@ const widgets = computed(() => {
const items = widgets.filter( const items = widgets.filter(
(d: { value: string; label: string } & LayoutConfig) => { (d: { value: string; label: string } & LayoutConfig) => {
if (dashboardStore.selectedGrid.id !== d.id) { if (dashboardStore.selectedGrid.id !== d.id) {
if (isLinear && d.widget && d.id) { if (isLinear && d.type === "Widget" && d.widget && d.id) {
d.value = d.id; d.value = d.id;
d.label = d.widget.name || d.id; d.label = d.widget.name || d.id;
return d; return d;
@ -67,6 +67,7 @@ const widgets = computed(() => {
return items; return items;
}); });
function updateWidgetConfig(options: Option[]) { function updateWidgetConfig(options: Option[]) {
const { widgets } = getDashboard(dashboardStore.currentDashboard);
const opt = options.map((d: Option) => { const opt = options.map((d: Option) => {
return { widgetId: d.value }; return { widgetId: d.value };
}); });
@ -75,6 +76,16 @@ function updateWidgetConfig(options: Option[]) {
associate: opt, associate: opt,
}; };
dashboardStore.selectWidget({ ...widget }); dashboardStore.selectWidget({ ...widget });
for (let i = 0; i < opt.length; i++) {
const item = JSON.parse(JSON.stringify(opt));
item[i] = { widgetId: dashboardStore.selectedGrid.id };
const w = widgets.find((d: { id: string }) => d.id === opt[i].widgetId);
const config = {
...w,
associate: item,
};
dashboardStore.setWidget(config);
}
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>