|
|
@ -91,9 +91,9 @@ import UpdateWorkApi from '../api/UpdateWorkApi'; |
|
|
|
import * as XLSX from 'xlsx'; |
|
|
|
import axios from 'axios'; |
|
|
|
import LoginApi from '../api/LoginApi'; |
|
|
|
import { useTokenStore } from '../stores/token'; |
|
|
|
const router = useRouter(); |
|
|
|
|
|
|
|
|
|
|
|
const back = () => { |
|
|
|
window.history.back() |
|
|
|
} |
|
|
@ -131,54 +131,11 @@ const form = ref({ |
|
|
|
shopId: "", |
|
|
|
}); |
|
|
|
|
|
|
|
const exportData = async () => { |
|
|
|
try { |
|
|
|
const params = { |
|
|
|
// 这里假设form.value和id.value是你已有的正确数据获取方式,按需替换成实际的准确值 |
|
|
|
...form.value, |
|
|
|
id: id.value |
|
|
|
}; |
|
|
|
const response = await axios.post('/api/api/homework_manage/export-record', params, { |
|
|
|
responseType: 'arraybuffer' |
|
|
|
}); |
|
|
|
console.log('导出数据:', response); |
|
|
|
console.log('导出数据:', response.data); |
|
|
|
// 将返回的二进制数据转换为Blob对象,用于创建下载链接 |
|
|
|
const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); |
|
|
|
const url = URL.createObjectURL(blob); |
|
|
|
const a = document.createElement('a'); |
|
|
|
a.href = url; |
|
|
|
// 尝试从响应头中获取Content-Disposition字段来解析文件名 |
|
|
|
const contentDisposition = response.headers['content-disposition']; |
|
|
|
console.log('文件名:', contentDisposition); |
|
|
|
if (contentDisposition) { |
|
|
|
// 使用正则表达式匹配filename |
|
|
|
const fileNameMatch = contentDisposition.match(/filename=([^"]+)/); |
|
|
|
if (fileNameMatch && fileNameMatch.length > 1) { |
|
|
|
const fileName = fileNameMatch[1]; |
|
|
|
a.download = fileName; |
|
|
|
} else { |
|
|
|
console.error('无法从Content-Disposition中解析出文件名'); |
|
|
|
return; |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.error('响应头中不存在Content-Disposition字段'); |
|
|
|
return; |
|
|
|
} |
|
|
|
document.body.appendChild(a); |
|
|
|
a.click(); |
|
|
|
document.body.removeChild(a); |
|
|
|
URL.revokeObjectURL(url); |
|
|
|
} catch (error) { |
|
|
|
console.error('详细的请求错误信息:', error); |
|
|
|
ElMessage.error('导出失败'); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
// 搜索方法 |
|
|
|
const searchData = async () => { |
|
|
|
try { |
|
|
|
const params = { |
|
|
|
id: id.value, |
|
|
|
...form.value |
|
|
|
}; |
|
|
|
const res = await UpdateWorkApi.getrecordbycondition(params); |
|
|
@ -249,10 +206,58 @@ const getContent = (index) => { |
|
|
|
replies: [] |
|
|
|
}; |
|
|
|
}; |
|
|
|
const exportData = async () => { |
|
|
|
try { |
|
|
|
const params = { |
|
|
|
// 这里假设form.value和id.value是你已有的正确数据获取方式,按需替换成实际的准确值 |
|
|
|
...form.value, |
|
|
|
id: id.value, |
|
|
|
}; |
|
|
|
const response = await axios.post('/api/api/homework_manage/export-record', params, { |
|
|
|
responseType: 'arraybuffer' |
|
|
|
}); |
|
|
|
console.log('导出数据:', response); |
|
|
|
console.log('导出数据:', response.data); |
|
|
|
// 将返回的二进制数据转换为Blob对象,用于创建下载链接 |
|
|
|
const blob = new Blob([response.data], { type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }); |
|
|
|
const url = URL.createObjectURL(blob); |
|
|
|
const a = document.createElement('a'); |
|
|
|
a.href = url; |
|
|
|
// 尝试从响应头中获取Content-Disposition字段来解析文件名 |
|
|
|
const contentDisposition = response.headers['content-disposition']; |
|
|
|
console.log('文件名:', contentDisposition); |
|
|
|
if (contentDisposition) { |
|
|
|
// 使用正则表达式匹配filename |
|
|
|
const fileNameMatch = contentDisposition.match(/filename=([^"]+)/); |
|
|
|
if (fileNameMatch && fileNameMatch.length > 1) { |
|
|
|
const fileName = fileNameMatch[1]; |
|
|
|
a.download = fileName; |
|
|
|
} else { |
|
|
|
console.error('无法从Content-Disposition中解析出文件名'); |
|
|
|
return; |
|
|
|
} |
|
|
|
} else { |
|
|
|
console.error('响应头中不存在Content-Disposition字段'); |
|
|
|
return; |
|
|
|
} |
|
|
|
document.body.appendChild(a); |
|
|
|
a.click(); |
|
|
|
document.body.removeChild(a); |
|
|
|
URL.revokeObjectURL(url); |
|
|
|
} catch (error) { |
|
|
|
console.error('详细的请求错误信息:', error); |
|
|
|
ElMessage.error('导出失败'); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
const tokenStore = useTokenStore(); |
|
|
|
// 退出登录 |
|
|
|
const logout = () => { |
|
|
|
LoginApi.logout().then(res => { |
|
|
|
|
|
|
|
console.log(tokenStore); |
|
|
|
tokenStore.clear(); |
|
|
|
localStorage.removeItem('token'); |
|
|
|
console.log(tokenStore); |
|
|
|
router.push('/'); |
|
|
|
}).catch(err => { |
|
|
|
// 处理退出登录接口调用失败的情况,比如提示错误信息等 |
|
|
|