公告项目2020/10/13

本文详述了在前端实现富文本编辑器中集成图片上传功能的过程,包括tinymce的配置和使用,以及遇到的重置表单避免校验问题。同时,文章提出了表格单元格内容超出隐藏导致布局错乱的待解决技术问题。

重点难点:

在这里插入图片描述

  1. 上传附件:在发布公告的时候需要上传附件:思路是将文件上传到一个新的接口中,得到返回的路径以及id,将id在发布公告的时候传给后台(此处后台会根据id进行关联,在查看这一条公告的时候通过这条公告的id重新请求这条公告的详情,在详情中会返回刚刚上传的附件)。(后台设计的这种模式并不是很好)

在这里插入图片描述

  1. 富文本框的编辑: 经历千难万险终于实现了富文本框的图片上传功能,下边附上代码,我是将富文本框抽离成了一个组件,在要使用的页面引入,其中就是配置比较麻烦 ,官网的介绍代码比较不全,引入的方法有些模糊,思路就是先注册tinymce然后通过自己的key来引入这tinymce,再配置自己想要的功能,最快的方法就是先实现一个完整的功能再去添加一些无关紧要的功能(即:先使用复杂的功能),比如我先实现了图片上传功能,再去添加文字格式化、对齐等等。
<template>
  <editor
    apiKey="自己官网注册tinymce的key值"
    initialValue="<p></p>"
     placeholder="在此输入内容"
    :init="inits"
    v-model="tinyContent"
    ref="fileObj"
  >
  </editor>
</template>
<script>
import Editor from '@tinymce/tinymce-vue'

export default {
  name: 'app',
  components: {
    editor: Editor
  },
  data() {
    return {
      tinyContent: '',
      inits: Object.freeze({
        height: 450,
        language: 'zh_CN',
        selector: 'textarea#local-upload',
        plugins: 'image code link',
        toolbar: 'undo redo | code|undo redo | bold italic underline strikethrough | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent |  numlist bullist checklist | forecolor backcolor casechange formatpainter removeformat | rotateleft rotateright | flipv fliph | editimage imageoptions| link image ',
        image_title: true,
        toolbar_mode: 'sliding',
        file_picker_types: 'image',
        file_picker_callback: (cb, value, meta) => {
          let _this = this
          var input = document.createElement('input')
          input.setAttribute('type', 'file')
          input.setAttribute('accept', 'image/*')

          input.onchange = function () {
            var file = this.files[0]
            var formData = new FormData()
            formData.append("file", file)
            let params = {
              type: 2
            }
            _this.$api.announce
              .upload(formData, params)
              .then((res) => {
                console.log(res)
                if (res) {
                  cb(res.fileAddress, { title: file.name })
                  success(res.fileAddress)
                }
              })
              .catch((err) => {
                _this.$message.error(err.$message)
              })
          }

          input.click()
        },
        content_style: 'body { font-family:Helvetica,Arial,sans-serif; font-size:14px }'
      })
    }
  },
  methods: {
  }
}
</script>

在引入的页面

 <TinymceEditor ref="tiny" />
 import TinymceEditor from './tinymce-editor'
  1. css:overflow:auto
  2. 发布新公告提交之后表单要重新置空这个发布公告页面,此时如果贸然的用 this.form = {} 那么会触发表单的校验,再次进入你的页面你的页面就会飘红如下图所示,所以最简单的方法就是重置表单(重置表单可以移除校验,此时就不会触发校验)。
    在这里插入图片描述
  // 取消
    resetForm(formName) {
      this.$refs[formName].resetFields()
      this.$emit('close')
    },

待解决问题:
table中某一个cell文字超长我想用超过的部分…隐藏,会导致table的布局错乱。如果所示
在这里插入图片描述

css样式也没什么问题

.border /deep/ .el-table {
  .el-table__body-wrapper {
    .cell {
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
      color: #666666;
      line-height: 1;
    }
  }
}


7.关于正则也使不熟练
例如 文本框 只能输入文字

 <el-input
          type="textarea"
          v-model="form.summary"
          maxlength="300"
          :rows="4"
          placeholder="只能输入文字内容 字数不超过300"
          onkeyup="value=value.replace(/[^\u4E00-\u9FA5]/g,'')"
        >
          ></el-input
        >
