|
|
@@ -58,7 +58,6 @@
|
|
|
|
|
|
<script>
|
|
|
import FilePreview from '@/components/FilePreview/index.vue';
|
|
|
- import { learn } from '@/api/onlineTrainingPlan/index.js';
|
|
|
|
|
|
export default {
|
|
|
components: {
|
|
|
@@ -76,20 +75,12 @@
|
|
|
children: 'children',
|
|
|
label: 'label'
|
|
|
},
|
|
|
- treeData: [],
|
|
|
- // 当前学习的任务ID
|
|
|
- currentTaskId: null,
|
|
|
- // 每分钟上报学习进度的定时器
|
|
|
- learnTimer: null
|
|
|
+ treeData: []
|
|
|
};
|
|
|
},
|
|
|
- beforeDestroy() {
|
|
|
- this.stopLearnTimer();
|
|
|
- },
|
|
|
methods: {
|
|
|
- open(row, needReport = false) {
|
|
|
+ open(row) {
|
|
|
this.visible = true;
|
|
|
- this.currentTaskId = row && row.id ? row.id : null;
|
|
|
const resources = (row && row.trainingResourceList) || [];
|
|
|
const materialName = (row && row.materialName) || '培训资料';
|
|
|
const children = resources.map((item, index) => ({
|
|
|
@@ -112,49 +103,16 @@
|
|
|
}
|
|
|
];
|
|
|
this.showOverlay = true;
|
|
|
- // 仅在「开始学习」调用时开启定时上报
|
|
|
- if (needReport) {
|
|
|
- this.startLearnTimer();
|
|
|
- }
|
|
|
this.$nextTick(() => {
|
|
|
if (children.length) {
|
|
|
this.$refs.treeRef.setCurrentKey(children[0].id);
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
- // 每分钟上报一次学习进度
|
|
|
- startLearnTimer() {
|
|
|
- this.stopLearnTimer();
|
|
|
- if (!this.currentTaskId) {
|
|
|
- return;
|
|
|
- }
|
|
|
- this.learnTimer = setInterval(() => {
|
|
|
- this.reportLearn();
|
|
|
- }, 60 * 1000);
|
|
|
- },
|
|
|
- stopLearnTimer() {
|
|
|
- if (this.learnTimer) {
|
|
|
- clearInterval(this.learnTimer);
|
|
|
- this.learnTimer = null;
|
|
|
- }
|
|
|
- },
|
|
|
- // 上报当前学习进度,无需传入learnedTime
|
|
|
- async reportLearn() {
|
|
|
- if (!this.currentTaskId) {
|
|
|
- return;
|
|
|
- }
|
|
|
- try {
|
|
|
- await learn({ taskId: this.currentTaskId });
|
|
|
- } catch (error) {
|
|
|
- this.$message.error(error.message || '学习进度上报失败');
|
|
|
- }
|
|
|
- },
|
|
|
cancel() {
|
|
|
- this.stopLearnTimer();
|
|
|
this.visible = false;
|
|
|
this.showOverlay = true;
|
|
|
this.currentFileIds = [];
|
|
|
- this.currentTaskId = null;
|
|
|
},
|
|
|
// 附件id标准化,兼容字符串和数组
|
|
|
parseAttachment(attachment) {
|
|
|
@@ -282,4 +240,4 @@
|
|
|
z-index: 10;
|
|
|
}
|
|
|
}
|
|
|
-</style>
|
|
|
+</style>
|