换成了系统定位

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 enUS from 'ant-design-vue/es/locale/en_US';
import zhCN from 'ant-design-vue/es/locale/zh_CN'; import zhCN from 'ant-design-vue/es/locale/zh_CN';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { getaddr } from './api';
export default defineComponent({ export default defineComponent({
setup(){ setup(){
@ -24,6 +25,7 @@ export default defineComponent({
const len = provideI18n(i18ninit); const len = provideI18n(i18ninit);
// len.locale.value = !getValue("Lanvuage") ? 'zh' : getValue("Lanvuage"); // len.locale.value = !getValue("Lanvuage") ? 'zh' : getValue("Lanvuage");
if(getValue('token')){ if(getValue('token')){
console.log("token")
store.commit("login", true) store.commit("login", true)
store.dispatch("setUserInfo"); store.dispatch("setUserInfo");
}else{ }else{

View File

@ -1039,28 +1039,62 @@ export async function luzhi(roomid: string){
console.log(res) console.log(res)
} }
export async function getaddr() { export function getaddr() {
const res = await get<any>('ip'); return new Promise((r)=>{
const gj = res.data.address.split("|")[0]; console.log("开始定位")
const lan = getValue("Lanvuage"); const lan = getValue("Lanvuage");
const qh = await get<any>('countryCode', { if ("geolocation" in navigator) {
longitude: res.data.content.point.x, /* 地理位置服务可用 */
latitude: res.data.content.point.y navigator.geolocation.getCurrentPosition(async (res) => {
}); console.log(res, 'res')
console.log(qh) const qh = await get<any>('countryCode', {
if(lan != null && lan){ longitude: res.coords.longitude,
if(gj == "CN"){ latitude: res.coords.latitude
return {hb: '人民币¥', qh}; });
}else { console.log(qh)
return {hb: '美元$'} 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}; // const res = await get<any>('ip');
}else { // const gj = res.data.address.split("|")[0];
return {yy: 'en', yyx: 'English', hb: '美元$', qh} // 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); commit('setUserInfo', user);
} else { } else {
const info = await getaddr(); const info = await getaddr();
console.log(info,11256445)
commit("setLanguage", info) commit("setLanguage", info)
} }
}, },
async getip({ commit }){ async getip({ commit }){
const info = await getaddr(); const info = await getaddr();
console.log(info,11256445);
commit("setLanguage", info) commit("setLanguage", info)
} }
}, },