换成了系统定位

This commit is contained in:
luyuan 2020-11-23 16:32:54 +08:00
parent 22e93bcdaa
commit 9cefed9bfe
Signed by: theluyuan
GPG Key ID: A7972FD973317FF3
3 changed files with 59 additions and 21 deletions

View File

@ -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{

View File

@ -1039,28 +1039,62 @@ export async function luzhi(roomid: string){
console.log(res)
}
export async function getaddr() {
const res = await get<any>('ip');
const gj = res.data.address.split("|")[0];
const lan = getValue("Lanvuage");
const qh = await get<any>('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<any>('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<any>('ip');
// const gj = res.data.address.split("|")[0];
// const lan = getValue("Lanvuage");
// const qh = await get<any>('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}
// }
// }
}

View File

@ -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)
}
},