assistant-todo-mobile/src/utils/index.js

24 lines
783 B
JavaScript

import axios from "axios"
export const getCurrentCity=()=>{
const localCity = JSON.parse(localStorage.getItem('local_city'))
if(!localCity){
return new Promise((resolve,reject)=>{
const curCity = new window.BMapGL.LocalCity()
curCity.get(async res=>{
try{
const result = await axios.get('http://localhost:8080/area/info?name=${res.name}')
localStorage.setItem('local_city',JSON.stringify(result.data.body))
resolve(result.data.body)
}catch(e){
reject(e)
}
})
})
}
// return new Promise((resolve)=>{
// return resolve(localCity)
// })
return Promise.resolve(localCity)
}