微信小程序使用editor富文本编辑器 以及回显 全屏弹窗的模式

这篇具有很好参考价值的文章主要介绍了微信小程序使用editor富文本编辑器 以及回显 全屏弹窗的模式。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

微信小程序使用editor富文本编辑器 以及回显 全屏弹窗的模式,微信小程序,小程序,前端,javascript,微信小程序

 

  <!--富文本接收的位置-->
  <view class="white-box">
    <view class="title">
      <view class="yellow-fence"></view>
      <view class="v1">教研记录</view>
    </view>
    <view class="add-btn" bindtap="addRecords">添加新的教研记录</view>
    <view wx:for="{{records}}" class="rich-text-box" wx:key="index">
      <!-- <mp-html content="{{item}}" selectable="true" show-img-menu="true" /> -->
      <rich-text nodes="{{item}}" data-index="{{index}}" bindtap="echoRecordsData"></rich-text>
    </view>
  </view>

  <view class="white-box">
    <view class="title">
      <view class="yellow-fence"></view>
      <view class="v1">研究成果</view>
    </view>
    <view class="add-btn" bindtap="addAchievement">添加研究成果说明</view>
    <view wx:for="{{achievement}}" class="rich-text-box" wx:key="index">
      <!-- <mp-html content="{{item}}" selectable="true" show-img-menu="true" /> -->
      <rich-text nodes="{{item}}" data-index="{{index}}" bindtap="echoAchievementData"></rich-text>
    </view>
  </view>

以上是富文本的值返回接收的地方 下面是富文本的html

  <!--富文本编辑器弹窗-->
  <view class="container" style="height:100vh;" wx:if="{{showEidter}}">
    <view class="save-box">
      <view class="v1" bindtap="cancelEidter">取消</view>
      <view class="v2" bindtap="saveEditer">确定</view>
    </view>
    <editor id="editor" class="ql-container" placeholder="{{placeholder}}" bindstatuschange="onStatusChange" bindready="onEditorReady" bindfocus="onFocus" bindinput="onBlur">
    </editor>
    <view class="toolbar" catchtouchend="format">
      <i class="iconfont icon-charutupian" catchtouchend="insertImage"></i>
      <i class="iconfont icon-format-header-2 {{formats.header === 2 ? 'ql-active' : ''}}" data-name="header" data-value="{{2}}"></i>
      <i class="iconfont icon-format-header-3 {{formats.header === 3 ? 'ql-active' : ''}}" data-name="header" data-value="{{3}}"></i>
      <i class="iconfont icon-zitijiacu {{formats.bold ? 'ql-active' : ''}}" data-name="bold"></i>
      <i class="iconfont icon-zitixieti {{formats.italic ? 'ql-active' : ''}}" data-name="italic"></i>
      <i class="iconfont icon-zitixiahuaxian {{formats.underline ? 'ql-active' : ''}}" data-name="underline"></i>
      <i class="iconfont icon--checklist" data-name="list" data-value="check"></i>
      <i class="iconfont icon-youxupailie {{formats.list === 'ordered' ? 'ql-active' : ''}}" data-name="list" data-value="ordered"></i>
      <i class="iconfont icon-wuxupailie {{formats.list === 'bullet' ? 'ql-active' : ''}}" data-name="list" data-value="bullet"></i>
    </view>
  </view>
