|
|
@@ -1,64 +1,46 @@
|
|
|
<template>
|
|
|
<div class="editor">
|
|
|
- <el-input v-model="title" class="title" placeholder="请输入文章标题" :maxlength="50"></el-input>
|
|
|
- <el-input
|
|
|
- type="textarea"
|
|
|
- :autosize="{ minRows: 1, maxRows: 8}"
|
|
|
- v-model="subTitle"
|
|
|
- class="sub-title"
|
|
|
- placeholder="请输入导语(选填)"
|
|
|
- :maxlength="300"
|
|
|
- ></el-input>
|
|
|
- <editor :content="content" @change="handleChange"></editor>
|
|
|
- <!-- <div class="quill-editor" v-model="content" v-quill:myQuillEditor="editorOption"></div>
|
|
|
- <input type="file" id="imgInput" @change="handleContentFileChange" style="display: none;" />-->
|
|
|
+ <el-input show-word-limit v-model="title" class="title" placeholder="请输入文章标题" :maxlength="60"></el-input>
|
|
|
+ <editor placeholder="支持富文本、支持超链接、插入图片、插入视频,最少100字符,最多10000字符" :content="content" @change="handleChange"></editor>
|
|
|
<h5 class="label">封面图</h5>
|
|
|
- <el-upload
|
|
|
- class="avatar-uploader"
|
|
|
- action="#"
|
|
|
- :show-file-list="false"
|
|
|
- :multiple="false"
|
|
|
- accept="image/png, image/jpeg"
|
|
|
- :before-upload="handleFileChange"
|
|
|
- >
|
|
|
- <i
|
|
|
- v-if="cover_url"
|
|
|
- class="el-icon-delete avatar-uploader-icon"
|
|
|
- @click.stop="handleDeleteFile"
|
|
|
- ></i>
|
|
|
- <img v-if="cover_url" :src="cover_url" class="avatar" />
|
|
|
- <i v-else class="el-icon-plus avatar-uploader-icon"></i>
|
|
|
- <div slot="tip" class="el-upload__tip">建议尺寸:480*330,大小在500k以内</div>
|
|
|
- </el-upload>
|
|
|
- <el-dialog :visible.sync="dialogVisible">
|
|
|
- <img width="100%" :src="cover_url" alt />
|
|
|
- </el-dialog>
|
|
|
- <h5 class="label">选择分类</h5>
|
|
|
- <el-select v-model="categoryId" placeholder="请选择文章分类" class="class">
|
|
|
- <el-option
|
|
|
- v-for="item in categoryList"
|
|
|
- :key="item.value"
|
|
|
- :label="item.label"
|
|
|
- :value="item.value"
|
|
|
- ></el-option>
|
|
|
- </el-select>
|
|
|
- <h5 class="label">标签</h5>
|
|
|
- <el-select
|
|
|
- class="tags"
|
|
|
- v-model="tags"
|
|
|
- multiple
|
|
|
- filterable
|
|
|
- allow-create
|
|
|
- default-first-option
|
|
|
- placeholder="每个标签以enter键隔开、最多5个,如:技术,经验"
|
|
|
- >
|
|
|
+
|
|
|
+ <div class="uploadInfo">
|
|
|
+ <div class="left">
|
|
|
+ <el-upload
|
|
|
+ class="avatar-uploader"
|
|
|
+ action="#"
|
|
|
+ :show-file-list="false"
|
|
|
+ :multiple="false"
|
|
|
+ accept="image/png, image/jpeg"
|
|
|
+ :before-upload="handleFileChange"
|
|
|
+ >
|
|
|
+ <i v-if="cover_url" class="el-icon-delete avatar-uploader-icon"
|
|
|
+ @click.stop="handleDeleteFile"></i>
|
|
|
+ <img v-if="cover_url" :src="cover_url" class="avatar"/>
|
|
|
+ <div v-else class="noneImage">
|
|
|
+ <i class="el-icon-plus avatar-uploader-icon"></i>
|
|
|
+ </div>
|
|
|
+ </el-upload>
|
|
|
+ </div>
|
|
|
+ <div class="right">
|
|
|
+ <p>建议尺寸: </p>
|
|
|
+ <p>180*140 大小在500k以内</p>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <h5 class="label">添加到合集(选填)</h5>
|
|
|
+ <el-select v-model="collectionId" placeholder="请选择合集" class="class">
|
|
|
<el-option
|
|
|
- v-for="item in tagOptions"
|
|
|
- :key="item.value"
|
|
|
- :label="item.label"
|
|
|
- :value="item.value"
|
|
|
+ v-for="item in collectionList"
|
|
|
+ :key="item.id"
|
|
|
+ :label="item.title"
|
|
|
+ :value="item.id"
|
|
|
></el-option>
|
|
|
</el-select>
|
|
|
+
|
|
|
+ <el-dialog :visible.sync="dialogVisible">
|
|
|
+ <img width="100%" :src="cover_url" alt />
|
|
|
+ </el-dialog>
|
|
|
<footer>
|
|
|
<el-button type="primary" @click="publish">发布</el-button>
|
|
|
<el-button @click="cancel">取消</el-button>
|
|
|
@@ -84,10 +66,10 @@ export default {
|
|
|
subTitle: "",
|
|
|
content: "",
|
|
|
cover_url: "",
|
|
|
- tags: [],
|
|
|
- categoryId: "",
|
|
|
dialogVisible: false,
|
|
|
disabled: false,
|
|
|
+ collectionId: "",
|
|
|
+ collectionList: [],
|
|
|
categoryList: [
|
|
|
{
|
|
|
value: "default",
|
|
|
@@ -95,63 +77,17 @@ export default {
|
|
|
}
|
|
|
],
|
|
|
fileList: [],
|
|
|
- tagOptions: [
|
|
|
- {
|
|
|
- value: "技术",
|
|
|
- label: "技术"
|
|
|
- },
|
|
|
- {
|
|
|
- value: "人工智能",
|
|
|
- label: "人工智能"
|
|
|
- },
|
|
|
- {
|
|
|
- value: "区块链",
|
|
|
- label: "区块链"
|
|
|
- }
|
|
|
- ],
|
|
|
uploading: false
|
|
|
- // editorOption: {
|
|
|
- // theme: "snow",
|
|
|
- // placeholder: "请输入正文...",
|
|
|
- // modules: {
|
|
|
- // toolbar: [
|
|
|
- // ["bold", "italic", "underline", "strike"],
|
|
|
- // ["blockquote", "code-block"],
|
|
|
- // [{ header: 1 }, { header: 2 }],
|
|
|
- // [{ list: "ordered" }, { list: "bullet" }],
|
|
|
- // [{ script: "sub" }, { script: "super" }],
|
|
|
- // [{ indent: "-1" }, { indent: "+1" }],
|
|
|
- // [{ direction: "rtl" }],
|
|
|
- // [{ size: ["small", false, "large", "huge"] }],
|
|
|
- // [{ header: [1, 2, 3, 4, 5, 6, false] }],
|
|
|
- // [{ font: [] }],
|
|
|
- // [{ color: [] }, { background: [] }],
|
|
|
- // [{ align: [] }],
|
|
|
- // ["clean"],
|
|
|
- // ["link", "image"]
|
|
|
- // ],
|
|
|
- // syntax: {
|
|
|
- // highlight: text => hljs.highlightAuto(text).value
|
|
|
- // }
|
|
|
- // }
|
|
|
- // }
|
|
|
};
|
|
|
},
|
|
|
computed: {},
|
|
|
mounted() {
|
|
|
this.needLogin();
|
|
|
this.needVerify();
|
|
|
+ this.getHejiList()
|
|
|
if (this.$route.params.id) {
|
|
|
this.loadData();
|
|
|
}
|
|
|
- this.$axios.$post(`/api/community/topic/get_category`).then(res => {
|
|
|
- if (res.status === 1) {
|
|
|
- this.categoryList = res.data.map(it => ({
|
|
|
- value: it.id,
|
|
|
- label: it.name
|
|
|
- }));
|
|
|
- }
|
|
|
- });
|
|
|
},
|
|
|
methods: {
|
|
|
loadData() {
|
|
|
@@ -169,8 +105,6 @@ export default {
|
|
|
this.title = topic.title;
|
|
|
this.subTitle = topic.intro;
|
|
|
this.content = topic.body;
|
|
|
- this.tags = topic.label ? topic.label.split(",") : "";
|
|
|
- this.categoryId = topic.category_id + "";
|
|
|
if (this.cover_url) {
|
|
|
this.fileList.push({
|
|
|
name: "cover_image",
|
|
|
@@ -183,34 +117,49 @@ export default {
|
|
|
// TODO go details
|
|
|
});
|
|
|
},
|
|
|
+ getHejiList() {
|
|
|
+ this.$axios.post("/api/jishuquan/get_collections", {
|
|
|
+ uid: this.$store.state.userinfo.uid,
|
|
|
+ page: 1,
|
|
|
+ size: 200
|
|
|
+ }).then(res=>{
|
|
|
+ if (res.data.status === 1) {
|
|
|
+ this.collectionList = res.data.data
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },
|
|
|
publish() {
|
|
|
this.needVerify();
|
|
|
- if (!this.content) {
|
|
|
- this.$message.error("请输入文章正文");
|
|
|
+ if (!this.title) {
|
|
|
+ this.$message.error("请输入文章标题");
|
|
|
return;
|
|
|
}
|
|
|
- if (this.content.length > 100000) {
|
|
|
- this.$message.error("文章正文不可超过10万字符,请删减");
|
|
|
+ if (this.title.length < 2) {
|
|
|
+ this.$message.error("文章标题不可少于2字符");
|
|
|
return;
|
|
|
}
|
|
|
- if (!this.title) {
|
|
|
- this.$message.error("请输入文章标题");
|
|
|
+ if (this.title.length > 60) {
|
|
|
+ this.$message.error("文章标题不可超过60字符,请删减");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!this.content) {
|
|
|
+ this.$message.error("请输入文章正文");
|
|
|
return;
|
|
|
}
|
|
|
- if (!this.categoryId) {
|
|
|
- this.$message.error("请选择文章分类");
|
|
|
+ if (this.content.length < 100) {
|
|
|
+ this.$message.error("文章正文不可少于100字符");
|
|
|
return;
|
|
|
}
|
|
|
- if (this.tags.length > 5) {
|
|
|
- this.$message.error("标签最多可填写5个标签,请删减");
|
|
|
+ if (this.content.length > 100000) {
|
|
|
+ this.$message.error("文章正文不可超过1万字符,请删减");
|
|
|
return;
|
|
|
}
|
|
|
const data = {
|
|
|
title: this.title,
|
|
|
intro: this.subTitle,
|
|
|
body: this.content,
|
|
|
- categoryId: parseInt(this.categoryId),
|
|
|
- label: this.tags && this.tags.length > 0 ? this.tags.join(",") : "",
|
|
|
+ collection_id: this.collectionId,
|
|
|
cover_url: this.cover_url
|
|
|
};
|
|
|
if (this.topicId) {
|
|
|
@@ -323,50 +272,6 @@ export default {
|
|
|
padding-left: 0;
|
|
|
}
|
|
|
}
|
|
|
- .el-icon-delete {
|
|
|
- display: none;
|
|
|
- }
|
|
|
- .avatar-uploader .el-upload {
|
|
|
- width: 160px;
|
|
|
- height: 110px;
|
|
|
- border: 1px dashed #d9d9d9;
|
|
|
- border-radius: 6px;
|
|
|
- cursor: pointer;
|
|
|
- position: relative;
|
|
|
- overflow: hidden;
|
|
|
- img {
|
|
|
- width: 100%;
|
|
|
- height: auto;
|
|
|
- object-fit: contain;
|
|
|
- object-position: top left;
|
|
|
- }
|
|
|
- }
|
|
|
- .avatar-uploader .el-upload:hover {
|
|
|
- border-color: #409eff;
|
|
|
- .el-icon-delete {
|
|
|
- display: block;
|
|
|
- }
|
|
|
- }
|
|
|
- .avatar-uploader-icon {
|
|
|
- position: absolute;
|
|
|
- top: 0;
|
|
|
- left: 0;
|
|
|
- font-size: 28px;
|
|
|
- color: #fff;
|
|
|
- width: 160px;
|
|
|
- height: 110px;
|
|
|
- line-height: 110px;
|
|
|
- text-align: center;
|
|
|
- background: rgba(1, 1, 1, 0.3);
|
|
|
- :hover {
|
|
|
- color: #409eff;
|
|
|
- }
|
|
|
- }
|
|
|
- .avatar {
|
|
|
- width: 178px;
|
|
|
- height: 178px;
|
|
|
- display: block;
|
|
|
- }
|
|
|
.label {
|
|
|
margin: 20px auto 10px;
|
|
|
font-size: 13px;
|
|
|
@@ -409,4 +314,77 @@ export default {
|
|
|
font-style: italic !important;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+.uploadInfo {
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ .left {
|
|
|
+ width: 180px;
|
|
|
+ flex-shrink: 0;
|
|
|
+ overflow: hidden;
|
|
|
+ position: relative;
|
|
|
+ background: #fff;
|
|
|
+ .el-icon-delete {
|
|
|
+ display: none;
|
|
|
+ }
|
|
|
+ .avatar-uploader .el-upload {
|
|
|
+ width: 180px;
|
|
|
+ height: 140px;
|
|
|
+ border: 1px dashed #dce1e8;
|
|
|
+ border-radius: 6px;
|
|
|
+ cursor: pointer;
|
|
|
+ position: relative;
|
|
|
+ overflow: hidden;
|
|
|
+ img {
|
|
|
+ width: 100%;
|
|
|
+ height: auto;
|
|
|
+ object-fit: contain;
|
|
|
+ object-position: top left;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .avatar-uploader .el-upload:hover {
|
|
|
+ border-color: #409eff;
|
|
|
+ .el-icon-delete {
|
|
|
+ display: block;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .avatar-uploader-icon {
|
|
|
+ position: absolute;
|
|
|
+ top: 0;
|
|
|
+ left: 0;
|
|
|
+ font-size: 44px;
|
|
|
+ color: #dce1e8;;
|
|
|
+ width: 180px;
|
|
|
+ height: 140px;
|
|
|
+ line-height: 140px;
|
|
|
+ text-align: center;
|
|
|
+ }
|
|
|
+ .avatar {
|
|
|
+ width: 180px;
|
|
|
+ height: 140px;
|
|
|
+ display: block;
|
|
|
+ }
|
|
|
+ .title {
|
|
|
+ position: absolute;
|
|
|
+ left: 50%;
|
|
|
+ bottom: 40px;
|
|
|
+ transform: translateX(-50%);
|
|
|
+ font-size: 13px;
|
|
|
+ font-weight: 500;
|
|
|
+ color: #dce1e8;
|
|
|
+ line-height: 18px;
|
|
|
+ text-decoration: underline;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .right {
|
|
|
+ margin-left: 18px;
|
|
|
+ height:34px;
|
|
|
+ p {
|
|
|
+ font-size:12px;
|
|
|
+ font-weight:400;
|
|
|
+ color:rgba(145,154,167,1);
|
|
|
+ line-height:17px;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
</style>
|