fix: FilePreview fileType case + Tailwind v4 gradient transparent bug
- FilePreview.vue: add normalizedFileType computed to handle backend returning uppercase HTML/MD/PPTX (fixes preview/download buttons) - FilePreview.vue: bg-gradient-to-r from-orange-500 -> bg-orange-500 (Tailwind v4 gradient + CSS variable = transparent) - ReportCard.vue: bg-gradient-to-r -> bg-orange-600 for selected state - Add .opencode/, node_modules/, dist/ to .gitignore - Initial git setup for publish project
This commit is contained in:
@@ -0,0 +1,144 @@
|
||||
import axios from 'axios'
|
||||
import { ref } from 'vue'
|
||||
|
||||
const api = axios.create({
|
||||
baseURL: '/api',
|
||||
timeout: 10000
|
||||
})
|
||||
|
||||
// Mock data for development
|
||||
const mockProjects = [
|
||||
{ id: 1, name: '项目一', description: '主要产品线', reportCount: 15, todayNewReports: 2 },
|
||||
{ id: 2, name: '项目二', description: '内部工具', reportCount: 8, todayNewReports: 1 },
|
||||
{ id: 3, name: '项目三', description: '客户定制', reportCount: 12, todayNewReports: 0 }
|
||||
]
|
||||
|
||||
const mockReports = {
|
||||
1: [
|
||||
{ id: 101, fileName: '2026-05-22 日报.html', fileType: 'html', reportDate: '2026-05-22', size: '15KB' },
|
||||
{ id: 102, fileName: '2026-05-21 日报.md', fileType: 'md', reportDate: '2026-05-21', size: '8KB' },
|
||||
{ id: 103, fileName: '2026-05-20 周报.pptx', fileType: 'pptx', reportDate: '2026-05-20', size: '256KB' }
|
||||
],
|
||||
2: [
|
||||
{ id: 201, fileName: '2026-05-22 开发日报.html', fileType: 'html', reportDate: '2026-05-22', size: '12KB' },
|
||||
{ id: 202, fileName: '2026-05-21 开发日报.html', fileType: 'html', reportDate: '2026-05-21', size: '11KB' }
|
||||
],
|
||||
3: [
|
||||
{ id: 301, fileName: '2026-05-22 进度报告.md', fileType: 'md', reportDate: '2026-05-22', size: '10KB' },
|
||||
{ id: 302, fileName: '2026-05-21 进度报告.md', fileType: 'md', reportDate: '2026-05-21', size: '9KB' }
|
||||
]
|
||||
}
|
||||
|
||||
const mockReportContent = {
|
||||
html: '<html><body><h1>日报内容</h1><p>这是一份HTML格式的日报。</p></body></html>',
|
||||
md: '# 日报标题\n\n## 工作内容\n\n1. 完成功能A\n2. 进行代码审查\n3. 修复Bug\n\n## 明日计划\n\n- 继续开发功能B\n- 优化性能',
|
||||
pptx: null
|
||||
}
|
||||
|
||||
export function useApi() {
|
||||
const loading = ref(false)
|
||||
const error = ref(null)
|
||||
|
||||
const fetchProjects = async () => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await api.get('/projects')
|
||||
return response.data
|
||||
} catch (e) {
|
||||
// Use mock data if API fails
|
||||
console.warn('API not available, using mock data')
|
||||
return mockProjects
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchReports = async (projectId) => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const response = await api.get(`/reports?projectId=${projectId}`)
|
||||
return response.data
|
||||
} catch (e) {
|
||||
console.warn('API not available, using mock data')
|
||||
return mockReports[projectId] || []
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchReportContent = async (reportId) => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
// Backend GET /api/reports/{id} returns ReportResponse with fileContent field
|
||||
const response = await api.get(`/reports/${reportId}`)
|
||||
return { content: response.data.fileContent, type: response.data.fileType }
|
||||
} catch (e) {
|
||||
console.warn('API not available, using mock data')
|
||||
// Find the report type from mock data
|
||||
for (const reports of Object.values(mockReports)) {
|
||||
const report = reports.find(r => r.id === reportId)
|
||||
if (report) {
|
||||
return { content: mockReportContent[report.fileType], type: report.fileType }
|
||||
}
|
||||
}
|
||||
return null
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const fetchReportBytes = async (reportId) => {
|
||||
try {
|
||||
const response = await api.get(`/reports/${reportId}/download`, { responseType: 'arraybuffer' })
|
||||
return response.data
|
||||
} catch (e) {
|
||||
console.warn('Failed to fetch report bytes:', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const fetchReportPdf = async (reportId) => {
|
||||
try {
|
||||
const response = await api.get(`/reports/${reportId}/pdf`, { responseType: 'arraybuffer' })
|
||||
return new Blob([response.data], { type: 'application/pdf' })
|
||||
} catch (e) {
|
||||
console.warn('Failed to fetch report PDF:', e)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
const updateProject = async (id, data) => {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
let response
|
||||
if (data instanceof FormData) {
|
||||
response = await api.put(`/projects/${id}`, data, {
|
||||
headers: { 'Content-Type': 'multipart/form-data' }
|
||||
})
|
||||
} else {
|
||||
response = await api.put(`/projects/${id}`, data)
|
||||
}
|
||||
return response.data
|
||||
} catch (e) {
|
||||
console.warn('API not available, failed to update project:', e)
|
||||
return null
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
loading,
|
||||
error,
|
||||
fetchProjects,
|
||||
fetchReports,
|
||||
fetchReportContent,
|
||||
fetchReportBytes,
|
||||
fetchReportPdf,
|
||||
updateProject
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user