Files
012-kaopeilian/frontend/src/api/material.ts
111 998211c483 feat: 初始化考培练系统项目
- 从服务器拉取完整代码
- 按框架规范整理项目结构
- 配置 Drone CI 测试环境部署
- 包含后端(FastAPI)、前端(Vue3)、管理端

技术栈: Vue3 + TypeScript + FastAPI + MySQL
2026-01-24 19:33:28 +08:00

73 lines
1.6 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* 课程资料相关API
*/
import request from '@/utils/http'
import type { Material, PreviewInfo } from '@/types/material'
/**
* 获取课程资料列表
*/
export function getMaterials(courseId: number) {
return request.get<{
code: number
message: string
data: Material[]
}>(`/api/v1/courses/${courseId}/materials`)
}
/**
* 获取资料预览信息
*/
export function getPreview(materialId: number) {
return request.get<{
code: number
message: string
data: PreviewInfo
}>(`/api/v1/preview/material/${materialId}`)
}
/**
* 下载资料
*/
export function downloadMaterial(materialId: number, fileName: string) {
// 创建隐藏的a标签触发下载
const link = document.createElement('a')
link.style.display = 'none'
link.href = `/api/v1/preview/material/${materialId}`
link.download = fileName
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
/**
* 直接下载文件通过URL
*/
export function downloadFile(fileUrl: string, fileName: string) {
const link = document.createElement('a')
link.style.display = 'none'
link.href = fileUrl
link.download = fileName
link.target = '_blank'
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
}
/**
* 检查转换服务状态(调试用)
*/
export function checkConverterStatus() {
return request.get<{
code: number
message: string
data: {
libreoffice_installed: boolean
libreoffice_version: string | null
supported_formats: string[]
converted_path: string
}
}>('/api/v1/preview/check-converter')
}