From 7bec00ff6ae838fd572337798efe5ba51ca4c667 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Wed, 27 Oct 2021 16:51:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20editor=20=E8=AE=BE=E7=BD=AE=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=E5=90=8E=EF=BC=8Cios=E4=B8=AD=E6=96=87=E8=BE=93?= =?UTF-8?q?=E5=85=A5=E6=B3=95=E8=BE=93=E5=85=A5=E7=8A=B6=E6=80=81=20placeh?= =?UTF-8?q?older=20=E4=B8=8D=E9=9A=90=E8=97=8F=20question/106127?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/view/components/editor/index.vue | 28 +++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/src/core/view/components/editor/index.vue b/src/core/view/components/editor/index.vue index 977901bbd..01d473c09 100644 --- a/src/core/view/components/editor/index.vue +++ b/src/core/view/components/editor/index.vue @@ -16,6 +16,19 @@ import HTMLParser from 'uni-helpers/html-parser' import * as formats from './formats' import loadScript from './load-script' +function isiOS () { + if (__PLATFORM__ === 'app-plus') { + return plus.os.name.toLowerCase() === 'ios' + } else if (__PLATFORM__ === 'h5') { + const ua = navigator.userAgent + const isIOS = /iphone|ipad|ipod/i.test(ua) + const isMac = /Macintosh|Mac/i.test(ua) + const isIPadOS = isMac && navigator.maxTouchPoints > 0 + return isIOS || isIPadOS + } + return false +} + let textChanging = false export default { name: 'Editor', @@ -65,7 +78,7 @@ export default { }, placeholder (value) { if (this.quillReady) { - this.quill.root.setAttribute('data-placeholder', value) + this.setPlaceHolder(value) } } }, @@ -238,6 +251,11 @@ export default { }, this.$page.id) } }, + setPlaceHolder (value) { + const placeHolderAttrName = 'data-placeholder' + const QuillRoot = this.quill.root + QuillRoot.getAttribute(placeHolderAttrName) !== value && QuillRoot.setAttribute(placeHolderAttrName, value) + }, initQuill (imageResizeModules) { const Quill = window.Quill formats.register(Quill) @@ -258,10 +276,16 @@ export default { const events = ['focus', 'blur', 'input'] events.forEach(name => { $el.addEventListener(name, ($event) => { + const contents = this.getContents() if (name === 'input') { + if (isiOS()) { + const regExpContent = (contents.html.match(/([\s\S]*)<\/span>/) || [])[1] + const placeholder = regExpContent && regExpContent.replace(/\s/g, '') ? '' : this.placeholder + this.setPlaceHolder(placeholder) + } $event.stopPropagation() } else { - this.$trigger(name, $event, this.getContents()) + this.$trigger(name, $event, contents) } }) }) -- GitLab