|
@@ -51,9 +51,14 @@
|
|
|
|
|
|
|
|
<view class="form-item">
|
|
<view class="form-item">
|
|
|
<text class="label">省/市</text>
|
|
<text class="label">省/市</text>
|
|
|
- <picker mode="region" :value="region" @change="onRegionChange">
|
|
|
|
|
- <view class="picker">{{ region.join(' ') || '请选择省/市' }}</view>
|
|
|
|
|
- </picker>
|
|
|
|
|
|
|
+ <view class="location-section">
|
|
|
|
|
+ <picker mode="region" :value="region" @change="onRegionChange">
|
|
|
|
|
+ <view class="picker">{{ region.join(' ') || '请选择省/市' }}</view>
|
|
|
|
|
+ </picker>
|
|
|
|
|
+ <button class="get-location-btn" @click="getCurrentLocation" :disabled="gettingLocation">
|
|
|
|
|
+ {{ gettingLocation ? '获取中...' : '自动获取' }}
|
|
|
|
|
+ </button>
|
|
|
|
|
+ </view>
|
|
|
</view>
|
|
</view>
|
|
|
|
|
|
|
|
|
|
|
|
@@ -82,6 +87,7 @@ const form = ref({
|
|
|
const region = ref<string[]>([])
|
|
const region = ref<string[]>([])
|
|
|
const submitting = ref(false)
|
|
const submitting = ref(false)
|
|
|
const isChoosing = ref(false)
|
|
const isChoosing = ref(false)
|
|
|
|
|
+const gettingLocation = ref(false)
|
|
|
|
|
|
|
|
|
|
|
|
|
const onChooseAvatar = (e: any) => {
|
|
const onChooseAvatar = (e: any) => {
|
|
@@ -140,6 +146,37 @@ const onRegionChange = (e: any) => {
|
|
|
form.value.address = region.value.join(' ')
|
|
form.value.address = region.value.join(' ')
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+const getCurrentLocation = async () => {
|
|
|
|
|
+ if (gettingLocation.value) return
|
|
|
|
|
+ gettingLocation.value = true
|
|
|
|
|
+ try {
|
|
|
|
|
+ // 获取经纬度
|
|
|
|
|
+ const locationRes = await uni.getLocation({ type: 'wgs84' })
|
|
|
|
|
+ const { latitude, longitude } = locationRes
|
|
|
|
|
+ console.log('getLocation success:', locationRes)
|
|
|
|
|
+
|
|
|
|
|
+ // 调用用户自己的地理编码接口
|
|
|
|
|
+ const geocodeRes = await uni.request({
|
|
|
|
|
+ url: `http://45.207.222.6/geo/nearest.php?latitude=${latitude}&longitude=${longitude}`,
|
|
|
|
|
+ method: 'GET'
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ const data = geocodeRes.data as any
|
|
|
|
|
+ if (data && data.province && data.city) {
|
|
|
|
|
+ region.value = [data.province, data.city,data.district]
|
|
|
|
|
+ form.value.address = region.value.join(' ')
|
|
|
|
|
+ uni.showToast({ title: '位置获取成功', icon: 'success' })
|
|
|
|
|
+ } else {
|
|
|
|
|
+ throw new Error('Geocode failed')
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (err) {
|
|
|
|
|
+ console.error('Get location error:', err)
|
|
|
|
|
+ uni.showToast({ title: '获取位置失败,请检查定位权限和网络', icon: 'none' })
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ gettingLocation.value = false
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
const onSubmit = async () => {
|
|
const onSubmit = async () => {
|
|
|
if (submitting.value) return
|
|
if (submitting.value) return
|
|
|
if (!form.value.nickname || !form.value.avatar) {
|
|
if (!form.value.nickname || !form.value.avatar) {
|
|
@@ -310,6 +347,27 @@ const onSubmit = async () => {
|
|
|
color: #333;
|
|
color: #333;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+.location-section {
|
|
|
|
|
+ display: flex;
|
|
|
|
|
+ align-items: center;
|
|
|
|
|
+ gap: 20rpx;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.get-location-btn {
|
|
|
|
|
+ flex-shrink: 0;
|
|
|
|
|
+ height: 80rpx;
|
|
|
|
|
+ background: linear-gradient(135deg, #07C160 0%, #00A854 100%);
|
|
|
|
|
+ color: #fff;
|
|
|
|
|
+ border-radius: 8rpx;
|
|
|
|
|
+ font-size: 28rpx;
|
|
|
|
|
+ padding: 0 30rpx;
|
|
|
|
|
+ border: none;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+.get-location-btn:disabled {
|
|
|
|
|
+ opacity: 0.5;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
.submit-section {
|
|
.submit-section {
|
|
|
margin-top: 60rpx;
|
|
margin-top: 60rpx;
|
|
|
}
|
|
}
|