This commit is contained in:
许允枞 2025-02-28 14:16:47 +08:00
parent 4fdb6b8d2e
commit 21f00e3702
2 changed files with 177 additions and 129 deletions

View File

@ -3,7 +3,7 @@ import request from "@/utils/request";
export function getLeavesCategoryList() {
return request({
url: '/ueditor/leavesCategoryList',
url: '/ueditor/getLeavesCategoryTree',
method: 'get'
})
}

View File

@ -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">
@ -62,7 +62,8 @@
<el-input
v-model="form.tagName"
maxlength="8"
show-word-limit>
show-word-limit
>
</el-input>
</el-form-item>
</div>
@ -72,7 +73,8 @@
type="textarea"
v-model="form.summary"
maxlength="360"
show-word-limit>
show-word-limit
>
</el-input>
</el-form-item>
</div>
@ -97,7 +99,8 @@
<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">
@ -106,7 +109,8 @@
v-model="form.link"
maxlength="360"
placeholder="http(s)://"
show-word-limit>
show-word-limit
>
</el-input>
</el-form-item>
</div>
@ -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,33 +261,76 @@ 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 = ""
// 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)
}
})
console.log('最终的categoryId', this.form.categoryId)
},
/**
* @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) {
// valueidtrue
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();
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' ? '保存' : '发布') + '内容,请稍候...')
// ifelse
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,15 +390,15 @@ 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 = [];
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)
@ -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
}
}
}