提交 d71fefc1 编写于 作者: Q qiang

feat: App、H5 端支持 uni.getSelectedTextRange

上级 307bc86d
......@@ -109,8 +109,8 @@ const device = [
'getBLEDeviceServices',
'getBLEDeviceCharacteristics',
'createBLEConnection',
'closeBLEConnection',
'setBLEMTU',
'closeBLEConnection',
'setBLEMTU',
'getBLEDeviceRSSI',
'onBeaconServiceChange',
'onBeaconUpdate',
......@@ -119,14 +119,15 @@ const device = [
'stopBeaconDiscovery',
'checkIsSupportSoterAuthentication',
'checkIsSoterEnrolledInDevice',
'startSoterAuthentication',
'startSoterAuthentication',
'onThemeChange',
'onUIStyleChange'
]
const keyboard = [
'hideKeyboard',
'onKeyboardHeightChange'
'onKeyboardHeightChange',
'getSelectedTextRange'
]
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 {
import emitter from './emitter'
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 {
name: 'BaseInput',
mixins: [emitter, keyboard],
......
......@@ -62,7 +62,7 @@ export * from './route/preload-page'
export * from './storage/storage'
export * from './ui/keyboard'
export * from './keyboard/keyboard'
export * from './ui/navigation-bar'
export * from './ui/popup'
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册