update param

This commit is contained in:
Qiuxia Fan 2022-03-23 12:31:52 +08:00
parent 64eafab10d
commit abcd41e5d1
3 changed files with 21 additions and 33 deletions

View File

@ -13,8 +13,8 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and See the License for the specific language governing permissions and
limitations under the License. --> limitations under the License. -->
<template> <template>
<Edit v-if="hasRoot" @update="changeStatus" /> <Edit v-if="dashboardStore.currentDashboard" />
<div class="no-root" v-else> <div v-else class="no-root">
{{ t("noRoot") }} {{ dashboardStore.layerId }} {{ t("noRoot") }} {{ dashboardStore.layerId }}
</div> </div>
</template> </template>
@ -26,9 +26,11 @@ import { EntityType } from "./dashboard/data";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import Edit from "./dashboard/Edit.vue"; import Edit from "./dashboard/Edit.vue";
import { useI18n } from "vue-i18n"; import { useI18n } from "vue-i18n";
import { useAppStoreWithOut } from "@/store/modules/app";
const route = useRoute(); const route = useRoute();
const { t } = useI18n(); const { t } = useI18n();
const appStore = useAppStoreWithOut();
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const routeNames = [ const routeNames = [
"GeneralServices", "GeneralServices",
@ -43,7 +45,6 @@ const routeNames = [
"Browser", "Browser",
]; ];
const layer = ref<string>("GENERAL"); const layer = ref<string>("GENERAL");
const hasRoot = ref<boolean>(false);
getDashboard(); getDashboard();
@ -52,11 +53,22 @@ async function getDashboard() {
dashboardStore.setLayer(layer.value); dashboardStore.setLayer(layer.value);
dashboardStore.setEntity(EntityType[1].value); dashboardStore.setEntity(EntityType[1].value);
dashboardStore.setMode(false); dashboardStore.setMode(false);
await dashboardStore.setDashboards();
const index = dashboardStore.dashboards.findIndex(
(d: { name: string; isRoot: boolean; layer: string; entity: string }) =>
d.layer === dashboardStore.layerId &&
d.entity === EntityType[1].value &&
d.isRoot
);
if (index < 0) {
appStore.setPageTitle(dashboardStore.layer);
dashboardStore.setCurrentDashboard(null);
return;
}
const item = dashboardStore.dashboards[index];
dashboardStore.setCurrentDashboard(item);
} }
function changeStatus(p: boolean) {
hasRoot.value = p;
}
function setLayer(n: string) { function setLayer(n: string) {
switch (n) { switch (n) {
case routeNames[0]: case routeNames[0]:

View File

@ -43,35 +43,18 @@ import TopologyConfig from "./configuration/Topology.vue";
import WidgetConfig from "./configuration/Widget.vue"; import WidgetConfig from "./configuration/Widget.vue";
import { useDashboardStore } from "@/store/modules/dashboard"; import { useDashboardStore } from "@/store/modules/dashboard";
import { useAppStoreWithOut } from "@/store/modules/app"; import { useAppStoreWithOut } from "@/store/modules/app";
import { EntityType } from "./data";
/*global defineEmits */
const emit = defineEmits(["update"]);
const dashboardStore = useDashboardStore(); const dashboardStore = useDashboardStore();
const appStore = useAppStoreWithOut(); const appStore = useAppStoreWithOut();
const { t } = useI18n(); const { t } = useI18n();
const p = useRoute().params; const p = useRoute().params;
const layoutKey = ref<string>(`${p.layerId}_${p.entity}_${p.name}`); const layoutKey = ref<string>(`${p.layerId}_${p.entity}_${p.name}`);
dashboardStore.setCurrentDashboard({});
setTemplate(); setTemplate();
async function setTemplate() { async function setTemplate() {
await dashboardStore.setDashboards(); await dashboardStore.setDashboards();
if (!p.entity) { if (!p.entity) {
const index = dashboardStore.dashboards.findIndex(
(d: { name: string; isRoot: boolean; layer: string; entity: string }) =>
d.layer === dashboardStore.layerId &&
d.entity === EntityType[1].value &&
d.isRoot
);
if (index < 0) {
appStore.setPageTitle(dashboardStore.layer);
dashboardStore.setCurrentDashboard(null);
emit("update", false);
return;
}
const item = dashboardStore.dashboards[index];
dashboardStore.setCurrentDashboard(item);
const { layer, entity, name } = dashboardStore.currentDashboard; const { layer, entity, name } = dashboardStore.currentDashboard;
layoutKey.value = `${layer}_${entity}_${name}`; layoutKey.value = `${layer}_${entity}_${name}`;
} }
@ -81,7 +64,6 @@ async function setTemplate() {
const layout: any = c.configuration || {}; const layout: any = c.configuration || {};
dashboardStore.setLayout(layout.children || []); dashboardStore.setLayout(layout.children || []);
appStore.setPageTitle(layout.name); appStore.setPageTitle(layout.name);
if (p.entity) { if (p.entity) {
dashboardStore.setCurrentDashboard({ dashboardStore.setCurrentDashboard({
layer: p.layerId, layer: p.layerId,
@ -91,7 +73,6 @@ async function setTemplate() {
isRoot: layout.isRoot, isRoot: layout.isRoot,
}); });
} }
emit("update", true);
} }
function handleClick(e: any) { function handleClick(e: any) {

View File

@ -165,12 +165,6 @@ function setCurrentDashboard() {
if (params.layerId) { if (params.layerId) {
dashboardStore.setLayer(params.layerId); dashboardStore.setLayer(params.layerId);
dashboardStore.setEntity(params.entity); dashboardStore.setEntity(params.entity);
const item = getDashboard({
name: String(params.name),
layer: dashboardStore.layerId,
entity: EntityType[3].value,
});
dashboardStore.setCurrentDashboard(item || null);
} }
const type = EntityType.filter( const type = EntityType.filter(
(d: Option) => d.value === dashboardStore.entity (d: Option) => d.value === dashboardStore.entity
@ -213,7 +207,8 @@ async function setSelector() {
} }
selectorStore.setCurrentService(currentService); selectorStore.setCurrentService(currentService);
selectorStore.setCurrentDestService(currentDestService); selectorStore.setCurrentDestService(currentDestService);
states.currentService = selectorStore.currentService.value; states.currentService =
selectorStore.currentService && selectorStore.currentService.value;
states.currentDestService = states.currentDestService =
selectorStore.currentDestService && selectorStore.currentDestService.value; selectorStore.currentDestService && selectorStore.currentDestService.value;
} }