|
|
@@ -312,17 +312,14 @@ const route = useRoute()
|
|
|
const templateStore = useTemplateStore()
|
|
|
|
|
|
const templateId = route.params.templateId
|
|
|
-const reportTitle = ref('智慧园区建设项目可行性研究报告')
|
|
|
+const reportTitle = ref('')
|
|
|
const viewMode = ref('edit')
|
|
|
const saved = ref(true)
|
|
|
const editorRef = ref(null)
|
|
|
+const loading = ref(false)
|
|
|
|
|
|
-// 来源文件
|
|
|
-const sourceFiles = ref([
|
|
|
- { id: '1', alias: '可研批复', required: true },
|
|
|
- { id: '2', alias: '项目建议书', required: true },
|
|
|
- { id: '3', alias: '技术方案', required: false }
|
|
|
-])
|
|
|
+// 来源文件(从 API 获取)
|
|
|
+const sourceFiles = ref([])
|
|
|
const selectedFile = ref(null)
|
|
|
const showAddSourceDialog = ref(false)
|
|
|
const newSourceFile = reactive({
|
|
|
@@ -331,13 +328,34 @@ const newSourceFile = reactive({
|
|
|
required: true
|
|
|
})
|
|
|
|
|
|
-// 变量
|
|
|
-const variables = ref([
|
|
|
- { id: '1', name: 'project_name', displayName: '项目名称', category: 'entity', exampleValue: '智慧园区建设项目', sourceType: 'document' },
|
|
|
- { id: '2', name: 'total_investment', displayName: '总投资额', category: 'data', exampleValue: '5000万元', sourceType: 'document' },
|
|
|
- { id: '3', name: 'project_location', displayName: '项目地点', category: 'location', exampleValue: '华南科技园', sourceType: 'document' },
|
|
|
- { id: '4', name: 'tech_solution', displayName: '技术方案', category: 'concept', exampleValue: '智能化管理平台', sourceType: 'document' }
|
|
|
-])
|
|
|
+// 变量(从 API 获取)
|
|
|
+const variables = ref([])
|
|
|
+
|
|
|
+// 加载模板数据
|
|
|
+onMounted(async () => {
|
|
|
+ await fetchTemplateData()
|
|
|
+})
|
|
|
+
|
|
|
+async function fetchTemplateData() {
|
|
|
+ loading.value = true
|
|
|
+ try {
|
|
|
+ await templateStore.fetchTemplateDetail(templateId)
|
|
|
+
|
|
|
+ // 设置模板标题
|
|
|
+ reportTitle.value = templateStore.currentTemplate?.name || '未命名模板'
|
|
|
+
|
|
|
+ // 设置来源文件
|
|
|
+ sourceFiles.value = templateStore.sourceFiles || []
|
|
|
+
|
|
|
+ // 设置变量
|
|
|
+ variables.value = templateStore.variables || []
|
|
|
+ } catch (error) {
|
|
|
+ console.error('加载模板失败:', error)
|
|
|
+ ElMessage.error('加载模板失败')
|
|
|
+ } finally {
|
|
|
+ loading.value = false
|
|
|
+ }
|
|
|
+}
|
|
|
const showVariableDialog = ref(false)
|
|
|
const showAddVariableDialog = ref(false)
|
|
|
const editingVariable = ref(null)
|
|
|
@@ -412,23 +430,30 @@ function selectFile(file) {
|
|
|
selectedFile.value = file
|
|
|
}
|
|
|
|
|
|
-function removeSourceFile(file) {
|
|
|
- sourceFiles.value = sourceFiles.value.filter(f => f.id !== file.id)
|
|
|
- ElMessage.success('删除成功')
|
|
|
+async function removeSourceFile(file) {
|
|
|
+ try {
|
|
|
+ await templateStore.deleteSourceFile(file.id)
|
|
|
+ sourceFiles.value = sourceFiles.value.filter(f => f.id !== file.id)
|
|
|
+ ElMessage.success('删除成功')
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error('删除失败: ' + error.message)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function addSourceFile() {
|
|
|
+async function addSourceFile() {
|
|
|
if (!newSourceFile.alias) {
|
|
|
ElMessage.warning('请输入文件别名')
|
|
|
return
|
|
|
}
|
|
|
- sourceFiles.value.push({
|
|
|
- id: Date.now().toString(),
|
|
|
- ...newSourceFile
|
|
|
- })
|
|
|
- showAddSourceDialog.value = false
|
|
|
- Object.assign(newSourceFile, { alias: '', description: '', required: true })
|
|
|
- ElMessage.success('添加成功')
|
|
|
+ try {
|
|
|
+ const sf = await templateStore.addSourceFile(templateId, newSourceFile)
|
|
|
+ sourceFiles.value.push(sf)
|
|
|
+ showAddSourceDialog.value = false
|
|
|
+ Object.assign(newSourceFile, { alias: '', description: '', required: true })
|
|
|
+ ElMessage.success('添加成功')
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error('添加失败: ' + error.message)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function getCategoryIcon(category) {
|
|
|
@@ -470,35 +495,43 @@ function editVariable(variable) {
|
|
|
showVariableDialog.value = true
|
|
|
}
|
|
|
|
|
|
-function saveVariable() {
|
|
|
+async function saveVariable() {
|
|
|
if (!variableForm.name || !variableForm.displayName) {
|
|
|
ElMessage.warning('请填写必要字段')
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- if (editingVariable.value) {
|
|
|
- // 更新
|
|
|
- Object.assign(editingVariable.value, variableForm)
|
|
|
- ElMessage.success('更新成功')
|
|
|
- } else {
|
|
|
- // 新增
|
|
|
- variables.value.push({
|
|
|
- id: Date.now().toString(),
|
|
|
- ...variableForm
|
|
|
- })
|
|
|
- ElMessage.success('添加成功')
|
|
|
- }
|
|
|
+ try {
|
|
|
+ if (editingVariable.value) {
|
|
|
+ // 更新
|
|
|
+ const updated = await templateStore.updateVariable(editingVariable.value.id, variableForm)
|
|
|
+ Object.assign(editingVariable.value, updated)
|
|
|
+ ElMessage.success('更新成功')
|
|
|
+ } else {
|
|
|
+ // 新增
|
|
|
+ const newVar = await templateStore.addVariable(templateId, variableForm)
|
|
|
+ variables.value.push(newVar)
|
|
|
+ ElMessage.success('添加成功')
|
|
|
+ }
|
|
|
|
|
|
- showVariableDialog.value = false
|
|
|
- resetVariableForm()
|
|
|
+ showVariableDialog.value = false
|
|
|
+ resetVariableForm()
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error('保存失败: ' + error.message)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-function deleteVariable() {
|
|
|
+async function deleteVariable() {
|
|
|
if (editingVariable.value) {
|
|
|
- variables.value = variables.value.filter(v => v.id !== editingVariable.value.id)
|
|
|
- showVariableDialog.value = false
|
|
|
- resetVariableForm()
|
|
|
- ElMessage.success('删除成功')
|
|
|
+ try {
|
|
|
+ await templateStore.deleteVariable(editingVariable.value.id)
|
|
|
+ variables.value = variables.value.filter(v => v.id !== editingVariable.value.id)
|
|
|
+ showVariableDialog.value = false
|
|
|
+ resetVariableForm()
|
|
|
+ ElMessage.success('删除成功')
|
|
|
+ } catch (error) {
|
|
|
+ ElMessage.error('删除失败: ' + error.message)
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|