| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- const util = require('../../../../util/util.js')
- const compareVersion = util.compareVersion
- Page({
- onShareAppMessage() {
- return {
- title: 'editor',
- path: 'page/component/pages/editor/editor'
- }
- },
- data: {
- formats: {},
- bottom: 0,
- readOnly: false,
- placeholder: '开始输入...',
- },
- readOnlyChange() {
- this.setData({
- readOnly: !this.data.readOnly
- })
- },
- onLoad() {
- this.canUse = true
- wx.loadFontFace({
- family: 'Pacifico',
- source: 'url("https://sungd.github.io/Pacifico.ttf")',
- success: console.log
- })
- const {SDKVersion} = wx.getSystemInfoSync()
- if (compareVersion(SDKVersion, '2.7.0') >= 0) {
- //
- } else {
- this.canUse = false
- // 如果希望用户在最新版本的客户端上体验您的小程序,可以这样子提示
- wx.showModal({
- title: '提示',
- content: '当前微信版本过低,无法使用该功能,请升级到最新微信版本后重试。'
- })
- }
- },
- onEditorReady() {
- const that = this
- wx.createSelectorQuery().select('#editor').context(function (res) {
- that.editorCtx = res.context
- }).exec()
- },
- undo() {
- this.editorCtx.undo()
- },
- redo() {
- this.editorCtx.redo()
- },
- format(e) {
- if (!this.canUse) return
- const {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() {
- console.log('insert divider success')
- }
- })
- },
- clear() {
- this.editorCtx.clear({
- success() {
- 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() {
- const that = this
- wx.chooseImage({
- count: 1,
- success() {
- that.editorCtx.insertImage({
- src: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1543767268337&di=5a3bbfaeb30149b2afd33a3c7aaa4ead&imgtype=0&src=http%3A%2F%2Fimg02.tooopen.com%2Fimages%2F20151031%2Ftooopen_sy_147004931368.jpg',
- data: {
- id: 'abcd',
- role: 'god'
- },
- success() {
- console.log('insert image success')
- }
- })
- }
- })
- }
- })
|