2025-10-17 15:58:58 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<el-dialog
|
2026-01-28 15:19:33 +08:00
|
|
|
|
:title="!dataForm.id ? '新增知识文档' : '编辑知识文档'"
|
2025-10-17 15:58:58 +08:00
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
|
|
:visible.sync="visible"
|
2026-01-28 15:19:33 +08:00
|
|
|
|
width="80%"
|
|
|
|
|
|
top="5vh">
|
|
|
|
|
|
<el-form :model="dataForm" :rules="dataRule" ref="dataForm" label-width="100px" size="small">
|
|
|
|
|
|
<el-row :gutter="20">
|
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
|
<el-form-item label="标题" prop="title">
|
|
|
|
|
|
<el-input v-model="dataForm.title" placeholder="请输入标题"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
|
<el-form-item label="副标题" prop="subtitle">
|
|
|
|
|
|
<el-input v-model="dataForm.subtitle" placeholder="请输入副标题"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
|
|
|
|
|
|
|
|
|
|
|
<!-- <el-row :gutter="20">-->
|
|
|
|
|
|
<!-- <el-col :span="12">-->
|
|
|
|
|
|
<!-- <el-form-item label="分类" prop="categoryId">-->
|
|
|
|
|
|
<!-- <el-input v-model.number="dataForm.categoryId" placeholder="请输入分类ID" type="number"></el-input>-->
|
|
|
|
|
|
<!-- </el-form-item>-->
|
|
|
|
|
|
<!-- </el-col>-->
|
|
|
|
|
|
<!-- <el-col :span="12">-->
|
|
|
|
|
|
<!--<!– <el-form-item label="封面图" prop="coverImage">–>-->
|
|
|
|
|
|
<!--<!– <el-input v-model="dataForm.coverImage" placeholder="请输入封面图URL">–>-->
|
|
|
|
|
|
<!--<!– <el-button slot="append" icon="el-icon-upload">上传</el-button>–>-->
|
|
|
|
|
|
<!--<!– </el-input>–>-->
|
|
|
|
|
|
<!--<!– </el-form-item>–>-->
|
|
|
|
|
|
<!-- </el-col>-->
|
|
|
|
|
|
<!-- </el-row>-->
|
|
|
|
|
|
|
|
|
|
|
|
<el-form-item label="摘要" prop="summary">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="dataForm.summary"
|
|
|
|
|
|
type="textarea"
|
|
|
|
|
|
:rows="3"
|
|
|
|
|
|
placeholder="请输入摘要(选填)">
|
|
|
|
|
|
</el-input>
|
2025-10-17 15:58:58 +08:00
|
|
|
|
</el-form-item>
|
2026-01-28 15:19:33 +08:00
|
|
|
|
|
|
|
|
|
|
<el-form-item label="内容" prop="content">
|
|
|
|
|
|
<el-input
|
|
|
|
|
|
v-model="dataForm.content"
|
|
|
|
|
|
type="textarea"
|
|
|
|
|
|
:rows="10"
|
|
|
|
|
|
placeholder="请输入HTML格式内容">
|
|
|
|
|
|
</el-input>
|
2025-10-17 15:58:58 +08:00
|
|
|
|
</el-form-item>
|
2026-01-28 15:19:33 +08:00
|
|
|
|
|
|
|
|
|
|
<el-row :gutter="20">
|
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
|
<el-form-item label="标签" prop="tags">
|
|
|
|
|
|
<el-input v-model="dataForm.tags" placeholder="多个标签用逗号分隔,如:Java,Spring,MySQL"></el-input>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
|
<el-form-item label="状态" prop="status">
|
|
|
|
|
|
<el-select v-model="dataForm.status" placeholder="请选择状态" style="width: 100%;">
|
|
|
|
|
|
<el-option label="草稿" value="DRAFT"></el-option>
|
|
|
|
|
|
<el-option label="已发布" value="PUBLISHED"></el-option>
|
|
|
|
|
|
<el-option label="审核中" value="REVIEWING"></el-option>
|
|
|
|
|
|
</el-select>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
|
|
|
|
|
|
|
|
|
|
|
<el-row :gutter="20">
|
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
|
<el-form-item label="是否置顶" prop="isTop">
|
|
|
|
|
|
<el-switch
|
|
|
|
|
|
v-model="dataForm.isTop"
|
|
|
|
|
|
:active-value="1"
|
|
|
|
|
|
:inactive-value="0">
|
|
|
|
|
|
</el-switch>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
<el-col :span="12">
|
|
|
|
|
|
<el-form-item label="过期时间" prop="expireTime">
|
|
|
|
|
|
<el-date-picker
|
|
|
|
|
|
v-model="dataForm.expireTime"
|
|
|
|
|
|
type="datetime"
|
|
|
|
|
|
placeholder="选择过期时间(选填)"
|
|
|
|
|
|
value-format="yyyy-MM-dd HH:mm:ss"
|
|
|
|
|
|
style="width: 100%;">
|
|
|
|
|
|
</el-date-picker>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-col>
|
|
|
|
|
|
</el-row>
|
2025-10-17 15:58:58 +08:00
|
|
|
|
</el-form>
|
2026-01-28 15:19:33 +08:00
|
|
|
|
|
2025-10-17 15:58:58 +08:00
|
|
|
|
<span slot="footer" class="dialog-footer">
|
2026-01-28 15:19:33 +08:00
|
|
|
|
<el-button @click="visible = false" size="small">取消</el-button>
|
|
|
|
|
|
<el-button type="primary" @click="dataFormSubmit()" size="small" :loading="submitLoading">确定</el-button>
|
2025-10-17 15:58:58 +08:00
|
|
|
|
</span>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
export default {
|
|
|
|
|
|
data () {
|
|
|
|
|
|
return {
|
|
|
|
|
|
visible: false,
|
2026-01-28 15:19:33 +08:00
|
|
|
|
submitLoading: false,
|
2025-10-17 15:58:58 +08:00
|
|
|
|
dataForm: {
|
2026-01-28 15:19:33 +08:00
|
|
|
|
id: null,
|
|
|
|
|
|
title: '',
|
|
|
|
|
|
subtitle: '',
|
|
|
|
|
|
content: '',
|
|
|
|
|
|
plainContent: '',
|
|
|
|
|
|
summary: '',
|
|
|
|
|
|
categoryId: null,
|
|
|
|
|
|
coverImage: '',
|
|
|
|
|
|
status: 'DRAFT',
|
|
|
|
|
|
tags: '',
|
|
|
|
|
|
isTop: 0,
|
|
|
|
|
|
expireTime: ''
|
2025-10-17 15:58:58 +08:00
|
|
|
|
},
|
|
|
|
|
|
dataRule: {
|
2026-01-28 15:19:33 +08:00
|
|
|
|
title: [
|
|
|
|
|
|
{ required: true, message: '标题不能为空', trigger: 'blur' }
|
2025-10-17 15:58:58 +08:00
|
|
|
|
],
|
2026-01-28 15:19:33 +08:00
|
|
|
|
content: [
|
|
|
|
|
|
{ required: true, message: '内容不能为空', trigger: 'blur' }
|
2025-10-17 15:58:58 +08:00
|
|
|
|
],
|
2026-01-28 15:19:33 +08:00
|
|
|
|
categoryId: [
|
|
|
|
|
|
{ required: true, message: '分类不能为空', trigger: 'blur' }
|
2025-10-17 15:58:58 +08:00
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
init (id) {
|
2026-01-28 15:19:33 +08:00
|
|
|
|
this.dataForm.id = id || null
|
2025-10-17 15:58:58 +08:00
|
|
|
|
this.visible = true
|
|
|
|
|
|
this.$nextTick(() => {
|
|
|
|
|
|
this.$refs['dataForm'].resetFields()
|
2026-01-28 15:19:33 +08:00
|
|
|
|
if (this.dataForm.id) {
|
|
|
|
|
|
this.getInfo()
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
// 获取信息
|
|
|
|
|
|
getInfo () {
|
|
|
|
|
|
this.$http({
|
|
|
|
|
|
url: this.$http.adornUrl(`/knowledge/info/${this.dataForm.id}`),
|
|
|
|
|
|
method: 'get'
|
|
|
|
|
|
}).then(({data}) => {
|
|
|
|
|
|
if (data && data.code === 200) {
|
|
|
|
|
|
const knowledge = data.knowledge
|
|
|
|
|
|
this.dataForm.title = knowledge.title
|
|
|
|
|
|
this.dataForm.subtitle = knowledge.subtitle
|
|
|
|
|
|
this.dataForm.content = knowledge.content
|
|
|
|
|
|
this.dataForm.plainContent = knowledge.plainContent
|
|
|
|
|
|
this.dataForm.summary = knowledge.summary
|
|
|
|
|
|
this.dataForm.categoryId = knowledge.categoryId
|
|
|
|
|
|
this.dataForm.coverImage = knowledge.coverImage
|
|
|
|
|
|
this.dataForm.status = knowledge.status
|
|
|
|
|
|
this.dataForm.tags = knowledge.tags
|
|
|
|
|
|
this.dataForm.isTop = knowledge.isTop
|
|
|
|
|
|
this.dataForm.expireTime = knowledge.expireTime
|
2025-10-17 15:58:58 +08:00
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
},
|
|
|
|
|
|
// 表单提交
|
|
|
|
|
|
dataFormSubmit () {
|
|
|
|
|
|
this.$refs['dataForm'].validate((valid) => {
|
|
|
|
|
|
if (valid) {
|
2026-01-28 15:19:33 +08:00
|
|
|
|
this.submitLoading = true
|
|
|
|
|
|
|
|
|
|
|
|
// 生成纯文本内容(去除HTML标签)
|
|
|
|
|
|
this.dataForm.plainContent = this.dataForm.content.replace(/<[^>]+>/g, '')
|
|
|
|
|
|
|
|
|
|
|
|
const url = !this.dataForm.id ? '/knowledge/save' : '/knowledge/update'
|
|
|
|
|
|
const method = !this.dataForm.id ? 'post' : 'put'
|
|
|
|
|
|
|
2025-10-17 15:58:58 +08:00
|
|
|
|
this.$http({
|
2026-01-28 15:19:33 +08:00
|
|
|
|
url: this.$http.adornUrl(url),
|
|
|
|
|
|
method: method,
|
|
|
|
|
|
data: this.$http.adornData(this.dataForm)
|
2025-10-17 15:58:58 +08:00
|
|
|
|
}).then(({data}) => {
|
2026-01-28 15:19:33 +08:00
|
|
|
|
this.submitLoading = false
|
2026-01-28 10:09:16 +08:00
|
|
|
|
if (data && data.code === 200) {
|
2025-10-17 15:58:58 +08:00
|
|
|
|
this.$message({
|
|
|
|
|
|
message: '操作成功',
|
|
|
|
|
|
type: 'success',
|
|
|
|
|
|
duration: 1500,
|
|
|
|
|
|
onClose: () => {
|
|
|
|
|
|
this.visible = false
|
|
|
|
|
|
this.$emit('refreshDataList')
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
|
|
|
|
|
this.$message.error(data.msg)
|
|
|
|
|
|
}
|
2026-01-28 15:19:33 +08:00
|
|
|
|
}).catch(() => {
|
|
|
|
|
|
this.submitLoading = false
|
2025-10-17 15:58:58 +08:00
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
2026-01-28 15:19:33 +08:00
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
</style>
|