bunny-admin-element-thin/src/store/i18n/i18n.ts

35 lines
862 B
TypeScript
Raw Normal View History

// import { fetchGetI18n } from '@/api/mock/i18n';
import { defineStore } from "pinia";
import { fetchGetI18n } from "@/api/v1/i18n/i18n";
import type { I18nState } from "../../../types/store/i18n";
export const userI18nStore = defineStore("i18nStore", {
persist: true,
state(): I18nState {
return {
// ? 多语言内容
i18n: {}
};
},
getters: {},
actions: {
/**
* *
*/
async fetchI18n() {
const result = await fetchGetI18n();
if (result.code === 200) {
localStorage.removeItem("i18nStore");
// 当前的返回参数
const data = result.data;
// 将返回对象中key设置name后端不好设置
for (let key in data) if (key !== "local") data[key].name = key;
// 赋值返回参数
this.i18n = data;
}
}
}
});