Page({
  data: {
    /*富文本-start*/
    formats: {},
    readOnly: false,
    placeholder: '开始输入...',
    isClickImg: false,

    records: [], //教研记录列表    
    isRecordsEidt: false, //是否编辑的是教研记录
    recordsEidtIndex: null, //教研记录编辑的是哪一条

    achievement: [], //研究成果列表
    isAchievementEidt: false, //是否编辑的是研究成果
    achievementEidtIndex: null, //研究成果编辑的是哪一条

    showEidter: false,
    editData: '',
    /*富文本-end*/    
  },

  onLoad(options) {},

  /*富文本编辑器-start*/
  //编辑教研记录列表
  echoRecordsData(e) {
    const that = this
    let oidx = e.currentTarget.dataset.index
    this.setData({
      isRecordsEidt: true,
      showEidter: true,
      recordsEidtIndex: oidx,

      isAchievementEidt: false, //是否编辑的是研究成果
      achievementEidtIndex: null, //研究成果编辑的是哪一条
    })
    //console.log(that.data.records[oidx])
    // 修改时,反显数据
    this.createSelectorQuery().select("#editor")
      .context((res) => {
        res.context.setContents({
          html: that.data.records[oidx],
        });
      })
      .exec();
  },
  echoAchievementData(e) {
    const that = this
    let oidx = e.currentTarget.dataset.index
    this.setData({
      isAchievementEidt: true,
      showEidter: true,
      achievementEidtIndex: oidx,

      isRecordsEidt: false, //是否编辑的是教研记录
      recordsEidtIndex: null, //教研记录编辑的是哪一条
    })
    //console.log(that.data.records[oidx])
    // 修改时,反显数据
    this.createSelectorQuery().select("#editor")
      .context((res) => {
        res.context.setContents({
          html: that.data.achievement[oidx],
        });
      })
      .exec();
  },
  //重置
  cancelEidter() {
    this.setData({
      isRecordsEidt: false,
      showEidter: false,
      recordsEidtIndex: null,
      isAchievementEidt: false,
      achievementEidtIndex: null,
      editData: ''
    })
  },
  saveEditer() {
    //如果是教研记录新增
    let recordsEidtIndex = this.data.recordsEidtIndex
    let achievementEidtIndex = this.data.achievementEidtIndex
    if (this.data.isRecordsEidt) {
      let odata = this.data.records
      if (recordsEidtIndex || recordsEidtIndex === 0) {
        //编辑
        odata[recordsEidtIndex] = this.data.editData
      } else {
        //新增
        odata.push(this.data.editData)
      }
      this.setData({
        records: odata
      })
      //console.log(this.data.records)
      this.cancelEidter()
    } else if (this.data.isAchievementEidt || achievementEidtIndex === 0) {
      let odata = this.data.achievement
      if (achievementEidtIndex) {
        //编辑
        odata[achievementEidtIndex] = this.data.editData
      } else {
        //新增
        odata.push(this.data.editData)
      }
      this.setData({
        achievement: odata
      })
      //console.log(this.data.records)
      this.cancelEidter()
    }
  },

  addRecords() {
    this.setData({
      isRecordsEidt: true,
      showEidter: true
    })
  },
  addAchievement() {
    this.setData({
      isAchievementEidt: true,
      showEidter: true
    })
  },
  readOnlyChange() {
    this.setData({
      readOnly: !this.data.readOnly
    })
  },

  onEditorReady() {
    const that = this
    wx.createSelectorQuery().select('#editor').context(function (res) {
      //console.log(res)
      if (res.context) {
        that.editorCtx = res.context
      }
    }).exec()
  },
  format(e) {
    let {
      name,
      value
    } = e.target.dataset
    if (!name) return
    // console.log('format', name, value)
    this.editorCtx.format(name, value)
  },
  onStatusChange(e) {
    const formats = e.detail
    this.setData({
      formats
    })
  },
  insertDivider() {
    this.editorCtx.insertDivider({
      success: function () {
        console.log('insert divider success')
      }
    })
  },
  clear() {
    this.editorCtx.clear({
      success: function (res) {
        console.log("clear success")
      }
    })
  },
  removeFormat() {
    this.editorCtx.removeFormat()
  },
  insertDate() {
    const date = new Date()
    const formatDate = `${date.getFullYear()}/${date.getMonth() + 1}/${date.getDate()}`
    this.editorCtx.insertText({
      text: formatDate
    })
  },
  insertImage() {
    this.setData({
      isClickImg: true
    })
    const that = this
    wx.chooseImage({
      count: 1,
      success: function (res) {
        that.editorCtx.insertImage({
          src: res.tempFilePaths[0],
          data: {
            id: 'abcd',
            role: 'god'
          },
          width: '80%',
          success: function () {
            console.log('insert image success')
          }
        })
      }
    })
  },
  onFocus() {
    this.setData({
      isClickImg: false
    })
  },
  onBlur(e) {
    //console.log(this.data.isClickImg)
    //防止上传的图片直接失焦 保存内容的问题    
    if (!this.data.isClickImg) {
      //console.log(e.detail.html)
      this.setData({
        editData: e.detail.html
      })
    }
    //this.oneEditor.blur()
  },
  /*富文本编辑器-end*/
  
})
/*富文本编辑器-start*/
.container {
  position: fixed; 
  top: 0; 
  right: 0;
  bottom: 0;
  left: 0; 
  z-index: 999;  
  display: flex;
  flex-direction: column;
  background: #fff;
}
.ql-container {
  flex: 1;
  padding: 10px 10px 50px 10px;
  box-sizing: border-box;
  font-size: 16px;
  line-height: 1.5;
}

.ql-active {
  color: #22C704;
}

.iconfont {
  display: inline-block;
  width: 30px;
  height: 30px;
  cursor: pointer;
  font-size: 20px;
}

