添加文章内容为空修复

master
yujialong 3 years ago
parent ae68f80069
commit f825231fc0
  1. 1052
      package-lock.json
  2. 6
      package.json
  3. 8
      src/apis/request.js
  4. 244
      src/components/quill/index.vue
  5. 9
      src/components/quill/options.js
  6. 4
      src/views/home/Homemange.vue
  7. 15
      src/views/title/Addtitle.vue

1052
package-lock.json generated

File diff suppressed because it is too large Load Diff

@ -16,7 +16,9 @@
"lib-flexible": "^0.3.2", "lib-flexible": "^0.3.2",
"moment": "^2.27.0", "moment": "^2.27.0",
"normalize.css": "^8.0.1", "normalize.css": "^8.0.1",
"quill": "^1.3.7",
"sortable.js": "^0.3.0", "sortable.js": "^0.3.0",
"style-loader": "^3.3.1",
"vue": "^2.6.11", "vue": "^2.6.11",
"vue-quill-editor": "^3.0.6", "vue-quill-editor": "^3.0.6",
"vue-router": "^3.2.0", "vue-router": "^3.2.0",
@ -36,10 +38,10 @@
"eslint-plugin-vue": "^6.2.2", "eslint-plugin-vue": "^6.2.2",
"less": "^3.0.4", "less": "^3.0.4",
"less-loader": "^5.0.0", "less-loader": "^5.0.0",
"node-sass": "^6.0.1", "node-sass": "^4.12.0",
"postcss-loader": "^4.0.4", "postcss-loader": "^4.0.4",
"postcss-px2rem": "^0.3.0", "postcss-px2rem": "^0.3.0",
"sass-loader": "^12.3.0", "sass-loader": "^7.3.1",
"vue-template-compiler": "^2.6.11" "vue-template-compiler": "^2.6.11"
} }
} }

