职站学生端小程序版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

209 lines
5.4 KiB

<template>
<view class="page">
<view v-if="practices.length" class="list">
<view v-for="(item, i) in practices" :key="i" class="item" @click="toDetail(item)">
<view class="c-name">{{ item.projectName }}</view>
<view class="line">得分:{{ item.score }}&emsp;&emsp;耗时:{{ item.timeSum }}min</view>
<view class="line">练习开始时间:{{ item.startTime }}</view>
<view class="line">练习结束时间:{{ item.submitTime }}</view>
<view class="btn">成绩报告</view>
</view>
</view>
</view>
</template>
<script>
import { practiceByStudentDetail, exportExamPaperReport } from '@/apis/modules/course.js'
export default {
data() {
return {
cid: '',
projectId: '',
paperId: '',
practices: [],
reachBottom: 0, // 是否是上拉加载。0->否,1->是,-1->加载完所有数据
status: 'more', // 上拉加载状态 more|loading|noMore
page: 1,
pageSize: 10,
}
},
// 下拉刷新
onPullDownRefresh() {
this.initList()
setTimeout(() => {
uni.stopPullDownRefresh()
}, 1500)
},
// 上拉加载
onReachBottom() {
if (this.reachBottom >= 0) {
this.reachBottom = 1
this.status = 'loading'
this.getList()
}
},
onShow() {
const pages = getCurrentPages()
const { options } = pages[pages.length - 1]
this.cid = options.cid
this.projectId = options.projectId
this.paperId = options.paperId
this.getList()
},
methods: {
// 练习成绩
async getList () {
const { data } = await practiceByStudentDetail({
page: this.page,
pageSize: this.pageSize,
projectId: this.projectId,
paperId: this.paperId,
cid: this.cid
})
this.practices = this.reachBottom > 0 ? [...this.practices, ...data.records] : data.records
this.page++ // 每次获取了数据后page+1
const noMore = this.practices.length === data.total // 是否加载完所有数据
this.status = noMore ? 'noMore' : 'more' // 加载完了则设置为noMore
this.reachBottom = noMore ? -1 : 0 // 加载完了则设置为-1
},
saveFile(fileData) {
const fs = uni.getFileSystemManager();
// 创建临时文件路径
const tempFilePath = `${uni.env.USER_DATA_PATH}/tempFile`;
console.log('临时文件路径:', uni.env, tempFilePath, fileData)
// 写入文件
fs.writeFile({
filePath: tempFilePath,
data: fileData,
encoding: 'binary', // 使用 binary 编码
success: (res) => {
console.log('文件写入成功', res);
// 保存文件到本地
uni.saveFile({
tempFilePath: tempFilePath,
success: (res) => {
console.log('文件保存成功', res.savedFilePath);
uni.downloadFile({
// url: 'https://eduvessel.com/images/occupationlab/ac校赛试卷四.docx',
url: res.savedFilePath,
success: function(res) {
console.log(11, res)
uni.hideLoading();
uni.showLoading({
title: '正在打开',
mask: true
})
// 新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。
uni.openDocument({
filePath: res.tempFilePath,
fileType: 'docx', // 文件类型,指定文件类型打开文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx
showMenu: true, // 允许出现分享功能
success: res => {
uni.hideLoading()
},
fail: openError => {
uni.hideLoading()
}
})
},
fail: function(err) {
uni.hideLoading()
}
})
},
fail: (err) => {
console.error('文件保存失败', err);
}
});
},
fail: (err) => {
console.error('文件写入失败', err);
}
});
},
// 跳转
async toDetail(row) {
uni.showLoading({
title: '加载中',
mask: true
})
const res = await exportExamPaperReport({
reportId: row.reportId
})
this.saveFile(res)
return
// 下载文件资源到本地
uni.downloadFile({
url: 'https://eduvessel.com/images/occupationlab/ac校赛试卷四.docx',
success: function(res) {
console.log(11, res)
uni.hideLoading();
uni.showLoading({
title: '正在打开',
mask: true
})
// 新开页面打开文档,支持格式:doc, xls, ppt, pdf, docx, xlsx, pptx。
uni.openDocument({
filePath: res.tempFilePath,
fileType: 'docx', // 文件类型,指定文件类型打开文件,有效值 doc, xls, ppt, pdf, docx, xlsx, pptx
showMenu: true, // 允许出现分享功能
success: res => {
uni.hideLoading()
},
fail: openError => {
uni.hideLoading()
}
})
},
fail: function(err) {
uni.hideLoading()
}
})
},
}
}
</script>
<style scoped lang="scss">
.page {
padding: 10rpx 30rpx;
background-color: #fff;
}
.list {
.item {
position: relative;
padding: 20rpx 0;
&:not(:last-child) {
border-bottom: 1px solid #e6e6e6;
}
}
.c-name {
font-size: 32rpx;
font-weight: 600;
color: #333;
}
.line {
margin-top: 14rpx;
font-size: 26rpx;
color: #828282;
}
.btn {
position: absolute;
bottom: 20rpx;
right: 0;
padding: 10rpx 30rpx;
font-size: 28rpx;
color: #fff;
background-color: #007EFF;
border-radius: 36rpx;
}
}
</style>