reset configs

This commit is contained in:
Qiuxia Fan 2022-07-08 11:10:12 +08:00
parent ec0758af07
commit ae294d48e8
3 changed files with 17 additions and 18 deletions

View File

@ -17,7 +17,7 @@ limitations under the License. -->
<span class="label">{{ t("widget") }}</span> <span class="label">{{ t("widget") }}</span>
<Selector <Selector
:multiple="true" :multiple="true"
:value="widgetId" :value="widgetIds"
:options="widgets" :options="widgets"
size="small" size="small"
placeholder="Select a widget" placeholder="Select a widget"
@ -37,7 +37,7 @@ import { Option } from "@/types/app";
const { t } = useI18n(); const { t } = useI18n();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const associate = dashboardStore.selectedGrid.associate || []; const associate = dashboardStore.selectedGrid.associate || [];
const widgetId = ref<string[]>( const widgetIds = ref<string[]>(
associate.map((d: { widgetId: string }) => d.widgetId) associate.map((d: { widgetId: string }) => d.widgetId)
); );
const widgets = computed(() => { const widgets = computed(() => {
@ -71,11 +71,25 @@ function updateWidgetConfig(options: Option[]) {
const opt = options.map((d: Option) => { const opt = options.map((d: Option) => {
return { widgetId: d.value }; return { widgetId: d.value };
}); });
const newVal = options.map((d: Option) => d.value);
// add association options in the source widget
const widget = { const widget = {
...dashboardStore.selectedGrid, ...dashboardStore.selectedGrid,
associate: opt, associate: opt,
}; };
dashboardStore.selectWidget({ ...widget }); dashboardStore.selectWidget({ ...widget });
// remove unuse association widget option
for (const id of widgetIds.value) {
if (!newVal.includes(id)) {
const w = widgets.find((d: { id: string }) => d.id === id);
const config = {
...w,
associate: [],
};
dashboardStore.setWidget(config);
}
}
// add association options in target widgets
for (let i = 0; i < opt.length; i++) { for (let i = 0; i < opt.length; i++) {
const item = JSON.parse(JSON.stringify(opt)); const item = JSON.parse(JSON.stringify(opt));
item[i] = { widgetId: dashboardStore.selectedGrid.id }; item[i] = { widgetId: dashboardStore.selectedGrid.id };
@ -86,6 +100,7 @@ function updateWidgetConfig(options: Option[]) {
}; };
dashboardStore.setWidget(config); dashboardStore.setWidget(config);
} }
widgetIds.value = newVal;
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>

View File

@ -156,14 +156,6 @@ function getOption() {
}, },
enterable: true, enterable: true,
extraCssText: "max-height: 300px; overflow: auto; border: none", extraCssText: "max-height: 300px; overflow: auto; border: none",
axisPointer: {
lineStyle: {
width: 2,
},
label: {
show: false,
},
},
}, },
legend: { legend: {
type: "scroll", type: "scroll",

View File

@ -162,14 +162,6 @@ function getOption() {
enterable: true, enterable: true,
confine: true, confine: true,
extraCssText: "max-height: 300px; overflow: auto; border: none;", extraCssText: "max-height: 300px; overflow: auto; border: none;",
axisPointer: {
lineStyle: {
width: 2,
},
label: {
show: false,
},
},
}; };
const tips = { const tips = {
formatter(params: any) { formatter(params: any) {