mirror of https://github.com/halo-dev/halo-admin
[release-2.0] fix: ui is not updated after the theme is activated in the production (#753)
This is an automated cherry-pick of #746 /assign ruibaby ```release-note 修复 Console 端激活主题之后页面没有更新数据的问题。 ```pull/755/head
parent
18012cd33b
commit
c51a1e4a98
|
@ -1,46 +1,41 @@
|
||||||
import { apiClient } from "@/utils/api-client";
|
import { apiClient } from "@/utils/api-client";
|
||||||
import type { Theme } from "@halo-dev/api-client";
|
import type { Theme } from "@halo-dev/api-client";
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
|
import { ref } from "vue";
|
||||||
|
|
||||||
interface ThemeStoreState {
|
export const useThemeStore = defineStore("theme", () => {
|
||||||
activatedTheme?: Theme;
|
const activatedTheme = ref<Theme>();
|
||||||
}
|
|
||||||
|
|
||||||
export const useThemeStore = defineStore("theme", {
|
async function fetchActivatedTheme() {
|
||||||
state: (): ThemeStoreState => ({
|
try {
|
||||||
activatedTheme: undefined,
|
const { data } = await apiClient.extension.configMap.getv1alpha1ConfigMap(
|
||||||
}),
|
{
|
||||||
actions: {
|
name: "system",
|
||||||
async fetchActivatedTheme() {
|
},
|
||||||
try {
|
{ mute: true }
|
||||||
const { data } =
|
);
|
||||||
await apiClient.extension.configMap.getv1alpha1ConfigMap(
|
|
||||||
{
|
|
||||||
name: "system",
|
|
||||||
},
|
|
||||||
{ mute: true }
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!data.data?.theme) {
|
if (!data.data?.theme) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
const themeConfig = JSON.parse(data.data.theme);
|
|
||||||
|
|
||||||
const { data: themeData } =
|
|
||||||
await apiClient.extension.theme.getthemeHaloRunV1alpha1Theme(
|
|
||||||
{
|
|
||||||
name: themeConfig.active,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
mute: true,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
this.activatedTheme = themeData;
|
|
||||||
} catch (e) {
|
|
||||||
console.error("Failed to fetch active theme", e);
|
|
||||||
}
|
}
|
||||||
},
|
|
||||||
},
|
const themeConfig = JSON.parse(data.data.theme);
|
||||||
|
|
||||||
|
const { data: themeData } =
|
||||||
|
await apiClient.extension.theme.getthemeHaloRunV1alpha1Theme(
|
||||||
|
{
|
||||||
|
name: themeConfig.active,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
mute: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
activatedTheme.value = themeData;
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Failed to fetch active theme", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return { activatedTheme, fetchActivatedTheme };
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue