更新
This commit is contained in:
parent
4fdb6b8d2e
commit
21f00e3702
@ -3,7 +3,7 @@ import request from "@/utils/request";
|
||||
|
||||
export function getLeavesCategoryList() {
|
||||
return request({
|
||||
url: '/ueditor/leavesCategoryList',
|
||||
url: '/ueditor/getLeavesCategoryTree',
|
||||
method: 'get'
|
||||
})
|
||||
}
|
||||
|
@ -16,21 +16,21 @@
|
||||
<el-tabs v-model="activeName">
|
||||
<el-tab-pane label="内容属性" name="basic">
|
||||
<el-form-item label="所属栏目" prop="categoryId">
|
||||
<el-select v-model="form.categoryId" placeholder="所属栏目">
|
||||
<el-option
|
||||
v-for="item in categoryList"
|
||||
:key="item.id"
|
||||
:label="item.categoryName"
|
||||
:value="item.id">
|
||||
</el-option>
|
||||
</el-select>
|
||||
<el-cascader v-model="form.selectCategoryId"
|
||||
:options="categoryList"
|
||||
:props="{ checkStrictly: true }"
|
||||
@change="handleCategorySelectChange"
|
||||
placeholder="所属栏目"
|
||||
>
|
||||
</el-cascader>
|
||||
</el-form-item>
|
||||
<el-form-item label="标题" prop="contentTitle">
|
||||
<el-input
|
||||
type="textarea"
|
||||
v-model="form.contentTitle"
|
||||
maxlength="360"
|
||||
show-word-limit>
|
||||
show-word-limit
|
||||
>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="是否置顶" prop="contentTitle">
|
||||
@ -38,31 +38,32 @@
|
||||
v-model="form.sortNum"
|
||||
:active-value="1"
|
||||
:inactive-value="0"
|
||||
>
|
||||
>
|
||||
</el-switch>
|
||||
|
||||
</el-form-item>
|
||||
<el-form-item label="封面图" prop="contentImg">
|
||||
<image-upload :limit="1" v-model="form.contentImg"></image-upload>
|
||||
</el-form-item>
|
||||
<!-- <el-form-item label="作者" prop="author">-->
|
||||
<!-- <el-input v-model="form.author"/>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="编辑" prop="editor">-->
|
||||
<!-- <el-input v-model="form.editor"/>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="来源" prop="source">-->
|
||||
<!-- <el-input v-model="form.source"/>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="来源地址" prop="sourceUrl">-->
|
||||
<!-- <el-input v-model="form.sourceUrl" placeholder="http(s)://"/>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="作者" prop="author">-->
|
||||
<!-- <el-input v-model="form.author"/>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="编辑" prop="editor">-->
|
||||
<!-- <el-input v-model="form.editor"/>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="来源" prop="source">-->
|
||||
<!-- <el-input v-model="form.source"/>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="来源地址" prop="sourceUrl">-->
|
||||
<!-- <el-input v-model="form.sourceUrl" placeholder="http(s)://"/>-->
|
||||
<!-- </el-form-item>-->
|
||||
<div class="art-title bg-purple-white">
|
||||
<el-form-item label="标签" prop="tagName">
|
||||
<el-input
|
||||
v-model="form.tagName"
|
||||
maxlength="8"
|
||||
show-word-limit>
|
||||
show-word-limit
|
||||
>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</div>
|
||||
@ -72,13 +73,14 @@
|
||||
type="textarea"
|
||||
v-model="form.summary"
|
||||
maxlength="360"
|
||||
show-word-limit>
|
||||
show-word-limit
|
||||
>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<!-- <el-form-item label="附件" prop="accessoryUrl">-->
|
||||
<!-- <file-upload v-model="form.accessoryUrl"/>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- <el-form-item label="附件" prop="accessoryUrl">-->
|
||||
<!-- <file-upload v-model="form.accessoryUrl"/>-->
|
||||
<!-- </el-form-item>-->
|
||||
<div class="art-title bg-purple-white">
|
||||
<el-form-item label="内容类型" prop="linkType">
|
||||
<el-radio-group v-model="form.linkType" @change="handleChangeLinkType">
|
||||
@ -97,32 +99,34 @@
|
||||
<el-cascader
|
||||
v-model="chooseValue"
|
||||
:options="linkList"
|
||||
@change="handleChange"></el-cascader>
|
||||
@change="handleChange"
|
||||
></el-cascader>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<div v-if="linkType === '1'" class="art-title bg-purple-white">
|
||||
<div v-if="linkType === '1'" class="art-title bg-purple-white">
|
||||
<el-form-item label="链接地址" prop="link">
|
||||
<el-input
|
||||
v-model="form.link"
|
||||
maxlength="360"
|
||||
placeholder="http(s)://"
|
||||
show-word-limit>
|
||||
show-word-limit
|
||||
>
|
||||
</el-input>
|
||||
</el-form-item>
|
||||
</div>
|
||||
<!-- <div class="art-title bg-purple-white">-->
|
||||
<!-- <el-form-item label="内容类型" prop="contentType">-->
|
||||
<!-- <el-radio-group v-model="form.contentType" @change="handleChangeType">-->
|
||||
<!-- <el-radio-button-->
|
||||
<!-- v-for="dict in dict.type.cms_content_type"-->
|
||||
<!-- :key="dict.value"-->
|
||||
<!-- :label="dict.value"-->
|
||||
<!-- >-->
|
||||
<!-- {{ dict.label }}-->
|
||||
<!-- </el-radio-button>-->
|
||||
<!-- </el-radio-group>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div class="art-title bg-purple-white">-->
|
||||
<!-- <el-form-item label="内容类型" prop="contentType">-->
|
||||
<!-- <el-radio-group v-model="form.contentType" @change="handleChangeType">-->
|
||||
<!-- <el-radio-button-->
|
||||
<!-- v-for="dict in dict.type.cms_content_type"-->
|
||||
<!-- :key="dict.value"-->
|
||||
<!-- :label="dict.value"-->
|
||||
<!-- >-->
|
||||
<!-- {{ dict.label }}-->
|
||||
<!-- </el-radio-button>-->
|
||||
<!-- </el-radio-group>-->
|
||||
<!-- </el-form-item>-->
|
||||
<!-- </div>-->
|
||||
</el-tab-pane>
|
||||
</el-tabs>
|
||||
</el-card>
|
||||
@ -132,19 +136,19 @@
|
||||
<el-row>
|
||||
<el-col class="pr10">
|
||||
<el-card shadow="always" v-show="linkType === '2'" class="card-editor">
|
||||
<div class="content bg-purple-white">
|
||||
<div class="content bg-purple-white">
|
||||
<vue-ueditor-wrap v-model="form.contentDetail"
|
||||
editor-id="editor"
|
||||
:config="editorConfig"
|
||||
:editorDependencies="['ueditor.config.js','ueditor.all.js']"
|
||||
/>
|
||||
</div>
|
||||
<!-- <div v-show="isType === '1'" class="content bg-purple-white btn-add-image">-->
|
||||
<!-- <image-upload v-model="form.imageUrl"/>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div v-show="isType === '2'" class="content bg-purple-white btn-add-image">-->
|
||||
<!-- <video-upload v-model="form.videoUrl"></video-upload>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div v-show="isType === '1'" class="content bg-purple-white btn-add-image">-->
|
||||
<!-- <image-upload v-model="form.imageUrl"/>-->
|
||||
<!-- </div>-->
|
||||
<!-- <div v-show="isType === '2'" class="content bg-purple-white btn-add-image">-->
|
||||
<!-- <video-upload v-model="form.videoUrl"></video-upload>-->
|
||||
<!-- </div>-->
|
||||
</el-card>
|
||||
</el-col>
|
||||
</el-row>
|
||||
@ -156,13 +160,13 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import VueUeditorWrap from "vue-ueditor-wrap";
|
||||
import {getLeavesCategoryList} from "@/api/cms/editor"
|
||||
import VueUeditorWrap from 'vue-ueditor-wrap'
|
||||
import { getLeavesCategoryList } from '@/api/cms/editor'
|
||||
import { getLeavesCategory, getLeavesContent } from '@/api/cms/category'
|
||||
import {addContent, getContent, updateContent} from "@/api/cms/content";
|
||||
import { addContent, getContent, updateContent } from '@/api/cms/content'
|
||||
|
||||
export default {
|
||||
name: "Content",
|
||||
name: 'Content',
|
||||
dicts: ['cms_content_type', 'cms_link_type'],
|
||||
components: {
|
||||
VueUeditorWrap
|
||||
@ -173,14 +177,14 @@ export default {
|
||||
},
|
||||
watch: {
|
||||
// 监听内容管理传过来的categoryId
|
||||
"$route.query.categoryId": {
|
||||
'$route.query.categoryId': {
|
||||
immediate: true,
|
||||
handler() {
|
||||
this.reset()
|
||||
this.getCategoryList()
|
||||
},
|
||||
}
|
||||
},
|
||||
"$route.query.contentId": {
|
||||
'$route.query.contentId': {
|
||||
immediate: true,
|
||||
handler(val) {
|
||||
if (val !== undefined) {
|
||||
@ -188,19 +192,19 @@ export default {
|
||||
this.getCategoryList()
|
||||
this.getContentById(val)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
chooseValue: [],
|
||||
openResourceDialog: false,
|
||||
isType: "0",
|
||||
activeName: "basic",
|
||||
isType: '0',
|
||||
activeName: 'basic',
|
||||
// 表单参数
|
||||
form: {
|
||||
contentType: "0",
|
||||
original: "0",
|
||||
contentType: '0',
|
||||
original: '0',
|
||||
categoryId: '',
|
||||
imageUrl: [],
|
||||
videoUrl: [],
|
||||
@ -215,25 +219,26 @@ export default {
|
||||
status: '0',
|
||||
isAccessory: '0',
|
||||
accessoryUrl: [],
|
||||
linkType: "2",
|
||||
link: ''
|
||||
linkType: '2',
|
||||
link: '',
|
||||
selectCategoryId:[]
|
||||
},
|
||||
rules: {
|
||||
contentTitle: [{required: true, message: "内容标题不能为空", trigger: "blur"}],
|
||||
categoryId: [{required: true, message: "所属栏目不能为空", trigger: "blur"}]
|
||||
contentTitle: [{ required: true, message: '内容标题不能为空', trigger: 'blur' }],
|
||||
categoryId: [{ required: true, message: '所属栏目不能为空', trigger: 'blur' }]
|
||||
},
|
||||
editorConfig: {
|
||||
initialFrameHeight: 1000, // 初始高度
|
||||
//serverUrl: process.env.VUE_APP_BASE_API + "/config"',
|
||||
//**更正代码231109**
|
||||
serverUrl: process.env.VUE_APP_BASE_API + "/ueditor/config",
|
||||
serverUrl: process.env.VUE_APP_BASE_API + '/ueditor/config',
|
||||
//前端资源
|
||||
UEDITOR_HOME_URL: '/static/UEditorPlus/',
|
||||
UEDITOR_CORS_URL: '/static/UEditorPlus/',
|
||||
UEDITOR_CORS_URL: '/static/UEditorPlus/'
|
||||
},
|
||||
categoryList: "",
|
||||
linkType: "2",
|
||||
linkList: [],
|
||||
categoryList: '',
|
||||
linkType: '2',
|
||||
linkList: []
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@ -241,8 +246,8 @@ export default {
|
||||
reset() {
|
||||
this.form = {
|
||||
contentType: this.isType,
|
||||
original: "0",
|
||||
categoryId: this.$route.query.categoryId === "0" ? this.form.categoryId : this.$route.query.categoryId,
|
||||
original: '0',
|
||||
categoryId: this.$route.query.categoryId === '0' ? this.form.categoryId : this.$route.query.categoryId,
|
||||
imageUrl: [],
|
||||
videoUrl: [],
|
||||
contentTitle: '',
|
||||
@ -256,34 +261,77 @@ export default {
|
||||
status: '0',
|
||||
isAccessory: '0',
|
||||
accessoryUrl: [],
|
||||
id: "",
|
||||
linkType: "2",
|
||||
id: '',
|
||||
linkType: '2',
|
||||
link: ''
|
||||
}
|
||||
},
|
||||
getCategoryList() {
|
||||
getLeavesCategoryList().then(response => {
|
||||
this.categoryList = response.data
|
||||
console.log(this.temp)
|
||||
console.log('category', this.categoryList)
|
||||
this.form.categoryId = this.$route.query.categoryId + ''
|
||||
console.log('categoryId', this.form.categoryId)
|
||||
if (!!this.$route.query.categoryId){
|
||||
console.log('执行')
|
||||
let flag = false;
|
||||
this.categoryList.forEach(item => {
|
||||
if (item.id == this.$route.query.categoryId) {
|
||||
this.form.categoryId = this.$route.query.categoryId.toString()
|
||||
flag = true;
|
||||
}
|
||||
if (!flag){
|
||||
this.form.categoryId = ""
|
||||
}
|
||||
})
|
||||
console.log('最终的categoryId', this.form.categoryId)
|
||||
if (!!this.$route.query.categoryId) {
|
||||
// let flag = this.isIdInTree(this.$route.query.categoryId, this.categoryList)
|
||||
// if (!flag) {
|
||||
// this.form.categoryId = ''
|
||||
// }
|
||||
this.form.selectCategoryId = this.getParentsById(this.categoryList,this.$route.query.categoryId)
|
||||
this.form.categoryId = this.form.selectCategoryId[this.form.selectCategoryId.length - 1]
|
||||
console.log('最终的categoryId', this.form.selectCategoryId)
|
||||
}
|
||||
})
|
||||
},
|
||||
/**
|
||||
* @param list 数据列表
|
||||
* @param id 后端返回的id
|
||||
**/
|
||||
getParentsById(list, id) {
|
||||
for (let i in list) {
|
||||
if (list[i].value == id) {
|
||||
//查询到就返回该数组对象的value
|
||||
return [list[i].value]
|
||||
}
|
||||
if (list[i].children) {
|
||||
let node = this.getParentsById(list[i].children, id)
|
||||
if (node !== undefined) {
|
||||
//查询到把父节把父节点加到数组前面
|
||||
node.unshift(list[i].value)
|
||||
return node
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
/**
|
||||
* @Description: 判断一个id是否存在于树形结构中
|
||||
* @Author: 86187
|
||||
* @Date: 2025/02/28 11:16
|
||||
* @Version: 1.0
|
||||
*/
|
||||
isIdInTree(id, tree) {
|
||||
console.log('id', id)
|
||||
console.log('tree', tree)
|
||||
// 遍历树形结构
|
||||
for (let node of tree) {
|
||||
// 如果当前节点的value等于目标id,返回true
|
||||
if (node.value == id.toString()) {
|
||||
return true
|
||||
}
|
||||
|
||||
// 如果当前节点有子节点,则递归查找子节点
|
||||
if (node.children && node.children.length > 0) {
|
||||
if (this.isIdInTree(id, node.children)) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 如果遍历完没有找到,则返回false
|
||||
return false
|
||||
},
|
||||
handleCategorySelectChange(e) {
|
||||
this.form.categoryId = e[e.length - 1]
|
||||
// console.log('选中的categoryId', this.form.categoryId)
|
||||
},
|
||||
handleChangeType() {
|
||||
this.isType = this.form.contentType
|
||||
},
|
||||
@ -291,44 +339,44 @@ export default {
|
||||
this.linkType = this.form.linkType
|
||||
},
|
||||
handleEdit() {
|
||||
this.openResourceDialog = true;
|
||||
this.openResourceDialog = true
|
||||
},
|
||||
// 发布
|
||||
handlePublish() {
|
||||
this.form.status = "1"
|
||||
this.form.status = '1'
|
||||
this.form.publishDate = this.formatTimer(new Date())
|
||||
this.handleSave();
|
||||
this.handleSave()
|
||||
},
|
||||
//保存
|
||||
handlerSaveBefore(){
|
||||
this.form.status = this.form.id === "" ? "0" : "3"
|
||||
this.handleSave();
|
||||
handlerSaveBefore() {
|
||||
this.form.status = this.form.id === '' ? '0' : '3'
|
||||
this.handleSave()
|
||||
},
|
||||
// 新增
|
||||
handleSave() {
|
||||
this.$refs["form"].validate(valid => {
|
||||
this.$refs['form'].validate(valid => {
|
||||
if (valid) {
|
||||
this.$modal.loading("正在" + (this.form.status !== "1" ? "保存" : "发布") + "内容,请稍候...");
|
||||
this.$modal.loading('正在' + (this.form.status !== '1' ? '保存' : '发布') + '内容,请稍候...')
|
||||
// if:修改,else:新增
|
||||
if (this.form.id !== "") {
|
||||
if (this.form.id !== '') {
|
||||
this.changeUrl()
|
||||
updateContent(this.form).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.$modal.msgSuccess(this.form.status !== "1" ? "保存成功" : "发布成功");
|
||||
this.$modal.msgSuccess(this.form.status !== '1' ? '保存成功' : '发布成功')
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.changeUrl()
|
||||
addContent(this.form).then(res => {
|
||||
if (res.code === 200) {
|
||||
this.$modal.msgSuccess(this.form.status !== "1" ? "保存成功" : "发布成功");
|
||||
this.$modal.msgSuccess(this.form.status !== '1' ? '保存成功' : '发布成功')
|
||||
}
|
||||
})
|
||||
}
|
||||
this.reset();
|
||||
this.$router.go(-1);
|
||||
this.reset()
|
||||
this.$router.go(-1)
|
||||
// this.$router.replace('/content/content')
|
||||
this.$modal.closeLoading();
|
||||
this.$modal.closeLoading()
|
||||
}
|
||||
})
|
||||
},
|
||||
@ -342,28 +390,28 @@ export default {
|
||||
})
|
||||
},
|
||||
StrToArr(value) {
|
||||
return value.toString().split(",")
|
||||
return value.toString().split(',')
|
||||
},
|
||||
changeUrl() {
|
||||
if (this.form.accessoryUrl !== null && this.form.accessoryUrl.length !== 0) {
|
||||
this.form.isAccessory = "1"
|
||||
this.form.isAccessory = '1'
|
||||
this.form.accessoryUrl = this.StrToArr(this.form.accessoryUrl)
|
||||
}else {
|
||||
this.form.isAccessory = "0";
|
||||
this.form.accessoryUrl = [];
|
||||
} else {
|
||||
this.form.isAccessory = '0'
|
||||
this.form.accessoryUrl = []
|
||||
}
|
||||
if (this.form.imageUrl !== null && this.form.imageUrl.length !== 0) {
|
||||
this.form.imageUrl = this.StrToArr(this.form.imageUrl)
|
||||
}else {
|
||||
} else {
|
||||
this.form.imageUrl = []
|
||||
}
|
||||
if (this.form.videoUrl !== null && this.form.videoUrl.length !== 0) {
|
||||
this.form.videoUrl = this.StrToArr(this.form.videoUrl)
|
||||
}else {
|
||||
} else {
|
||||
this.form.videoUrl = []
|
||||
}
|
||||
},
|
||||
listLeavesCategory(id){
|
||||
listLeavesCategory(id) {
|
||||
getLeavesCategory(id).then(res => {
|
||||
res.data.forEach(item => {
|
||||
const x = {
|
||||
@ -375,7 +423,7 @@ export default {
|
||||
})
|
||||
})
|
||||
},
|
||||
createLink(contents){
|
||||
createLink(contents) {
|
||||
let list = []
|
||||
contents.forEach(item => {
|
||||
const x = {
|
||||
@ -390,19 +438,19 @@ export default {
|
||||
this.form.link = value[1]
|
||||
},
|
||||
formatTimer: function(value) {
|
||||
let date = new Date(value);
|
||||
let y = date.getFullYear();
|
||||
let MM = date.getMonth() + 1;
|
||||
MM = MM < 10 ? "0" + MM : MM;
|
||||
let d = date.getDate();
|
||||
d = d < 10 ? "0" + d : d;
|
||||
let h = date.getHours();
|
||||
h = h < 10 ? "0" + h : h;
|
||||
let m = date.getMinutes();
|
||||
m = m < 10 ? "0" + m : m;
|
||||
let s = date.getSeconds();
|
||||
s = s < 10 ? "0" + s : s;
|
||||
return y + "-" + MM + "-" + d + " " + h + ":" + m;
|
||||
let date = new Date(value)
|
||||
let y = date.getFullYear()
|
||||
let MM = date.getMonth() + 1
|
||||
MM = MM < 10 ? '0' + MM : MM
|
||||
let d = date.getDate()
|
||||
d = d < 10 ? '0' + d : d
|
||||
let h = date.getHours()
|
||||
h = h < 10 ? '0' + h : h
|
||||
let m = date.getMinutes()
|
||||
m = m < 10 ? '0' + m : m
|
||||
let s = date.getSeconds()
|
||||
s = s < 10 ? '0' + s : s
|
||||
return y + '-' + MM + '-' + d + ' ' + h + ':' + m
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user