修改登录页样式、车牌号输入问题、定位加载问题、联系物业权限问题
This commit is contained in:
@@ -65,7 +65,7 @@
|
||||
<up-row justify="space-between" customStyle="margin-bottom: 10px">
|
||||
<up-col span="4">
|
||||
<view class="info-image-left">
|
||||
<image :src="activity.coverImage" style="width: 100%;height: 100%;border-radius: 16rpx;"></image>
|
||||
<image :src="activity.coverImage" mode="aspectFit" style="width: 100%;height: 100%;border-radius: 16rpx;"></image>
|
||||
</view>
|
||||
</up-col>
|
||||
<up-col span="8">
|
||||
|
||||
@@ -58,6 +58,9 @@ import { ref } from 'vue';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import { addActivityLive, signinActivityLive, uploadFile } from '../api/api.js';
|
||||
|
||||
// 高德地图 Web API Key(用于逆地址解析,需要去 https://lbs.amap.com 申请免费 Key)
|
||||
const AMAP_KEY = 'f362f595be12ab7d84bd502b48b30d2a';
|
||||
|
||||
// 活动ID
|
||||
const activityId = ref('');
|
||||
// 实况描述内容
|
||||
@@ -82,6 +85,29 @@ const handleTextInput = (e) => {
|
||||
currentLength.value = e.detail.value.length;
|
||||
};
|
||||
|
||||
// 逆地址解析(坐标转地址)
|
||||
const reverseGeocode = async (lng, lat) => {
|
||||
if (!AMAP_KEY) return null;
|
||||
try {
|
||||
const [err, res] = await uni.request({
|
||||
url: 'https://restapi.amap.com/v3/geocode/regeo',
|
||||
data: {
|
||||
key: AMAP_KEY,
|
||||
location: `${lng},${lat}`,
|
||||
extensions: 'base'
|
||||
}
|
||||
});
|
||||
if (err) throw err;
|
||||
if (res.data?.status === '1' && res.data.regeocode?.formatted_address) {
|
||||
return res.data.regeocode.formatted_address;
|
||||
}
|
||||
return null;
|
||||
} catch (e) {
|
||||
console.error('逆地址解析失败:', e);
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
// 选择图片
|
||||
const chooseImg = () => {
|
||||
uni.chooseImage({
|
||||
@@ -103,43 +129,92 @@ const chooseImg = () => {
|
||||
imgList.value.splice(index, 1);
|
||||
};
|
||||
|
||||
// 重新定位
|
||||
// 定位并获取具体地点名称
|
||||
// 检查 App 端定位权限(Android/iOS)
|
||||
const checkAppLocationPermission = () => {
|
||||
// #ifdef APP-PLUS
|
||||
try {
|
||||
const platform = uni.getSystemInfoSync().platform;
|
||||
if (platform === 'android') {
|
||||
const main = plus.android.runtimeMainActivity();
|
||||
const PackageManager = plus.android.importClass('android.content.pm.PackageManager');
|
||||
return main.checkSelfPermission('android.permission.ACCESS_FINE_LOCATION') === PackageManager.PERMISSION_GRANTED;
|
||||
}
|
||||
if (platform === 'ios') {
|
||||
const CLAuthorizationStatus = plus.ios.importClass('CLAuthorizationStatus');
|
||||
const CLLocationManager = plus.ios.importClass('CLLocationManager');
|
||||
return CLLocationManager.authorizationStatus() !== 2; // 2 = denied
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('检查权限失败', e);
|
||||
}
|
||||
// #endif
|
||||
return true; // 非 App 端默认通过
|
||||
};
|
||||
|
||||
// 跳转系统设置(App 端)
|
||||
const openAppSettings = () => {
|
||||
// #ifdef APP-PLUS
|
||||
const platform = uni.getSystemInfoSync().platform;
|
||||
if (platform === 'android') {
|
||||
const Intent = plus.android.importClass('android.content.Intent');
|
||||
const Settings = plus.android.importClass('android.provider.Settings');
|
||||
const Uri = plus.android.importClass('android.net.Uri');
|
||||
const intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
||||
intent.setData(Uri.parse('package:' + plus.runtime.packageName));
|
||||
plus.android.runtimeMainActivity().startActivity(intent);
|
||||
} else if (platform === 'ios') {
|
||||
const UIApplication = plus.ios.importClass('UIApplication');
|
||||
const app = UIApplication.sharedApplication();
|
||||
const NSURL = plus.ios.importClass('NSURL');
|
||||
const url = NSURL.URLWithString('app-settings:');
|
||||
app.openURL(url);
|
||||
}
|
||||
// #endif
|
||||
};
|
||||
|
||||
// 重新定位(获取当前位置 + 逆地址解析)
|
||||
const reLocate = () => {
|
||||
// 调用微信原生选择位置接口(自带地址解析,无调用上限)
|
||||
uni.chooseLocation({
|
||||
success: (res) => {
|
||||
// res.address = 具体地址(如:XX市XX区XX街道XX小区)
|
||||
// res.name = 地点名称(如:XX小区)
|
||||
// App 端先检查权限,无权限直接引导设置
|
||||
// #ifdef APP-PLUS
|
||||
if (!checkAppLocationPermission()) {
|
||||
uni.showModal({
|
||||
title: '需要定位权限',
|
||||
content: '请前往系统设置中允许本应用使用定位权限',
|
||||
confirmText: '去设置',
|
||||
success: (res) => {
|
||||
if (res.confirm) openAppSettings();
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
// #endif
|
||||
|
||||
uni.showLoading({ title: '正在定位...', mask: true });
|
||||
|
||||
uni.getLocation({
|
||||
type: 'gcj02',
|
||||
isHighAccuracy: true,
|
||||
success: async (res) => {
|
||||
longitude.value = res.longitude;
|
||||
latitude.value = res.latitude;
|
||||
location.value = res.address; // 显示具体地址
|
||||
uni.showToast({ title: `定位成功:${res.name}`, icon: 'success' });
|
||||
// 逆地址解析
|
||||
const address = await reverseGeocode(res.longitude, res.latitude);
|
||||
location.value = address || `${res.longitude.toFixed(6)}, ${res.latitude.toFixed(6)}`;
|
||||
uni.hideLoading();
|
||||
},
|
||||
fail: (err) => {
|
||||
// 处理权限拒绝/定位失败
|
||||
if (err.errMsg.includes('auth deny')) {
|
||||
uni.hideLoading();
|
||||
const errMsgStr = err?.errMsg || err?.message || JSON.stringify(err);
|
||||
console.error('定位失败:', err);
|
||||
if (err?.code === -22 || /权限|auth|deny|permission/i.test(errMsgStr)) {
|
||||
uni.showModal({
|
||||
title: '需要定位权限',
|
||||
content: '请允许获取位置信息以显示具体地点',
|
||||
confirmText: '去设置',
|
||||
success: (modalRes) => {
|
||||
if (modalRes.confirm) {
|
||||
uni.openSetting({
|
||||
success: (settingRes) => {
|
||||
// 用户开启权限后重新定位
|
||||
if (settingRes.authSetting['scope.userLocation']) {
|
||||
reLocate();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
success: (res) => { if (res.confirm) openAppSettings(); }
|
||||
});
|
||||
} else {
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: '定位失败,请重试', icon: 'none' });
|
||||
// console.error('定位失败:', err);
|
||||
uni.showToast({ title: `定位失败:${errMsgStr}`, icon: 'none', duration: 3000 });
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user