|
@@ -138,31 +138,13 @@
|
|
|
v-model="newTemplate.description"
|
|
v-model="newTemplate.description"
|
|
|
type="textarea"
|
|
type="textarea"
|
|
|
:rows="3"
|
|
:rows="3"
|
|
|
- placeholder="请输入模板描述"
|
|
|
|
|
|
|
+ placeholder="请输入模板描述(可选)"
|
|
|
/>
|
|
/>
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
- <el-form-item label="基础文档" required>
|
|
|
|
|
- <el-upload
|
|
|
|
|
- class="upload-demo"
|
|
|
|
|
- drag
|
|
|
|
|
- action="/api/v1/parse/upload"
|
|
|
|
|
- :on-success="handleUploadSuccess"
|
|
|
|
|
- >
|
|
|
|
|
- <el-icon class="el-icon--upload"><upload-filled /></el-icon>
|
|
|
|
|
- <div class="el-upload__text">
|
|
|
|
|
- 拖拽文件到此处,或<em>点击上传</em>
|
|
|
|
|
- </div>
|
|
|
|
|
- <template #tip>
|
|
|
|
|
- <div class="el-upload__tip">
|
|
|
|
|
- 支持 Word、PDF 格式
|
|
|
|
|
- </div>
|
|
|
|
|
- </template>
|
|
|
|
|
- </el-upload>
|
|
|
|
|
- </el-form-item>
|
|
|
|
|
</el-form>
|
|
</el-form>
|
|
|
<template #footer>
|
|
<template #footer>
|
|
|
<el-button @click="showCreateDialog = false">取消</el-button>
|
|
<el-button @click="showCreateDialog = false">取消</el-button>
|
|
|
- <el-button type="primary" @click="handleCreateTemplate">创建</el-button>
|
|
|
|
|
|
|
+ <el-button type="primary" @click="handleCreateTemplate" :loading="creating">创建</el-button>
|
|
|
</template>
|
|
</template>
|
|
|
</el-dialog>
|
|
</el-dialog>
|
|
|
</div>
|
|
</div>
|
|
@@ -171,7 +153,7 @@
|
|
|
<script setup>
|
|
<script setup>
|
|
|
import { ref, reactive, computed, onMounted } from 'vue'
|
|
import { ref, reactive, computed, onMounted } from 'vue'
|
|
|
import { useRouter } from 'vue-router'
|
|
import { useRouter } from 'vue-router'
|
|
|
-import { Promotion, UploadFilled } from '@element-plus/icons-vue'
|
|
|
|
|
|
|
+import { Promotion } from '@element-plus/icons-vue'
|
|
|
import { ElMessage } from 'element-plus'
|
|
import { ElMessage } from 'element-plus'
|
|
|
import { useTemplateStore } from '@/stores/template'
|
|
import { useTemplateStore } from '@/stores/template'
|
|
|
import { templateApi } from '@/api'
|
|
import { templateApi } from '@/api'
|
|
@@ -207,9 +189,9 @@ const stats = reactive({
|
|
|
|
|
|
|
|
const newTemplate = reactive({
|
|
const newTemplate = reactive({
|
|
|
name: '',
|
|
name: '',
|
|
|
- description: '',
|
|
|
|
|
- baseDocumentId: ''
|
|
|
|
|
|
|
+ description: ''
|
|
|
})
|
|
})
|
|
|
|
|
+const creating = ref(false)
|
|
|
|
|
|
|
|
// 推荐模板数据(从 API 获取)
|
|
// 推荐模板数据(从 API 获取)
|
|
|
const recommendTemplates = ref([])
|
|
const recommendTemplates = ref([])
|
|
@@ -253,30 +235,27 @@ function useTemplate(tpl) {
|
|
|
router.push(`/editor/${tpl.id}`)
|
|
router.push(`/editor/${tpl.id}`)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-function handleUploadSuccess(response) {
|
|
|
|
|
- if (response.code === 200) {
|
|
|
|
|
- newTemplate.baseDocumentId = response.data.id
|
|
|
|
|
- ElMessage.success('文档上传成功')
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
async function handleCreateTemplate() {
|
|
async function handleCreateTemplate() {
|
|
|
if (!newTemplate.name) {
|
|
if (!newTemplate.name) {
|
|
|
ElMessage.warning('请输入模板名称')
|
|
ElMessage.warning('请输入模板名称')
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
- if (!newTemplate.baseDocumentId) {
|
|
|
|
|
- ElMessage.warning('请上传基础文档')
|
|
|
|
|
- return
|
|
|
|
|
- }
|
|
|
|
|
|
|
|
|
|
|
|
+ creating.value = true
|
|
|
try {
|
|
try {
|
|
|
- const template = await templateStore.createTemplate(newTemplate)
|
|
|
|
|
|
|
+ const template = await templateStore.createTemplate({
|
|
|
|
|
+ name: newTemplate.name,
|
|
|
|
|
+ description: newTemplate.description || ''
|
|
|
|
|
+ })
|
|
|
showCreateDialog.value = false
|
|
showCreateDialog.value = false
|
|
|
|
|
+ // 重置表单
|
|
|
|
|
+ Object.assign(newTemplate, { name: '', description: '' })
|
|
|
ElMessage.success('模板创建成功')
|
|
ElMessage.success('模板创建成功')
|
|
|
router.push(`/editor/${template.id}`)
|
|
router.push(`/editor/${template.id}`)
|
|
|
} catch (error) {
|
|
} catch (error) {
|
|
|
ElMessage.error('创建失败: ' + error.message)
|
|
ElMessage.error('创建失败: ' + error.message)
|
|
|
|
|
+ } finally {
|
|
|
|
|
+ creating.value = false
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
</script>
|
|
</script>
|