提交 fba61e7e 编写于 作者: Q qiang

fix: 优化 core components 中的平台判断

上级 c6964211
import { import {
invokeMethod, invokeMethod,
getCurrentPageVm getCurrentPageVm
} from '../../platform' } from '../../platform'
import { import {
callback callback
...@@ -16,8 +16,8 @@ UniServiceJSBridge.subscribe('onMapMethodCallback', ({ ...@@ -16,8 +16,8 @@ UniServiceJSBridge.subscribe('onMapMethodCallback', ({
data data
}) => { }) => {
callback.invoke(callbackId, data) callback.invoke(callbackId, data)
}) })
const methods = ['getCenterLocation', 'moveToLocation', 'getScale', 'getRegion', 'includePoints', 'translateMarker'] const methods = ['getCenterLocation', 'moveToLocation', 'getScale', 'getRegion', 'includePoints', 'translateMarker']
export class MapContext { export class MapContext {
...@@ -25,18 +25,20 @@ export class MapContext { ...@@ -25,18 +25,20 @@ export class MapContext {
this.id = id this.id = id
this.pageVm = pageVm this.pageVm = pageVm
} }
} }
MapContext.prototype.$getAppMap = function () { MapContext.prototype.$getAppMap = function () {
return plus.maps.getMapById(this.pageVm.$page.id + '-map-' + this.id) if (__PLATFORM__ === 'app-plus') {
} return plus.maps.getMapById(this.pageVm.$page.id + '-map-' + this.id)
}
}
methods.forEach(function (method) { methods.forEach(function (method) {
MapContext.prototype[method] = callback.warp(function (options, callbackId) { MapContext.prototype[method] = callback.warp(function (options, callbackId) {
options.callbackId = callbackId options.callbackId = callbackId
operateMapPlayer(this.id, this.pageVm, method, options) operateMapPlayer(this.id, this.pageVm, method, options)
}) })
}) })
export function createMapContext (id, context) { export function createMapContext (id, context) {
if (context) { if (context) {
......
...@@ -65,7 +65,7 @@ export default { ...@@ -65,7 +65,7 @@ export default {
) )
return return
} }
if (this.openType === 'feedback') { if (this.openType === 'feedback' && __PLATFORM__ === 'app-plus') {
const feedback = plus.webview.create( const feedback = plus.webview.create(
'https://service.dcloud.net.cn/uniapp/feedback.html', 'https://service.dcloud.net.cn/uniapp/feedback.html',
'feedback', 'feedback',
......
...@@ -351,17 +351,17 @@ export default { ...@@ -351,17 +351,17 @@ export default {
loadBlob(this.response) loadBlob(this.response)
} }
} }
xhr.onerror = window.plus ? plusDownload : function () { xhr.onerror = __PLATFORM__ === 'app-plus' ? plusDownload : function () {
self._images[src].src = src self._images[src].src = src
} }
xhr.send() xhr.send()
} }
if (window.plus && (!window.webkit || !window.webkit.messageHandlers)) { if (__PLATFORM__ === 'app-plus' && (!window.webkit || !window.webkit.messageHandlers)) {
self._images[src].src = src self._images[src].src = src
} else { } else {
// 解决 PLUS-APP(wkwebview)以及 H5 图像跨域问题(H5图像响应头需包含access-control-allow-origin) // 解决 PLUS-APP(wkwebview)以及 H5 图像跨域问题(H5图像响应头需包含access-control-allow-origin)
if (window.plus && src.indexOf('http://') !== 0 && src.indexOf('https://') !== if (__PLATFORM__ === 'app-plus' && src.indexOf('http://') !== 0 && src.indexOf('https://') !==
0 && !/^data:.*,.*/.test(src)) { 0 && !/^data:.*,.*/.test(src)) {
loadFile(src) loadFile(src)
} else if (/^data:.*,.*/.test(src)) { } else if (/^data:.*,.*/.test(src)) {
......
...@@ -226,7 +226,7 @@ export default { ...@@ -226,7 +226,7 @@ export default {
return return
} }
const script = document.createElement('script') const script = document.createElement('script')
script.src = window.plus ? './__uniappquill.js' : 'https://unpkg.com/quill@1.3.7/dist/quill.min.js' script.src = __PLATFORM__ === 'app-plus' ? './__uniappquill.js' : 'https://unpkg.com/quill@1.3.7/dist/quill.min.js'
document.body.appendChild(script) document.body.appendChild(script)
script.onload = callback script.onload = callback
}, },
...@@ -238,7 +238,7 @@ export default { ...@@ -238,7 +238,7 @@ export default {
return return
} }
const script = document.createElement('script') const script = document.createElement('script')
script.src = window.plus ? './__uniappquillimageresize.js' : 'https://unpkg.com/quill-image-resize-mp@3.0.1/image-resize.min.js' script.src = __PLATFORM__ === 'app-plus' ? './__uniappquillimageresize.js' : 'https://unpkg.com/quill-image-resize-mp@3.0.1/image-resize.min.js'
document.body.appendChild(script) document.body.appendChild(script)
script.onload = callback script.onload = callback
}, },
......
...@@ -28,7 +28,7 @@ export default { ...@@ -28,7 +28,7 @@ export default {
}, },
watch: { watch: {
focus (val) { focus (val) {
if (val && __PLATFORM__ === 'app-plus') { if (val) {
this.showSoftKeybord() this.showSoftKeybord()
} }
} }
...@@ -49,68 +49,72 @@ export default { ...@@ -49,68 +49,72 @@ export default {
} }
UniViewJSBridge.subscribe('hideKeyboard', this.hideKeyboardTemp) UniViewJSBridge.subscribe('hideKeyboard', this.hideKeyboardTemp)
document.addEventListener('click', iosHideKeyboard, false) document.addEventListener('click', iosHideKeyboard, false)
if (__PLATFORM__ === 'app-plus') { this.setSoftinputNavBar()
this.setSoftinputNavBar() this.setSoftinputTemporary()
this.setSoftinputTemporary()
}
}) })
el.addEventListener('blur', this.onKeyboardHide.bind(this)) el.addEventListener('blur', this.onKeyboardHide.bind(this))
}, },
showSoftKeybord () { showSoftKeybord () {
plusReady(() => { if (__PLATFORM__ === 'app-plus') {
plus.key.showSoftKeybord() plusReady(() => {
}) plus.key.showSoftKeybord()
})
}
}, },
setSoftinputTemporary () { setSoftinputTemporary () {
plusReady(() => { if (__PLATFORM__ === 'app-plus') {
const currentWebview = plus.webview.currentWebview() plusReady(() => {
const style = currentWebview.getStyle() || {} const currentWebview = plus.webview.currentWebview()
const rect = this.$el.getBoundingClientRect() const style = currentWebview.getStyle() || {}
currentWebview.setSoftinputTemporary && currentWebview.setSoftinputTemporary({ const rect = this.$el.getBoundingClientRect()
mode: style.softinputMode === 'adjustResize' ? 'adjustResize' : (this.adjustPosition ? 'adjustPan' : 'nothing'), currentWebview.setSoftinputTemporary && currentWebview.setSoftinputTemporary({
position: { mode: style.softinputMode === 'adjustResize' ? 'adjustResize' : (this.adjustPosition ? 'adjustPan' : 'nothing'),
top: rect.top, position: {
height: rect.height + (Number(this.cursorSpacing) || 0) top: rect.top,
} height: rect.height + (Number(this.cursorSpacing) || 0)
}
})
}) })
}) }
}, },
setSoftinputNavBar () { setSoftinputNavBar () {
if (this.showConfirmBar === 'auto') { if (__PLATFORM__ === 'app-plus') {
delete this.__softinputNavBar if (this.showConfirmBar === 'auto') {
return
}
plusReady(() => {
const currentWebview = plus.webview.currentWebview()
const { softinputNavBar } = currentWebview.getStyle() || {}
const showConfirmBar = softinputNavBar !== 'none'
if (showConfirmBar !== this.showConfirmBar) {
this.__softinputNavBar = softinputNavBar || 'auto'
currentWebview.setStyle({
softinputNavBar: this.showConfirmBar ? 'auto' : 'none'
})
} else {
delete this.__softinputNavBar delete this.__softinputNavBar
return
} }
})
},
resetSoftinputNavBar () {
const softinputNavBar = this.__softinputNavBar
if (softinputNavBar) {
plusReady(() => { plusReady(() => {
const currentWebview = plus.webview.currentWebview() const currentWebview = plus.webview.currentWebview()
currentWebview.setStyle({ const { softinputNavBar } = currentWebview.getStyle() || {}
softinputNavBar const showConfirmBar = softinputNavBar !== 'none'
}) if (showConfirmBar !== this.showConfirmBar) {
this.__softinputNavBar = softinputNavBar || 'auto'
currentWebview.setStyle({
softinputNavBar: this.showConfirmBar ? 'auto' : 'none'
})
} else {
delete this.__softinputNavBar
}
}) })
} }
}, },
resetSoftinputNavBar () {
if (__PLATFORM__ === 'app-plus') {
const softinputNavBar = this.__softinputNavBar
if (softinputNavBar) {
plusReady(() => {
const currentWebview = plus.webview.currentWebview()
currentWebview.setStyle({
softinputNavBar
})
})
}
}
},
onKeyboardHide () { onKeyboardHide () {
UniViewJSBridge.unsubscribe('hideKeyboard', this.hideKeyboardTemp) UniViewJSBridge.unsubscribe('hideKeyboard', this.hideKeyboardTemp)
document.removeEventListener('click', iosHideKeyboard, false) document.removeEventListener('click', iosHideKeyboard, false)
if (__PLATFORM__ === 'app-plus') { this.resetSoftinputNavBar()
this.resetSoftinputNavBar()
}
// 修复ios端显示与点击位置错位的Bug by:wyq // 修复ios端显示与点击位置错位的Bug by:wyq
if (String(navigator.vendor).indexOf('Apple') === 0) { if (String(navigator.vendor).indexOf('Apple') === 0) {
document.documentElement.scrollTo(document.documentElement.scrollLeft, document.documentElement.scrollTop) document.documentElement.scrollTo(document.documentElement.scrollLeft, document.documentElement.scrollTop)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册