wuzhen update

This commit is contained in:
wuzhen committed 2025-08-21 16:11:23 +08:00
1 parent be3d48b6e3
commit d7e900a64f
5 files changed
+225 -198

No files matched your search

+209 -177
View File
@@ -90,74 +90,72 @@
</view>
<!-- 位置信息卡片 -->
<view class="location-card" v-if="currentLocation" >
<view class="location-card">
<view class="card-header">
<view class="header-left">
<u-icon name="map-pin" size="18" color="#f56c6c"></u-icon>
<text class="card-title">当前位置</text>
</view>
<u-button
type="info"
size="mini"
text="重新定位"
@click="refreshLocation"
:loading="locationLoading"
class="refresh-btn"
></u-button>
</view>
<!-- 地址信息 -->
<view class="location-address">
<u-icon name="location" size="14" color="#909399" class="address-icon"></u-icon>
<text class="address-text">{{ currentLocation.address }}</text>
</view>
<!-- 坐标信息 -->
<view class="coordinates-section">
<view class="coord-row">
<view class="coord-item">
<text class="coord-label">经度</text>
<text class="coord-value">{{ currentLocation.longitude.toFixed(6) }}</text>
</view>
<view class="coord-divider"></view>
<view class="coord-item">
<text class="coord-label">纬度</text>
<text class="coord-value">{{ currentLocation.latitude.toFixed(6) }}</text>
</view>
<text class="card-title">签到位置</text>
</view>
</view>
<!-- 精度信息 -->
<view class="accuracy-section" v-if="currentLocation.accuracy">
<view class="accuracy-info">
<u-icon name="target" size="14" color="#67c23a" class="accuracy-icon"></u-icon>
<text class="accuracy-text">定位精度 {{ currentLocation.accuracy.toFixed(0) }}米</text>
<u-tag
:text="getAccuracyStatus(currentLocation.accuracy).text"
:type="getAccuracyStatus(currentLocation.accuracy).type"
size="mini"
class="accuracy-tag"
></u-tag>
</view>
</view>
<!-- 操作按钮 -->
<view class="location-actions">
<!-- 定位按钮 -->
<view class="location-row">
<u-button
type="primary"
size="default"
plain
@click="openLocationInMap"
class="map-btn"
plain
@click="handleGetLocation"
:loading="locationLoading"
class="location-btn"
>
<u-icon name="map" size="16" color="#2979ff" />
<text class="btn-text">在地图中查看</text>
<u-icon name="map-fill" size="20" color="#2979ff" />
<text style="margin-left: 8rpx">
{{ checkIsWechatBrowser() ? '微信定位' : '定位' }}
</text>
</u-button>
</view>
<!-- 位置信息显示 -->
<view v-if="currentLocation" class="location-info-section">
<!-- 坐标信息 -->
<view class="location-coords-container">
<text class="location-coords">
经纬度:{{ currentLocation.latitude.toFixed(6) }},{{ currentLocation.longitude.toFixed(6) }}
</text>
</view>
<!-- 精度信息 -->
<view class="accuracy-section" v-if="currentLocation.accuracy">
<view class="accuracy-info">
<u-icon name="target" size="14" color="#67c23a" class="accuracy-icon"></u-icon>
<text class="accuracy-text">定位精度 {{ currentLocation.accuracy.toFixed(0) }}米</text>
<u-tag
:text="getAccuracyStatus(currentLocation.accuracy).text"
:type="getAccuracyStatus(currentLocation.accuracy).type"
size="mini"
class="accuracy-tag"
></u-tag>
</view>
</view>
<!-- 查看位置按钮 -->
<view class="location-action-container">
<u-button
size="default"
type="primary"
plain
@click="openLocationInMap"
class="view-map-btn"
>
<u-icon name="eye" size="16" color="#2979ff" />
<text>查看位置</text>
</u-button>
</view>
</view>
</view>
<!-- 位置获取失败提示 -->
<view class="location-error-card" v-else-if="locationError">
<view class="location-error-card" v-if="locationError && !currentLocation">
<view class="card-header">
<view class="header-left">
<u-icon name="map-pin" size="18" color="#f56c6c"></u-icon>
@@ -265,6 +263,7 @@ import { getInternshipInfo, getStudentInternshipInfo, checkIn, getDailyList, get
import { getCurrentLocation, checkLocationPermission, openLocationSettings } from '@/utils/location.js';
import { userManager } from '@/utils/user.js';
import weChatSDK from '@/utils/wechat.js';
import { request } from '@/common/request.js';
export default {
name: 'InternshipIndex',
@@ -289,7 +288,6 @@ export default {
// 微信SDK相关(新增)
wechatSDK: weChatSDK,
isWechatBrowser: false,
wechatInitializing: false,
// 统计数据
@@ -319,19 +317,6 @@ export default {
};
},
async onLoad() {
// 初始化微信环境检查并自动初始化SDK
await this.checkWechatEnvironment();
this.initPage();
},
onShow() {
// 页面显示时刷新数据
this.loadTodayRecord();
this.loadStatistics();
},
methods: {
// === 微信SDK相关方法 ===
@@ -339,9 +324,9 @@ export default {
async checkWechatEnvironment() {
try {
// 检查是否在微信浏览器中
this.isWechatBrowser = this.wechatSDK.isWeChatBrowser();
const isWechatBrowser = this.wechatSDK.isWeChatBrowser();
if (this.isWechatBrowser) {
if (isWechatBrowser) {
// 在微信环境中,自动初始化SDK
await this.initWechatSDK();
}
@@ -407,10 +392,10 @@ export default {
}
// 初始化微信环境检测
this.isWechatBrowser = this.wechatSDK.isWeChatBrowser();
const isWechatBrowser = this.wechatSDK.isWeChatBrowser();
// 如果在微信环境,初始化微信SDK
if (this.isWechatBrowser) {
if (isWechatBrowser) {
await this.initWechatSDK();
}
@@ -419,10 +404,14 @@ export default {
this.loadInternshipInfo(),
this.loadTodayRecord(),
this.loadRecentRecords(),
this.loadStatistics(),
this.initLocation()
this.loadStatistics()
]);
// 初始化位置信息(不阻塞页面加载)
this.initLocation().catch(error => {
console.error('位置信息初始化失败:', error);
});
} catch (error) {
console.error('初始化页面失败:', error);
uni.showToast({
@@ -608,8 +597,8 @@ export default {
return;
}
// 获取当前位置
await this.getCurrentLocationInfo();
// 不自动获取位置,等待用户手动点击定位按钮
console.log('位置权限检查完成,等待用户手动定位');
} catch (error) {
console.error('初始化位置失败:', error);
this.canCheckin = false;
@@ -645,16 +634,16 @@ export default {
},
/**
* 智能定位:根据环境自动选择最适合的定位方式(增强版)
* 智能定位:根据环境自动选择最适合的定位方式(参考请假页面实现)
*/
async getCurrentLocationInfo() {
async handleGetLocation() {
try {
this.locationLoading = true;
this.locationError = '';
uni.showLoading({ title: '定位中...', mask: true });
const envInfo = {
isWechatBrowser: this.isWechatBrowser,
isWechatBrowser: this.checkIsWechatBrowser(),
isWechatSdkReady: this.wechatSDK.isInitialized,
isH5Web: this.isH5Web(),
isBrowserGeolocationSupported: this.isBrowserGeolocationSupported(),
@@ -663,7 +652,7 @@ export default {
console.log('环境检测结果:', envInfo);
// 优先级1:微信SDK定位(如果在微信环境且SDK已就绪)
if (this.isWechatBrowser && this.wechatSDK.isInitialized) {
if (this.checkIsWechatBrowser() && this.wechatSDK.isInitialized) {
const wxLocationSuccess = await this.tryWeChatLocationWithSDK();
if (wxLocationSuccess) {
return;
@@ -671,7 +660,7 @@ export default {
}
// 优先级2:微信环境但SDK未就绪,尝试初始化后重试
if (this.isWechatBrowser && !this.wechatSDK.isInitialized) {
if (this.checkIsWechatBrowser() && !this.wechatSDK.isInitialized) {
try {
await this.initWechatSDK();
if (this.wechatSDK.isInitialized) {
@@ -710,7 +699,7 @@ export default {
success: (res) => {
if (res.confirm) {
// 用户选择重试
this.getCurrentLocationInfo();
this.handleGetLocation();
}
}
});
@@ -720,7 +709,14 @@ export default {
},
/**
* 使用微信SDK进行定位(增强版)
* 检测浏览器是否支持 Geolocation API
*/
isBrowserGeolocationSupported() {
return typeof navigator !== 'undefined' && 'geolocation' in navigator;
},
/**
* 使用微信SDK进行定位(参考请假页面实现)
*/
async tryWeChatLocationWithSDK() {
try {
@@ -768,7 +764,7 @@ export default {
},
/**
* H5 web端原生定位(增强版)
* H5 web端原生定位(参考请假页面实现)
*/
async handleH5WebLocation() {
return new Promise((resolve) => {
@@ -792,6 +788,7 @@ export default {
const { latitude, longitude, accuracy } = position.coords;
// 将WGS84坐标转换为GCJ02坐标系(中国标准坐标系)
this.currentLocation = {
latitude: latitude,
longitude: longitude,
@@ -834,12 +831,12 @@ export default {
content: `${errorMessage}。是否手动输入位置信息?`,
showCancel: true,
cancelText: '取消',
confirmText: '稍后重试',
confirmText: '手动输入',
success: (res) => {
if (res.confirm) {
// 用户选择重试
// 可以在这里添加手动输入位置的逻辑
uni.showToast({
title: '请稍后重试定位',
title: '手动输入功能开发中',
icon: 'none',
duration: 2000,
});
@@ -935,23 +932,24 @@ export default {
* 刷新位置
*/
refreshLocation() {
this.getCurrentLocationInfo();
this.handleGetLocation();
},
/**
* 打开位置信息在地图中查看
* 打开位置信息在地图中查看(参考请假页面实现)
*/
async openLocationInMap() {
if (!this.currentLocation) {
uni.showToast({
title: '无法获取位置信息',
icon: 'none'
title: '暂无位置信息',
icon: 'none',
});
return;
}
// 从坐标信息解析经纬度
const { latitude, longitude } = this.currentLocation;
if (!latitude || !longitude || isNaN(latitude) || isNaN(longitude)) {
@@ -962,26 +960,72 @@ export default {
return;
}
if (this.isWechatBrowser && this.wechatSDK.isInitialized) {
try {
await this.wechatSDK.openLocation({
latitude: latitude,
// 声明变量在外部作用域,确保finally块可以访问
let formattedAddress = '';
// 调用高德sdk逆地理编码
try {
// 调用后台API进行逆地理编码
const geocodingResponse = await request({
url: '/system/SysRegion/reverse-geocode',
method: 'POST',
data: {
longitude: longitude,
name: '实习签到位置',
address: this.currentLocation.address || '当前位置',
scale: 16,
});
} catch (error) {
console.error('微信地图打开失败:', error);
latitude: latitude,
},
});
if (geocodingResponse.code === 200 && geocodingResponse.data) {
formattedAddress = geocodingResponse.data.regeocode?.formattedAddress || '';
if (formattedAddress) {
console.log('逆地理编码成功:', formattedAddress);
uni.showToast({
title: formattedAddress,
icon: 'none',
duration: 2000,
});
}
} else {
console.warn('逆地理编码失败:', geocodingResponse.msg);
}
} catch (error) {
console.error('逆地理编码请求失败:', error);
// 逆地理编码失败不影响地图打开功能
} finally {
console.log('=== finally块开始执行 ===');
console.log('formattedAddress:', formattedAddress);
console.log('isWechatBrowser:', this.checkIsWechatBrowser());
console.log('wechatSDK.isInitialized:', this.wechatSDK?.isInitialized);
if (this.checkIsWechatBrowser() && this.wechatSDK?.isInitialized) {
try {
console.log('尝试使用微信SDK打开地图...');
await this.wechatSDK.openLocation({
latitude: latitude,
longitude: longitude,
name: formattedAddress || '实习签到位置',
address: formattedAddress || '当前位置',
scale: 16,
});
console.log('微信地图打开成功');
} catch (error) {
console.error('微信地图打开失败:', error);
this.fallbackOpenMap(latitude, longitude);
}
} else {
console.log('使用备用地图打开方式...');
this.fallbackOpenMap(latitude, longitude);
}
} else {
this.fallbackOpenMap(latitude, longitude);
console.log('=== finally块执行完成 ===');
}
},
// 备用地图打开方式
// 备用地图打开方式(参考请假页面实现)
fallbackOpenMap(latitude, longitude) {
const url = `https://apis.map.qq.com/uri/v1/marker?marker=coord:${latitude},${longitude};title:实习签到位置;addr:${encodeURIComponent(
this.currentLocation.address || '当前位置',
)}&referer=智慧校园`;
// 首先尝试使用uni.openLocation(原生地图)
if (typeof uni.openLocation === 'function') {
uni.showLoading({
@@ -1059,7 +1103,7 @@ export default {
confirmText: '重新获取',
success: (res) => {
if (res.confirm) {
this.initLocation();
this.handleGetLocation();
}
}
});
@@ -1269,6 +1313,24 @@ export default {
checkIsWechatBrowser() {
const ua = navigator.userAgent.toLowerCase();
return ua.includes('micromessenger');
},
/**
* 刷新数据
*/
async refreshData() {
try {
// 刷新位置信息
if (!this.currentLocation) {
await this.getCurrentLocationInfo();
}
// 检查今日签到状态
await this.checkTodayCheckInStatus();
} catch (error) {
console.error('数据刷新失败:', error);
}
}
},
@@ -1295,8 +1357,8 @@ export default {
// 设置当前日期
this.currentDate = this.formatDate(new Date());
// 检测微信环境
this.isWechatBrowser = this.checkIsWechatBrowser();
// 检测微信环境(在methods中有相应方法)
// this.checkIsWechatBrowser() 在需要时调用
// 获取用户信息(不阻塞)
this.loadUserInfo().catch(error => {
@@ -1308,33 +1370,15 @@ export default {
console.error('实习信息加载失败:', error);
});
// 获取位置信息(核心功能,但不阻塞页面显示)
this.getCurrentLocationInfo().catch(error => {
console.error('位置信息获取失败:', error);
});
// 初始化位置权限检查(不阻塞页面显示)
this.initLocation().catch(error => {
console.error('位置信息初始化失败:', error);
});
// 检查今日签到状态(不阻塞)
this.checkTodayCheckInStatus().catch(error => {
console.error('签到状态检查失败:', error);
});
},
/**
* 刷新数据
*/
async refreshData() {
try {
// 刷新位置信息
if (!this.currentLocation) {
await this.getCurrentLocationInfo();
}
// 检查今日签到状态
await this.checkTodayCheckInStatus();
} catch (error) {
console.error('数据刷新失败:', error);
}
}
};
</script>
@@ -1517,68 +1561,56 @@ export default {
margin-left: 4px;
}
/* 位置信息 */
.location-address {
display: flex;
align-items: flex-start;
margin-bottom: 16px;
padding: 12px;
background: #f8f9fa;
border-radius: 8px;
border-left: 3px solid #67c23a;
}
.address-icon {
margin-right: 8px;
margin-top: 2px;
flex-shrink: 0;
}
.address-text {
font-size: 14px;
color: #303133;
line-height: 1.5;
flex: 1;
}
/* 坐标信息 */
.coordinates-section {
/* 位置信息(参考请假页面样式) */
.location-row {
margin-bottom: 16px;
}
.coord-row {
.location-btn {
width: 100%;
height: 44px;
display: flex;
align-items: center;
justify-content: center;
border-radius: 8px;
border: 1px solid #2979ff;
background: #fff;
color: #2979ff;
}
.location-info-section {
margin-top: 16px;
padding: 16px;
background: #f8f9fa;
border-radius: 8px;
padding: 12px;
border: 1px solid #e4e7ed;
}
.coord-item {
flex: 1;
text-align: center;
.location-coords-container {
margin-bottom: 12px;
}
.coord-divider {
width: 1px;
height: 32px;
background: #e4e7ed;
margin: 0 16px;
}
.coord-label {
display: block;
font-size: 12px;
color: #909399;
margin-bottom: 4px;
}
.coord-value {
display: block;
.location-coords {
font-size: 14px;
color: #303133;
font-weight: 500;
font-family: monospace;
line-height: 1.5;
word-break: break-all;
}
.location-action-container {
display: flex;
justify-content: center;
margin-top: 12px;
}
.view-map-btn {
min-width: 120px;
height: 36px;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}
/* 精度信息 */