|
|
@@ -17,6 +17,14 @@
|
|
|
import emitter from '@/utils/emitter';
|
|
|
import dayjs from "dayjs";
|
|
|
import * as XLSX from 'xlsx'
|
|
|
+ import useApis from "@/apis";
|
|
|
+ import {useRoute} from "vue-router";
|
|
|
+
|
|
|
+ const apis = useApis()
|
|
|
+ // 获取当前路由对象
|
|
|
+ const route = useRoute();
|
|
|
+ // 从路由对象中提取 id 参数
|
|
|
+ const assignmentId = Number(route.params.assignmentId);
|
|
|
|
|
|
let range = reactive({})
|
|
|
let lastChange = reactive({})
|
|
|
@@ -184,14 +192,14 @@
|
|
|
delete keyEventMap[key];
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // TODO:测试片段,需删除
|
|
|
+ emitter.emit('record-test', changeRecordList)
|
|
|
}
|
|
|
|
|
|
const download = () => {
|
|
|
- // const ws = XLSX.utils.json_to_sheet(flattenOps(changeRecordList))
|
|
|
const ws = XLSX.utils.json_to_sheet(changeRecordList)
|
|
|
- /* 新建空workbook */
|
|
|
const wb = XLSX.utils.book_new()
|
|
|
- /* 添加worksheet,当然你可以添加多个,这里我只添加一个 */
|
|
|
XLSX.utils.book_append_sheet(wb, ws, 'result')
|
|
|
|
|
|
const wbout = XLSX.write(wb, {
|
|
|
@@ -200,16 +208,23 @@
|
|
|
type: 'array'
|
|
|
})
|
|
|
|
|
|
- let url = window.URL.createObjectURL(new Blob([wbout]))
|
|
|
- let link = document.createElement('a')
|
|
|
- link.style.display = 'none'
|
|
|
- link.href = url
|
|
|
- link.setAttribute('download', '测试数据' + '.xls')
|
|
|
- document.body.appendChild(link)
|
|
|
- link.click()
|
|
|
- document.body.removeChild(link) //下载完成移除元素
|
|
|
- window.URL.revokeObjectURL(url) //释放掉blob对象
|
|
|
+ // 创建 Blob 对象(使用正确的 MIME 类型)
|
|
|
+ const blob = new Blob([wbout], {
|
|
|
+ type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
|
|
+ })
|
|
|
|
|
|
+ // 创建 File 对象并设置文件名(添加时间戳防止重复)
|
|
|
+ const filename = `行为记录.xlsx`
|
|
|
+ const file = new File([blob], filename, { type: blob.type })
|
|
|
+ if(assignmentId != null){
|
|
|
+ apis.addBehaviorRecord(assignmentId, file)
|
|
|
+ .then(res => {
|
|
|
+ console.log(res.data.data)
|
|
|
+ })
|
|
|
+ .catch(err => {
|
|
|
+ console.log(err)
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// 监听 changeRecordList 数组变化
|
|
|
@@ -223,6 +238,7 @@
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
emitter.off("change-record")
|
|
|
+ download()
|
|
|
})
|
|
|
|
|
|
</script>
|