提交 d71fefc1 编写于 作者: Q qiang

feat: App、H5 端支持 uni.getSelectedTextRange

上级 307bc86d
...@@ -126,7 +126,8 @@ const device = [ ...@@ -126,7 +126,8 @@ const device = [
const keyboard = [ const keyboard = [
'hideKeyboard', 'hideKeyboard',
'onKeyboardHeightChange' 'onKeyboardHeightChange',
'getSelectedTextRange'
] ]
const ui = [ const ui = [
......
import createCallbacks from 'uni-helpers/callbacks'
import {
getCurrentPageId
} from '../../platform'
import {
invoke
} from '../../bridge'
const getSelectedTextRangeEventCallbacks = createCallbacks('getSelectedTextRangeEvent')
UniServiceJSBridge.subscribe('onGetSelectedTextRange', ({
callbackId,
data
}) => {
console.log('onGetSelectedTextRange')
const callback = getSelectedTextRangeEventCallbacks.pop(callbackId)
if (callback) {
callback(data)
}
})
export function getSelectedTextRange (_, callbackId) {
const pageId = getCurrentPageId()
UniServiceJSBridge.publishHandler('getSelectedTextRange', {
pageId,
callbackId: getSelectedTextRangeEventCallbacks.push(function (res) {
invoke(callbackId, res)
})
}, pageId)
}
...@@ -5,6 +5,24 @@ import { ...@@ -5,6 +5,24 @@ import {
import emitter from './emitter' import emitter from './emitter'
import keyboard from './keyboard' import keyboard from './keyboard'
UniViewJSBridge.subscribe('getSelectedTextRange', function ({ pageId, callbackId }) {
const activeElement = document.activeElement
const tagName = activeElement.tagName.toLowerCase()
const tagNames = ['input', 'textarea']
const data = {}
if (tagNames.includes(tagName)) {
data.errMsg = 'getSelectedTextRange:ok'
data.start = activeElement.selectionStart
data.end = activeElement.selectionEnd
} else {
data.errMsg = 'getSelectedTextRange:fail:no focused'
}
UniViewJSBridge.publishHandler('onGetSelectedTextRange', {
callbackId,
data
}, pageId)
})
export default { export default {
name: 'BaseInput', name: 'BaseInput',
mixins: [emitter, keyboard], mixins: [emitter, keyboard],
......
...@@ -62,7 +62,7 @@ export * from './route/preload-page' ...@@ -62,7 +62,7 @@ export * from './route/preload-page'
export * from './storage/storage' export * from './storage/storage'
export * from './ui/keyboard' export * from './keyboard/keyboard'
export * from './ui/navigation-bar' export * from './ui/navigation-bar'
export * from './ui/popup' export * from './ui/popup'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册