You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
/**
|
|
|
|
|
* 延时函数
|
|
|
|
|
* @param {number} ms - 延迟时间(毫秒)
|
|
|
|
|
* @returns {Promise} - 返回一个 Promise,在指定时间后 resolve
|
|
|
|
|
*/
|
|
|
|
|
export function delay(ms) {
|
|
|
|
|
return new Promise(resolve => setTimeout(resolve, ms));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function getLatLng() {
|
|
|
|
|
return new Promise((reslove) => {
|
|
|
|
|
uni.getLocation({
|
|
|
|
|
type: 'gcj02',
|
|
|
|
|
success: function(res) {
|
|
|
|
|
console.log('当前位置的经度:' + res.longitude);
|
|
|
|
|
console.log('当前位置的纬度:' + res.latitude);
|
|
|
|
|
reslove({
|
|
|
|
|
lat: res.latitude,
|
|
|
|
|
lng: res.longitude
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
fail: function(res) {
|
|
|
|
|
reslove({
|
|
|
|
|
lat: null,
|
|
|
|
|
lng: null
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 使用示例:
|
|
|
|
|
// async function example() {
|
|
|
|
|
// console.log('开始');
|
|
|
|
|
// await delay(2000); // 延时 2 秒
|
|
|
|
|
// console.log('2秒后执行');
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 判断用户是否已登录
|
|
|
|
|
* @returns {boolean} - 返回用户是否已登录
|
|
|
|
|
*/
|
|
|
|
|
export function isLoggedIn() {
|
|
|
|
|
try {
|
|
|
|
|
// 从loginRes中读取token,与user.js中的登录存储逻辑保持一致
|
|
|
|
|
const loginRes = uni.getStorageSync('loginRes');
|
|
|
|
|
console.log(loginRes)
|
|
|
|
|
return !!(loginRes && loginRes.accessToken); // 确保loginRes存在且包含token
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('检查登录状态时出错:', error);
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|