@ -18,6 +18,14 @@ axios.interceptors.request.use((req)=>{
} }
return req; return req;
}); });
// 图片上传
export function joggleFn(file){
return axios.post(joggle, file, {
headers: { "Content-Type": "multipart/form-data" }
}).then(res => {
return res.data.data
})
}
//获取栏目信息,未被删除的 //获取栏目信息,未被删除的
export function allColumn(){ export function allColumn(){
return axios.get('/column/column' return axios.get('/column/column'

@ -0,0 +1,244 @@
<template>
<div class="quill" ref="quill" :class="classes">
<div ref="editor" :style="styles" v-loading="loading"></div>
</div>
</template>
<script>
import Quill from "quill";
import "quill/dist/quill.core.css";
import "quill/dist/quill.snow.css";
import "quill/dist/quill.bubble.css";
import toolbarOptions from "./options";
import { joggleFn } from "@/apis/request.js";
export default {
name: "quill",
props: {
value: {
type: String,
default: ""
},
readonly: {
type: Boolean,
default: false
},
toTop: {
type: Boolean,
default: true
},
border: {
type: Boolean,
default: false
},
height: {
type: Number
},
minHeight: {
type: Number
},
/*
* 原本的readOnly失效,对比其他项目发现是quill版本不同导致
* 使用props传入elseRead = 'true'手动隐藏工具栏
*/
elseRead: {
type: String, default: "false"
}
},
data() {
return {
headers: {
token: sessionStorage.getItem('token')
},
Quill: null,
currentValue: "",
options: {
theme: "snow",
bounds: document.body,
debug: "warn",
modules: {
toolbar: {
container: toolbarOptions,
handlers: {
"image": function(value) {
if (value) {
// iview
document.querySelector(".editorUpload").click();
} else {
this.Quill.format("image", false);
}
}
}
}
},
placeholder: "",
readOnly: this.readonly
},
loading: false
};
},
computed: {
classes() {
return [
{
"quill-no-border": !this.border
}
];
},
styles() {
let style = {};
if (this.minHeight) {
style.minHeight = `${this.minHeight}px`;
}
if (this.height) {
style.height = `${this.height}px`;
}
return style;
}
},
watch: {
value: {
handler(val) {
if (val !== this.currentValue) {
this.currentValue = val;
if (this.Quill) {
this.Quill.pasteHTML(this.value);
}
}
},
immediate: true
}
},
created() {
},
mounted() {
this.init();
//
if (this.elseRead === "true") {
let children = this.$refs.quill.children[0].style;
children.padding = "0";
children.overflow = "hidden";
children.height = "0";
children.borderTop = "0";
}
},
beforeDestroy() {
//
this.Quill = null;
},
methods: {
init () {
const editor = this.$refs.editor;
//
this.Quill = new Quill(editor, this.options);
const ins = this.Quill
//
ins.pasteHTML(this.currentValue);
if(this.toTop){
this.$nextTick(() => {
window.scrollTo(0,0)
})
}
//
ins.on('text-change', () => {
const html = this.$refs.editor.children[0].innerHTML;
const text = ins.getText();
const quill = this.Quill;
//
this.currentValue = html;
// v-model
this.$emit('input', html);
//
this.$emit('on-change', { html, text, quill });
});
// quill
ins.on('text-change', (delta, oldDelta, source) => {
this.$emit('on-text-change', delta, oldDelta, source);
});
ins.on('selection-change', (range, oldRange, source) => {
this.$emit('on-selection-change', range, oldRange, source);
});
ins.on('editor-change', (eventName, ...args) => {
this.$emit('on-editor-change', eventName, ...args);
});
//
ins.root.addEventListener('paste', evt => {
if (evt.clipboardData && evt.clipboardData.files && evt.clipboardData.files.length) {
evt.preventDefault();
//
[].forEach.call(evt.clipboardData.files, file => {
if (!file.type.match(/^image\/(gif|jpe?g|a?png|bmp)/i)) {
return
}
const param = new FormData()
param.append('file', file)
// base64
joggleFn(param, {
headers: { "Content-Type": "multipart/form-data" }
}).then(res => {
var range = ins.getSelection()
if (range) {
//
ins.insertEmbed(range.index, 'image', res.fileUrl)
//
ins.setSelection(range.index + 1)
}
}).catch(res => {
console.log(res)
})
});
}
}, false)
},
beforeUpload() {
this.loading = true;
},
editorUploadSuccess(res) {
//
let quill = this.Quill;
//
if (res.data.filesResult.fileUrl) {
//
let length = quill.getSelection().index;
// res
quill.insertEmbed(length, "image", res.data.filesResult.fileUrl);
//
quill.setSelection(length + 1);
} else {
this.$message.error("图片插入失败");
}
this.loading = false;
}
}
};
</script>
<style lang="less">
.quill-no-border {
.ql-toolbar.ql-snow {
border: none;
border-bottom: 1px solid #e8eaec;
}
.ql-container.ql-snow {
border: none;
}
}
.else {
.ql-toolbar.ql-snow {
height: 0;
overflow: hidden;
padding: 0;
border-top: 0;
}
}
/deep/.ql-snow {
position: relative;
.ql-tooltip {
position: absolute !important;
top: 10px !important;
left: 10px !important;
transform: translateY(10px);
}
}
</style>

@ -0,0 +1,9 @@
export default [
["bold", "italic", "underline", "strike"],
["blockquote", "code-block"],
[{ "header": 1 }, { "header": 2 }],
[{ "list": "ordered" }, { "list": "bullet" }],
[{ "script": "sub" }, { "script": "super" }],
[{ "indent": "-1" }, { "indent": "+1" }],
["clean"],
];

@ -66,9 +66,7 @@
<!-- 轮播图文字部分 --> <!-- 轮播图文字部分 -->
<div class="right"> <div class="right">
<h3>{{ homeFormfirst.tableData.title }}</h3> <h3>{{ homeFormfirst.tableData.title }}</h3>
<p class="description"> <div class="description" v-html="homeFormfirst.tableData.description"></div>
{{ homeFormfirst.tableData.description }}
</p>
</div> </div>
<div class="back" v-show="a" @click="changecarousel()"> <div class="back" v-show="a" @click="changecarousel()">
<p>点击我更改视频图片文字描述</p> <p>点击我更改视频图片文字描述</p>

@ -35,11 +35,7 @@
<el-input v-model="photoForm.description" autocomplete="off"></el-input> <el-input v-model="photoForm.description" autocomplete="off"></el-input>
</el-form-item> </el-form-item>
<el-form-item label="文章内容" :label-width="formLabelWidth" prop="textContent"> <el-form-item label="文章内容" :label-width="formLabelWidth" prop="textContent">
<quill-editor <quill :border="true" v-model="photoForm.textContent" :height="300" />
ref="text"
v-model="photoForm.textContent"
class="myQuillEditor"
:options="editorOption"/>
</el-form-item> </el-form-item>
<div class="footer"> <div class="footer">
@ -90,7 +86,7 @@
</el-upload> </el-upload>
</el-form-item> </el-form-item>
<el-form-item label="文章内容" :label-width="formLabelWidth" prop="textContent"> <el-form-item label="文章内容" :label-width="formLabelWidth" prop="textContent">
<quill-editor ref="text" v-model="videoForm.textContent" class="myQuillEditor" :options="editorOption"/> <quill :border="true" v-model="videoForm.textContent" :height="300" />
</el-form-item> </el-form-item>
<div class="footer"> <div class="footer">
<el-button type="primary" @click="videoAdd('videoForm')">确认</el-button> <el-button type="primary" @click="videoAdd('videoForm')">确认</el-button>
@ -157,8 +153,7 @@
</div> </div>
</template> </template>
<script> <script>
// import { editArticle } from "@/apis/request.js"; import quill from "@/components/quill";
import { quillEditor } from "vue-quill-editor";
import { allColumn } from "@/apis/request.js"; import { allColumn } from "@/apis/request.js";
import moment from "moment"; import moment from "moment";
import { getColumnarticle } from "@/apis/request.js"; import { getColumnarticle } from "@/apis/request.js";
@ -167,7 +162,7 @@ import { getColumnallarticle } from "@/apis/request.js";
import { joggle } from "@/apis/request.js"; import { joggle } from "@/apis/request.js";
export default { export default {
components: { components: {
quillEditor, quill,
}, },
data() { data() {
return { return {
@ -449,7 +444,7 @@ export default {
return false; return false;
}, },
photoAdd(formName) { photoAdd(formName) {
let a=localStorage.getItem('columnid') let a = localStorage.getItem('columnid')
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
if (valid) { if (valid) {
var form = { ...this.photoForm }; var form = { ...this.photoForm };

Loading…
Cancel
Save