|
|
@@ -0,0 +1,402 @@
|
|
|
+<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;" />-->
|
|
|
+ <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个,如:技术,经验"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="item in tagOptions"
|
|
|
+ :key="item.value"
|
|
|
+ :label="item.label"
|
|
|
+ :value="item.value"
|
|
|
+ ></el-option>
|
|
|
+ </el-select>
|
|
|
+ <footer>
|
|
|
+ <el-button type="primary" @click="publish">发布</el-button>
|
|
|
+ <el-button @click="cancel">取消</el-button>
|
|
|
+ </footer>
|
|
|
+ </div>
|
|
|
+</template>
|
|
|
+
|
|
|
+<script>
|
|
|
+import editor from "@/components/editor";
|
|
|
+export default {
|
|
|
+ head() {
|
|
|
+ return {
|
|
|
+ script: []
|
|
|
+ };
|
|
|
+ },
|
|
|
+ components: {
|
|
|
+ editor
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ topicId: "", // 编辑
|
|
|
+ title: "",
|
|
|
+ subTitle: "",
|
|
|
+ content: "",
|
|
|
+ cover_url: "",
|
|
|
+ tags: [],
|
|
|
+ categoryId: "",
|
|
|
+ dialogVisible: false,
|
|
|
+ disabled: false,
|
|
|
+ categoryList: [
|
|
|
+ {
|
|
|
+ value: "default",
|
|
|
+ label: "推荐"
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ 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();
|
|
|
+ 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() {
|
|
|
+ const data = {
|
|
|
+ topicId: this.$route.params.id
|
|
|
+ };
|
|
|
+ this.$axios
|
|
|
+ .$post(`/api/community/topic/get_edit_topic`, data)
|
|
|
+ .then(res => {
|
|
|
+ console.log(res);
|
|
|
+ const topic = res.data;
|
|
|
+ if (topic) {
|
|
|
+ this.cover_url = topic.cover_url;
|
|
|
+ this.topicId = topic.id;
|
|
|
+ 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",
|
|
|
+ url: this.cover_url
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.goHome();
|
|
|
+ }
|
|
|
+ // TODO go details
|
|
|
+ });
|
|
|
+ },
|
|
|
+ publish() {
|
|
|
+ this.needVerify();
|
|
|
+ if (!this.content) {
|
|
|
+ this.$message.error("请输入文章正文");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.content.length > 100000) {
|
|
|
+ this.$message.error("文章正文不可超过10万字符,请删减");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.title) {
|
|
|
+ this.$message.error("请输入文章标题");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!this.categoryId) {
|
|
|
+ this.$message.error("请选择文章分类");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (this.tags.length > 5) {
|
|
|
+ this.$message.error("标签最多可填写5个标签,请删减");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ const data = {
|
|
|
+ title: this.title,
|
|
|
+ intro: this.subTitle,
|
|
|
+ body: this.content,
|
|
|
+ categoryId: this.categoryId,
|
|
|
+ label: this.tags && this.tags.length > 0 ? this.tags.join(",") : "",
|
|
|
+ cover_url: this.cover_url
|
|
|
+ };
|
|
|
+ if (this.topicId) {
|
|
|
+ data.topicId = this.topicId;
|
|
|
+ this.$axios
|
|
|
+ .$post(`/api/community/topic/update_topic`, data)
|
|
|
+ .then(res => {
|
|
|
+ console.log(res);
|
|
|
+ if (res.status === -99) {
|
|
|
+ this.goHome();
|
|
|
+ }
|
|
|
+ this.$message.success("编辑成功!");
|
|
|
+ // TODO go details
|
|
|
+ // window.location.href = `/p/${this.topicId}.html`;
|
|
|
+ });
|
|
|
+ } else {
|
|
|
+ this.$axios
|
|
|
+ .$post(`/api/community/topic/create_topic`, data)
|
|
|
+ .then(res => {
|
|
|
+ console.log(res);
|
|
|
+ if (!res.data) {
|
|
|
+ this.goHome();
|
|
|
+ }
|
|
|
+ this.$message.success("发布成功!");
|
|
|
+ // TODO go details
|
|
|
+ // window.location.href = `/p/${res.data.id}.html`;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ },
|
|
|
+ cancel() {
|
|
|
+ this.$router.back();
|
|
|
+ },
|
|
|
+ handleChange(val) {
|
|
|
+ this.content = val;
|
|
|
+ },
|
|
|
+ handleDeleteFile() {
|
|
|
+ this.cover_url = "";
|
|
|
+ },
|
|
|
+ handleFileChange(file) {
|
|
|
+ console.log(file);
|
|
|
+ if (file.size / 1024 > 500) {
|
|
|
+ this.$message.error("图片大小不得超过500k,请重新选择");
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ const formData = new FormData();
|
|
|
+ formData.append("target", '{ "type": 3 }');
|
|
|
+ formData.append("id", "WU_FILE_0");
|
|
|
+ formData.append("name", file.name);
|
|
|
+ formData.append("type", file.type);
|
|
|
+ formData.append("lastModifiedDate", file.lastModifiedDate);
|
|
|
+ formData.append("size", file.size);
|
|
|
+ formData.append("file", file);
|
|
|
+ this.$axios
|
|
|
+ .$post(`/file/proxyUpload`, formData, {
|
|
|
+ headers: { "Content-Type": "multipart/form-data" }
|
|
|
+ })
|
|
|
+ .then(res => {
|
|
|
+ this.cover_url = (res.data && res.data.url) || "";
|
|
|
+ this.fileList = [
|
|
|
+ {
|
|
|
+ name: "file.name",
|
|
|
+ url: this.cover_url
|
|
|
+ }
|
|
|
+ ];
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+</script>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+.editor {
|
|
|
+ position: relative;
|
|
|
+ padding: 20px;
|
|
|
+ width: 740px;
|
|
|
+ background: #fff;
|
|
|
+ .title,
|
|
|
+ .sub-title {
|
|
|
+ .el-input__inner {
|
|
|
+ padding: 0;
|
|
|
+ border: 0;
|
|
|
+ border-radius: 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ .title {
|
|
|
+ margin: 10px auto 20px;
|
|
|
+ font-size: 28px;
|
|
|
+ font-family: PingFangSC-Medium;
|
|
|
+ font-weight: 500;
|
|
|
+ color: rgba(29, 42, 58, 1);
|
|
|
+ line-height: 40px;
|
|
|
+ }
|
|
|
+ .sub-title {
|
|
|
+ margin-bottom: 28px;
|
|
|
+ min-height: 18px;
|
|
|
+ font-size: 14px;
|
|
|
+ font-family: PingFangSC-Regular;
|
|
|
+ font-weight: 400;
|
|
|
+ color: rgba(145, 154, 167, 1);
|
|
|
+ line-height: 18px;
|
|
|
+ border: 0;
|
|
|
+ .el-textarea__inner {
|
|
|
+ height: 18px;
|
|
|
+ line-height: 18px;
|
|
|
+ border: 0;
|
|
|
+ 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;
|
|
|
+ font-family: PingFangSC-Medium;
|
|
|
+ font-weight: 500;
|
|
|
+ color: rgba(25, 34, 46, 1);
|
|
|
+ line-height: 18px;
|
|
|
+ }
|
|
|
+ .ql-toolbar {
|
|
|
+ border-width: 1px 0 0 0 !important;
|
|
|
+ }
|
|
|
+ .quill-editor {
|
|
|
+ height: 450px;
|
|
|
+ border-left: 0 !important;
|
|
|
+ border-right: 0 !important;
|
|
|
+ font-size: 14px;
|
|
|
+ line-height: 25px;
|
|
|
+ }
|
|
|
+ .ql-snow.ql-toolbar::after {
|
|
|
+ display: inline-block;
|
|
|
+ }
|
|
|
+ .class {
|
|
|
+ width: 320px;
|
|
|
+ }
|
|
|
+ .tags {
|
|
|
+ width: 560px;
|
|
|
+ }
|
|
|
+ footer {
|
|
|
+ margin: 40px 0;
|
|
|
+ button {
|
|
|
+ width: 100px;
|
|
|
+ height: 40px;
|
|
|
+ border-radius: 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|