提交 f810c035 编写于 作者: fxy060608's avatar fxy060608

Merge branch 'dev' of https://github.com/dcloudio/uni-app into v3

const path = require('path')
const babel = require('rollup-plugin-babel')
const alias = require('rollup-plugin-alias')
const uglify = require('rollup-plugin-uglify')
module.exports = {
input: 'src/core/runtime/web-view/index.js',
output: {
name: 'uni',
file: `dist/uni.webview.1.5.2.js`,
format: 'umd'
},
plugins: [
alias({
'uni-platforms': path.resolve(__dirname, '../src/platforms')
}),
babel(),
uglify.uglify({
output: {
ascii_only: true
}
})
]
}
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self).uni=n()}(this,function(){"use strict";function i(e,n){var i={options:{timestamp:+new Date},name:e,arg:n};if(!window.plus)return window.parent.postMessage({type:s,data:i,pageId:""},"*");if(0===d.length){var t=plus.webview.currentWebview();if(!t)throw new Error("plus.webview.currentWebview() is undefined");var o=t.parent(),a="";a=o?o.id:t.id,d.push(a)}var r=JSON.stringify(i);plus.webview.getWebviewById(u)?plus.webview.postMessageToUniNView({type:s,args:{data:i,webviewIds:d}},u):plus.webview.getLaunchWebview().evalJS('UniPlusBridge.subscribeHandler("'.concat(s,'",').concat(r,",").concat(JSON.stringify(d),");"))}var d=[],u="__uniapp__service",s="WEB_INVOKE_APPSERVICE",n={navigateTo:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("navigateTo",{url:encodeURI(n)})},navigateBack:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).delta;i("navigateBack",{delta:parseInt(n)||1})},switchTab:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("switchTab",{url:encodeURI(n)})},reLaunch:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("reLaunch",{url:encodeURI(n)})},redirectTo:function(e){var n=(0<arguments.length&&void 0!==e?e:{}).url;i("redirectTo",{url:encodeURI(n)})},getEnv:function(e){window.plus?e({plus:!0}):e({h5:!0})},postMessage:function(e){i("postMessage",(0<arguments.length&&void 0!==e?e:{}).data||{})}},t=/uni-app/i.test(navigator.userAgent),o=/complete|loaded|interactive/;var a=window.my&&-1<navigator.userAgent.indexOf("AlipayClient");var r=window.swan&&window.swan.webView&&/swan-baiduboxapp/i.test(navigator.userAgent);var w=window.qq&&window.qq.miniProgram&&/QQ/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);var c=window.tt&&window.tt.miniProgram&&/toutiaomicroapp/i.test(navigator.userAgent);var g=window.wx&&window.wx.miniProgram&&/micromessenger/i.test(navigator.userAgent)&&/miniProgram/i.test(navigator.userAgent);for(var e,v=function(){window.UniAppJSBridge=!0,document.dispatchEvent(new CustomEvent("UniAppJSBridgeReady",{bubbles:!0,cancelable:!0}))},f=[function(e){if(t)return setTimeout(function(){window.plus&&o.test(document.readyState)?e():document.addEventListener("plusready",e)},0),n},function(e){if(g)return setTimeout(function(){window.WeixinJSBridge&&window.WeixinJSBridge.invoke?e():document.addEventListener("WeixinJSBridgeReady",e)},0),window.wx.miniProgram},function(e){if(w)return setTimeout(function(){window.QQJSBridge&&window.QQJSBridge.invoke?e():document.addEventListener("QQJSBridgeReady",e)},0),window.qq.miniProgram},function(e){if(a){setTimeout(function(){document.addEventListener("DOMContentLoaded",e)},0);var n=window.my;return{navigateTo:n.navigateTo,navigateBack:n.navigateBack,switchTab:n.switchTab,reLaunch:n.reLaunch,redirectTo:n.redirectTo,postMessage:n.postMessage,getEnv:n.getEnv}}},function(e){if(r)return setTimeout(function(){document.addEventListener("DOMContentLoaded",e)},0),window.swan.webView},function(e){if(c)return setTimeout(function(){document.addEventListener("DOMContentLoaded",e)},0),window.tt.miniProgram},function(e){return setTimeout(function(){document.addEventListener("DOMContentLoaded",e)},0),n}],m=0;m<f.length&&!(e=f[m](v));m++);e=e||{};var p="undefined"!=typeof uni?uni:{};return p.navigateTo?p.miniProgram=e:Object.assign(p,e,{miniProgram:e}),p});
......@@ -24,6 +24,7 @@
"build:mp-weixin:mp": "npm run lint && cross-env UNI_PLATFORM=mp-weixin UNI_MP=true rollup -c build/rollup.config.mp.js",
"build:runtime": "npm run lint && npm run build:mp-weixin && npm run build:mp-qq && npm run build:mp-alipay && npm run build:mp-baidu && npm run build:mp-toutiao && npm run build:app-plus",
"build:stat": "npm run lint && rollup -c build/rollup.config.stat.js",
"build:web-view": "npm run lint && rollup -c build/rollup.config.web-view.js",
"test:cli": "cross-env NODE_ENV=test jest",
"test:unit": "cross-env NODE_ENV=test UNI_PLATFORM=h5 mocha-webpack --require tests/unit/setup.js --webpack-config build/webpack.config.test.js tests/unit/**/*.spec.js",
"release": "npm run lint:cli && lerna publish --force-publish=*",
......@@ -66,9 +67,11 @@
"jsonfile": "^5.0.0",
"rollup": "^1.17.0",
"rollup-plugin-alias": "^1.4.0",
"rollup-plugin-babel": "^4.3.3",
"rollup-plugin-commonjs": "^10.0.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-uglify": "^6.0.3",
"shell-exec": "^1.0.2",
"strip-json-comments": "^2.0.1",
"vue": "^2.6.8",
......
......@@ -1191,6 +1191,13 @@ function parseBaseApp (vm, {
// 兼容旧版本 globalData
appOptions.globalData = vm.$options.globalData || {};
// 将 methods 中的方法挂在 getApp() 中
const methods = vm.$options.methods;
if (methods) {
Object.keys(methods).forEach(name => {
appOptions[name] = methods[name];
});
}
initHooks(appOptions, hooks);
......
......@@ -1583,6 +1583,13 @@ function parseBaseApp (vm, {
// 兼容旧版本 globalData
appOptions.globalData = vm.$options.globalData || {};
// 将 methods 中的方法挂在 getApp() 中
const methods = vm.$options.methods;
if (methods) {
Object.keys(methods).forEach(name => {
appOptions[name] = methods[name];
});
}
initHooks(appOptions, hooks);
......
......@@ -1328,6 +1328,13 @@ function parseBaseApp (vm, {
// 兼容旧版本 globalData
appOptions.globalData = vm.$options.globalData || {};
// 将 methods 中的方法挂在 getApp() 中
const methods = vm.$options.methods;
if (methods) {
Object.keys(methods).forEach(name => {
appOptions[name] = methods[name];
});
}
initHooks(appOptions, hooks);
......
......@@ -1251,6 +1251,13 @@ function parseBaseApp (vm, {
// 兼容旧版本 globalData
appOptions.globalData = vm.$options.globalData || {};
// 将 methods 中的方法挂在 getApp() 中
const methods = vm.$options.methods;
if (methods) {
Object.keys(methods).forEach(name => {
appOptions[name] = methods[name];
});
}
initHooks(appOptions, hooks);
......
......@@ -1338,6 +1338,13 @@ function parseBaseApp (vm, {
// 兼容旧版本 globalData
appOptions.globalData = vm.$options.globalData || {};
// 将 methods 中的方法挂在 getApp() 中
const methods = vm.$options.methods;
if (methods) {
Object.keys(methods).forEach(name => {
appOptions[name] = methods[name];
});
}
initHooks(appOptions, hooks);
......
......@@ -1191,6 +1191,13 @@ function parseBaseApp (vm, {
// 兼容旧版本 globalData
appOptions.globalData = vm.$options.globalData || {};
// 将 methods 中的方法挂在 getApp() 中
const methods = vm.$options.methods;
if (methods) {
Object.keys(methods).forEach(name => {
appOptions[name] = methods[name];
});
}
initHooks(appOptions, hooks);
......
const path = require('path')
const {
removeExt,
normalizePath,
getPagesJson
} = require('@dcloudio/uni-cli-shared')
const {
normalizeNodeModules
} = require('@dcloudio/webpack-uni-mp-loader/lib/shared')
const SCROLLER_COMPONENTS = [
'list',
'scroller',
'scroll-view',
'waterfall'
]
module.exports = function(content) {
this.cacheable && this.cacheable()
if (content.indexOf('recycle-list') === -1) {
return `<scroll-view :scroll-y="true" :enableBackToTop="true" bubble="true" style="flex-direction:column">${content}</scroll-view>`
const source = content.trim()
if (SCROLLER_COMPONENTS.find(name => source.indexOf('<' + name) === 0)) {
return content
}
if (source.indexOf('<recycle-list') !== -1) {
return content
}
let resourcePath = normalizeNodeModules(
removeExt(normalizePath(path.relative(process.env.UNI_INPUT_DIR, this.resourcePath)))
)
if (
!process.UNI_NVUE_ENTRY[resourcePath] &&
this._module.issuer &&
this._module.issuer.issuer
) {
// <template src=""/>
resourcePath = normalizeNodeModules(
removeExt(normalizePath(path.relative(process.env.UNI_INPUT_DIR, this._module.issuer.issuer.resource)))
)
}
if (!process.UNI_NVUE_ENTRY[resourcePath]) {
return content
}
// 暂时实时读取配置信息,查找是否 disableScroll
const appJson = getPagesJson()
if (!appJson.nvue || !appJson.nvue.pages) {
return content
}
const pagePath = resourcePath + '.html'
const pageJson = appJson.nvue.pages.find(page => page.path === pagePath)
if (!pageJson) {
return content
}
Object.assign(appJson.globalStyle, appJson.globalStyle['app-plus'] || {})
Object.assign(pageJson.style, pageJson.style['app-plus'] || {})
const pageJsonStyle = Object.assign(appJson.globalStyle, pageJson.style)
if (pageJsonStyle.disableScroll === true) {
return content
}
return `<scroll-view :scroll-y="true" :enableBackToTop="true" bubble="true" style="flex-direction:column">${content}</scroll-view>`
}
import {
initWebviewApi as initAppplusWebviewApi
} from 'uni-platforms/app-plus/runtime/web-view'
import {
initWebviewApi as initH5WebviewApi
} from 'uni-platforms/h5/runtime/web-view'
import {
initWebviewApi as initAlipayWebviewApi
} from 'uni-platforms/mp-alipay/runtime/web-view'
import {
initWebviewApi as initBaiduWebviewApi
} from 'uni-platforms/mp-baidu/runtime/web-view'
import {
initWebviewApi as initQQWebviewApi
} from 'uni-platforms/mp-qq/runtime/web-view'
import {
initWebviewApi as initToutiaoWebviewApi
} from 'uni-platforms/mp-toutiao/runtime/web-view'
import {
initWebviewApi as initWeixinWebviewApi
} from 'uni-platforms/mp-weixin/runtime/web-view'
const UniAppJSBridgeReady = function () {
window.UniAppJSBridge = true
document.dispatchEvent(new CustomEvent('UniAppJSBridgeReady', {
bubbles: true,
cancelable: true
}))
}
const initWebviewApis = [
initAppplusWebviewApi,
initWeixinWebviewApi,
initQQWebviewApi,
initAlipayWebviewApi,
initBaiduWebviewApi,
initToutiaoWebviewApi,
initH5WebviewApi
]
let webViewApi
for (let i = 0; i < initWebviewApis.length; i++) {
webViewApi = initWebviewApis[i](UniAppJSBridgeReady)
if (webViewApi) {
break
}
}
if (!webViewApi) {
webViewApi = {}
}
const api = typeof uni !== 'undefined' ? uni : {}
if (api.navigateTo) {
api.miniProgram = webViewApi
} else {
Object.assign(api, webViewApi, {
miniProgram: webViewApi
})
}
export default api
const webviewIds = []
const UNIAPP_SERVICE_NVUE_ID = '__uniapp__service'
const WEB_INVOKE_APPSERVICE = 'WEB_INVOKE_APPSERVICE'
const publish = function (method, params) {
const paramsObj = {
options: {
timestamp: +new Date()
},
name: method,
arg: params
}
if (!window.plus) { // h5
return window.parent.postMessage({
type: WEB_INVOKE_APPSERVICE,
data: paramsObj,
pageId: ''
}, '*')
}
// app-plus
if (webviewIds.length === 0) {
const currentWebview = plus.webview.currentWebview()
if (!currentWebview) {
throw new Error('plus.webview.currentWebview() is undefined')
}
const parentWebview = currentWebview.parent()
let webviewId = ''
if (!parentWebview) {
webviewId = currentWebview.id
// throw new Error('plus.webview.currentWebview().parent() is undefined')
} else {
webviewId = parentWebview.id
}
webviewIds.push(webviewId)
}
const paramsString = JSON.stringify(paramsObj)
if (plus.webview.getWebviewById(UNIAPP_SERVICE_NVUE_ID)) {
plus.webview.postMessageToUniNView({
type: WEB_INVOKE_APPSERVICE,
args: {
data: paramsObj,
webviewIds
}
}, UNIAPP_SERVICE_NVUE_ID)
} else {
plus.webview.getLaunchWebview().evalJS(
`UniPlusBridge.subscribeHandler("${WEB_INVOKE_APPSERVICE}",${paramsString},${JSON.stringify(webviewIds)});`
)
}
}
export default {
navigateTo ({
url
} = {}) {
publish('navigateTo', {
url: encodeURI(url)
})
},
navigateBack ({
delta
} = {}) {
publish('navigateBack', {
delta: parseInt(delta) || 1
})
},
switchTab ({
url
} = {}) {
publish('switchTab', {
url: encodeURI(url)
})
},
reLaunch ({
url
} = {}) {
publish('reLaunch', {
url: encodeURI(url)
})
},
redirectTo ({
url
} = {}) {
publish('redirectTo', {
url: encodeURI(url)
})
},
getEnv (callback) {
/* eslint-disable standard/no-callback-literal */
if (window.plus) {
callback({
plus: true
})
} else {
callback({
h5: true
})
}
},
postMessage (params = {}) {
publish('postMessage', params.data || {})
}
}
import api from './web-view-api'
const isAppPlus = /uni-app/i.test(navigator.userAgent)
const readyRE = /complete|loaded|interactive/
export function initWebviewApi (readyCallback) {
if (!isAppPlus) {
return
}
setTimeout(() => {
if (window.plus && readyRE.test(document.readyState)) {
readyCallback()
} else {
document.addEventListener('plusready', readyCallback)
}
}, 0)
return api
}
import api from '../../app-plus/runtime/web-view-api'
export function initWebviewApi (readyCallback) {
setTimeout(() => {
document.addEventListener('DOMContentLoaded', readyCallback)
}, 0)
return api
}
const isAlipay = window.my && navigator.userAgent.indexOf('AlipayClient') > -1
export function initWebviewApi (readyCallback) {
if (!isAlipay) {
return
}
setTimeout(() => {
document.addEventListener('DOMContentLoaded', readyCallback)
}, 0)
const {
navigateTo,
navigateBack,
switchTab,
reLaunch,
redirectTo,
postMessage,
getEnv
} = window.my
return {
navigateTo,
navigateBack,
switchTab,
reLaunch,
redirectTo,
postMessage,
getEnv
}
}
const isBaidu = window.swan &&
window.swan.webView &&
/swan-baiduboxapp/i.test(navigator.userAgent)
export function initWebviewApi (readyCallback) {
if (!isBaidu) {
return
}
setTimeout(() => {
document.addEventListener('DOMContentLoaded', readyCallback)
}, 0)
return window.swan.webView
}
const isQQ = window.qq &&
window.qq.miniProgram &&
/QQ/i.test(navigator.userAgent) &&
/miniProgram/i.test(navigator.userAgent)
export function initWebviewApi (readyCallback) {
if (!isQQ) {
return
}
setTimeout(() => {
if (window.QQJSBridge && window.QQJSBridge.invoke) {
readyCallback()
} else {
document.addEventListener('QQJSBridgeReady', readyCallback)
}
}, 0)
return window.qq.miniProgram
}
const isToutiao = window.tt &&
window.tt.miniProgram &&
/toutiaomicroapp/i.test(navigator.userAgent)
export function initWebviewApi (readyCallback) {
if (!isToutiao) {
return
}
setTimeout(() => {
document.addEventListener('DOMContentLoaded', readyCallback)
}, 0)
return window.tt.miniProgram
}
const isWeixin = window.wx &&
window.wx.miniProgram &&
/micromessenger/i.test(navigator.userAgent) &&
/miniProgram/i.test(navigator.userAgent)
export function initWebviewApi (readyCallback) {
if (!isWeixin) {
return
}
setTimeout(() => {
if (window.WeixinJSBridge && window.WeixinJSBridge.invoke) {
readyCallback()
} else {
document.addEventListener('WeixinJSBridgeReady', readyCallback)
}
}, 0)
return window.wx.miniProgram
}
......@@ -77,6 +77,13 @@ export default function parseBaseApp (vm, {
// 兼容旧版本 globalData
appOptions.globalData = vm.$options.globalData || {}
// 将 methods 中的方法挂在 getApp() 中
const methods = vm.$options.methods
if (methods) {
Object.keys(methods).forEach(name => {
appOptions[name] = methods[name]
})
}
initHooks(appOptions, hooks)
......
......@@ -2496,6 +2496,10 @@ commander@~2.19.0:
version "2.19.0"
resolved "https://registry.npm.taobao.org/commander/download/commander-2.19.0.tgz#f6198aa84e5b83c46054b94ddedbfed5ee9ff12a"
commander@~2.20.3:
version "2.20.3"
resolved "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
commondir@^1.0.1:
version "1.0.1"
resolved "https://registry.npm.taobao.org/commondir/download/commondir-1.0.1.tgz#ddd800da0c66127393cca5950ea968a3aaf1253b"
......@@ -5403,7 +5407,7 @@ jest-watcher@^24.9.0:
jest-util "^24.9.0"
string-length "^2.0.0"
jest-worker@^24.6.0, jest-worker@^24.9.0:
jest-worker@^24.0.0, jest-worker@^24.6.0, jest-worker@^24.9.0:
version "24.9.0"
resolved "https://registry.npm.taobao.org/jest-worker/download/jest-worker-24.9.0.tgz?cache=0&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fjest-worker%2Fdownload%2Fjest-worker-24.9.0.tgz#5dbfdb5b2d322e98567898238a9697bcce67b3e5"
dependencies:
......@@ -7683,6 +7687,13 @@ rollup-plugin-alias@^1.4.0:
dependencies:
slash "^3.0.0"
rollup-plugin-babel@^4.3.3:
version "4.3.3"
resolved "https://registry.npmjs.org/rollup-plugin-babel/-/rollup-plugin-babel-4.3.3.tgz#7eb5ac16d9b5831c3fd5d97e8df77ba25c72a2aa"
dependencies:
"@babel/helper-module-imports" "^7.0.0"
rollup-pluginutils "^2.8.1"
rollup-plugin-commonjs@^10.0.1:
version "10.0.1"
resolved "https://registry.npm.taobao.org/rollup-plugin-commonjs/download/rollup-plugin-commonjs-10.0.1.tgz#fbfcadf4ce2e826068e056a9f5c19287d9744ddf"
......@@ -7710,6 +7721,15 @@ rollup-plugin-replace@^2.1.0:
magic-string "^0.25.2"
rollup-pluginutils "^2.6.0"
rollup-plugin-uglify@^6.0.3:
version "6.0.3"
resolved "https://registry.npmjs.org/rollup-plugin-uglify/-/rollup-plugin-uglify-6.0.3.tgz#e3f776171344b580bec6c6ab8888622b67099457"
dependencies:
"@babel/code-frame" "^7.0.0"
jest-worker "^24.0.0"
serialize-javascript "^1.9.0"
uglify-js "^3.4.9"
rollup-pluginutils@^2.6.0, rollup-pluginutils@^2.8.1:
version "2.8.1"
resolved "https://registry.npm.taobao.org/rollup-pluginutils/download/rollup-pluginutils-2.8.1.tgz#8fa6dd0697344938ef26c2c09d2488ce9e33ce97"
......@@ -7865,6 +7885,10 @@ serialize-javascript@^1.4.0, serialize-javascript@^1.7.0:
version "1.7.0"
resolved "https://registry.npm.taobao.org/serialize-javascript/download/serialize-javascript-1.7.0.tgz#d6e0dfb2a3832a8c94468e6eb1db97e55a192a65"
serialize-javascript@^1.9.0:
version "1.9.1"
resolved "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-1.9.1.tgz#cfc200aef77b600c47da9bb8149c943e798c2fdb"
serve-index@^1.9.1:
version "1.9.1"
resolved "https://registry.npm.taobao.org/serve-index/download/serve-index-1.9.1.tgz#d3768d69b1e7d82e5ce050fff5b453bea12a9239"
......@@ -8660,6 +8684,13 @@ uglify-js@^3.1.4:
commander "~2.20.0"
source-map "~0.6.1"
uglify-js@^3.4.9:
version "3.6.9"
resolved "https://registry.npmjs.org/uglify-js/-/uglify-js-3.6.9.tgz#85d353edb6ddfb62a9d798f36e91792249320611"
dependencies:
commander "~2.20.3"
source-map "~0.6.1"
unc-path-regex@^0.1.0:
version "0.1.2"
resolved "https://registry.npm.taobao.org/unc-path-regex/download/unc-path-regex-0.1.2.tgz#e73dd3d7b0d7c5ed86fbac6b0ae7d8c6a69d50fa"
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册