add:新增知识库功能
This commit is contained in:
@@ -1,39 +1,101 @@
|
||||
<template>
|
||||
<el-dialog
|
||||
:title="!dataForm.materialId ? '新增' : '修改'"
|
||||
:title="!dataForm.id ? '新增知识文档' : '编辑知识文档'"
|
||||
:close-on-click-modal="false"
|
||||
:visible.sync="visible"
|
||||
width="500px">
|
||||
<el-form :model="dataForm" :rules="dataRule" size="mini" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
|
||||
<el-form-item label="物料编码" prop="materialCode">
|
||||
<el-input v-model="dataForm.materialCode" placeholder="物料编码"></el-input>
|
||||
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>
|
||||
</el-form-item>
|
||||
<el-form-item label="物料名称" prop="materialName">
|
||||
<el-input v-model="dataForm.materialName" placeholder="物料名称"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="物料类型" prop="materialType">
|
||||
<el-select v-model="dataForm.materialType" placeholder="物料类型">
|
||||
<el-option
|
||||
v-for="item in dictData[0]"
|
||||
:key="item.value"
|
||||
:label="item.label"
|
||||
:value="item.value">
|
||||
</el-option>
|
||||
</el-select>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否启用" prop="isOn">
|
||||
<el-switch
|
||||
v-model="dataForm.isOn"
|
||||
active-color="#409EFF"
|
||||
inactive-color="#F56C6C"
|
||||
:active-value="1"
|
||||
:inactive-value="0"
|
||||
/>
|
||||
|
||||
<el-form-item label="内容" prop="content">
|
||||
<el-input
|
||||
v-model="dataForm.content"
|
||||
type="textarea"
|
||||
:rows="10"
|
||||
placeholder="请输入HTML格式内容">
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
|
||||
<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>
|
||||
</el-form>
|
||||
|
||||
<span slot="footer" class="dialog-footer">
|
||||
<el-button size="mini" @click="visible = false">取消</el-button>
|
||||
<el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
|
||||
<el-button @click="visible = false" size="small">取消</el-button>
|
||||
<el-button type="primary" @click="dataFormSubmit()" size="small" :loading="submitLoading">确定</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
</template>
|
||||
@@ -43,48 +105,64 @@ export default {
|
||||
data () {
|
||||
return {
|
||||
visible: false,
|
||||
submitLoading: false,
|
||||
dataForm: {
|
||||
materialId: 0,
|
||||
materialCode: '',
|
||||
materialName: '',
|
||||
materialType: '',
|
||||
isOn: 0
|
||||
id: null,
|
||||
title: '',
|
||||
subtitle: '',
|
||||
content: '',
|
||||
plainContent: '',
|
||||
summary: '',
|
||||
categoryId: null,
|
||||
coverImage: '',
|
||||
status: 'DRAFT',
|
||||
tags: '',
|
||||
isTop: 0,
|
||||
expireTime: ''
|
||||
},
|
||||
dataRule: {
|
||||
materialCode: [
|
||||
{ required: true, message: '物料编码不能为空', trigger: 'blur' }
|
||||
title: [
|
||||
{ required: true, message: '标题不能为空', trigger: 'blur' }
|
||||
],
|
||||
materialName: [
|
||||
{ required: true, message: '物料名称不能为空', trigger: 'blur' }
|
||||
content: [
|
||||
{ required: true, message: '内容不能为空', trigger: 'blur' }
|
||||
],
|
||||
materialType: [
|
||||
{ required: true, message: '物料类型不能为空', trigger: 'blur' }
|
||||
categoryId: [
|
||||
{ required: true, message: '分类不能为空', trigger: 'blur' }
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
props: {
|
||||
dictData: Array
|
||||
},
|
||||
methods: {
|
||||
init (id) {
|
||||
this.dataForm.materialId = id || 0
|
||||
this.dataForm.id = id || null
|
||||
this.visible = true
|
||||
this.$nextTick(() => {
|
||||
this.$refs['dataForm'].resetFields()
|
||||
if (this.dataForm.materialId) {
|
||||
this.$http({
|
||||
url: this.$http.adornUrl(`/material/material/info/${this.dataForm.materialId}`),
|
||||
method: 'get',
|
||||
params: this.$http.adornParams()
|
||||
}).then(({data}) => {
|
||||
if (data && data.code === 200) {
|
||||
this.dataForm.materialCode = data.material.materialCode
|
||||
this.dataForm.materialName = data.material.materialName
|
||||
this.dataForm.materialType = String(data.material.materialType)
|
||||
this.dataForm.isOn = data.material.isOn
|
||||
}
|
||||
})
|
||||
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
|
||||
}
|
||||
})
|
||||
},
|
||||
@@ -92,17 +170,20 @@ export default {
|
||||
dataFormSubmit () {
|
||||
this.$refs['dataForm'].validate((valid) => {
|
||||
if (valid) {
|
||||
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'
|
||||
|
||||
this.$http({
|
||||
url: this.$http.adornUrl(`/material/material/${!this.dataForm.materialId ? 'save' : 'update'}`),
|
||||
method: 'post',
|
||||
data: this.$http.adornData({
|
||||
'materialId': this.dataForm.materialId || undefined,
|
||||
'materialCode': this.dataForm.materialCode,
|
||||
'materialName': this.dataForm.materialName,
|
||||
'materialType': this.dataForm.materialType,
|
||||
'isOn': this.dataForm.isOn
|
||||
})
|
||||
url: this.$http.adornUrl(url),
|
||||
method: method,
|
||||
data: this.$http.adornData(this.dataForm)
|
||||
}).then(({data}) => {
|
||||
this.submitLoading = false
|
||||
if (data && data.code === 200) {
|
||||
this.$message({
|
||||
message: '操作成功',
|
||||
@@ -116,6 +197,8 @@ export default {
|
||||
} else {
|
||||
this.$message.error(data.msg)
|
||||
}
|
||||
}).catch(() => {
|
||||
this.submitLoading = false
|
||||
})
|
||||
}
|
||||
})
|
||||
@@ -123,3 +206,6 @@ export default {
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user