.toolbar {
  position: fixed;
  left: 0;
  right: 100%;
  bottom: 0;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 50px;  
  box-sizing: border-box;    
  background: #fff;
  border-top: 1rpx solid #f2f2f2;
}
.save-box{ margin: 10rpx 10rpx 0 0; display: flex; justify-content: flex-end;}
.save-box .v1,.save-box .v2{ font-size: 28rpx; width: 100rpx; height: 60rpx; text-align: center; line-height: 60rpx; border-radius: 12rpx;}
.save-box .v1{ margin-right: 10rpx; background: #ddd; color: #fff;}
.save-box .v2{ background: #ffb81c; color: #fff;}
.rich-text-box{ margin-bottom: 20rpx;}
/*富文本编辑器-end*/

记录一下使用方法 也可以参考一下怎么使用文章来源地址https://www.toymoban.com/news/detail-650150.html

到了这里,关于微信小程序使用editor富文本编辑器 以及回显 全屏弹窗的模式的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 小程序Editor富文本编辑器-封装使用用法

    本文章主要讲述editor中小程序的图片上传和pc端数据不同步的问题,建议多看下代码 完整代码在最下面 1、创建个用于组件封装的editor文件夹,存放三个文件  2、editor.vue文件是主要封装代码 3、editor-icon.css文件样式 5、如果上传图片失败或者是图片裂开,和pc端数据不同步的话

    2024年02月11日
    浏览(30)
  • 富文本编辑器 ck-editor5 的使用

    最近在项目中需要用到富文本编辑器,据说ck-editor5很不错,于是就使用它了,不过在期间也遇到了很多问题,这里记录下。 一、引入ck-editor5 文档地址:Predefined builds - CKEditor 5 Documentation 这里有个坑,我最初是根据文档执行下面的npm命令下载的,最后捣腾了半天发现里面功能

    2024年01月20日
    浏览(32)
  • vue-quill-editor富文本编辑器使用步骤

    首先放上效果图 目录 1.安装 2.引入到项目中 3.在页面上写组件 4.配置option 5.给工具栏鼠标悬停加上中文释义 6.上传图片到七牛云 7.自定义控制图片大小 1.安装 2.引入到项目中         有两种挂载方式: 全局挂载 和 在组件中挂载,根据自己的项目需求选择,一般用到富文

    2024年02月06日
    浏览(36)
  • 富文本编辑器 VUE-QUILL-EDITOR 使用教程

    1、NPM 导入 VUE-QUILL-EDITOR 2、引入 VUE-QUILL-EDITOR 在全局中引入 在指定的 vue 文件中引入 3、在 VUE 中使用 到这里一个默认的富文本编辑器已经导入使用了,如下图所视! 一般的,我们在使用的时候并不需要这么多功能,可以适当的对编辑器配置项进行配置。 可以根据自己的实际

    2024年02月09日
    浏览(52)
  • vue使用富文本编辑器vue-quill-editor

    问题描述: 我们在开发过程中经常会遇到使用富文本编辑器进行操作,当前插件市场上关于富文本的编辑器挺多的,我们就不一一个介绍了,现在我们主要讲解一些vue-quill-editor富文本编辑器的使用操作和注意事项。 效果图 具体操作使用 1. 安装 2. 引入到项目中 有两种挂载方

    2024年02月02日
    浏览(34)
  • 富文本编辑器 VUE-QUILL-EDITOR 使用教程 (最全)

    VUE-QUILL-EDITOR 基于 QUILL、适用于 VUE 的富文本编辑器,支持服务端渲染和单页应用,非常高效简洁。 在全局中引入 在指定的 vue 文件中引入 到这里一个默认的富文本编辑器已经导入使用了,如下图所视! 一般的,我们在使用的时候并不需要这么多功能,可以适当的对编辑器配

    2024年02月04日
    浏览(37)
  • element ui富文本编辑器的使用(quill-editor)

    可以拖拽图片大小及其位置 为了便于大家直接使用,直接把script以及css放在一个页面里,之际copy就可以使用 注意: 1、我是在elementUi使用的,上传图片以及页面的访问需要有登录权限,所以我的上传图片视频的组件里有:headers=“headers”,携带登录权限 2、需要更改自己的上

    2024年02月03日
    浏览(34)
  • 简版的富文本编辑器、VUE+ElementUI 富文本编辑器 element ui富文本编辑器的使用(quill-editor) 不好用你来打我!全网醉简单!要复杂的别来!

    实现效果   1.安装插件 npm install vue-quill-editor --save 2.安装成功后在package.json中查看 3.在main.js中全局引入插件 4.页面实现 感谢老哥: ElementUI生成富文本编辑器 https://blog.csdn.net/keplerm/article/details/123379511?spm=1001.2101.3001.6650.9utm_medium=distribute.pc_relevant.none-task-blog-2%7Edefault%7EBlogCom

    2024年02月16日
    浏览(53)
  • Eclipse - Text Editors (文本编辑器)

    Window - Preferences - General - Editors - Text Editors Displayed tab witdth: 4 勾选 Insert spaces for tabs 勾选 Show line number [1] Yongqiang Cheng, https://yongqiang.blog.csdn.net/

    2024年02月21日
    浏览(35)
  • Vue +vue-quill-editor+ Element UI使用富文本编辑器,上传图片,上传视频

    如果你们有问题,可以发评论提问,我看见一定回复!!!!! 一、基本使用 1、下载vue-quill-editor组件 2、引入· 富文本组件 方式一:全局引入 (在 main.js 文件中) 方式二:按需引入 (在 单个组件 中引用) 3、工具栏相关配置 4、设置工具栏中文提示 5、修改vue-quill-editor字体

    2024年02月08日
    浏览(41)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包