Merge pull request '[lisa-feat]feat: 接口调整' (#5) from lisa-feat into main
Reviewed-on: http://gitea.xhzone.cn/felix/miniprogram-1/pulls/5
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"navigationBarTitleText": "口语评估",
|
||||
"navigationBarTextStyle": "black",
|
||||
"navigationBarBackgroundColor": "#fef6e4",
|
||||
"navigationBarBackgroundColor": "#faeee7",
|
||||
"backgroundColor": "#f8f9fa",
|
||||
"backgroundTextStyle": "light",
|
||||
"enablePullDownRefresh": false,
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
.assessment-container {
|
||||
min-height: 100vh;
|
||||
/* background-color: #f5f5f5; */
|
||||
background-color: #fef6e4;
|
||||
/* background-color: #fef6e4; */
|
||||
background-color: #faeee7;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
@@ -53,7 +53,12 @@ Page({
|
||||
// 加载识别结果
|
||||
async loadRecognitionResult(imageId: string) {
|
||||
try {
|
||||
const result = await apiManager.getRecognizeImage(imageId)
|
||||
const { task_id } = await apiManager.recognizeImageAsync(imageId)
|
||||
|
||||
// 轮询获取识别结果
|
||||
const result = await apiManager.recognizeGetTask(task_id)
|
||||
|
||||
|
||||
|
||||
// 设置识别结果
|
||||
this.setData({ recognitionResult: result })
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
},
|
||||
"navigationBarTitleText": "",
|
||||
"navigationBarTextStyle": "white",
|
||||
"navigationBarBackgroundColor": "#f3d2c1",
|
||||
"navigationBarBackgroundColor": "#fffffe",
|
||||
"backgroundColor": "#fffffe",
|
||||
"backgroundTextStyle": "light",
|
||||
"enablePullDownRefresh": false,
|
||||
|
||||
@@ -16,7 +16,6 @@ const DayTypeMap: Record<IDayType, string> = {
|
||||
|
||||
Page({
|
||||
data: {
|
||||
move_camera_pos_to: 'top' as 'top' | 'bottom',
|
||||
DayTypeMap,
|
||||
current_date: '',
|
||||
day_type: 'morning' as IDayType,
|
||||
@@ -34,7 +33,10 @@ Page({
|
||||
// 添加加载状态
|
||||
isLoading: true,
|
||||
// 添加文件基础URL
|
||||
fileBaseUrl: FILE_BASE_URL
|
||||
fileBaseUrl: FILE_BASE_URL,
|
||||
// 添加表情位置状态
|
||||
facePosition: 'normal' as 'up' | 'down' | 'normal',
|
||||
scrollTop: 0
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
@@ -56,6 +58,35 @@ Page({
|
||||
this.setData({ isProcessing: false }) // 清理处理状态
|
||||
},
|
||||
|
||||
// 处理页面滚动
|
||||
onPageScroll(e: WechatMiniprogram.Page.IPageScrollOption): void {
|
||||
const scrollTop = e.scrollTop
|
||||
const lastScrollTop = this.data.scrollTop
|
||||
const threshold = 30 // 滚动阈值
|
||||
|
||||
// 更新滚动位置
|
||||
this.setData({ scrollTop })
|
||||
|
||||
// 向上滚动
|
||||
if (scrollTop < lastScrollTop && scrollTop > threshold) {
|
||||
if (this.data.facePosition !== 'up') {
|
||||
this.setData({ facePosition: 'up' })
|
||||
}
|
||||
}
|
||||
// 向下滚动
|
||||
else if (scrollTop > lastScrollTop && scrollTop > threshold) {
|
||||
if (this.data.facePosition !== 'down') {
|
||||
this.setData({ facePosition: 'down' })
|
||||
}
|
||||
}
|
||||
// 回到顶部附近
|
||||
else if (scrollTop <= threshold) {
|
||||
if (this.data.facePosition !== 'normal') {
|
||||
this.setData({ facePosition: 'normal' })
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
checkDayType() {
|
||||
const currentHour = new Date().getHours();
|
||||
@@ -70,7 +101,7 @@ Page({
|
||||
// 根据日间/夜间模式设置导航栏颜色
|
||||
wx.setNavigationBarColor({
|
||||
frontColor: '#ffffff',
|
||||
backgroundColor: dayType === 'night' ? '#232946' : '#f3d2c1',
|
||||
backgroundColor: dayType === 'night' ? '#232946' : '#fffffe',
|
||||
animation: {
|
||||
duration: 300,
|
||||
timingFunc: 'easeIn'
|
||||
@@ -158,19 +189,6 @@ Page({
|
||||
}
|
||||
},
|
||||
|
||||
onPageScroll(e: any) {
|
||||
const scrollTop = e.scrollTop;
|
||||
if (scrollTop >= 30) {
|
||||
this.setData({
|
||||
move_camera_pos_to: 'top',
|
||||
})
|
||||
} else {
|
||||
this.setData({
|
||||
move_camera_pos_to: 'bottom',
|
||||
})
|
||||
}
|
||||
},
|
||||
|
||||
// 下拉刷新
|
||||
onPullDownRefresh() {
|
||||
this.setData({
|
||||
@@ -183,12 +201,20 @@ Page({
|
||||
|
||||
// 图片点击事件
|
||||
onImageTap(e: any) {
|
||||
const { imageId } = e.currentTarget.dataset;
|
||||
if (imageId) {
|
||||
wx.navigateTo({
|
||||
url: `/pages/assessment/assessment?imageId=${imageId}`
|
||||
})
|
||||
}
|
||||
const { imageItems } = e.currentTarget.dataset;
|
||||
if (!imageItems?.images?.length) return;
|
||||
|
||||
const items = imageItems.images.map((item: any) => ({
|
||||
image_id: item.image_id,
|
||||
image: item.thumbnail_url,
|
||||
}));
|
||||
ActionSheet.show({
|
||||
theme: ActionSheetTheme.Grid,
|
||||
selector: '#t-images-sheet',
|
||||
context: this,
|
||||
items,
|
||||
cancelText: '取消',
|
||||
} as ActionSheet.ShowOption);
|
||||
},
|
||||
|
||||
onImageCardTap(e: any) {
|
||||
@@ -205,7 +231,7 @@ Page({
|
||||
context: this,
|
||||
items,
|
||||
cancelText: '取消'
|
||||
});
|
||||
} as ActionSheet.ShowOption);
|
||||
},
|
||||
|
||||
// 检查登录状态
|
||||
@@ -268,7 +294,7 @@ Page({
|
||||
cancelText: '取消',
|
||||
align: 'center',
|
||||
description: ''
|
||||
})
|
||||
} as ActionSheet.ShowOption);
|
||||
},
|
||||
|
||||
handleSelected(e: any) {
|
||||
|
||||
@@ -21,8 +21,8 @@
|
||||
</view> -->
|
||||
<!-- 欢迎区域 -->
|
||||
<view class="sunny-wrap" wx:if="{{ day_type !== 'night' }}">
|
||||
<image src="/static/sun.png" class="sunny-icon" />
|
||||
<view class="face">•ᴗ•</view>
|
||||
<image src="/static/sun-2.png" class="sunny-icon" />
|
||||
<view class="face {{facePosition}}">•ᴗ•</view>
|
||||
</view>
|
||||
<view wx:else>
|
||||
<view class="moon-wrap">
|
||||
@@ -37,7 +37,7 @@
|
||||
<view class="hello">{{DayTypeMap[day_type]}}</view>
|
||||
<!-- <view class="begin-text">用一个新单词, 开启美好的一天</view> -->
|
||||
<!-- 功能按钮区域 -->
|
||||
<view class="{{['action-section welcome-card', move_camera_pos_to]}}">
|
||||
<view class="action-section welcome-card">
|
||||
<view class="action-buttons">
|
||||
<t-icon name="image-add" size="140rpx" bind:click="handleImageSelect" />
|
||||
<t-action-sheet id="t-action-sheet" bind:selected="handleSelected" />
|
||||
|
||||
@@ -2,7 +2,8 @@
|
||||
|
||||
.upload-container.morning,
|
||||
.upload-container.afternoon {
|
||||
background-color: #f3d2c1;
|
||||
/* background-color: #f3d2c1; */
|
||||
background-color: #fffffe;
|
||||
}
|
||||
.morning .history-wrap,
|
||||
.afternoon .history-wrap {
|
||||
@@ -81,6 +82,7 @@
|
||||
|
||||
/* 历史记录区域 */
|
||||
.history-wrap {
|
||||
position: relative;
|
||||
padding: 40rpx 40rpx;
|
||||
color: #b8c1ec;
|
||||
}
|
||||
@@ -93,7 +95,8 @@
|
||||
|
||||
.morning .history-card-item,
|
||||
.afternoon .history-card-item {
|
||||
background-color: rgb(254, 246, 228);
|
||||
/* background-color: rgb(254, 246, 228); */
|
||||
background-color: #faeee7;
|
||||
}
|
||||
|
||||
.history-card-item {
|
||||
@@ -129,10 +132,14 @@
|
||||
|
||||
/* 欢迎区域 */
|
||||
.moon-wrap {
|
||||
position: fixed;
|
||||
opacity: 0;
|
||||
color: #ffef22c7;
|
||||
width: 210rpx;
|
||||
height: 210rpx;
|
||||
animation: slideInFromTopRight 3s forwards ease-in-out, fadeIn 3s forwards linear;
|
||||
transform: translate(50%, -50%);
|
||||
|
||||
}
|
||||
.moon-icon {
|
||||
top: 100rpx;
|
||||
@@ -180,6 +187,7 @@
|
||||
right: -100px;
|
||||
color: #ffef22c7;
|
||||
animation: appear 3s ease-out forwards; */
|
||||
position: fixed;
|
||||
width: 210rpx;
|
||||
height: 210rpx;
|
||||
opacity: 0;
|
||||
@@ -195,12 +203,28 @@
|
||||
}
|
||||
.face {
|
||||
position: fixed;
|
||||
top: 64%;
|
||||
left: 50%;
|
||||
transform: translate(-70%, -74%);
|
||||
font-size: 50rpx;
|
||||
font-weight: 500;
|
||||
color:black;
|
||||
color: black;
|
||||
transition: all 0.8s ease;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.face.normal {
|
||||
top: 45%;
|
||||
transform: translate(-70%, -74%);
|
||||
}
|
||||
|
||||
.face.up {
|
||||
top: 55%;
|
||||
transform: translate(-70%, -74%);
|
||||
}
|
||||
|
||||
.face.down {
|
||||
top: 65%;
|
||||
transform: translate(-70%, -74%);
|
||||
}
|
||||
|
||||
@keyframes slideInFromTopRight {
|
||||
@@ -250,7 +274,7 @@
|
||||
position: fixed;
|
||||
top: 440rpx;
|
||||
left: -100rpx;
|
||||
color: #fefefe;
|
||||
color: #eff0f3;
|
||||
opacity: 0.8;
|
||||
animation: moveLeftRight 4s infinite alternate linear;
|
||||
}
|
||||
@@ -318,13 +342,13 @@
|
||||
|
||||
/* 功能描述区域 */
|
||||
.feature-section {
|
||||
margin-top: -130rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
font-size: 28rpx;
|
||||
color: rgb(184, 193, 236);
|
||||
font-weight: bold;
|
||||
z-index: 1;
|
||||
}
|
||||
.hello {
|
||||
margin-top: 80rpx;
|
||||
|
||||
BIN
miniprogram/static/sun-2.png
Normal file
BIN
miniprogram/static/sun-2.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
@@ -722,17 +722,30 @@ class ApiManager {
|
||||
return response.data
|
||||
}
|
||||
|
||||
// 获取图片识别结果
|
||||
async getRecognizeImage(fileId: string): Promise<IRecognitionResult & { file_id: string }> {
|
||||
|
||||
// 图片识别(第二步:通过文件ID进行识别)
|
||||
async recognizeImageAsync(fileId: string, type: string = 'word'): Promise<{task_id: string, status: string, message: string}> {
|
||||
console.log('开始图片识别请求:', { fileId, type })
|
||||
|
||||
// 获取当前的词典等级配置
|
||||
const app = getApp<IAppOption>()
|
||||
const dictLevel = app.globalData.dictLevel || wx.getStorageSync('dictLevel') || 'PRIMARY'
|
||||
|
||||
const response = await this.request<IRecognitionResult>(`/api/v1/image/${fileId}`, 'GET', {
|
||||
dict_level: dictLevel
|
||||
const response = await this.request<{task_id: string, status: string, message: string}>('/api/v1/image/recognize/async', 'POST', {
|
||||
file_id: fileId,
|
||||
type: type,
|
||||
dict_level: dictLevel // 添加词典等级参数
|
||||
})
|
||||
|
||||
console.log('图片识别结果获取成功:', response.data)
|
||||
console.log('图片识别成功:', response.data)
|
||||
return response.data
|
||||
}
|
||||
|
||||
// 获取识别结果
|
||||
async recognizeGetTask(taskId: string | number): Promise<{task_id: string, status: string, error_message: string, result?: IRecognitionResult}> {
|
||||
|
||||
const response = await this.request<{task_id: string, status: string, error_message: string, result?: IRecognitionResult}>(`/api/v1/recognize/task/${taskId}`, 'GET')
|
||||
|
||||
console.log('图片识别成功:', response.data)
|
||||
return response.data
|
||||
}
|
||||
|
||||
@@ -750,7 +763,23 @@ class ApiManager {
|
||||
// wx.showLoading({ title: '识别中...' })
|
||||
|
||||
// 第二步:通过文件ID进行图片识别
|
||||
const recognitionResult = await this.recognizeImage(fileId, type)
|
||||
const { task_id } = await this.recognizeImageAsync(fileId, type)
|
||||
|
||||
// 轮询获取识别结果
|
||||
let recognitionResult: IRecognitionResult | null = null
|
||||
while (true) {
|
||||
try {
|
||||
const res = await this.recognizeGetTask(task_id)
|
||||
if (res.status === 'completed' && res.result) {
|
||||
recognitionResult = res.result
|
||||
break
|
||||
}
|
||||
await new Promise(resolve => setTimeout(resolve, 3000)) // 2秒轮询一次
|
||||
} catch (error) {
|
||||
console.error('轮询获取识别结果失败:', error)
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
// wx.hideLoading()
|
||||
console.log('图片上传和识别流程完成')
|
||||
|
||||
Reference in New Issue
Block a user