Browse Source

feat(student): 优化体测记录功能并添加孩子按钮

-体测记录数据处理和PDF文件格式转换
- 添加获取图片文件对外网络路径的函数
-优化反馈页面的提交逻辑
- 改进体测记录卡片的文件预览功能
- 更新体测记录弹窗的文件上传逻辑
- 在学生首页添加"添加孩子"按钮和相关导航
master
王泽彦 8 months ago
parent
commit
c59bea87c9
  1. 11
      niucloud/app/api/controller/apiController/PhysicalTest.php
  2. 71
      niucloud/app/api/controller/parent/ParentController.php
  3. 36
      niucloud/app/api/controller/student/StudentController.php
  4. 13
      niucloud/app/api/route/student.php
  5. 10
      niucloud/app/common.php
  6. 53
      niucloud/app/service/api/apiService/PhysicalTestService.php
  7. 55
      niucloud/app/service/api/student/PhysicalTestService.php
  8. 52
      niucloud/app/service/api/student/StudentService.php
  9. 82
      uniapp/api/member.js
  10. 69
      uniapp/components/fitness-record-card/fitness-record-card.vue
  11. 9
      uniapp/components/fitness-record-popup/fitness-record-popup.vue
  12. 9
      uniapp/pages.json
  13. 4
      uniapp/pages/common/feedback.vue
  14. 4
      uniapp/pages/common/my_message.vue
  15. 75
      uniapp/pages/market/clue/clue_info.vue
  16. 69
      uniapp/pages/student/home/index.vue
  17. 857
      uniapp/pages/student/physical-test/index.vue
  18. 48
      uniapp/pages/student/profile/index.vue

11
niucloud/app/api/controller/apiController/PhysicalTest.php

