|
|
@@ -84,34 +84,9 @@
|
|
|
v-model="newTemplate.description"
|
|
|
type="textarea"
|
|
|
:rows="3"
|
|
|
- placeholder="请输入模板描述"
|
|
|
+ placeholder="请输入模板描述(可选)"
|
|
|
/>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="基础文档" required>
|
|
|
- <el-upload
|
|
|
- class="upload-demo"
|
|
|
- drag
|
|
|
- action="/api/v1/parse/upload"
|
|
|
- :on-success="handleUploadSuccess"
|
|
|
- :show-file-list="false"
|
|
|
- >
|
|
|
- <div v-if="newTemplate.baseDocumentId" class="upload-success">
|
|
|
- <el-icon size="40" color="#52c41a"><CircleCheckFilled /></el-icon>
|
|
|
- <div>文档已上传</div>
|
|
|
- </div>
|
|
|
- <template v-else>
|
|
|
- <el-icon class="el-icon--upload"><UploadFilled /></el-icon>
|
|
|
- <div class="el-upload__text">
|
|
|
- 拖拽文件到此处,或<em>点击上传</em>
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- <template #tip>
|
|
|
- <div class="el-upload__tip">
|
|
|
- 支持 Word、PDF 格式,上传后可标记变量
|
|
|
- </div>
|
|
|
- </template>
|
|
|
- </el-upload>
|
|
|
- </el-form-item>
|
|
|
</el-form>
|
|
|
<template #footer>
|
|
|
<el-button @click="showCreateDialog = false">取消</el-button>
|
|
|
@@ -126,7 +101,7 @@
|
|
|
<script setup>
|
|
|
import { ref, reactive, computed, onMounted } from 'vue'
|
|
|
import { useRouter } from 'vue-router'
|
|
|
-import { Plus, More, UploadFilled, CircleCheckFilled } from '@element-plus/icons-vue'
|
|
|
+import { Plus, More } from '@element-plus/icons-vue'
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
import { useTemplateStore } from '@/stores/template'
|
|
|
|
|
|
@@ -141,8 +116,7 @@ const showCreateDialog = ref(false)
|
|
|
|
|
|
const newTemplate = reactive({
|
|
|
name: '',
|
|
|
- description: '',
|
|
|
- baseDocumentId: ''
|
|
|
+ description: ''
|
|
|
})
|
|
|
|
|
|
// 模板列表数据(从 API 获取)
|
|
|
@@ -271,30 +245,23 @@ async function handleCommand(command, tpl) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-function handleUploadSuccess(response) {
|
|
|
- if (response.code === 200) {
|
|
|
- newTemplate.baseDocumentId = response.data.id
|
|
|
- ElMessage.success('文档上传成功')
|
|
|
- } else {
|
|
|
- ElMessage.error('上传失败: ' + response.msg)
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
async function handleCreateTemplate() {
|
|
|
if (!newTemplate.name) {
|
|
|
ElMessage.warning('请输入模板名称')
|
|
|
return
|
|
|
}
|
|
|
- if (!newTemplate.baseDocumentId) {
|
|
|
- ElMessage.warning('请上传基础文档')
|
|
|
- return
|
|
|
- }
|
|
|
|
|
|
creating.value = true
|
|
|
try {
|
|
|
- const template = await templateStore.createTemplate(newTemplate)
|
|
|
+ const template = await templateStore.createTemplate({
|
|
|
+ name: newTemplate.name,
|
|
|
+ description: newTemplate.description || ''
|
|
|
+ })
|
|
|
showCreateDialog.value = false
|
|
|
+ // 重置表单
|
|
|
+ Object.assign(newTemplate, { name: '', description: '' })
|
|
|
ElMessage.success('模板创建成功')
|
|
|
+ // 跳转到空白编辑页
|
|
|
router.push(`/editor/${template.id}`)
|
|
|
} catch (error) {
|
|
|
ElMessage.error('创建失败: ' + error.message)
|
|
|
@@ -330,14 +297,4 @@ async function handleCreateTemplate() {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-.upload-success {
|
|
|
- text-align: center;
|
|
|
- color: #52c41a;
|
|
|
- padding: 20px;
|
|
|
-
|
|
|
- div {
|
|
|
- margin-top: 8px;
|
|
|
- font-size: 14px;
|
|
|
- }
|
|
|
-}
|
|
|
</style>
|