<template> <div> <div style="margin: 20px 0"> <el-button @click="showWin = !showWin" size="mini" type="primary" plain> {{ showWin ? '关闭' : '打开' }}会话列表 </el-button> <el-button @click="showRightBox = !showRightBox" size="mini" type="danger" plain> {{ showRightBox ? '关闭' : '打开' }}右侧组件 </el-button> <el-button @click="Rightopen = !Rightopen" size="mini" type="success" plain> 切换:{{ Rightopen ? '公告通知' : '快速回复' }}-组件 </el-button> </div> <JwChat-index ref="jwChat" v-model="inputMsg" :taleList="taleList" :scrollType="scrollType" :toolConfig="tool" :placeholder="placeholder" :config="config" :winBarConfig="winBarConfig" :showRightBox="showRightBox" @enter="bindEnter" @clickTalk="talkEvent" > <JwChat-talk v-if="Rightopen" class="rightSlot" :Talelist="talk" :config="quickConfig" @event="bindTalk" /> <JwChat-rightbox v-else class="rightSlot" :config="rightConfig" @click="rightClick" /> <template slot="tools"> <div style="width: 20rem; text-align: right" @click="toolEvent(12)"> <JwChat-icon type="icon-lishi" title="自定义" /> </div> </template> </JwChat-index> </div> </template> <script> export default { data() { return { scrollType: 'scroll', // scroll noroll 俩种类型 scroll (滚动到最新消息) noroll (停留当期位置) placeholder: '', inputMsg: '', taleList: [], tool: { callback: this.toolEvent, }, //当前聊天窗口 config: { img: '../image/cover.png', name: 'JwChat', dept: '最简单、最便捷11111', callback: this.bindCover, historyConfig: { show: true, tip: '加载更多提示框,可以直接使用组件的1234', callback: this.bindLoadHistory, }, //快捷回复 quickList: [ { text: '这里是jwchat,您想了解什么问题。', id: 3 }, { text: 'jwchat是最好的聊天组件', id: 4 }, { text: '谁将烟焚散,散了纵横的牵绊;听弦断,断那三千痴缠。', id: 5 }, { text: '长夏逝去。山野间的初秋悄然涉足。', id: 6 }, { text: '江南风骨,天水成碧,天教心愿与身违。', id: 7 }, { text: '总在不经意的年生。回首彼岸。纵然发现光景绵长。', id: 8 }, { text: '外面的烟花奋力的燃着,屋里的人激情的说着情话', id: 10 }, { text: '假如你是云,我就是雨,一生相伴,风风雨雨;', id: 11 }, { text: '即使泪水在眼中打转,我依旧可以笑的很美,这是你学不来的坚强。', id: 12, }, { text: ' 因为不知来生来世会不会遇到你,所以今生今世我会加倍爱你。', id: 13, }, ], maxlength: 30, }, //公告信息栏 rightConfig: { listTip: '人员列表-在线', notice: '【公告】这是一款高度自由的聊天组件,基于AVueVue、Element-ui开发。点个赞再走吧 ', filterTip: '好友过滤', list: [ { name: 'JwChat1', img: '../image/cover.png', id: 1, }, { id: 2, name: 'JwChat', img: 'image/three.jpeg', }, { id: 3, name: 'JwChat', img: 'image/three.jpeg', }, { id: 4, name: '留恋人间不羡仙', img: 'image/one.jpeg', }, { name: '只盼流星不盼雨', img: 'image/two.jpeg', }, ], }, //快捷回复 talk: ['快捷回复1', '快捷回复2', '快捷回复3', '快捷回复4', '快捷回复5', '快捷回复6'], quickConfig: { nav: ['快捷回复', '超级回复'], showAdd: true, maxlength: 200, showHeader: true, showDeleteBtn: true, }, //右侧快捷栏开关 showRightBox: false, showWin: false, //左侧快捷栏 winBarConfig: { active: 'win00', width: '180px', listHeight: '60px', list: [ { id: 'win00', img: '../image/two.jpeg', name: 'JwChat', dept: '最简单、最便捷', readNum: 1, }, { id: 'win01', img: '@/assets/wx/cover.png', name: '阳光明媚爱万物', dept: '沙拉黑油', readNum: 12, }, { id: 'win02', img: 'image/two.jpeg', name: '只盼流星不盼雨', dept: '最后说的话', readNum: 12, }, { id: 'win03', img: 'image/one.jpeg', name: '留恋人间不羡仙', dept: '这里可以放万物', readNum: 0, }, { id: 'win04', img: 'image/three.jpeg', name: '阳光明媚爱万物', dept: '官方客服', }, { id: 'win05', img: 'image/three.jpeg', name: '测试', dept: '官方客服', }, ], callback: this.bindWinBar, }, } }, methods: { /** * @description: 点击加载更多的回调函数 * @param {*} * @return {*} */ async bindLoadHistory() { const history = new Array(3).fill().map((i, j) => { return { date: '2020/05/20 23:19:07', text: { text: j + new Date() }, mine: false, name: 'JwChat', img: 'image/three.jpeg', } }) let list = history.concat(this.taleList) this.taleList = list console.log('加载历史', list, history) // 加载完成后通知组件关闭加载动画 this.config.historyConfig.tip = '加载完成' this.$nextTick(() => { this.$refs.jwChat.finishPullDown() }) }, bindEnter(e) { console.log(e) const msg = this.inputMsg if (!msg) return const msgObj = { date: '2020/05/20 23:19:07', text: { text: msg }, mine: true, name: 'JwChat', img: '../image/three.jpeg', } this.list.push(msgObj) }, toolEvent(type, obj) { console.log('tools', type, obj) }, talkEvent(play) { console.log(play) }, rightClick(type) { console.log('rigth', type) }, bindTalk(play) { console.log('talk', play) const { key, value } = play if (key === 'navIndex') this.talk = [1, 1, 1, 1, 1, 1, 1, 1].reduce((p) => { p.push('随机修改颜色 #' + Math.random().toString(16).substr(-6)) return p }, []) if (key === 'select') { this.inputMsg = value this.bindEnter() } if (key === 'delIndex') { this.talk.splice(value, 1) } }, }, mounted() { const img = 'https://www.baidu.com/img/flexible/logo/pc/result.png' const list = [ { date: '2020/04/25 21:19:07', text: { text: '起床不' }, mine: false, name: '留恋人间不羡仙', img: '../image/one.jpeg', }, { date: '2020/04/25 21:19:07', text: { text: "<audio data-src='https://www.w3school.com.cn/i/horse.mp3'/>" }, mine: false, name: '只盼流星不盼雨', img: '../image/two.jpeg', }, { date: '2020/04/25 21:19:07', text: { text: "<img data-src='" + img + "'/>" }, mine: false, name: '只盼流星不盼雨', img: '../image/two.jpeg', }, { date: '2020/04/25 21:19:07', text: { text: "<img data-src='../image/three.jpeg'/>" }, mine: false, name: '只盼流星不盼雨', img: '../image/two.jpeg', }, { date: '2020/04/16 21:19:07', text: { text: "<video data-src='https://www.w3school.com.cn/i/movie.mp4' controls='controls' />" }, mine: false, name: 'JwChat', img: '../image/three.jpeg', }, { date: '2021/03/02 13:14:21', mine: false, name: '留恋人间不羡仙', img: '../image/one.jpeg', text: { system: { title: '在接入人工前,智能助手将为您首次应答。', subtitle: '猜您想问:', content: [ { id: `system1`, text: '组件如何使用', }, { id: `system2`, text: '组件参数在哪里查看', }, { id: 'system', text: '我可不可把组件用在商业', }, ], }, }, }, { date: '2020/04/25 21:19:07', text: { text: "<i class='el-icon-document-checked' style='font-size:2rem;'/>", subLink: { text: 'a.txt', prop: { underline: false, }, }, }, mine: false, name: '留恋人间不羡仙', img: '../image/one.jpeg', }, ] this.taleList = list }, } </script> 修改以上代码,思路如下 1.添加import { listMessage, addMessage } from '@/api/mod/nkimxx' 可以通过listMessage获取fromId为消息发送ID,toId为消息接送ID,sendTime为消息发送时间,content为消息内容 addMessage 为消息发送代码 2.然后添加import { getUserProfile, listUser } from '@/api/system/user' listUser 获取用户信息 通过userID=fromId、userID=toId,提取用户的头像avatar=以上代码的img,用户姓名nickName=以上代码的name,部门dept.deptName=以上代码的dept getUserProfile,可以获取当前登录用户信息
最新发布
08-30
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值