@ -27,13 +27,10 @@ class PhysicalTest extends BaseApiService
//列表
public function index(Request $request)
{
$resource_id = $request->param('resource_id', '');//学生资源表id
if (empty($resource_id)) {
return fail('缺少参数');
}
$student_id = $request->param('student_id', '');//学生资源表id
$where = [
'resource_id' => $resource_id,
'student_id' => $student_id,
];
$res = (new PhysicalTestService())->getList($where);
@ -68,8 +65,8 @@ class PhysicalTest extends BaseApiService
{
$data = $request->param();
// 验证必填字段
$required_fields = ['resource_id', 'student_id', 'age', 'height', 'weight'];
// 验证必填字段 - 根据新的数据库表结构调整
$required_fields = ['resource_id', 'student_id', 'height', 'weight'];
foreach ($required_fields as $field) {
if (empty($data[$field])) {
return fail("缺少参数:{$field}");

71
niucloud/app/api/controller/parent/ParentController.php

@ -20,78 +20,7 @@ use think\Response;
*/
class ParentController extends BaseController
{
/**
* 获取家长下的孩子列表
* @return Response
*/
public function getChildrenList()
{
try {
$service = new ParentService();
$result = $service->getChildrenList();
return success($result, '获取孩子列表成功');
} catch (\Exception $e) {
return fail($e->getMessage());
}
}
/**
* 获取指定孩子的详细信息
* @return Response
*/
public function getChildInfo()
{
$data = $this->request->params([
['child_id', '']
]);
$this->validate($data, [
'child_id' => 'require'
]);
try {
$service = new ParentService();
$result = $service->getChildInfo($data['child_id']);
return success($result, '获取孩子信息成功');
} catch (\Exception $e) {
return fail($e->getMessage());
}
}
/**
* 新增孩子信息
* @return Response
*/
public function addChild()
{
$data = $this->request->params([
['name', ''],
['gender', 1],
['birthday', ''],
['age', 0],
['remark', '']
]);
$this->validate($data, [
'name' => 'require',
'gender' => 'require|in:1,2',
'birthday' => 'require|date'
]);
try {
$service = new ParentService();
$result = $service->addChild($data);
return success($result, '添加孩子成功');
} catch (\Exception $e) {
return fail($e->getMessage());
}
}
/**
* 更新孩子信息

36
niucloud/app/api/controller/student/StudentController.php

@ -9,6 +9,7 @@
namespace app\api\controller\student;
use app\service\api\parent\ParentService;
use app\service\api\student\StudentService;
use core\base\BaseController;
use think\Response;
@ -189,4 +190,39 @@ class StudentController extends BaseController
return fail($e->getMessage());
}
}
/**
* 新增孩子信息
* @return Response
*/
public function addChild()
{
$data = $this->request->params([
['name', ''],
['gender', '1'],
['birthday', ''],
['headimg', ''],
['emergency_contact', ''],
['contact_phone', ''],
['note', '']
]);
$this->validate($data, [
'name' => 'require|length:2,20',
'gender' => 'require|in:1,2',
'birthday' => 'require|date',
'contact_phone' => 'mobile',
'emergency_contact' => 'max:20'
]);
try {
$service = new StudentService();
$result = $service->addChild($data);
return success($result, '添加孩子成功');
} catch (\Exception $e) {
return fail($e->getMessage());
}
}
}

13
niucloud/app/api/route/student.php

@ -20,10 +20,7 @@ Route::group('student', function () {
// 上传头像
Route::post('avatar', 'app\api\controller\student\StudentController@uploadAvatar');
//家长端接口
Route::get('parent/children', 'parent.ParentController/getChildrenList');
Route::get('parent/child/info', 'parent.ParentController/getChildInfo');
Route::post('parent/child/add', 'parent.ParentController/addChild');
Route::post('add-child', 'app\api\controller\student\StudentController@addChild');
Route::post('parent/child/update', 'parent.ParentController/updateChildInfo');
Route::get('parent/child/courses', 'parent.ParentController/getChildCourses');
Route::get('parent/child/orders', 'parent.ParentController/getChildOrders');
@ -35,13 +32,13 @@ Route::group('student', function () {
// 体测数据管理
Route::group('physical-test', function () {
// 获取体测记录列表
Route::get('list', 'student.PhysicalTestController@getPhysicalTestList');
Route::get('list', 'app\api\controller\student\PhysicalTestController@getPhysicalTestList');
// 获取体测详情
Route::get('detail/:test_id', 'student.PhysicalTestController@getPhysicalTestDetail');
Route::get('detail/:test_id', 'app\api\controller\student\PhysicalTestController@getPhysicalTestDetail');
// 获取体测趋势数据
Route::get('trend', 'student.PhysicalTestController@getPhysicalTestTrend');
Route::get('trend', 'app\api\controller\student\PhysicalTestController@getPhysicalTestTrend');
// PDF转图片分享
Route::post('share/:test_id', 'student.PhysicalTestController@sharePhysicalTestPdf');
Route::post('share/:test_id', 'app\api\controller\student\PhysicalTestController@sharePhysicalTestPdf');
})->middleware(['ApiCheckToken']);
// 课程预约管理

10
niucloud/app/common.php

@ -280,6 +280,16 @@ function get_file_url(string $path)
}
}
/**
* 获取图片文件的对外网络路径(get_file_url的别名)
* @param string $path
* @return string
*/
function get_image_url(string $path)
{
return get_file_url($path);
}
/**
* 新增队列工作
* @param $job

53
niucloud/app/service/api/apiService/PhysicalTestService.php

@ -37,9 +37,10 @@ class PhysicalTestService extends BaseApiService
$limit = $page_params['limit'];
$model = new PhysicalTest();
//判断用没有员工id
if (!empty($where['resource_id'])) {
$model = $model->where('resource_id', $where['resource_id']);
if (!empty($where['student_id'])) {
$model = $model->where('student_id', $where['student_id']);
}
$data = $model
@ -56,15 +57,6 @@ class PhysicalTestService extends BaseApiService
'page' => $page,
])->toArray();
foreach ($data['data'] as &$v) {
$age = $v['age'];//年龄
$gender = $v['customerResourcesHasOne']['gender'] == 'female' ? 2:1 ;//性别( 1:男,2:女)
$height = $v['height'];//身高
$weight = $v['weight'];//体重
$v['calculateChildHealthScore'] = calculateChildHealthScore($age, $gender, $height, $weight);//综合评分
}
return $data;
}
@ -90,13 +82,6 @@ class PhysicalTestService extends BaseApiService
if ($data) {
$data = $data->toArray();
$age = $data['age'];//年龄
$gender = $data['customerResourcesHasOne']['gender'] == 'female' ? 2 : 1;//性别( 1:男,2:女)
$height = $data['height'];//身高
$weight = $data['weight'];//体重
$data['calculateChildHealthScore'] = calculateChildHealthScore($age, $gender, $height, $weight);//综合评分
$res = [
'code' => 1,
'msg' => '操作成功',
@ -123,11 +108,10 @@ class PhysicalTestService extends BaseApiService
try {
$model = new PhysicalTest();
// 设置基础数据
// 设置基础数据 - 根据新的数据库表结构调整
$physicalTestData = [
'resource_id' => $data['resource_id'],
'student_id' => $data['student_id'],
'age' => $data['age'],
'height' => $data['height'],
'weight' => $data['weight'],
'coach_id' => $data['coach_id'] ?? null,
@ -135,18 +119,18 @@ class PhysicalTestService extends BaseApiService
'updated_at' => date('Y-m-d H:i:s')
];
// 设置体测项目数据
$test_items = [
'seated_forward_bend', 'sit_ups', 'push_ups', 'flamingo_balance',
'thirty_sec_jump', 'standing_long_jump', 'agility_run', 'balance_beam',
'tennis_throw', 'ten_meter_shuttle_run'
];
// 数据库表结构已简化,移除体测项目字段的处理
// $test_items = [
// 'seated_forward_bend', 'sit_ups', 'push_ups', 'flamingo_balance',
// 'thirty_sec_jump', 'standing_long_jump', 'agility_run', 'balance_beam',
// 'tennis_throw', 'ten_meter_shuttle_run'
// ];
foreach ($test_items as $item) {
if (isset($data[$item])) {
$physicalTestData[$item] = $data[$item];
}
}
// foreach ($test_items as $item) {
// if (isset($data[$item])) {
// $physicalTestData[$item] = $data[$item];
// }
// }
// 处理体测报告附件
if (!empty($data['physical_test_report'])) {
@ -203,12 +187,9 @@ class PhysicalTestService extends BaseApiService
'updated_at' => date('Y-m-d H:i:s')
];
// 允许更新的字段
// 允许更新的字段 - 根据新的数据库表结构调整
$allowed_fields = [
'age', 'height', 'weight', 'coach_id',
'seated_forward_bend', 'sit_ups', 'push_ups', 'flamingo_balance',
'thirty_sec_jump', 'standing_long_jump', 'agility_run', 'balance_beam',
'tennis_throw', 'ten_meter_shuttle_run'
'height', 'weight', 'coach_id'
];
foreach ($allowed_fields as $field) {

55
niucloud/app/service/api/student/PhysicalTestService.php

@ -24,16 +24,13 @@ class PhysicalTestService extends BaseService
public function getPhysicalTestList($data)
{
$studentId = $data['student_id'];
// 验证学员权限
$this->checkStudentPermission($studentId);
$page = $data['page'] ?? 1;
$limit = $data['limit'] ?? 20;
$list = (new PhysicalTest())
->where('student_id', $studentId)
->field('id,student_id,age,height,weight,physical_test_report,created_at,updated_at')
->field('id,student_id,height,weight,physical_test_report,created_at,updated_at')
->order('created_at desc')
->page($page, $limit)
->select()
@ -87,9 +84,6 @@ class PhysicalTestService extends BaseService
throw new CommonException('体测记录不存在');
}
// 验证学员权限
$this->checkStudentPermission($physicalTest['student_id']);
$data = $physicalTest->toArray();
// 格式化数据
@ -151,9 +145,6 @@ class PhysicalTestService extends BaseService
{
$studentId = $data['student_id'];
$months = $data['months'] ?? 12;
// 验证学员权限
$this->checkStudentPermission($studentId);
// 获取指定月份内的体测数据
$startDate = date('Y-m-d', strtotime("-{$months} months"));
@ -220,13 +211,6 @@ class PhysicalTestService extends BaseService
throw new CommonException('体测记录不存在');
}
// 验证学员权限
$this->checkStudentPermission($physicalTest['student_id']);
if (!$physicalTest['physical_test_report']) {
throw new CommonException('该体测记录没有PDF报告');
}
// 获取第一个PDF文件
$files = explode(',', $physicalTest['physical_test_report']);
$pdfFile = trim($files[0]);
@ -282,41 +266,4 @@ class PhysicalTestService extends BaseService
}
}
/**
* 检查学员权限
* @param int $studentId
* @return bool
*/
private function checkStudentPermission($studentId)
{
$customerId = $this->getUserId();
// 获取客户资源信息
$customerResource = (new CustomerResources())->where('id', $customerId)->find();
if (!$customerResource) {
throw new CommonException('用户信息不存在');
}
// 检查学员是否属于当前用户
$student = (new Student())
->where('id', $studentId)
->where('member_id', $customerResource['member_id'])
->where('delete_time', 0)
->find();
if (!$student) {
throw new CommonException('无权限访问该学员信息');
}
return true;
}
/**
* 获取当前登录用户ID
* @return int
*/
private function getUserId()
{
return request()->userId ?? 0;
}
}

52
niucloud/app/service/api/student/StudentService.php

@ -239,11 +239,8 @@ class StudentService extends BaseService
$this->checkStudentPermission($studentId);
// 处理文件上传
$uploadService = new \app\service\core\upload\UploadService();
$result = $uploadService->image([
'image' => request()->file('image'),
'thumb_type' => 'avatar'
]);
$uploadService = new \app\service\api\upload\UploadService();
$result = $uploadService->avatar(request()->file('image'));
if (!$result) {
throw new CommonException('头像上传失败');
@ -334,6 +331,51 @@ class StudentService extends BaseService
return $years + ($months / 100);
}
/**
* 添加孩子信息
* @param array $data
* @return array
*/
public function addChild($data)
{
$customerId = $this->getUserId();
// 创建学员数据
$studentData = [
'user_id' => $customerId,
'name' => $data['name'],
'gender' => (int)$data['gender'],
'birthday' => $data['birthday'],
'headimg' => $data['headimg'] ?? '',
'emergency_contact' => $data['emergency_contact'] ?? '',
'contact_phone' => $data['contact_phone'] ?? '',
'note' => $data['note'] ?? '',
'age' => $this->calculateAgeFromBirthday($data['birthday']),
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
'deleted_at' => 0
];
try {
// 插入学员数据
$studentId = Db::table('school_student')->insertGetId($studentData);
if (!$studentId) {
throw new CommonException('添加孩子失败');
}
return [
'student_id' => $studentId,
'name' => $data['name'],
'gender_text' => $data['gender'] == 1 ? '男' : '女',
'age' => $this->calculateAge($data['birthday'])
];
} catch (\Exception $e) {
throw new CommonException('添加孩子失败:' . $e->getMessage());
}
}
/**
* 获取当前登录用户ID
* @return int

82
uniapp/api/member.js

@ -1,4 +1,5 @@
import http from '../common/axios.js'
import { Api_url } from '../common/config.js'
export default {
//↓↓↓↓↓↓↓↓↓↓↓↓-----学员信息管理接口-----↓↓↓↓↓↓↓↓↓↓↓↓
@ -37,4 +38,85 @@ export default {
}
};
},
//↓↓↓↓↓↓↓↓↓↓↓↓-----体测数据管理接口-----↓↓↓↓↓↓↓↓↓↓↓↓
// 获取学员体测数据列表(从school_physical_test表)
async getPhysicalTestList(data = {}) {
return await http.get('/physical-test/list', data);
},
// PDF转图片接口
async convertPdfToImage(data = {}) {
return await http.post('/physical-test/pdf-to-image', data);
},
// 生成体测分享图片
async generateShareImage(data = {}) {
return await http.post('/share-image', data);
},
//↓↓↓↓↓↓↓↓↓↓↓↓-----添加孩子相关接口-----↓↓↓↓↓↓↓↓↓↓↓↓
// 添加孩子
async addChild(data = {}) {
return await http.post('/student/add-child', data);
},
// 上传头像
async uploadAvatar(filePath, studentId) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: Api_url + '/student/avatar',
filePath: filePath,
name: 'image',
formData: {
'student_id': studentId
},
header: {
'token': uni.getStorageSync('token') || ''
},
success: (uploadFileRes) => {
console.log('上传文件响应:', uploadFileRes)
try {
const result = JSON.parse(uploadFileRes.data)
resolve(result)
} catch (e) {
console.error('响应数据解析失败:', e)
reject(new Error('响应数据解析失败'))
}
},
fail: (error) => {
console.error('文件上传失败:', error)
reject(error)
}
})
})
},
// 添加孩子时上传头像(不需要student_id)
async uploadAvatarForAdd(filePath) {
return new Promise((resolve, reject) => {
uni.uploadFile({
url: Api_url + '/file/avatar',
filePath: filePath,
name: 'file',
header: {
'token': uni.getStorageSync('token') || ''
},
success: (uploadFileRes) => {
console.log('上传文件响应:', uploadFileRes)
try {
const result = JSON.parse(uploadFileRes.data)
resolve(result)
} catch (e) {
console.error('响应数据解析失败:', e)
reject(new Error('响应数据解析失败'))
}
},
fail: (error) => {
console.error('文件上传失败:', error)
reject(error)
}
})
})
},
}

69
uniapp/components/fitness-record-card/fitness-record-card.vue

@ -63,48 +63,37 @@ export default {
async handleFileClick(file) {
try {
// PDF
const response = await this.$api.get('/fitness/record/pdf/preview', {
file_id: file.id,
record_id: this.record.id
})
if (response.code === 1 && response.data) {
// PDF
uni.downloadFile({
url: response.data.file_url,
success: (res) => {
if (res.statusCode === 200) {
uni.openDocument({
filePath: res.tempFilePath,
fileType: 'pdf',
success: () => {
console.log('PDF预览成功')
},
fail: (err) => {
console.error('PDF预览失败:', err)
uni.showToast({
title: 'PDF预览失败',
icon: 'none'
})
}
})
}
},
fail: (err) => {
console.error('PDF下载失败:', err)
uni.showToast({
title: 'PDF下载失败',
icon: 'none'
let url = this.$util.getResourceUrl(file)
console.log('file url:', url)
// PDF
uni.downloadFile({
url: url,
success: (res) => {
if (res.statusCode === 200) {
uni.openDocument({
filePath: res.tempFilePath,
fileType: 'pdf',
success: () => {
console.log('PDF预览成功')
},
fail: (err) => {
console.error('PDF预览失败:', err)
uni.showToast({
title: 'PDF预览失败',
icon: 'none'
})
}
})
}
})
} else {
uni.showToast({
title: response.msg || 'PDF预览失败',
icon: 'none'
})
}
},
fail: (err) => {
console.error('PDF下载失败:', err)
uni.showToast({
title: 'PDF下载失败',
icon: 'none'
})
}
})
} catch (error) {
console.error('PDF预览异常:', error)
uni.showToast({

9
uniapp/components/fitness-record-popup/fitness-record-popup.vue

@ -175,13 +175,14 @@ export default {
const params = {
resource_id: this.resourceId,
student_id: this.resourceId, // student_id
age: 18, //
test_date: this.recordData.test_date,
height: this.recordData.height,
weight: this.recordData.weight,
pdf_files: this.recordData.pdf_files,
// PDF
physical_test_report: this.recordData.pdf_files.map(file => file.server_path || file.url).filter(path => path)
// PDF
physical_test_report: this.recordData.pdf_files
.map(file => file.server_path || file.url)
.filter(path => path)
.join(',') //
}
if (this.isEditing) {

9
uniapp/pages.json

@ -180,6 +180,15 @@
"navigationBarTextStyle": "white"
}
},
{
"path": "pages/student/child/add",
"style": {
"navigationBarTitleText": "添加孩子",
"navigationStyle": "custom",
"navigationBarBackgroundColor": "#29d3b4",
"navigationBarTextStyle": "white"
}
},
{
"path": "pages/common/privacy_agreement",
"style": {

4
uniapp/pages/common/feedback.vue

@ -123,10 +123,6 @@
title:'提交成功',
icon:'none'
})
//1s
setTimeout(() => {
this.$util.openHomeView();
}, 1000);
}
},

4
uniapp/pages/common/my_message.vue

@ -238,10 +238,6 @@ export default {
title: '提交成功',
icon: 'none'
})
//1s
setTimeout(() => {
this.$util.openHomeView();
}, 1000);
}
},

75
uniapp/pages/market/clue/clue_info.vue

@ -761,7 +761,8 @@ export default {
})
if (res.code === 1 && res.data) {
this.fitnessRecords = res.data.data || []
// PDF
this.fitnessRecords = this.processFitnessRecords(res.data.data || [])
} else {
console.warn('获取体测记录失败:', res.msg)
this.fitnessRecords = []
@ -772,13 +773,83 @@ export default {
}
},
// PDF
processFitnessRecords(records) {
if (!records || !Array.isArray(records)) return []
return records.map(record => {
const processedRecord = {
...record,
test_date: record.created_at ? record.created_at.split(' ')[0] : '', // created_at
pdf_files: []
}
// PDF
if (record.physical_test_report) {
// physical_test_report
if (typeof record.physical_test_report === 'string') {
const pdfPaths = record.physical_test_report.split(',').filter(path => path.trim())
processedRecord.pdf_files = pdfPaths.map((path, index) => ({
id: `${record.id}_${index}`,
name: this.extractFileName(path) || `体测报告_${index + 1}.pdf`,
size: 0, //
url: this.getFullPdfUrl(path),
server_path: path.trim(),
upload_time: record.created_at || ''
}))
}
// physical_test_report
else if (Array.isArray(record.physical_test_report)) {
processedRecord.pdf_files = record.physical_test_report
}
}
return processedRecord
})
},
//
extractFileName(filePath) {
if (!filePath) return ''
const parts = filePath.split('/')
return parts[parts.length - 1] || ''
},
// PDFURL
getFullPdfUrl(relativePath) {
if (!relativePath) return ''
// URL
if (relativePath.startsWith('http://') || relativePath.startsWith('https://')) {
return relativePath
}
// URL
const { img_domian } = require('@/common/config.js')
//
let cleanPath = relativePath
if (cleanPath.startsWith('./')) {
cleanPath = cleanPath.substring(2)
}
if (cleanPath.startsWith('/')) {
cleanPath = cleanPath.substring(1)
}
return `${img_domian}${cleanPath}`
},
openAddFitnessRecord() {
this.$refs.fitnessRecordPopup.openAdd()
},
openEditFitnessRecord(record) {
this.$refs.fitnessRecordPopup.openEdit(record)
// PDF
const processedRecord = {
...record,
pdf_files: record.pdf_files || [] // 使pdf_files
}
this.$refs.fitnessRecordPopup.openEdit(processedRecord)
},
async handleFitnessRecordConfirm(result) {

69
uniapp/pages/student/home/index.vue

@ -162,6 +162,14 @@
</view>
</view>
</view>
<!-- 添加孩子按钮 -->
<view class="popup_footer">
<button class="add_child_button" @click="navigateToAddChild">
<image src="/static/icon-img/add.png" class="add_icon"></image>
添加孩子
</button>
</view>
</view>
</view>
</view>
@ -419,6 +427,14 @@
})
},
navigateToAddChild() {
console.log('跳转到添加孩子页面')
this.closeStudentPopup()
uni.navigateTo({
url: '/pages/student/child/add'
})
},
checkStudentSelected() {
if (!this.selectedStudent) {
uni.showToast({
@ -682,6 +698,7 @@
justify-content: center;
align-items: center;
z-index: 1000;
animation: fadeIn 0.3s ease-out;
.popup_content {
background: #fff;
@ -689,6 +706,8 @@
width: 80%;
max-height: 60vh;
overflow: hidden;
animation: slideUp 0.3s ease-out;
box-shadow: 0 8rpx 32rpx rgba(0, 0, 0, 0.1);
.popup_header {
display: flex;
@ -768,6 +787,56 @@
}
}
}
.popup_footer {
padding: 32rpx;
border-top: 1px solid #f0f0f0;
.add_child_button {
width: 100%;
background: linear-gradient(135deg, #29D3B4 0%, #1BA297 100%);
color: #fff;
border: none;
border-radius: 16rpx;
padding: 24rpx 0;
font-size: 28rpx;
font-weight: 600;
display: flex;
align-items: center;
justify-content: center;
gap: 12rpx;
.add_icon {
width: 24rpx;
height: 24rpx;
}
&:active {
opacity: 0.8;
}
}
}
}
}
//
@keyframes fadeIn {
from {
opacity: 0;
}
to {
opacity: 1;
}
}
@keyframes slideUp {
from {
transform: translateY(100rpx);
opacity: 0;
}
to {
transform: translateY(0);
opacity: 1;
}
}
</style>

857
uniapp/pages/student/physical-test/index.vue

File diff suppressed because it is too large

48
uniapp/pages/student/profile/index.vue

@ -324,26 +324,24 @@
})
try {
//
await new Promise(resolve => setTimeout(resolve, 1500))
// API
const response = await apiRoute.uploadAvatarForAdd(tempFilePath)
console.log('头像上传API响应:', response)
//
const mockUploadResponse = {
code: 1,
data: {
url: tempFilePath, // 使
path: '/uploads/avatar/student_' + this.studentId + '_' + Date.now() + '.jpg'
}
}
if (mockUploadResponse.code === 1) {
this.studentInfo.headimg = mockUploadResponse.data.url
if (response.code === 1) {
// URL
this.studentInfo.headimg = response.data.url
this.formData.headimg = response.data.url
//
await this.saveAvatarToDatabase(response.data.url)
uni.showToast({
title: '头像上传成功',
icon: 'success'
})
} else {
throw new Error('上传失败')
throw new Error(response.msg || '上传失败')
}
} catch (uploadError) {
console.error('头像上传失败:', uploadError)
@ -364,6 +362,28 @@
}
},
async saveAvatarToDatabase(avatarUrl) {
try {
const updateData = {
student_id: this.studentId,
headimg: avatarUrl
}
console.log('保存头像到数据库:', updateData)
// API
const response = await apiRoute.updateStudentInfo(updateData)
console.log('保存头像API响应:', response)
if (response.code !== 1) {
throw new Error(response.msg || '保存头像失败')
}
} catch (error) {
console.error('保存头像到数据库失败:', error)
throw error
}
},
async saveStudentInfo() {
//
if (!this.formData.name.trim()) {

Loading…
Cancel
Save