diff --git a/src/platforms/app-plus/view/components/picker/page.js b/src/platforms/app-plus/helpers/page.js similarity index 92% rename from src/platforms/app-plus/view/components/picker/page.js rename to src/platforms/app-plus/helpers/page.js index 9cf25df873769eadb2a23c4c944042fe1682b59d..9b0fe80968c25005a56e65fd42e18ba17b2103c3 100644 --- a/src/platforms/app-plus/view/components/picker/page.js +++ b/src/platforms/app-plus/helpers/page.js @@ -100,7 +100,8 @@ export function showPage ({ animationType: 'pop-in', animationDuration: 200, uniNView: { - path: `${(typeof process === 'object' && process.env && process.env.VUE_APP_TEMPLATE_PATH) || ''}/${url}.js`, + // eslint-disable-next-line + path: `${typeof VUE_APP_TEMPLATE_PATH === 'string' ? VUE_APP_TEMPLATE_PATH : ''}/${url}.js`, defaultFontSize: 16, viewport: plus_.screen.resolutionWidth } diff --git a/src/platforms/app-plus/service/api/device/scan-code-weex.js b/src/platforms/app-plus/service/api/device/scan-code-weex.js index a21de97763276906c2ad746a29ee9f71af34fe20..8cffe84dee641adfbb5ae35f55de139d1b50916a 100644 --- a/src/platforms/app-plus/service/api/device/scan-code-weex.js +++ b/src/platforms/app-plus/service/api/device/scan-code-weex.js @@ -4,7 +4,7 @@ import { import { showPage -} from '../page.js' +} from '../../../helpers/page.js' import { t diff --git a/src/platforms/app-plus/service/api/location/choose-location-weex.js b/src/platforms/app-plus/service/api/location/choose-location-weex.js index e1c1c94c6e0419dc64ac97f080e4ca0af2fdae9e..4251773fc4efaccbede82c7c760d6f5ab10a6fe5 100644 --- a/src/platforms/app-plus/service/api/location/choose-location-weex.js +++ b/src/platforms/app-plus/service/api/location/choose-location-weex.js @@ -4,7 +4,7 @@ import { import { showPage -} from '../page.js' +} from '../../../helpers/page.js' function getStatusBarStyle () { let style = plus.navigator.getStatusBarStyle() diff --git a/src/platforms/app-plus/service/api/location/open-location-weex.js b/src/platforms/app-plus/service/api/location/open-location-weex.js index fe76469f4d087c574eb699ec4259ad1e99fec7bc..4a41516316212059345d11eb0cc324d0b644b726 100644 --- a/src/platforms/app-plus/service/api/location/open-location-weex.js +++ b/src/platforms/app-plus/service/api/location/open-location-weex.js @@ -1,10 +1,10 @@ import { invoke } from '../../bridge' - + import { showPage -} from '../page.js' +} from '../../../helpers/page.js' export function openLocation (data, callbackId) { showPage({ @@ -16,11 +16,11 @@ export function openLocation (data, callbackId) { }, popGesture: 'close', backButtonAutoControl: 'close' - }, - onClose () { - invoke(callbackId, { - errMsg: 'openLocation:fail cancel' - }) + }, + onClose () { + invoke(callbackId, { + errMsg: 'openLocation:fail cancel' + }) } }) return { diff --git a/src/platforms/app-plus/service/api/page.js b/src/platforms/app-plus/service/api/page.js deleted file mode 100644 index 29afc5cf30a9a453fd503ac785c61eb97165530a..0000000000000000000000000000000000000000 --- a/src/platforms/app-plus/service/api/page.js +++ /dev/null @@ -1,128 +0,0 @@ -let plus_ -let weex_ -let BroadcastChannel_ - -function getRuntime () { - return typeof window === 'object' && typeof navigator === 'object' && typeof document === 'object' ? 'webview' : 'v8' -} - -function getPageId () { - return plus_.webview.currentWebview().id -} - -let channel -let globalEvent -const callbacks = {} - -function onPlusMessage (res) { - const message = res.data && res.data.__message - if (!message || !message.__page) { - return - } - const pageId = message.__page - const callback = callbacks[pageId] - callback && callback(message) - if (!message.keep) { - delete callbacks[pageId] - } -} - -function addEventListener (pageId, callback) { - if (getRuntime() === 'v8') { - if (BroadcastChannel_) { - channel && channel.close() - channel = new BroadcastChannel_(getPageId()) - channel.onmessage = onPlusMessage - } else if (!globalEvent) { - globalEvent = weex_.requireModule('globalEvent') - globalEvent.addEventListener('plusMessage', onPlusMessage) - } - } else { - window.__plusMessage = onPlusMessage - } - callbacks[pageId] = callback -} - -class Page { - constructor (webview) { - this.webview = webview - } - - sendMessage (data) { - const message = { - __message: { - data - } - } - const id = this.webview.id - if (BroadcastChannel_) { - const channel = new BroadcastChannel_(id) - channel.postMessage(message) - } else { - plus_.webview.postMessageToUniNView(message, id) - } - } - - close () { - this.webview.close() - } -} - -export function showPage ({ - context = {}, - url, - data = {}, - style = {}, - onMessage, - onClose -}) { - // eslint-disable-next-line - plus_ = context.plus || plus - // eslint-disable-next-line - weex_ = context.weex || (typeof weex === 'object' ? weex : null) - // eslint-disable-next-line - BroadcastChannel_ = context.BroadcastChannel || (typeof BroadcastChannel === 'object' ? BroadcastChannel : null) - const titleNView = { - autoBackButton: true, - titleSize: '17px' - } - const pageId = `page${Date.now()}` - style = Object.assign({}, style) - if (style.titleNView !== false && style.titleNView !== 'none') { - style.titleNView = Object.assign(titleNView, style.titleNView) - } - const defaultStyle = { - top: 0, - bottom: 0, - usingComponents: {}, - popGesture: 'close', - scrollIndicator: 'none', - animationType: 'pop-in', - animationDuration: 200, - uniNView: { - path: `${(typeof process === 'object' && process.env && process.env.VUE_APP_TEMPLATE_PATH) || ''}/${url}.js`, - defaultFontSize: 16, - viewport: plus_.screen.resolutionWidth - } - } - style = Object.assign(defaultStyle, style) - const page = plus_.webview.create('', pageId, style, { - extras: { - from: getPageId(), - runtime: getRuntime(), - data, - useGlobalEvent: !BroadcastChannel_ - } - }) - page.addEventListener('close', onClose) - addEventListener(pageId, message => { - if (typeof onMessage === 'function') { - onMessage(message.data) - } - if (!message.keep) { - page.close('auto') - } - }) - page.show(style.animationType, style.animationDuration) - return new Page(page) -} diff --git a/src/platforms/app-plus/view/components/picker/index.vue b/src/platforms/app-plus/view/components/picker/index.vue index ebb338274a0188451d369a34be7209bc599d812a..e12cde97f6d6918bdd10feae6b8ecd53d1037e90 100644 --- a/src/platforms/app-plus/view/components/picker/index.vue +++ b/src/platforms/app-plus/view/components/picker/index.vue @@ -9,7 +9,7 @@