完成科学研究部分
This commit is contained in:
477
management/src/views/devproject/devprojectView.vue
Normal file
477
management/src/views/devproject/devprojectView.vue
Normal file
@@ -0,0 +1,477 @@
|
||||
<template>
|
||||
<div class="research-management">
|
||||
<!-- 页面图片管理(单张图片) -->
|
||||
<el-card class="page-header-card">
|
||||
<h1 class="page-title">科学研究管理</h1>
|
||||
<div class="page-image-management mt-4">
|
||||
<h3 class="section-title">页面封面图管理</h3>
|
||||
<p class="section-desc">上传科学研究页面的顶部封面图,建议16:9比例,支持JPG/PNG/WEBP格式,大小不超过5MB</p>
|
||||
|
||||
<div class="cover-uploader">
|
||||
<!-- 已上传图片预览 -->
|
||||
<div v-if="formData.pageImageUrl" class="cover-preview">
|
||||
<img :src="formData.pageImageUrl" alt="科学研究页面封面" class="cover-img">
|
||||
<button
|
||||
class="remove-cover-btn"
|
||||
@click="removePageImage"
|
||||
title="删除封面图"
|
||||
:disabled="isSaving"
|
||||
>
|
||||
<el-icon><Close /></el-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- 未上传时的上传区域 -->
|
||||
<el-upload
|
||||
v-else
|
||||
class="cover-upload-area"
|
||||
:action="uploadAction"
|
||||
name="image"
|
||||
:show-file-list="false"
|
||||
:on-success="handleCoverSuccess"
|
||||
:before-upload="beforeUpload"
|
||||
:on-error="handlePageImageUploadError"
|
||||
:disabled="isSaving"
|
||||
>
|
||||
<div class="upload-placeholder">
|
||||
<el-icon class="upload-icon"><Upload /></el-icon>
|
||||
<p class="upload-text">点击或拖拽图片至此处上传</p>
|
||||
<p class="upload-subtext">支持JPG/PNG/WEBP,最大5MB,建议16:9比例</p>
|
||||
</div>
|
||||
</el-upload>
|
||||
</div>
|
||||
|
||||
<div class="cover-action-buttons mt-3">
|
||||
<el-button
|
||||
type="primary"
|
||||
@click="saveImage"
|
||||
:loading="isSaving"
|
||||
:disabled="!formData.pageImageUrl || isSaving"
|
||||
>
|
||||
<el-icon><Check /></el-icon>
|
||||
保存封面图
|
||||
</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</el-card>
|
||||
|
||||
<!-- 标签页切换 -->
|
||||
<el-tabs v-model="activeTab" type="card" class="mt-4">
|
||||
<el-tab-pane label="基地开放项目管理制度" name="management">
|
||||
<el-card class="mt-2">
|
||||
<el-form ref="managementForm" :model="formData" label-width="120px">
|
||||
<el-form-item label="制度内容">
|
||||
<el-input
|
||||
type="textarea"
|
||||
v-model="formData.basicDevProjectManagementSystem"
|
||||
rows="10"
|
||||
placeholder="请输入基地开放项目管理制度内容(支持Markdown格式)"
|
||||
clearable
|
||||
resize="vertical"
|
||||
style="white-space: pre-line;"
|
||||
/>
|
||||
<div class="form-hint mt-2">
|
||||
提示:支持Markdown格式排版(标题、列表、表格等),换行请直接按Enter键
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="基地开放项目立项结果" name="approval">
|
||||
<el-card class="mt-2">
|
||||
<el-form ref="approvalForm" :model="formData" label-width="120px">
|
||||
<el-form-item label="立项结果">
|
||||
<el-input
|
||||
type="textarea"
|
||||
v-model="formData.basicDevProjectInitiationResult"
|
||||
rows="10"
|
||||
placeholder="请输入基地开放项目立项结果内容(支持Markdown格式)"
|
||||
clearable
|
||||
resize="vertical"
|
||||
style="white-space: pre-line;"
|
||||
/>
|
||||
<div class="form-hint mt-2">
|
||||
提示:支持Markdown格式排版(标题、列表、表格等),换行请直接按Enter键
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="基地开放项目中期检查" name="midterm">
|
||||
<el-card class="mt-2">
|
||||
<el-form ref="midtermForm" :model="formData" label-width="120px">
|
||||
<el-form-item label="中期检查">
|
||||
<el-input
|
||||
type="textarea"
|
||||
v-model="formData.basicDevProjectMidtermInspection"
|
||||
rows="10"
|
||||
placeholder="请输入基地开放项目中期检查内容(支持Markdown格式)"
|
||||
clearable
|
||||
resize="vertical"
|
||||
style="white-space: pre-line;"
|
||||
/>
|
||||
<div class="form-hint mt-2">
|
||||
提示:支持Markdown格式排版(标题、列表、表格等),换行请直接按Enter键
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
|
||||
<el-tab-pane label="基地开放项目成果" name="results">
|
||||
<el-card class="mt-2">
|
||||
<el-form ref="resultsForm" :model="formData" label-width="120px">
|
||||
<el-form-item label="项目成果">
|
||||
<el-input
|
||||
type="textarea"
|
||||
v-model="formData.basicDevProjectAchievements"
|
||||
rows="10"
|
||||
placeholder="请输入基地开放项目成果内容(支持Markdown格式)"
|
||||
clearable
|
||||
resize="vertical"
|
||||
style="white-space: pre-line;"
|
||||
/>
|
||||
<div class="form-hint mt-2">
|
||||
提示:支持Markdown格式排版(标题、列表、表格等),换行请直接按Enter键
|
||||
</div>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</el-card>
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
|
||||
<!-- 操作按钮(仅保留“保存全部”) -->
|
||||
<div class="action-buttons mt-4">
|
||||
<el-button type="primary" @click="saveAll" :loading="isSaving">保存全部</el-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts" setup>
|
||||
import { ref, reactive, onMounted } from 'vue';
|
||||
import { ElMessage } from 'element-plus';
|
||||
import { Close, Upload, Check } from '@element-plus/icons-vue';
|
||||
import type { UploadProps } from 'element-plus';
|
||||
import axios from "axios";
|
||||
|
||||
// 激活的标签页(默认显示管理制度)
|
||||
const activeTab = ref('management');
|
||||
// 保存状态(防止重复提交)
|
||||
const isSaving = ref(false);
|
||||
// 上传接口地址
|
||||
const uploadAction = import.meta.env.VITE_API_BASE_URL + '/upload/cover';
|
||||
|
||||
// 统一管理表单数据(与数据库字段对应)
|
||||
const formData = reactive({
|
||||
pageImageUrl: '', // 页面封面图URL
|
||||
basicDevProjectManagementSystem: '', // 基地开放项目管理制度
|
||||
basicDevProjectInitiationResult: '', // 基地开放项目立项结果
|
||||
basicDevProjectMidtermInspection: '', // 基地开放项目中期检查
|
||||
basicDevProjectAchievements: '' // 基地开放项目成果
|
||||
});
|
||||
|
||||
// 页面挂载时加载数据:1.封面图 2.研究信息
|
||||
onMounted(() => {
|
||||
console.log('API 基础地址:', import.meta.env.VITE_API_BASE_URL);
|
||||
fetchCarouselImages();
|
||||
fetchResearchInfo();
|
||||
});
|
||||
|
||||
// 从后端获取封面图
|
||||
const fetchCarouselImages = async () => {
|
||||
try {
|
||||
const response = await axios.post('http://localhost:8080/api/page-image/get', { page: 'ScientificResearch' });
|
||||
console.log('封面图加载结果:', response);
|
||||
if (response.data.message === '查询成功' && Array.isArray(response.data.images) && response.data.images.length) {
|
||||
formData.pageImageUrl = response.data.images[0].image_url;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('封面图加载失败:', error);
|
||||
ElMessage.warning('未获取到现有封面图,可重新上传');
|
||||
}
|
||||
};
|
||||
|
||||
// 加载数据库数据(适配新接口返回格式)
|
||||
const fetchResearchInfo = async () => {
|
||||
try {
|
||||
isSaving.value = true;
|
||||
const response = await axios.get('http://localhost:8080/api/devproject/get');
|
||||
console.log('科学研究数据加载结果:', response);
|
||||
|
||||
if (response.data.message === '查询成功' && response.data.dev_project) {
|
||||
const dbData = response.data.dev_project;
|
||||
// 直接赋值Markdown格式内容,保持原始排版
|
||||
formData.basicDevProjectManagementSystem = dbData.basic_dev_project_management_system || '';
|
||||
formData.basicDevProjectInitiationResult = dbData.basic_dev_project_initiation_result || '';
|
||||
formData.basicDevProjectMidtermInspection = dbData.basic_dev_project_midterm_inspection || '';
|
||||
formData.basicDevProjectAchievements = dbData.basic_dev_project_achievements || '';
|
||||
} else {
|
||||
ElMessage.warning('获取研究信息失败:' + (response.data.message || '未知错误'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取科学研究信息失败:', error);
|
||||
ElMessage.error('获取研究信息失败,请刷新页面重试');
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 上传前校验
|
||||
const beforeUpload: UploadProps['beforeUpload'] = (rawFile) => {
|
||||
const allowTypes = ['image/jpeg', 'image/png', 'image/webp'];
|
||||
if (!allowTypes.includes(rawFile.type)) {
|
||||
ElMessage.error('仅支持JPG/PNG/WEBP格式的图片');
|
||||
return false;
|
||||
}
|
||||
if (rawFile.size / 1024 / 1024 > 5) {
|
||||
ElMessage.error('图片大小不能超过5MB');
|
||||
return false;
|
||||
}
|
||||
console.log("图片校验成功");
|
||||
return true;
|
||||
};
|
||||
|
||||
// 封面上传成功
|
||||
const handleCoverSuccess: UploadProps['onSuccess'] = (response) => {
|
||||
const ossUrl = response.data?.url;
|
||||
if (ossUrl) {
|
||||
formData.pageImageUrl = ossUrl;
|
||||
ElMessage.success('封面上传成功');
|
||||
} else {
|
||||
ElMessage.error('封面上传失败:未获取到图片地址');
|
||||
}
|
||||
};
|
||||
|
||||
// 页面图片上传失败处理
|
||||
const handlePageImageUploadError = (error: any) => {
|
||||
console.error('页面封面图上传错误:', error);
|
||||
ElMessage.error('页面封面图上传失败,请重试');
|
||||
};
|
||||
|
||||
// 删除页面图片
|
||||
const removePageImage = () => {
|
||||
formData.pageImageUrl = '';
|
||||
ElMessage.info('页面封面图已删除');
|
||||
};
|
||||
|
||||
// 保存封面图(单独保存)
|
||||
const saveImage = async () => {
|
||||
try {
|
||||
isSaving.value = true;
|
||||
if (!formData.pageImageUrl) {
|
||||
ElMessage.warning('请先上传封面图再保存');
|
||||
return;
|
||||
}
|
||||
|
||||
const response = await axios.post('http://localhost:8080/api/page-image/save', {
|
||||
id: 5, // 科学研究页面封面图ID
|
||||
image_url: formData.pageImageUrl,
|
||||
});
|
||||
|
||||
if (response.data.success || response.data.message === '保存成功') {
|
||||
ElMessage.success('封面图保存成功');
|
||||
console.log('封面图保存成功,地址:', formData.pageImageUrl);
|
||||
} else {
|
||||
ElMessage.error('封面图保存失败:' + (response.data.message || '未知错误'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('封面图保存失败:', error);
|
||||
ElMessage.error('封面图保存失败,请重试');
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
// 保存全部内容(适配数据库字段,保留原始换行符)
|
||||
const saveAll = async () => {
|
||||
try {
|
||||
isSaving.value = true;
|
||||
|
||||
// 构建提交数据(直接使用输入框原始换行符\n,保持数据库输入两个换行则会自动保留为两个\n)
|
||||
const submitData = {
|
||||
basic_dev_project_management_system: formData.basicDevProjectManagementSystem,
|
||||
basic_dev_project_initiation_result: formData.basicDevProjectInitiationResult,
|
||||
basic_dev_project_midterm_inspection: formData.basicDevProjectMidtermInspection,
|
||||
basic_dev_project_achievements: formData.basicDevProjectAchievements
|
||||
};
|
||||
|
||||
console.log("保存的数据(含原始换行换行符):", submitData);
|
||||
|
||||
// 提交数据到后端保存
|
||||
const response = await axios.post('http://localhost:8080/api/devproject/save', submitData);
|
||||
|
||||
if (response.data.success || response.data.message === '查询成功') {
|
||||
// 控制台输出格式化信息,展示实际换行符
|
||||
console.log('【数据库存储格式】修改后的完整数据:');
|
||||
console.log('='.repeat(60));
|
||||
console.log('管理制度(原始字符串):', JSON.stringify(submitData.basic_dev_project_management_system));
|
||||
console.log('立项结果(原始字符串):', JSON.stringify(submitData.basic_dev_project_initiation_result));
|
||||
console.log('中期检查(原始字符串):', JSON.stringify(submitData.basic_dev_project_midterm_inspection));
|
||||
console.log('项目成果(原始字符串):', JSON.stringify(submitData.basic_dev_project_achievements));
|
||||
|
||||
// 构建Markdown预览(保持输入时的换行格式)
|
||||
const mdContent = `# 科学研究(修改后)\n\n` +
|
||||
`## 页面封面图\n` +
|
||||
`\n\n` +
|
||||
`## 基地开放项目管理制度\n${formData.basicDevProjectManagementSystem || '暂无内容'}\n\n` +
|
||||
`## 基地开放项目立项结果\n${formData.basicDevProjectInitiationResult || '暂无内容'}\n\n` +
|
||||
`## 基地开放项目中期检查\n${formData.basicDevProjectMidtermInspection || '暂无内容'}\n\n` +
|
||||
`## 基地开放项目成果\n${formData.basicDevProjectAchievements || '暂无内容'}`;
|
||||
|
||||
console.log('\n\n【Markdown显示预览】:\n');
|
||||
console.log(mdContent);
|
||||
|
||||
ElMessage.success('内容保存成功!');
|
||||
} else {
|
||||
ElMessage.error('保存失败:' + (response.data.message || '未知错误'));
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('保存全部内容失败:', error);
|
||||
ElMessage.error('保存失败,请重试');
|
||||
} finally {
|
||||
isSaving.value = false;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
<style scoped>
|
||||
.research-management {
|
||||
max-width: 1200px;
|
||||
margin: 0 auto;
|
||||
padding: 20px;
|
||||
}
|
||||
|
||||
.page-header-card {
|
||||
margin-bottom: 20px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
|
||||
.page-title {
|
||||
font-size: 24px;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* 页面图片管理样式 */
|
||||
.page-image-management {
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
.section-title {
|
||||
font-size: 16px;
|
||||
font-weight: 500;
|
||||
margin-bottom: 8px;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.section-desc {
|
||||
font-size: 14px;
|
||||
color: #666;
|
||||
margin-bottom: 15px;
|
||||
}
|
||||
|
||||
.cover-uploader {
|
||||
width: 100%;
|
||||
max-width: 800px;
|
||||
}
|
||||
|
||||
.cover-preview {
|
||||
width: 100%;
|
||||
height: 225px; /* 16:9比例适配 */
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
position: relative;
|
||||
background: #f5f5f5;
|
||||
}
|
||||
|
||||
.cover-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.remove-cover-btn {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
right: 10px;
|
||||
width: 36px;
|
||||
height: 36px;
|
||||
border-radius: 50%;
|
||||
background: rgba(0, 0, 0, 0.6);
|
||||
color: white;
|
||||
border: none;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
transition: background 0.3s;
|
||||
}
|
||||
|
||||
.remove-cover-btn:hover {
|
||||
background: rgba(255, 0, 0, 0.8);
|
||||
}
|
||||
|
||||
.cover-action-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.cover-upload-area {
|
||||
width: 100%;
|
||||
height: 225px;
|
||||
}
|
||||
|
||||
.upload-placeholder {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border: 2px dashed #ccc;
|
||||
border-radius: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: #fafafa;
|
||||
cursor: pointer;
|
||||
transition: all 0.3s;
|
||||
}
|
||||
|
||||
.upload-placeholder:hover {
|
||||
border-color: #409eff;
|
||||
background: #f0f7ff;
|
||||
}
|
||||
|
||||
.upload-icon {
|
||||
font-size: 36px;
|
||||
color: #999;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
|
||||
.upload-text {
|
||||
color: #666;
|
||||
font-size: 14px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.upload-subtext {
|
||||
color: #999;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
/* 操作按钮样式 */
|
||||
.action-buttons {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
flex-wrap: wrap;
|
||||
margin-top: 20px;
|
||||
}
|
||||
|
||||
/* 确保textarea正确渲染换行 */
|
||||
:deep(.el-textarea__inner) {
|
||||
min-height: 200px;
|
||||
resize: vertical;
|
||||
white-space: pre-line;
|
||||
line-height: 1.6;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user