diff --git a/src/App.vue b/src/App.vue index 686aa3d..9c88408 100644 --- a/src/App.vue +++ b/src/App.vue @@ -25,6 +25,8 @@ export default defineComponent({ store.commit("login", true) store.dispatch("setUserInfo"); }else{ + console.log('ip') + store.dispatch("getip"); router.push("/") } return{ diff --git a/src/api/index.ts b/src/api/index.ts index 294f114..6f1b1a2 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -985,6 +985,16 @@ export async function luzhi(roomid: string){ console.log(res) } +export async function getaddr() { + const res = await get('ip'); + const gj = res.data.address.split("|")[0]; + if(gj == "CN"){ + return ["zh", "中文", '人民币¥']; + }else { + return ['en', 'English', '美元$'] + } +} + // export async function StopMCUMixTranscode(roomid: number) { // const res = await get('StopMCUMixTranscode', {roomid}); // console.log(res) diff --git a/src/store/index.ts b/src/store/index.ts index a281356..7c3fadc 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -1,4 +1,5 @@ -import { userinfo } from '@/api'; +import { getaddr, userinfo } from '@/api'; +import { isProxy } from 'vue'; import { createStore } from 'vuex' export default createStore({ @@ -57,6 +58,14 @@ export default createStore({ }, login(state, islogin: boolean){ state.islogin = islogin; + }, + setLanguage(state, data){ + const split = new Date().toString().split(" "); + const timeZoneFormatted = split[split.length - 2] + " " + split[split.length - 1]; + state.userinfo.language = data[1] // English 中文 + state.userinfo.languageValue = data[0] // 'en' 'zh' + state.userinfo.zoneStr = timeZoneFormatted; + state.userinfo.currency = data[2]; } }, actions: { @@ -64,7 +73,14 @@ export default createStore({ const user = await userinfo(); if(user != '未登录'){ commit('setUserInfo', user); + } else { + const info = await getaddr(); + commit("setLanguage", info) } + }, + async getip({ commit }){ + const info = await getaddr(); + commit("setLanguage", info) } }, modules: {