From 9cefed9bfec55a267f439ea2e3ef98c309453582 Mon Sep 17 00:00:00 2001 From: luyuan <1162963624@qq.com> Date: Mon, 23 Nov 2020 16:32:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8D=A2=E6=88=90=E4=BA=86=E7=B3=BB=E7=BB=9F?= =?UTF-8?q?=E5=AE=9A=E4=BD=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 2 ++ src/api/index.ts | 76 +++++++++++++++++++++++++++++++++------------- src/store/index.ts | 2 ++ 3 files changed, 59 insertions(+), 21 deletions(-) diff --git a/src/App.vue b/src/App.vue index d574b12..f2e6b6c 100644 --- a/src/App.vue +++ b/src/App.vue @@ -17,6 +17,7 @@ import i18ninit from "@/i18n/init" import enUS from 'ant-design-vue/es/locale/en_US'; import zhCN from 'ant-design-vue/es/locale/zh_CN'; import dayjs from 'dayjs'; +import { getaddr } from './api'; export default defineComponent({ setup(){ @@ -24,6 +25,7 @@ export default defineComponent({ const len = provideI18n(i18ninit); // len.locale.value = !getValue("Lanvuage") ? 'zh' : getValue("Lanvuage"); if(getValue('token')){ + console.log("token") store.commit("login", true) store.dispatch("setUserInfo"); }else{ diff --git a/src/api/index.ts b/src/api/index.ts index 5449749..e17f566 100644 --- a/src/api/index.ts +++ b/src/api/index.ts @@ -1039,28 +1039,62 @@ 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]; - const lan = getValue("Lanvuage"); - const qh = await get('countryCode', { - longitude: res.data.content.point.x, - latitude: res.data.content.point.y - }); - console.log(qh) - if(lan != null && lan){ - if(gj == "CN"){ - return {hb: '人民币¥', qh}; - }else { - return {hb: '美元$'} +export function getaddr() { + return new Promise((r)=>{ + console.log("开始定位") + const lan = getValue("Lanvuage"); + if ("geolocation" in navigator) { + /* 地理位置服务可用 */ + navigator.geolocation.getCurrentPosition(async (res) => { + console.log(res, 'res') + const qh = await get('countryCode', { + longitude: res.coords.longitude, + latitude: res.coords.latitude + }); + console.log(qh) + if(lan != null && lan){ + if(qh.data.ename == "China"){ + r({hb: '人民币¥', qh}); + }else { + r({hb: '美元$'}) + } + }else{ + if(qh.data.ename == "China"){ + r({yy: "zh", yyx: "中文", hb: '人民币¥', qh}); + }else { + r({yy: 'en', yyx: 'English', hb: '美元$', qh}) + } + } + },(err) => { + console.log(err, 'err') + }) + } else { + /* 地理位置服务不可用 */ + console.log("无法定位") } - }else{ - if(gj == "CN"){ - return {yy: "zh", yyx: "中文", hb: '人民币¥', qh}; - }else { - return {yy: 'en', yyx: 'English', hb: '美元$', qh} - } - } + }) + + // const res = await get('ip'); + // const gj = res.data.address.split("|")[0]; + // const lan = getValue("Lanvuage"); + // const qh = await get('countryCode', { + // longitude: res.data.content.point.x, + // latitude: res.data.content.point.y + // }); + // console.log(qh) + // if(lan != null && lan){ + // if(gj == "CN"){ + // return {hb: '人民币¥', qh}; + // }else { + // return {hb: '美元$'} + // } + // }else{ + // if(gj == "CN"){ + // return {yy: "zh", yyx: "中文", hb: '人民币¥', qh}; + // }else { + // return {yy: 'en', yyx: 'English', hb: '美元$', qh} + // } + // } } diff --git a/src/store/index.ts b/src/store/index.ts index 483d750..5b6776d 100644 --- a/src/store/index.ts +++ b/src/store/index.ts @@ -126,11 +126,13 @@ export default createStore({ commit('setUserInfo', user); } else { const info = await getaddr(); + console.log(info,11256445) commit("setLanguage", info) } }, async getip({ commit }){ const info = await getaddr(); + console.log(info,11256445); commit("setLanguage", info) } },