|
-
-
- <template>
- <div class="home-container">
-
- <div class="top-container">
- <TopMenu :buttonList="buttonList"/>
- </div>
-
- <el-form ref="form" :model="form" label-width="80px" size="small">
- <el-form-item label="文章标题:">
- <el-input v-model="form.articleTitle" ></el-input>
- </el-form-item>
- <el-form-item label="文章类型:">
- <el-select v-model="form.articleType" placeholder="请选择文章类型">
- <el-option :label="item.label" :value="item.label" v-for="(item, index) in articleTypes" :key="index"/>
- </el-select>
- </el-form-item>
- <el-form-item label="分享标题:">
- <el-input v-model="form.shareTitle"></el-input>
- </el-form-item>
- <el-form-item label="分享简介:">
- <el-input v-model="form.shareAbout"></el-input>
- </el-form-item>
- <el-form-item label="分享图片:">
- <el-button v-show="fileList.length > 0" disabled type="warning">请删除图片后再上传</el-button>
- <el-upload
- class="upload-img"
- action="https://jsonplaceholder.typicode.com/posts/"
- :on-preview="onPreview"
- :on-remove="onRemove"
- :on-progress="onProgress"
- :before-remove="beforeRemove"
- :before-upload="beforeUpload"
- :on-error="onError"
- :on-success="onSuccess"
- :on-change="onUploadChange"
- :auto-upload="false"
- :limit="1"
- list-type="picture"
- :file-list="fileList">
- <el-button size="small" type="primary" v-show="fileList.length <= 0">点击上传</el-button>
- <div slot="tip" class="el-upload__tip">
- <p>最多上传一张,尺寸750X300</p>
- </div>
- </el-upload>
- </el-form-item>
-
-
-
- <el-form-item label="文章内容:">
-
- {{form.articleContent}}
- <div style="border: 1px solid #ccc;">
- <Toolbar
- style="border-bottom: 1px solid #ccc"
- :editor="editor"
- :defaultConfig="toolbarConfig"
- :mode="mode"
- />
- <Editor
- style="height: 350px; overflow-y: hidden;"
- v-model="form.articleContent"
- :defaultConfig="editorConfig"
- :mode="mode"
- @onCreated="onCreated"
- @onChange="onChange"
- @onDestroyed="onDestroyed"
- @onMaxLength="onMaxLength"
- @onFocus="onFocus"
- @onBlur="onBlur"
- @customPaste="customPaste"
- />
- </div>
- </el-form-item>
-
-
- <el-form-item class="footer-btn">
- <el-button type="primary" @click="onSave">保存</el-button>
- <el-button>取消</el-button>
- </el-form-item>
- </el-form>
- </div>
- </template>
-
- <script>
- import TopMenu from "@/components/TopMenu/index";
- import { Editor, Toolbar } from '@wangeditor/editor-for-vue';
-
- export default {
- name: 'wechat-fans',
- components: { TopMenu, Editor, Toolbar },
- data(){
- return {
- buttonList: [],
-
- form: {
- articleTitle: '',
- articleType: '普通文章',
- shareTitle: '',
- shareAbout: '',
- shareImage: '',
- articleContent: '',
-
- },
-
- articleTypes: [
- { label: '普通文章', value: '普通文章' },
- { label: '特别文章', value: '特别文章' },
- { label: '其它文章', value: '其它文章' },
- ],
-
- fileList: [],
- editor: null,
- toolbarConfig: { },
- mode: 'default',
-
- editorConfig: {
- MENU_CONF: {
- uploadImage: {
- server: '',
-
- }
- }
- }
-
- }
- },
- mounted() {},
- created() {
- this.clearFiles();
- console.log("本地的上传图片列表", this.fileList);
- },
- beforeDestroy() {
- const editor = this.editor
- if (editor == null) return
- editor.destroy()
- },
- methods: {
- onCreated(editor) {
- this.editor = Object.seal(editor)
- },
- onChange(editor) { console.log('onChange', editor.children) },
- onDestroyed(editor) { console.log('onDestroyed', editor) },
- onMaxLength(editor) { console.log('onMaxLength', editor) },
- onFocus(editor) { console.log('onFocus', editor) },
- onBlur(editor) { console.log('onBlur', editor) },
- customPaste(editor, event, callback) {
- console.log('ClipboardEvent 粘贴事件对象', event)
-
-
-
-
-
- editor.insertText('')
-
-
- event.preventDefault()
- callback(false)
-
-
-
- },
-
- clearFiles() {},
-
- onRemove() {
- this.fileList = []
- },
-
- onPreview(file) {
- console.log("点击了上传图片", file);
- },
-
- beforeRemove(file) {
- return this.$confirm(`确定删除 ${ file.name }?`);
- },
-
- beforeUpload(file) {
- console.log("上传图片前::", file);
- },
-
- onError(err) {
- return this.$confirm(`上传失败,请联系管理人`);
- },
-
- onSuccess(file) {
- console.log("上传成功", file);
- },
-
- onProgress(fileList) {
- console.log("fileList", fileList);
- },
-
- onUploadChange(file) {
- console.log('传文件发生变化时', file);
- if(this.fileList.length > 0) {
- this.fileList.length = 0
- } else {
- this.fileList.push(file);
- }
- },
-
- onSave() {
- console.log("保存的内容::", this.form);
- }
- }
- }
- </script>
-
- <style src="@wangeditor/editor/dist/css/style.css"></style>
- <style scoped lang="scss">
- .home-container {
- position: relative;
- height: 600px;
- overflow-y: scroll;
- overflow-x: hidden;
- padding: 0 20px;
- p {
- padding: 5px;
- }
- }
- .upload-img {
- width: 400px;
- .el-button {
- margin-left: 0;
- }
- }
- </style>
|