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

35 lines
862 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 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;
}
}
}
});