提交 d7d59a12 编写于 作者: Q qiang

Merge branch 'nvue-dev' into dev

# Conflicts:
#	package.json
#	src/platforms/app-plus-nvue/service/api/util.js
#	yarn.lock
......@@ -6,7 +6,7 @@ root = true
[*]
charset = utf-8
indent_style = space
indent_size = 4
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
......
src/core/helpers/html-parser.js
\ No newline at end of file
src/core/helpers/html-parser.js
src/platforms/app-plus-nvue/runtime
build/rollup-plugin-require-context
node_modules/
.project
unpackage/
.vscode/
\ No newline at end of file
.vscode/
.DS_Store
module.exports = {
ignore: [
"./packages",
],
presets: [
["@vue/app", {
useBuiltIns: "entry"
}]
]
ignore: [
"./packages",
],
presets: [
["@vue/app", {
useBuiltIns: "entry"
}]
],
plugins: [require('./lib/babel-plugin-uni-api/index.js')]
}
......@@ -9,9 +9,15 @@ const copy = require('copy')
const path = require('path')
const jsonfile = require('jsonfile')
const {
generateApiManifest
} = require('./manifest')
const service = new Service(process.env.VUE_CLI_CONTEXT || process.cwd(), {
inlineOptions: require('./vue.config.js')
})
// 删除 cache 目录
del.sync(['node_modules/.cache'])
service.run('build', {
name: 'index',
......@@ -19,6 +25,11 @@ service.run('build', {
target: 'lib',
formats: process.env.UNI_WATCH === 'true' ? 'umd' : 'umd-min',
entry: './lib/' + process.env.UNI_PLATFORM + '/main.js'
}).then(function () {
generateApiManifest(
JSON.parse(JSON.stringify(process.UNI_SERVICE_API_MANIFEST)),
JSON.parse(JSON.stringify(process.UNI_SERVICE_API_PROTOCOL))
)
}).catch(err => {
error(err)
process.exit(1)
......@@ -44,9 +55,11 @@ if (process.env.UNI_WATCH === 'false') {
})
})
.then(obj => {
return jsonfile.writeFile(packageJsonPath, obj, { spaces: 2 })
return jsonfile.writeFile(packageJsonPath, obj, {
spaces: 2
})
})
.catch(err => {
throw err
})
}
}
const fs = require('fs')
const path = require('path')
const apis = require('../lib/apis')
const AUTO_LOADS = [
'upx2px',
'canIUse',
'getSystemInfo',
'getSystemInfoSync',
'navigateTo',
'redirectTo',
'switchTab',
'reLaunch',
'navigateBack'
]
const TOAST_DEPS = [
['/platforms/h5/components/app/popup/toast.vue', 'Toast'],
['/platforms/h5/components/app/popup/mixins/toast.js', 'ToastMixin']
]
// TODO 暂不考虑 head,tabBar 的动态拆分
const DEPS = {
'chooseLocation': [
['/platforms/h5/components/system-routes/choose-location/index.vue', 'ChooseLocation']
],
'openLocation': [
['/platforms/h5/components/system-routes/open-location/index.vue', 'OpenLocation']
],
'previewImage': [
['/platforms/h5/components/system-routes/preview-image/index.vue', 'PreviewImage']
],
'showToast': TOAST_DEPS,
'hideToast': TOAST_DEPS,
'showLoading': TOAST_DEPS,
'hideLoading': TOAST_DEPS,
'showModal': [
['/platforms/h5/components/app/popup/modal.vue', 'Modal'],
['/platforms/h5/components/app/popup/mixins/modal.js', 'ModalMixin']
],
'showActionSheet': [
['/platforms/h5/components/app/popup/actionSheet.vue', 'ActionSheet'],
['/platforms/h5/components/app/popup/mixins/action-sheet.js', 'ActionSheetMixin']
],
'createSelectorQuery': [
['/core/view/bridge/subscribe/api/request-component-info.js', 'requestComponentInfo']
],
'createIntersectionObserver': [
['/core/view/bridge/subscribe/api/request-component-observer.js', 'requestComponentObserver'],
['/core/view/bridge/subscribe/api/request-component-observer.js', 'destroyComponentObserver']
]
}
// 检查依赖文件是否存在
Object.keys(DEPS).reduce(function (depFiles, name) {
DEPS[name].forEach(function (dep) {
depFiles.add(dep[0])
})
return depFiles
}, new Set()).forEach(file => {
if (!fs.existsSync(path.join(__dirname, '../src', file))) {
console.error(file + ' 不存在')
process.exit(0)
}
})
function parseApiManifestDeps (manifest, protocol) {
// 解析 platform 依赖
Object.keys(manifest).forEach(name => {
const deps = manifest[name][1]
if (deps.length) {
deps.forEach(dep => {
if (manifest[dep[1]]) {
dep[0] = manifest[dep[1]][0]
} else {
console.error(`依赖模块[${dep[1]}]不存在,删除 ${name} 接口\n`)
delete manifest[name]
}
})
}
})
// 解析 protocol 依赖
Object.keys(manifest).forEach(name => {
const deps = manifest[name][1]
if (protocol[name]) {
deps.push([protocol[name], name])
} else {
console.warn(`${name} 缺少 protocol`)
}
})
// 追加默认依赖
Object.keys(DEPS).forEach(name => {
if (manifest[name]) {
manifest[name][1].push(...DEPS[name])
} else {
console.error(`缺少 ${name}`)
}
})
// 设置自动加载标记
AUTO_LOADS.forEach(name => {
if (manifest[name]) {
manifest[name][2] = true
} else {
console.error(`缺少 ${name}`)
}
})
}
module.exports = {
generateApiManifest (manifest, protocol) {
if (!Object.keys(manifest).length) {
throw new Error('api manifest.json 生成失败')
}
parseApiManifestDeps(manifest, protocol)
const manifestJson = Object.create(null)
const todoApis = []
apis.forEach(name => {
if (manifest[name]) {
manifestJson[name] = manifest[name]
} else {
todoApis.push(name)
}
})
if (todoApis.length) {
console.log('\n')
console.warn(`${process.env.UNI_PLATFORM} 平台缺少以下 API 实现(共 ${todoApis.length} 个)`)
todoApis.forEach(name => {
console.warn(name)
})
}
fs.writeFileSync(path.resolve(__dirname, '../packages/uni-' + process.env.UNI_PLATFORM + '/manifest.json'),
JSON.stringify(manifestJson, null, 4)
)
}
}
const path = require('path')
const alias = require('rollup-plugin-alias')
const replace = require('rollup-plugin-replace')
const nodeResolve = require('rollup-plugin-node-resolve')
const commonjs = require('rollup-plugin-commonjs')
const requireContext = require('../lib/rollup-plugin-require-context')
let input = 'src/platforms/app-plus/service/framework/create-instance-context.js'
const output = {
file: 'packages/uni-app-plus-nvue/dist/index.js',
format: 'es'
}
const external = []
if (process.env.UNI_SERVICE === 'legacy') {
input = 'src/platforms/app-plus-nvue/services/index.legacy.js'
output.file = 'packages/uni-app-plus-nvue/dist/index.legacy.js'
} else {
input = 'src/platforms/app-plus/service/index.js'
output.file = 'packages/uni-app-plus-nvue/dist/index.js'
output.format = 'iife'
output.name = 'serviceContext'
output.banner =
`export function createServiceContext(Vue, weex, plus, __uniConfig, __uniRoutes, UniServiceJSBridge,instanceContext){
var localStorage = plus.storage
var setTimeout = instanceContext.setTimeout
var clearTimeout = instanceContext.clearTimeout
var setInterval = instanceContext.setInterval
var clearInterval = instanceContext.clearInterval
`
output.footer =
`
var uni = serviceContext.uni
var getApp = serviceContext.getApp
var getCurrentPages = serviceContext.getCurrentPages
var __registerPage = serviceContext.__registerPage
return serviceContext \n}
`
}
const resolve = dir => path.resolve(__dirname, '../', dir)
module.exports = {
input,
output,
plugins: [
nodeResolve(),
commonjs(),
requireContext(),
alias({
'uni-core': resolve('src/core'),
'uni-platform': resolve('src/platforms/' + process.env.UNI_PLATFORM),
'uni-platforms': resolve('src/platforms'),
'uni-shared': resolve('src/shared/index.js'),
'uni-helpers': resolve('src/core/helpers'),
'uni-invoke-api': resolve('src/platforms/app-plus/service/api'),
'uni-service-api': resolve('src/core/service/platform-api'),
'uni-api-protocol': resolve('src/core/helpers/protocol')
}),
replace({
__GLOBAL__: 'getGlobalUni()',
__PLATFORM__: JSON.stringify('app-plus'),
__PLATFORM_TITLE__: 'app-plus-nvue'
})
],
external
}
......@@ -6,10 +6,10 @@ const PLATFORMS = {
'mp-weixin': {
prefix: 'wx',
title: '微信小程序'
},
'mp-qq': {
prefix: 'wx',
title: 'QQ小程序'
},
'mp-qq': {
prefix: 'wx',
title: 'QQ小程序'
},
'mp-alipay': {
prefix: 'my',
......@@ -40,8 +40,8 @@ module.exports = {
plugins: [
alias({
'uni-shared': path.resolve(__dirname, '../src/shared/util.js'),
'uni-platform': path.resolve(__dirname, '../src/platforms/' + process.env.UNI_PLATFORM),
'uni-wrapper': path.resolve(__dirname, '../src/core/runtime/wrapper'),
'uni-platform': path.resolve(__dirname, '../src/platforms/' + process.env.UNI_PLATFORM),
'uni-wrapper': path.resolve(__dirname, '../src/core/runtime/wrapper'),
'uni-helpers': path.resolve(__dirname, '../src/core/helpers')
}),
replace({
......
const path = require('path')
const alias = require('rollup-plugin-alias')
const replace = require('rollup-plugin-replace')
module.exports = {
input: 'src/platforms/app-plus-nvue/services/index.legacy.js',
output: {
file: `packages/uni-app-plus-nvue/dist/service.legacy.js`,
format: 'es'
},
plugins: [
alias({
'uni-core': path.resolve(__dirname, '../src/core'),
'uni-shared': path.resolve(__dirname, '../src/shared/util.js')
}),
replace({
__GLOBAL__: 'getGlobalUni()',
__PLATFORM_TITLE__: 'app-plus-nvue'
})
]
}
......@@ -29,7 +29,16 @@ module.exports = {
'uni-mixins': resolve('src/core/view/mixins'),
'uni-helpers': resolve('src/core/helpers'),
'uni-platform': resolve('src/platforms/' + process.env.UNI_PLATFORM),
'uni-components': resolve('src/core/view/components')
// tree shaking
'uni-components': resolve('src/core/view/components'),
'uni-invoke-api': resolve('src/platforms/' + process.env.UNI_PLATFORM + '/service/api'),
'uni-service-api': resolve('src/core/service/platform-api'),
'uni-api-protocol': resolve('src/core/helpers/protocol'),
'uni-api-subscribe': resolve('src/core/view/bridge/subscribe/api/index'),
// h5 components
'uni-h5-app-components': resolve('src/platforms/h5/components/app/popup/index'),
'uni-h5-app-mixins': resolve('src/platforms/h5/components/app/popup/mixins/index'),
'uni-h5-system-routes': resolve('src/platforms/h5/components/system-routes/index')
}
},
module: {
......@@ -42,8 +51,8 @@ module.exports = {
}),
new webpack.ProvidePlugin({
'console': [resolve('src/core/helpers/console'), 'default'],
'UniViewJSBridge': [resolve('src/core/view/bridge')],
'UniServiceJSBridge': [resolve('src/core/service/bridge')]
'UniViewJSBridge': [resolve('src/core/view/bridge/index')],
'UniServiceJSBridge': [resolve('src/core/service/bridge/index')]
})
]
}
......@@ -23,7 +23,16 @@ config.resolve.alias = {
'uni-mixins': resolve('src/core/view/mixins'),
'uni-helpers': resolve('src/core/helpers'),
'uni-platform': resolve('src/platforms/' + process.env.UNI_PLATFORM),
'uni-components': resolve('src/core/view/components')
// tree shaking
'uni-components': resolve('src/core/view/components'),
'uni-invoke-api': resolve('src/platforms/' + process.env.UNI_PLATFORM + '/service/api'),
'uni-service-api': resolve('src/core/service/platform-api'),
'uni-api-protocol': resolve('src/core/helpers/protocol'),
'uni-api-subscribe': resolve('src/core/view/bridge/subscribe/api/index'),
// h5 components
'uni-h5-app-components': resolve('src/platforms/h5/components/app/popup/index'),
'uni-h5-app-mixins': resolve('src/platforms/h5/components/app/popup/mixins/index'),
'uni-h5-system-routes': resolve('src/platforms/h5/components/system-routes/index')
}
const isEslintLoader = config.module.rules[config.module.rules.length - 1].enforce
......@@ -41,8 +50,8 @@ config.plugins = config.plugins.concat([
}),
new webpack.ProvidePlugin({
'console': [resolve('src/core/helpers/console'), 'default'],
'UniViewJSBridge': [resolve('src/core/view/bridge')],
'UniServiceJSBridge': [resolve('src/core/service/bridge')]
'UniViewJSBridge': [resolve('src/core/view/bridge/index')],
'UniServiceJSBridge': [resolve('src/core/service/bridge/index')]
})
])
module.exports = config
const base = [
'base64ToArrayBuffer',
'arrayBufferToBase64',
'addInterceptor',
'removeInterceptor'
]
const network = [
'request',
'uploadFile',
'downloadFile',
'connectSocket',
'onSocketOpen',
'onSocketError',
'sendSocketMessage',
'onSocketMessage',
'closeSocket',
'onSocketClose'
]
const route = [
'navigateTo',
'redirectTo',
'reLaunch',
'switchTab',
'navigateBack'
]
const storage = [
'setStorage',
'setStorageSync',
'getStorage',
'getStorageSync',
'getStorageInfo',
'getStorageInfoSync',
'removeStorage',
'removeStorageSync',
'clearStorage',
'clearStorageSync'
]
const location = [
'getLocation',
'chooseLocation',
'openLocation',
'createMapContext'
]
const media = [
'chooseImage',
'previewImage',
'getImageInfo',
'saveImageToPhotosAlbum',
'compressImage',
'getRecorderManager',
'getBackgroundAudioManager',
'createInnerAudioContext',
'chooseVideo',
'saveVideoToPhotosAlbum',
'createVideoContext',
'createCameraContext',
'createLivePlayerContext'
]
const device = [
'getSystemInfo',
'getSystemInfoSync',
'canIUse',
'onMemoryWarning',
'getNetworkType',
'onNetworkStatusChange',
'onAccelerometerChange',
'startAccelerometer',
'stopAccelerometer',
'onCompassChange',
'startCompass',
'stopCompass',
'onGyroscopeChange',
'startGyroscope',
'stopGyroscope',
'makePhoneCall',
'scanCode',
'setClipboardData',
'getClipboardData',
'setScreenBrightness',
'getScreenBrightness',
'setKeepScreenOn',
'onUserCaptureScreen',
'vibrateLong',
'vibrateShort',
'addPhoneContact',
'openBluetoothAdapter',
'startBluetoothDevicesDiscovery',
'onBluetoothDeviceFound',
'stopBluetoothDevicesDiscovery',
'onBluetoothAdapterStateChange',
'getConnectedBluetoothDevices',
'getBluetoothDevices',
'getBluetoothAdapterState',
'closeBluetoothAdapter',
'writeBLECharacteristicValue',
'readBLECharacteristicValue',
'onBLEConnectionStateChange',
'onBLECharacteristicValueChange',
'notifyBLECharacteristicValueChange',
'getBLEDeviceServices',
'getBLEDeviceCharacteristics',
'createBLEConnection',
'closeBLEConnection',
'onBeaconServiceChange',
'onBeaconUpdate',
'getBeacons',
'startBeaconDiscovery',
'stopBeaconDiscovery'
]
const keyboard = [
'hideKeyboard',
'onKeyboardHeightChange'
]
const ui = [
'showToast',
'hideToast',
'showLoading',
'hideLoading',
'showModal',
'showActionSheet',
'setNavigationBarTitle',
'setNavigationBarColor',
'showNavigationBarLoading',
'hideNavigationBarLoading',
'setTabBarItem',
'setTabBarStyle',
'hideTabBar',
'showTabBar',
'setTabBarBadge',
'removeTabBarBadge',
'showTabBarRedDot',
'hideTabBarRedDot',
'setBackgroundColor',
'setBackgroundTextStyle',
'createAnimation',
'pageScrollTo',
'onWindowResize',
'offWindowResize',
'loadFontFace',
'startPullDownRefresh',
'stopPullDownRefresh',
'createSelectorQuery',
'createIntersectionObserver'
]
const event = [
'$emit',
'$on',
'$once',
'$off'
]
const file = [
'saveFile',
'getSavedFileList',
'getSavedFileInfo',
'removeSavedFile',
'getFileInfo',
'openDocument',
'getFileSystemManager'
]
const canvas = [
'createOffscreenCanvas',
'createCanvasContext',
'canvasToTempFilePath',
'canvasPutImageData',
'canvasGetImageData'
]
const third = [
'getProvider',
'login',
'checkSession',
'getUserInfo',
'share',
'showShareMenu',
'hideShareMenu',
'requestPayment',
'subscribePush',
'unsubscribePush',
'onPush',
'offPush',
'requireNativePlugin',
'upx2px'
]
const apis = [
...base,
...network,
...route,
...storage,
...location,
...media,
...device,
...keyboard,
...ui,
...event,
...file,
...canvas,
...third
]
module.exports = apis
const path = require('path')
const isWin = /^win/.test(process.platform)
const normalizePath = path => (isWin ? path.replace(/\\/g, '/') : path)
function resolve(...args) {
return normalizePath(path.resolve.apply(path, [__dirname, ...args]))
}
const srcPath = resolve('../../src/')
const protocolPath = resolve('../../src/core/helpers/protocol')
const coreApiPath = resolve('../../src/core/service/api')
const platformApiPath = resolve('../../src/platforms/' + process.env.UNI_PLATFORM + '/service/api')
const apis = require('../apis')
process.UNI_SERVICE_API_MANIFEST = Object.create(null)
process.UNI_SERVICE_API_PROTOCOL = Object.create(null)
function parseProtocolExport({
file,
exports
}) {
const filepath = file.replace(srcPath, '')
exports.forEach(exportName => {
if (process.UNI_SERVICE_API_PROTOCOL[exportName]) {
console.warn(`API[${exportName}] 冲突:`)
console.warn(process.UNI_SERVICE_API_PROTOCOL[exportName])
console.warn(filepath)
} else {
process.UNI_SERVICE_API_PROTOCOL[exportName] = filepath
}
})
}
function parseApiExport({
file,
methods,
exports,
isPlatform
}) {
const deps = []
methods && methods.forEach(method => {
deps.push(['', method])
})
const filepath = file.replace(srcPath, '')
exports.forEach(exportName => {
if (process.UNI_SERVICE_API_MANIFEST[exportName]) {
console.warn('\n')
console.warn(`API[${exportName}] 冲突:`)
console.warn(process.UNI_SERVICE_API_MANIFEST[exportName][0])
console.warn(filepath)
if (isPlatform) { // 优先使用 platform
process.UNI_SERVICE_API_MANIFEST[exportName] = [filepath, deps]
console.warn(`优先使用` + filepath)
}
} else {
process.UNI_SERVICE_API_MANIFEST[exportName] = [filepath, deps]
}
})
}
function parseExports(node, t, file) {
if (t.isFunctionDeclaration(node)) {
return [node.id.name]
} else if (
t.isVariableDeclaration(node) &&
node.declarations.length === 1
) {
return [node.declarations[0].id.name]
} else if (Array.isArray(node) && node.length) {
return node.map(specifier => {
return specifier.exported.name
})
} else {
console.warn('\n')
console.warn(`${file} 解析 export 失败`, node)
}
}
module.exports = function({
types: t
}) {
return {
visitor: {
Program: {
enter(path, state) {
state.file.opts.file = normalizePath(state.file.opts.filename)
state.file.opts.isCore = state.file.opts.file.indexOf(coreApiPath) === 0
state.file.opts.isPlatform = state.file.opts.file.indexOf(platformApiPath) === 0
state.file.opts.isProtocol = state.file.opts.file.indexOf(protocolPath) === 0
},
exit(path, state) {
const {
exports,
isProtocol
} = state.file.opts
if (exports && exports.length) {
if (isProtocol) {
parseProtocolExport(state.file.opts)
} else {
parseApiExport(state.file.opts)
}
}
}
},
ExportNamedDeclaration(path, state) {
const {
file,
isCore,
isPlatform,
isProtocol
} = state.file.opts
if (isCore || isPlatform || isProtocol) {
const exports = parseExports(path.node.declaration || path.node.specifiers, t, file)
if (Array.isArray(exports)) {
(state.file.opts.exports || (state.file.opts.exports = [])).push(...exports)
}
}
},
CallExpression(path, state) {
const {
file,
isCore,
isPlatform
} = state.file.opts
if (
isCore &&
path.node.callee.name === 'invokeMethod'
) {
(state.file.opts.methods || (state.file.opts.methods = new Set())).add(path.node.arguments[0].value)
}
}
}
}
}
......@@ -17,7 +17,7 @@ const {
default: uni,
getApp,
getCurrentPages
} = require('uni-service')
} = require('uni-platform/service/index')
global.uni = uni
......
[{
"name": "base",
"title": "基础",
"apiList": {
"uni.getSystemInfo": true,
"uni.getSystemInfoSync": true,
"uni.canIUse": true,
"uni.upx2px": true,
"uni.navigateTo": true,
"uni.redirectTo": true,
"uni.switchTab": true,
"uni.reLaunch": true,
"uni.navigateBack": true
}
}, {
"name": "network",
"title": "网络",
"apiList": {
"uni.request": true,
"uni.connectSocket": true,
"uni.sendSocketMessage": true,
"uni.closeSocket": true,
"uni.onSocketOpen": true,
"uni.onSocketError": true,
"uni.onSocketMessage": true,
"uni.onSocketClose": true,
"uni.downloadFile": true,
"uni.uploadFile": true
}
}, {
"name": "storage",
"title": "数据缓存",
"apiList": {
"uni.setStorage": true,
"uni.setStorageSync": true,
"uni.getStorage": true,
"uni.getStorageSync": true,
"uni.removeStorage": true,
"uni.removeStorageSync": true,
"uni.clearStorage": true,
"uni.clearStorageSync": true,
"uni.getStorageInfo": true,
"uni.getStorageInfoSync": true
}
}, {
"name": "location",
"title": "位置",
"apiList": {
"uni.getLocation": true,
"uni.openLocation": true,
"uni.chooseLocation": true
}
}, {
"name": "media",
"title": "媒体",
"apiList": {
"uni.chooseImage": true,
"uni.previewImage": true,
"uni.getImageInfo": true,
"uni.saveImageToPhotosAlbum": true,
"uni.compressImage": true,
"uni.getRecorderManager": true,
"uni.getBackgroundAudioManager": true,
"uni.createInnerAudioContext": true,
"uni.chooseVideo": true,
"uni.saveVideoToPhotosAlbum": true,
"uni.createVideoContext": true,
"uni.createCameraContext": true,
"uni.createLivePlayerContext": true
}
}, {
"name": "device",
"title": "设备",
"apiList": {
"uni.onMemoryWarning": true,
"uni.getNetworkType": true,
"uni.onNetworkStatusChange": true,
"uni.onAccelerometerChange": true,
"uni.startAccelerometer": true,
"uni.stopAccelerometer": true,
"uni.onCompassChange": true,
"uni.startCompass": true,
"uni.stopCompass": true,
"uni.onGyroscopeChange": true,
"uni.startGyroscope": true,
"uni.stopGyroscope": true,
"uni.makePhoneCall": true,
"uni.scanCode": true,
"uni.setClipboardData": true,
"uni.getClipboardData": true,
"uni.setScreenBrightness": true,
"uni.getScreenBrightness": true,
"uni.setKeepScreenOn": true,
"uni.onUserCaptureScreen": true,
"uni.vibrateLong": true,
"uni.vibrateShort": true,
"uni.addPhoneContact": true,
"uni.openBluetoothAdapter": true,
"uni.startBluetoothDevicesDiscovery": true,
"uni.onBluetoothDeviceFound": true,
"uni.stopBluetoothDevicesDiscovery": true,
"uni.onBluetoothAdapterStateChange": true,
"uni.getConnectedBluetoothDevices": true,
"uni.getBluetoothDevices": true,
"uni.getBluetoothAdapterState": true,
"uni.closeBluetoothAdapter": true,
"uni.writeBLECharacteristicValue": true,
"uni.readBLECharacteristicValue": true,
"uni.onBLEConnectionStateChange": true,
"uni.onBLECharacteristicValueChange": true,
"uni.notifyBLECharacteristicValueChange": true,
"uni.getBLEDeviceServices": true,
"uni.getBLEDeviceCharacteristics": true,
"uni.createBLEConnection": true,
"uni.closeBLEConnection": true,
"uni.onBeaconServiceChange": true,
"uni.onBeaconUpdate": true,
"uni.getBeacons": true,
"uni.startBeaconDiscovery": true,
"uni.stopBeaconDiscovery": true
}
}, {
"name": "ui",
"title": "界面",
"apiList": {
"uni.showToast": true,
"uni.hideToast": true,
"uni.showLoading": true,
"uni.hideLoading": true,
"uni.showModal": true,
"uni.showActionSheet": true,
"uni.setNavigationBarTitle": true,
"uni.setNavigationBarColor": true,
"uni.showNavigationBarLoading": true,
"uni.hideNavigationBarLoading": true,
"uni.setTabBarItem": true,
"uni.setTabBarStyle": true,
"uni.hideTabBar": true,
"uni.showTabBar": true,
"uni.setTabBarBadge": true,
"uni.removeTabBarBadge": true,
"uni.showTabBarRedDot": true,
"uni.hideTabBarRedDot": true,
"uni.setBackgroundColor": true,
"uni.setBackgroundTextStyle": true,
"uni.createAnimation": true,
"uni.pageScrollTo": true,
"uni.onWindowResize": true,
"uni.offWindowResize": true,
"uni.loadFontFace": true,
"uni.startPullDownRefresh": true,
"uni.stopPullDownRefresh": true,
"uni.createSelectorQuery": true,
"uni.createIntersectionObserver": true,
"uni.hideKeyboard": true,
"uni.onKeyboardHeightChange": true
}
}, {
"name": "event",
"title": "页面通讯",
"apiList": {
"uni.$emit": true,
"uni.$on": true,
"uni.$once": true,
"uni.$off": true
}
}, {
"name": "file",
"title": "文件",
"apiList": {
"uni.saveFile": true,
"uni.getSavedFileList": true,
"uni.getSavedFileInfo": true,
"uni.removeSavedFile": true,
"uni.getFileInfo": true,
"uni.openDocument": true,
"uni.getFileSystemManager": true
}
}, {
"name": "canvas",
"title": "绘画",
"apiList": {
"uni.createOffscreenCanvas": true,
"uni.createCanvasContext": true,
"uni.canvasToTempFilePath": true,
"uni.canvasPutImageData": true,
"uni.canvasGetImageData": true
}
}, {
"name": "third",
"title": "第三方服务",
"apiList": {
"uni.getProvider": true,
"uni.login": true,
"uni.checkSession": true,
"uni.getUserInfo": true,
"uni.share": true,
"uni.showShareMenu": true,
"uni.hideShareMenu": true,
"uni.requestPayment": true,
"uni.subscribePush": true,
"uni.unsubscribePush": true,
"uni.onPush": true,
"uni.offPush": true,
"uni.requireNativePlugin": true,
"uni.base64ToArrayBuffer": true,
"uni.arrayBufferToBase64": true
}
}]
# rollup-plugin-require-context
rollup plugin for resovling webpack require-context.
## usage
```javascript
import requireContext from 'rollup-plugin-require-context';
export default {
input: 'main.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
requireContext()
]
};
```
{
"name": "rollup-plugin-require-context",
"version": "1.0.0",
"description": "rollup-plugin for webpack requrie-context",
"main": "src/index.js",
"scripts": {
"brk": "node --inspect-brk example/run.js",
"example": "rollup -c example/rollup.config.js",
"test:dev": "jest --watchAll"
},
"repository": {
"type": "git",
"url": "git+https://github.com/elcarim5efil/rollup-plugin-require-context.git"
},
"keywords": [
"rollup",
"plugin",
"require-context",
"webpack-context"
],
"author": "elcarim5efil",
"license": "MIT",
"bugs": {
"url": "https://github.com/elcarim5efil/rollup-plugin-require-context/issues"
},
"homepage": "https://github.com/elcarim5efil/rollup-plugin-require-context#readme",
"dependencies": {
"acorn": "^6.1.1",
"acorn-dynamic-import": "^4.0.0",
"acorn-walk": "^6.1.1",
"rollup-pluginutils": "^2.5.0"
},
"devDependencies": {
"jest": "^24.5.0",
"rollup": "^1.7.4",
"rollup-plugin-virtual": "^1.0.1"
}
}
const Path = require('path')
const { parse } = require('acorn')
const walk = require('acorn-walk')
function stripHeadAndTailChar (str) {
return str.substring(1, str.length - 1)
}
function extract (code) {
return new Promise((resolve, reject) => {
const ast = parse(code, {
sourceType: 'module'
})
const res = []
walk.simple(ast, {
CallExpression (node) {
const {
start,
end,
callee,
arguments: argNodes
} = node
let args = []
if (
callee.type === 'MemberExpression' &&
callee.object.name === 'require' &&
callee.property.name === 'context'
) {
args = argNodes.map(a => a.value)
res.push({
start,
end,
args
})
}
}
})
resolve(res)
})
}
module.exports = async function extractArgs (code, baseDirname) {
const data = await extract(code)
return data.map(r => {
const { start, end, args } = r
const [
rawDirname = '',
rawRecursive,
rawRegexp
] = args
const dirname = Path.join(baseDirname, rawDirname)
const recursive = rawRecursive
const regexp = rawRegexp
return {
dirname,
recursive,
regexp,
start,
end
}
})
}
const Path = require('path')
const extractArgs = require('./extract-args')
const resolveRequireModules = require('./resolve-reqquire-modules')
const resolveRequireCode = require('./resolve-require-code')
module.exports = async function gernerateRequireContextCode (id, code) {
const currentCodeDirname = Path.dirname(id)
const data = await extractArgs(code, currentCodeDirname)
let head = ''
const body = data.reduceRight((res, r) => {
const {
start, end,
dirname, recursive, regexp
} = r
const modules = resolveRequireModules(dirname, recursive, regexp)
const moduleCode = resolveRequireCode(dirname, modules)
const {
importCode,
requireFnCode
} = moduleCode
head += importCode
res = [
res.slice(0, start),
requireFnCode,
res.slice(end)
].join('')
return res
}, code)
return [
head,
body
].join('\n')
}
module.exports = function hasRequireContext (code) {
return /require\.context/g.test(code)
}
const fs = require('fs')
const Path = require('path')
function readDirRecursive (dir) {
return fs.statSync(dir).isDirectory()
? Array.prototype.concat(
...fs.readdirSync(dir).map(f => readDirRecursive(Path.join(dir, f)))
)
: dir
}
function readDir (dir, recursive) {
const isDirectory = fs.statSync(dir).isDirectory()
if (recursive) {
return readDirRecursive(dir)
} else if (isDirectory) {
const files = fs.readdirSync(dir)
if (files) {
return files.map(file => Path.resolve(dir, file))
}
} else {
return [ dir ]
}
}
module.exports = function resolveRequireModules (baseDirname = './', recursive = false, regexp = /^\.\//) {
let files = readDir(baseDirname, recursive)
if (!Array.isArray(files)) {
files = [files]
}
files = files.map(file => {
const fileAbsolutePath = `./${Path.relative(baseDirname, file)}`
return fileAbsolutePath
})
return files.filter(file => regexp.test(file.replace(/\\/g, '/')))
}
const Path = require('path')
let uid = 0
function getUID () {
return uid++
}
function genImportCode (name, path) {
return `import * as ${name} from '${path}';\n`
}
function genPropsCode (key, value) {
return `'${key}': ${value},\n`
}
module.exports = function genRequireCode (baseDirname, modules) {
const uid = getUID()
let importCode = ''
let moduleProps = ''
modules.forEach((file, index) => {
const moduleName = `require_context_module_${uid}_${index}`
const moduleAbsolutePath = Path.resolve(baseDirname, file).replace(/\\/g, '/')
importCode += genImportCode(moduleName, moduleAbsolutePath)
moduleProps += genPropsCode(file, moduleName)
})
const requireFnCode = (`
(function() {
var map = {
${moduleProps}
};
var req = function req(key) {
return map[key] || (function() { throw new Error("Cannot find module '" + key + "'.") }());
}
req.keys = function() {
return Object.keys(map);
}
return req;
})()
`)
return {
importCode,
requireFnCode
}
}
const _ = require('rollup-pluginutils')
const hasRequireContext = require('./helper/has-require-context')
const gernerateRequireContextCode = require('./helper/generate-require-context-code')
module.exports = function plugin (options = {}) {
const filter = _.createFilter(options.include || ['**/*.js'], options.exclude || 'node_modules/**')
return {
name: 'require_content',
async transform (code, id) {
if (!filter(id) || !hasRequireContext(code)) {
return
}
code = await gernerateRequireContextCode(id, code)
return code
}
}
}
{
"name": "uniapp-js-framework",
"version": "0.0.1",
"scripts": {
"lint": "eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore build src",
"dev:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.js",
"build:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.js",
"build:app-plus": "cross-env UNI_PLATFORM=app-plus rollup -c build/rollup.config.js",
"build:service:legacy": "npm run lint && rollup -c build/rollup.config.service.js",
"build:mp-qq": "cross-env UNI_PLATFORM=mp-qq rollup -c build/rollup.config.js",
"build:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin rollup -c build/rollup.config.js",
"build:mp-baidu": "cross-env UNI_PLATFORM=mp-baidu rollup -c build/rollup.config.js",
"build:mp-alipay": "cross-env UNI_PLATFORM=mp-alipay rollup -c build/rollup.config.js",
"build:mp-toutiao": "cross-env UNI_PLATFORM=mp-toutiao rollup -c build/rollup.config.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",
"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"
"name": "uniapp-js-framework",
"version": "0.0.1",
"scripts": {
"lint": "eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore build src",
"dev:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.js",
"build:h5": "npm run lint && cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.js",
"build:app-plus": "cross-env UNI_PLATFORM=app-plus rollup -c build/rollup.config.mp.js",
"build:app:all": "npm run lint && npm run build:app:nvue && npm run build:app:legacy",
"build:app:nvue": "cross-env UNI_PLATFORM=app-plus-nvue rollup -c build/rollup.config.app.js",
"build:app:legacy": "cross-env UNI_PLATFORM=app-plus-nvue UNI_SERVICE=legacy rollup -c build/rollup.config.app.js",
"build:mp-qq": "cross-env UNI_PLATFORM=mp-qq rollup -c build/rollup.config.mp.js",
"build:mp-weixin": "cross-env UNI_PLATFORM=mp-weixin rollup -c build/rollup.config.mp.js",
"build:mp-baidu": "cross-env UNI_PLATFORM=mp-baidu rollup -c build/rollup.config.mp.js",
"build:mp-alipay": "cross-env UNI_PLATFORM=mp-alipay rollup -c build/rollup.config.mp.js",
"build:mp-toutiao": "cross-env UNI_PLATFORM=mp-toutiao 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",
"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"
},
"dependencies": {
"base64-arraybuffer": "^0.2.0",
"intersection-observer": "^0.7.0"
},
"private": true,
"devDependencies": {
"@vue/cli-plugin-babel": "^3.4.1",
"@vue/cli-plugin-eslint": "^3.4.1",
"@vue/cli-plugin-unit-mocha": "^3.4.1",
"@vue/cli-service": "^3.4.1",
"@vue/test-utils": "^1.0.0-beta.25",
"babel-eslint": "^10.0.1",
"babylon": "^6.18.0",
"browserslist": "^4.4.2",
"caniuse-lite": "^1.0.30000940",
"chai": "^4.1.2",
"copy": "^0.3.2",
"cross-env": "^5.2.0",
"del": "^5.0.0",
"eslint": "^5.5.0",
"eslint-config-standard": "^12.0.0",
"eslint-loader": "^2.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.0",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^4.7.1",
"jsdom": "^13.0.0",
"jsdom-global": "^3.0.2",
"jsonfile": "^5.0.0",
"rollup": "^1.17.0",
"rollup-plugin-alias": "^1.4.0",
"rollup-plugin-commonjs": "^10.0.1",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-replace": "^2.1.0",
"strip-json-comments": "^2.0.1",
"vue": "^2.6.8",
"vue-router": "^3.0.1",
"vue-template-compiler": "^2.6.8",
"webpack": "^4.18.0",
"webpack-bundle-analyzer": "^3.0.3",
"webpack-virtual-modules": "^0.1.10"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"dependencies": {
"base64-arraybuffer": "^0.2.0",
"intersection-observer": "^0.7.0"
},
"private": true,
"devDependencies": {
"@vue/cli-plugin-babel": "^3.4.1",
"@vue/cli-plugin-eslint": "^3.4.1",
"@vue/cli-plugin-unit-mocha": "^3.4.1",
"@vue/cli-service": "^3.4.1",
"@vue/test-utils": "^1.0.0-beta.25",
"babel-eslint": "^10.0.1",
"babylon": "^6.18.0",
"browserslist": "^4.4.2",
"caniuse-lite": "^1.0.30000940",
"chai": "^4.1.2",
"copy": "^0.3.2",
"cross-env": "^5.2.0",
"del": "^5.0.0",
"eslint": "^5.5.0",
"eslint-config-standard": "^12.0.0",
"eslint-loader": "^2.1.0",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-node": "^7.0.1",
"eslint-plugin-promise": "^4.0.0",
"eslint-plugin-standard": "^4.0.0",
"eslint-plugin-vue": "^4.7.1",
"jsdom": "^13.0.0",
"jsdom-global": "^3.0.2",
"jsonfile": "^5.0.0",
"rollup": "^0.67.4",
"rollup-plugin-alias": "^1.4.0",
"rollup-plugin-replace": "^2.1.0",
"strip-json-comments": "^2.0.1",
"vue": "^2.6.8",
"vue-router": "^3.0.1",
"vue-template-compiler": "^2.6.8",
"webpack": "^4.18.0",
"webpack-bundle-analyzer": "^3.3.2",
"webpack-virtual-modules": "^0.1.10"
"extends": [
"plugin:vue/recommended",
"standard"
],
"globals": {
"App": true,
"Page": true,
"Component": true,
"Behavior": true,
"getApp": true,
"getCurrentPages": true,
"plus": true,
"uni": true,
"Vue": true,
"wx": true,
"my": true,
"swan": true,
"weex": true,
"__id__": true,
"__uniConfig": true,
"__uniRoutes": true,
"__registerPage": true,
"UniViewJSBridge": true,
"UniServiceJSBridge": true,
"__PLATFORM__": true,
"__VERSION__": true,
"__GLOBAL__": true,
"__PLATFORM_TITLE__": true,
"__PLATFORM_PREFIX__": true
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/recommended",
"standard"
],
"globals": {
"App": true,
"Page": true,
"Component": true,
"Behavior": true,
"getApp": true,
"getCurrentPages": true,
"plus": true,
"uni": true,
"Vue": true,
"wx": true,
"my": true,
"swan": true,
"__uniConfig": true,
"__uniRoutes": true,
"UniViewJSBridge": true,
"UniServiceJSBridge": true,
"__PLATFORM__": true,
"__VERSION__": true,
"__GLOBAL__": true,
"__PLATFORM_TITLE__": true,
"__PLATFORM_PREFIX__": true
},
"rules": {
"no-tabs": 0,
"standard/no-callback-literal": 0
},
"parserOptions": {
"parser": "babel-eslint"
}
"rules": {
"no-tabs": 0,
"standard/no-callback-literal": 0
},
"browserslist": [
"last 3 versions",
"Android >= 4.1",
"ios >= 8"
],
"license": "Apache-2.0",
"main": "index.js",
"description": "",
"author": ""
}
"parserOptions": {
"parser": "babel-eslint"
}
},
"browserslist": [
"last 3 versions",
"Android >= 4.1",
"ios >= 8"
],
"license": "Apache-2.0",
"main": "index.js",
"description": "",
"author": ""
}
let supportsPassive = false;
try {
const opts = {};
Object.defineProperty(opts, 'passive', ({
get () {
/* istanbul ignore next */
supportsPassive = true;
}
})); // https://github.com/facebook/flow/issues/285
window.addEventListener('test-passive', null, opts);
} catch (e) {}
const hasOwnProperty = Object.prototype.hasOwnProperty;
function isFn (fn) {
......@@ -8,7 +20,109 @@ function hasOwn (obj, key) {
return hasOwnProperty.call(obj, key)
}
const SYNC_API_RE = /^\$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const globalInterceptors = {};
const scopedInterceptors = {};
function wrapperHook (hook) {
return function (data) {
return hook(data) || data
}
}
function isPromise (obj) {
return !!obj && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function'
}
function queue (hooks, data) {
let promise = false;
for (let i = 0; i < hooks.length; i++) {
const hook = hooks[i];
if (promise) {
promise = Promise.then(wrapperHook(hook));
} else {
const res = hook(data);
if (isPromise(res)) {
promise = Promise.resolve(res);
}
if (res === false) {
return {
then () {}
}
}
}
}
return promise || {
then (callback) {
return callback(data)
}
}
}
function wrapperOptions (interceptor, options = {}) {
['success', 'fail', 'complete'].forEach(name => {
if (Array.isArray(interceptor[name])) {
const oldCallback = options[name];
options[name] = function callbackInterceptor (res) {
queue(interceptor[name], res).then((res) => {
/* eslint-disable no-mixed-operators */
return isFn(oldCallback) && oldCallback(res) || res
});
};
}
});
return options
}
function wrapperReturnValue (method, returnValue) {
const returnValueHooks = [];
if (Array.isArray(globalInterceptors.returnValue)) {
returnValueHooks.push(...globalInterceptors.returnValue);
}
const interceptor = scopedInterceptors[method];
if (interceptor && Array.isArray(interceptor.returnValue)) {
returnValueHooks.push(...interceptor.returnValue);
}
returnValueHooks.forEach(hook => {
returnValue = hook(returnValue) || returnValue;
});
return returnValue
}
function getApiInterceptorHooks (method) {
const interceptor = Object.create(null);
Object.keys(globalInterceptors).forEach(hook => {
if (hook !== 'returnValue') {
interceptor[hook] = globalInterceptors[hook].slice();
}
});
const scopedInterceptor = scopedInterceptors[method];
if (scopedInterceptor) {
Object.keys(scopedInterceptor).forEach(hook => {
if (hook !== 'returnValue') {
interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook]);
}
});
}
return interceptor
}
function invokeApi (method, api, options, ...params) {
const interceptor = getApiInterceptorHooks(method);
if (interceptor && Object.keys(interceptor).length) {
if (Array.isArray(interceptor.invoke)) {
const res = queue(interceptor.invoke, options);
return res.then((options) => {
return api(wrapperOptions(interceptor, options), ...params)
})
} else {
return api(wrapperOptions(interceptor, options), ...params)
}
}
return api(options, ...params)
}
const SYNC_API_RE =
/^\$|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
......@@ -35,8 +149,8 @@ function handlePromise (promise) {
function shouldPromise (name) {
if (
isContextApi(name) ||
isSyncApi(name) ||
isCallbackApi(name)
isSyncApi(name) ||
isCallbackApi(name)
) {
return false
}
......@@ -49,10 +163,10 @@ function promisify (name, api) {
}
return function promiseApi (options = {}, ...params) {
if (isFn(options.success) || isFn(options.fail) || isFn(options.complete)) {
return api(options, ...params)
return wrapperReturnValue(name, invokeApi(name, api, options, ...params))
}
return handlePromise(new Promise((resolve, reject) => {
api(Object.assign({}, options, {
return wrapperReturnValue(name, handlePromise(new Promise((resolve, reject) => {
invokeApi(name, api, Object.assign({}, options, {
success: resolve,
fail: reject
}), ...params);
......@@ -68,132 +182,27 @@ function promisify (name, api) {
)
};
}
}))
})))
}
}
const SUCCESS = 'success';
const FAIL = 'fail';
const COMPLETE = 'complete';
const CALLBACKS = [SUCCESS, FAIL, COMPLETE];
const UNIAPP_SERVICE_NVUE_ID = '__uniapp__service';
function noop$1 () {
}
/**
* 调用无参数,或仅一个参数且为 callback 的 API
* @param {Object} vm
* @param {Object} method
* @param {Object} args
* @param {Object} extras
*/
function invokeVmMethodWithoutArgs (vm, method, args, extras) {
if (!vm) {
return
}
if (typeof args === 'undefined') {
return vm[method]()
}
const [, callbacks] = normalizeArgs(args, extras);
if (!Object.keys(callbacks).length) {
return vm[method]()
}
return vm[method](normalizeCallback(method, callbacks))
}
/**
* 调用两个参数(第一个入参为普通参数,第二个入参为 callback) API
* @param {Object} vm
* @param {Object} method
* @param {Object} args
* @param {Object} extras
*/
function invokeVmMethod (vm, method, args, extras) {
if (!vm) {
return
}
const [pureArgs, callbacks] = normalizeArgs(args, extras);
if (!Object.keys(callbacks).length) {
return vm[method](pureArgs)
}
return vm[method](pureArgs, normalizeCallback(method, callbacks))
}
function findRefById (id, vm) {
return findRefByVNode(id, vm._vnode)
}
function findRefByVNode (id, vnode) {
if (!id || !vnode) {
return
}
if (vnode.data &&
vnode.data.ref &&
vnode.data.attrs &&
vnode.data.attrs.id === id) {
return vnode.data.ref
}
const children = vnode.children;
if (!children) {
return
}
for (let i = 0, len = children.length; i < len; i++) {
const ref = findRefByVNode(id, children[i]);
if (ref) {
return ref
function initPostMessage (nvue) {
const plus = nvue.requireModule('plus');
return {
postMessage (data) {
plus.postMessage(data, UNIAPP_SERVICE_NVUE_ID);
}
}
}
function normalizeArgs (args = {}, extras) {
const callbacks = Object.create(null);
const iterator = function iterator (name) {
const callback = args[name];
if (isFn(callback)) {
callbacks[name] = callback;
delete args[name];
}
};
CALLBACKS.forEach(iterator);
extras && extras.forEach(iterator);
return [args, callbacks]
}
function normalizeCallback (method, callbacks) {
return function weexCallback (ret) {
const type = ret.type;
delete ret.type;
const callback = callbacks[type];
if (type === SUCCESS) {
ret.errMsg = `${method}:ok`;
} else if (type === FAIL) {
ret.errMsg = method + ':fail' + (ret.msg ? (' ' + ret.msg) : '');
}
delete ret.code;
delete ret.msg;
isFn(callback) && callback(ret);
if (type === SUCCESS || type === FAIL) {
const complete = callbacks['complete'];
isFn(complete) && complete(ret);
}
}
}
function initSubNVue (nvue, plus, BroadcastChannel) {
function initSubNVue (nvue, plus, BroadcastChannel) {
let origin;
const onMessageCallbacks = [];
const postMessage = nvue.requireModule('plus').postMessage;
const postMessage = nvue.requireModule('plus').postMessage;
const onSubNVueMessage = function onSubNVueMessage (data) {
onMessageCallbacks.forEach(callback => callback({
......@@ -278,14 +287,14 @@ function initSubNVue (nvue, plus, BroadcastChannel) {
closeMask();
return oldClose.apply(webview, args)
};
};
const getSubNVueById = function getSubNVueById (id) {
const webview = plus.webview.getWebviewById(id);
if (webview && !webview.$processed) {
wrapper(webview);
}
return webview
};
const getSubNVueById = function getSubNVueById (id) {
const webview = plus.webview.getWebviewById(id);
if (webview && !webview.$processed) {
wrapper(webview);
}
return webview
};
return {
......@@ -296,21 +305,14 @@ function initSubNVue (nvue, plus, BroadcastChannel) {
}
}
function initPostMessage (nvue) {
const plus = nvue.requireModule('plus');
return {
postMessage (data) {
plus.postMessage(data, UNIAPP_SERVICE_NVUE_ID);
}
}
}
function noop () {}
function initTitleNView (nvue) {
const eventMaps = {
onNavigationBarButtonTap: noop$1,
onNavigationBarSearchInputChanged: noop$1,
onNavigationBarSearchInputConfirmed: noop$1,
onNavigationBarSearchInputClicked: noop$1
onNavigationBarButtonTap: noop,
onNavigationBarSearchInputChanged: noop,
onNavigationBarSearchInputConfirmed: noop,
onNavigationBarSearchInputClicked: noop
};
nvue.requireModule('globalEvent').addEventListener('plusMessage', e => {
if (eventMaps[e.data.type]) {
......@@ -383,6 +385,114 @@ function initEventBus (getGlobalEmitter) {
getEmitter = getGlobalEmitter;
}
const SUCCESS = 'success';
const FAIL = 'fail';
const COMPLETE = 'complete';
const CALLBACKS = [SUCCESS, FAIL, COMPLETE];
/**
* 调用无参数,或仅一个参数且为 callback 的 API
* @param {Object} vm
* @param {Object} method
* @param {Object} args
* @param {Object} extras
*/
function invokeVmMethodWithoutArgs (vm, method, args, extras) {
if (!vm) {
return
}
if (typeof args === 'undefined') {
return vm[method]()
}
const [, callbacks] = normalizeArgs(args, extras);
if (!Object.keys(callbacks).length) {
return vm[method]()
}
return vm[method](normalizeCallback(method, callbacks))
}
/**
* 调用两个参数(第一个入参为普通参数,第二个入参为 callback) API
* @param {Object} vm
* @param {Object} method
* @param {Object} args
* @param {Object} extras
*/
function invokeVmMethod (vm, method, args, extras) {
if (!vm) {
return
}
const [pureArgs, callbacks] = normalizeArgs(args, extras);
if (!Object.keys(callbacks).length) {
return vm[method](pureArgs)
}
return vm[method](pureArgs, normalizeCallback(method, callbacks))
}
function findElmById (id, vm) {
return findRefByElm(id, vm.$el)
}
function findRefByElm (id, elm) {
if (!id || !elm) {
return
}
if (elm.attr.id === id) {
return elm
}
const children = elm.children;
if (!children) {
return
}
for (let i = 0, len = children.length; i < len; i++) {
const elm = findRefByElm(id, children[i]);
if (elm) {
return elm
}
}
}
function normalizeArgs (args = {}, extras) {
const callbacks = Object.create(null);
const iterator = function iterator (name) {
const callback = args[name];
if (isFn(callback)) {
callbacks[name] = callback;
delete args[name];
}
};
CALLBACKS.forEach(iterator);
extras && extras.forEach(iterator);
return [args, callbacks]
}
function normalizeCallback (method, callbacks) {
return function weexCallback (ret) {
const type = ret.type;
delete ret.type;
const callback = callbacks[type];
if (type === SUCCESS) {
ret.errMsg = `${method}:ok`;
} else if (type === FAIL) {
ret.errMsg = method + ':fail' + (ret.msg ? (' ' + ret.msg) : '');
}
delete ret.code;
delete ret.msg;
isFn(callback) && callback(ret);
if (type === SUCCESS || type === FAIL) {
const complete = callbacks['complete'];
isFn(complete) && complete(ret);
}
}
}
class MapContext {
constructor (id, ctx) {
this.id = id;
......@@ -415,66 +525,72 @@ class MapContext {
}
function createMapContext (id, vm) {
const ref = findRefById(id, vm);
if (!ref) {
global.nativeLog('Can not find `' + id + '`', '__WARN');
if (!vm) {
return console.warn('uni.createMapContext 必须传入第二个参数,即当前 vm 对象(this)')
}
return new MapContext(id, vm.$refs[ref])
}
class VideoContext {
constructor (id, ctx) {
this.id = id;
this.ctx = ctx;
}
play () {
return invokeVmMethodWithoutArgs(this.ctx, 'play')
}
pause () {
return invokeVmMethodWithoutArgs(this.ctx, 'pause')
}
seek (args) {
return invokeVmMethod(this.ctx, 'seek', args)
}
stop () {
return invokeVmMethodWithoutArgs(this.ctx, 'stop')
}
sendDanmu (args) {
return invokeVmMethod(this.ctx, 'sendDanmu', args)
}
playbackRate (args) {
return invokeVmMethod(this.ctx, 'playbackRate', args)
}
requestFullScreen (args) {
return invokeVmMethod(this.ctx, 'requestFullScreen', args)
}
exitFullScreen () {
return invokeVmMethodWithoutArgs(this.ctx, 'exitFullScreen')
}
showStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'showStatusBar')
}
hideStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'hideStatusBar')
}
const elm = findElmById(id, vm);
if (!elm) {
return console.warn('Can not find `' + id + '`')
}
return new MapContext(id, elm)
}
function createVideoContext (id, vm) {
const ref = findRefById(id, vm);
if (!ref) {
global.nativeLog('Can not find `' + id + '`', '__WARN');
}
return new VideoContext(id, vm.$refs[ref])
class VideoContext {
constructor (id, ctx) {
this.id = id;
this.ctx = ctx;
}
play () {
return invokeVmMethodWithoutArgs(this.ctx, 'play')
}
pause () {
return invokeVmMethodWithoutArgs(this.ctx, 'pause')
}
seek (args) {
return invokeVmMethod(this.ctx, 'seek', args)
}
stop () {
return invokeVmMethodWithoutArgs(this.ctx, 'stop')
}
sendDanmu (args) {
return invokeVmMethod(this.ctx, 'sendDanmu', args)
}
playbackRate (args) {
return invokeVmMethod(this.ctx, 'playbackRate', args)
}
requestFullScreen (args) {
return invokeVmMethod(this.ctx, 'requestFullScreen', args)
}
exitFullScreen () {
return invokeVmMethodWithoutArgs(this.ctx, 'exitFullScreen')
}
showStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'showStatusBar')
}
hideStatusBar () {
return invokeVmMethodWithoutArgs(this.ctx, 'hideStatusBar')
}
}
function createVideoContext (id, vm) {
if (!vm) {
return console.warn('uni.createVideoContext 必须传入第二个参数,即当前 vm 对象(this)')
}
const elm = findElmById(id, vm);
if (!elm) {
return console.warn('Can not find `' + id + '`')
}
return new VideoContext(id, elm)
}
class LivePusherContext {
......@@ -493,10 +609,10 @@ class LivePusherContext {
pause (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'pause', cbs)
}
resume (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'resume', cbs)
}
resume (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'resume', cbs)
}
switchCamera (cbs) {
......@@ -510,42 +626,45 @@ class LivePusherContext {
toggleTorch (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'toggleTorch', cbs)
}
playBGM (args) {
return invokeVmMethod(this.ctx, 'playBGM', args)
}
stopBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'stopBGM', cbs)
}
pauseBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'pauseBGM', cbs)
}
resumeBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'resumeBGM', cbs)
}
setBGMVolume (cbs) {
return invokeVmMethod(this.ctx, 'setBGMVolume', cbs)
}
startPreview (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'startPreview', cbs)
playBGM (args) {
return invokeVmMethod(this.ctx, 'playBGM', args)
}
stopBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'stopBGM', cbs)
}
pauseBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'pauseBGM', cbs)
}
resumeBGM (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'resumeBGM', cbs)
}
setBGMVolume (cbs) {
return invokeVmMethod(this.ctx, 'setBGMVolume', cbs)
}
startPreview (cbs) {
return invokeVmMethodWithoutArgs(this.ctx, 'startPreview', cbs)
}
stopPreview (args) {
return invokeVmMethodWithoutArgs(this.ctx, 'stopPreview', args)
}
}
}
function createLivePusherContext (id, vm) {
const ref = findRefById(id, vm);
if (!ref) {
global.nativeLog('Can not find `' + id + '`', '__WARN');
if (!vm) {
return console.warn('uni.createLivePusherContext 必须传入第二个参数,即当前 vm 对象(this)')
}
return new LivePusherContext(id, vm.$refs[ref])
const elm = findElmById(id, vm);
if (!elm) {
return console.warn('Can not find `' + id + '`')
}
return new LivePusherContext(id, elm)
}
......@@ -576,6 +695,9 @@ function initUni (uni, nvue, plus, BroadcastChannel) {
if (typeof Proxy !== 'undefined') {
return new Proxy({}, {
get (target, name) {
if (target[name]) {
return target[name]
}
if (apis[name]) {
return apis[name]
}
......@@ -586,6 +708,9 @@ function initUni (uni, nvue, plus, BroadcastChannel) {
return
}
return promisify(name, uni[name])
},
set (target, name, value) {
target[name] = value;
}
})
}
......@@ -609,48 +734,36 @@ let getGlobalApp;
let getGlobalUniEmitter;
let getGlobalCurrentPages;
var index_legacy = {
create (id, env, config) {
return {
initUniApp ({
nvue,
getUni,
getApp,
getUniEmitter,
getCurrentPages
}) {
getGlobalUni = getUni;
getGlobalApp = getApp;
getGlobalUniEmitter = getUniEmitter;
getGlobalCurrentPages = getCurrentPages;
initUpx2px(nvue);
initEventBus(getUniEmitter);
},
instance: {
getUni (nvue, plus, BroadcastChannel) {
return initUni(getGlobalUni(), nvue, plus, BroadcastChannel)
},
getApp () {
return getGlobalApp()
},
getUniEmitter () {
return getGlobalUniEmitter()
},
getCurrentPages () {
return getGlobalCurrentPages()
}
}
function createInstanceContext () {
return {
initUniApp ({
nvue,
getUni,
getApp,
getUniEmitter,
getCurrentPages
}) {
getGlobalUni = getUni;
getGlobalApp = getApp;
getGlobalUniEmitter = getUniEmitter;
getGlobalCurrentPages = getCurrentPages;
initUpx2px(nvue);
initEventBus(getUniEmitter);
},
getUni (nvue, plus, BroadcastChannel) {
return initUni(getGlobalUni(), nvue, plus, BroadcastChannel)
},
getApp () {
return getGlobalApp()
},
getUniEmitter () {
return getGlobalUniEmitter()
},
getCurrentPages () {
return getGlobalCurrentPages()
}
},
refresh: function (id, env, config) {
},
destroy: function (id, env) {
}
};
}
export default index_legacy;
export { createInstanceContext };
......@@ -231,7 +231,7 @@ const promiseInterceptor = {
};
const SYNC_API_RE =
/^\$|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
/^\$|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
......@@ -258,8 +258,8 @@ function handlePromise (promise) {
function shouldPromise (name) {
if (
isContextApi(name) ||
isSyncApi(name) ||
isCallbackApi(name)
isSyncApi(name) ||
isCallbackApi(name)
) {
return false
}
......@@ -491,8 +491,6 @@ function $emit () {
return apply(getEmitter(), '$emit', [...arguments])
}
var eventApi = /*#__PURE__*/Object.freeze({
$on: $on,
$off: $off,
......@@ -653,8 +651,8 @@ function hasHook (hook, vueOptions) {
return true
}
if (vueOptions.super &&
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
return true
}
return false
......@@ -679,14 +677,14 @@ function initHooks (mpOptions, hooks, vueOptions) {
});
}
function initVueComponent (Vue$$1, vueOptions) {
function initVueComponent (Vue, vueOptions) {
vueOptions = vueOptions.default || vueOptions;
let VueComponent;
if (isFn(vueOptions)) {
VueComponent = vueOptions;
vueOptions = VueComponent.extendOptions;
} else {
VueComponent = Vue$$1.extend(vueOptions);
VueComponent = Vue.extend(vueOptions);
}
return [VueComponent, vueOptions]
}
......@@ -853,7 +851,7 @@ function initProperties (props, isBehavior = false, file = '') {
value = value();
}
opts.type = parsePropType(key, opts.type, value, file);
opts.type = parsePropType(key, opts.type);
properties[key] = {
type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
......@@ -861,7 +859,7 @@ function initProperties (props, isBehavior = false, file = '') {
observer: createObserver(key)
};
} else { // content:String
const type = parsePropType(key, opts, null, file);
const type = parsePropType(key, opts);
properties[key] = {
type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
observer: createObserver(key)
......@@ -936,16 +934,16 @@ function processEventExtra (vm, extra, event) {
if (Array.isArray(extra) && extra.length) {
/**
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
extra.forEach((dataPath, index) => {
if (typeof dataPath === 'string') {
if (!dataPath) { // model,prop.sync
......@@ -981,8 +979,8 @@ function processEventArgs (vm, event, args = [], extra = [], isCustom, methodNam
let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
if (isCustom) { // 自定义事件
isCustomMPEvent = event.currentTarget &&
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
if (!args.length) { // 无参数,直接传入 event 或 detail 数组
if (isCustomMPEvent) {
return [event]
......@@ -1024,30 +1022,33 @@ const CUSTOM = '^';
function isMatchEventType (eventType, optType) {
return (eventType === optType) ||
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
}
function handleEvent (event) {
event = wrapper$2(event);
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
}
const eventOpts = dataset.eventOpts || dataset['event-opts'];// 支付宝 web-view 组件 dataset 非驼峰
const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
if (!eventOpts) {
return console.warn(`事件信息不存在`)
}
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
const eventType = event.type;
const ret = [];
eventOpts.forEach(eventOpt => {
let type = eventOpt[0];
const eventsArray = eventOpt[1];
......@@ -1064,8 +1065,8 @@ function handleEvent (event) {
let handlerCtx = this.$vm;
if (
handlerCtx.$options.generic &&
handlerCtx.$parent &&
handlerCtx.$parent.$parent
handlerCtx.$parent &&
handlerCtx.$parent.$parent
) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
handlerCtx = handlerCtx.$parent.$parent;
}
......@@ -1079,18 +1080,26 @@ function handleEvent (event) {
}
handler.once = true;
}
handler.apply(handlerCtx, processEventArgs(
ret.push(handler.apply(handlerCtx, processEventArgs(
this.$vm,
event,
eventArray[1],
eventArray[2],
isCustom,
methodName
));
)));
}
});
}
});
if (
eventType === 'input' &&
ret.length === 1 &&
typeof ret[0] !== 'undefined'
) {
return ret[0]
}
}
const hooks = [
......@@ -1257,8 +1266,8 @@ function createApp (vm) {
}
function parseBaseComponent (vueComponentOptions, {
isPage: isPage$$1,
initRelation: initRelation$$1
isPage,
initRelation
} = {}) {
let [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
......@@ -1275,7 +1284,7 @@ function parseBaseComponent (vueComponentOptions, {
const properties = this.properties;
const options = {
mpType: isPage$$1.call(this) ? 'page' : 'component',
mpType: isPage.call(this) ? 'page' : 'component',
mpInstance: this,
propsData: properties
};
......@@ -1283,7 +1292,7 @@ function parseBaseComponent (vueComponentOptions, {
initVueIds(properties.vueId, this);
// 处理父子关系
initRelation$$1.call(this, {
initRelation.call(this, {
vuePid: this._$vuePid,
vueOptions: options
});
......@@ -1327,7 +1336,7 @@ function parseBaseComponent (vueComponentOptions, {
}
};
if (isPage$$1) {
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
......@@ -1361,10 +1370,7 @@ function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent$1(vuePageOptions, {
isPage,
initRelation
});
const pageOptions = parseComponent$1(vuePageOptions);
initHooks(pageOptions.methods, hooks$2, vuePageOptions);
......@@ -1428,6 +1434,9 @@ let uni = {};
if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') {
uni = new Proxy({}, {
get (target, name) {
if (target[name]) {
return target[name]
}
if (baseApi[name]) {
return baseApi[name]
}
......@@ -1441,9 +1450,13 @@ if (typeof Proxy !== 'undefined' && "app-plus" !== 'app-plus') {
return
}
return promisify(name, wrapper(name, wx[name]))
},
set (target, name, value) {
target[name] = value;
return true
}
});
} else {
} else {
Object.keys(baseApi).forEach(name => {
uni[name] = baseApi[name];
});
......@@ -1477,4 +1490,4 @@ wx.createComponent = createComponent;
var uni$1 = uni;
export default uni$1;
export { createApp, createPage, createComponent };
export { createApp, createComponent, createPage };
{
"name": "@dcloudio/uni-app-plus",
"version": "0.0.248",
"version": "0.0.252",
"description": "uni-app app-plus",
"main": "dist/index.js",
"scripts": {
......
此差异已折叠。
{
"base64ToArrayBuffer": [
"/core/service/api/base/base64.js",
[
[
"/core/helpers/protocol/base/base64.js",
"base64ToArrayBuffer"
]
]
],
"arrayBufferToBase64": [
"/core/service/api/base/base64.js",
[
[
"/core/helpers/protocol/base/base64.js",
"arrayBufferToBase64"
]
]
],
"addInterceptor": [
"/core/service/api/base/interceptor.js",
[
[
"/core/helpers/protocol/base/interceptor.js",
"addInterceptor"
]
]
],
"removeInterceptor": [
"/core/service/api/base/interceptor.js",
[
[
"/core/helpers/protocol/base/interceptor.js",
"removeInterceptor"
]
]
],
"request": [
"/platforms/h5/service/api/network/request.js",
[
[
"/core/helpers/protocol/network/request.js",
"request"
]
]
],
"uploadFile": [
"/platforms/h5/service/api/network/upload-file.js",
[
[
"/core/helpers/protocol/network/upload-file.js",
"uploadFile"
]
]
],
"downloadFile": [
"/platforms/h5/service/api/network/download-file.js",
[
[
"/core/helpers/protocol/network/download-file.js",
"downloadFile"
]
]
],
"connectSocket": [
"/platforms/h5/service/api/network/socket.js",
[
[
"/core/helpers/protocol/network/socket.js",
"connectSocket"
]
]
],
"onSocketOpen": [
"/platforms/h5/service/api/network/socket.js",
[]
],
"onSocketError": [
"/platforms/h5/service/api/network/socket.js",
[]
],
"sendSocketMessage": [
"/platforms/h5/service/api/network/socket.js",
[
[
"/core/helpers/protocol/network/socket.js",
"sendSocketMessage"
]
]
],
"onSocketMessage": [
"/platforms/h5/service/api/network/socket.js",
[]
],
"closeSocket": [
"/platforms/h5/service/api/network/socket.js",
[
[
"/core/helpers/protocol/network/socket.js",
"closeSocket"
]
]
],
"onSocketClose": [
"/platforms/h5/service/api/network/socket.js",
[]
],
"navigateTo": [
"/platforms/h5/service/api/route/route.js",
[
[
"/core/helpers/protocol/route/route.js",
"navigateTo"
]
],
true
],
"redirectTo": [
"/platforms/h5/service/api/route/route.js",
[
[
"/core/helpers/protocol/route/route.js",
"redirectTo"
]
],
true
],
"reLaunch": [
"/platforms/h5/service/api/route/route.js",
[
[
"/core/helpers/protocol/route/route.js",
"reLaunch"
]
],
true
],
"switchTab": [
"/platforms/h5/service/api/route/route.js",
[
[
"/core/helpers/protocol/route/route.js",
"switchTab"
]
],
true
],
"navigateBack": [
"/platforms/h5/service/api/route/route.js",
[
[
"/core/helpers/protocol/route/route.js",
"navigateBack"
]
],
true
],
"setStorage": [
"/core/service/api/storage/storage.js",
[
[
"/core/helpers/protocol/storage/storage.js",
"setStorage"
]
]
],
"setStorageSync": [
"/core/service/api/storage/storage.js",
[
[
"/core/helpers/protocol/storage/storage.js",
"setStorageSync"
]
]
],
"getStorage": [
"/core/service/api/storage/storage.js",
[
[
"/core/helpers/protocol/storage/storage.js",
"getStorage"
]
]
],
"getStorageSync": [
"/core/service/api/storage/storage.js",
[
[
"/core/helpers/protocol/storage/storage.js",
"getStorageSync"
]
]
],
"getStorageInfo": [
"/core/service/api/storage/storage.js",
[]
],
"getStorageInfoSync": [
"/core/service/api/storage/storage.js",
[]
],
"removeStorage": [
"/core/service/api/storage/storage.js",
[
[
"/core/helpers/protocol/storage/storage.js",
"removeStorage"
]
]
],
"removeStorageSync": [
"/core/service/api/storage/storage.js",
[
[
"/core/helpers/protocol/storage/storage.js",
"removeStorageSync"
]
]
],
"clearStorage": [
"/core/service/api/storage/storage.js",
[]
],
"clearStorageSync": [
"/core/service/api/storage/storage.js",
[]
],
"getLocation": [
"/platforms/h5/service/api/location/get-location.js",
[
[
"/core/helpers/protocol/location/get-location.js",
"getLocation"
]
]
],
"chooseLocation": [
"/platforms/h5/service/api/location/choose-location.js",
[
[
"/core/helpers/protocol/location/choose-location.js",
"chooseLocation"
],
[
"/platforms/h5/components/system-routes/choose-location/index.vue",
"ChooseLocation"
]
]
],
"openLocation": [
"/platforms/h5/service/api/location/open-location.js",
[
[
"/core/helpers/protocol/location/open-location.js",
"openLocation"
],
[
"/platforms/h5/components/system-routes/open-location/index.vue",
"OpenLocation"
]
]
],
"createMapContext": [
"/platforms/h5/service/api/context/map.js",
[
[
"/core/helpers/protocol/context/context.js",
"createMapContext"
]
]
],
"chooseImage": [
"/platforms/h5/service/api/media/choose-image.js",
[
[
"/core/helpers/protocol/media/choose-image.js",
"chooseImage"
]
]
],
"previewImage": [
"/platforms/h5/service/api/media/preview-image.js",
[
[
"/core/helpers/protocol/media/preview-image.js",
"previewImage"
],
[
"/platforms/h5/components/system-routes/preview-image/index.vue",
"PreviewImage"
]
]
],
"getImageInfo": [
"/platforms/h5/service/api/media/get-image-info.js",
[
[
"/core/helpers/protocol/media/get-image-info.js",
"getImageInfo"
]
]
],
"createInnerAudioContext": [
"/platforms/h5/service/api/context/inner-audio.js",
[]
],
"chooseVideo": [
"/platforms/h5/service/api/media/choose-video.js",
[
[
"/core/helpers/protocol/media/choose-video.js",
"chooseVideo"
]
]
],
"createVideoContext": [
"/platforms/h5/service/api/context/video.js",
[
[
"/core/helpers/protocol/context/context.js",
"createVideoContext"
]
]
],
"getSystemInfo": [
"/platforms/h5/service/api/device/get-system-info.js",
[],
true
],
"getSystemInfoSync": [
"/platforms/h5/service/api/device/get-system-info.js",
[],
true
],
"canIUse": [
"/core/service/api/base/can-i-use.js",
[
[
"/core/helpers/protocol/base/can-i-use.js",
"canIUse"
]
],
true
],
"getNetworkType": [
"/platforms/h5/service/api/device/network-info.js",
[]
],
"onNetworkStatusChange": [
"/platforms/h5/service/api/device/network-info.js",
[]
],
"onAccelerometerChange": [
"/core/service/api/device/accelerometer.js",
[
[
"/platforms/h5/service/api/device/accelerometer.js",
"enableAccelerometer"
]
]
],
"startAccelerometer": [
"/core/service/api/device/accelerometer.js",
[
[
"/platforms/h5/service/api/device/accelerometer.js",
"enableAccelerometer"
]
]
],
"stopAccelerometer": [
"/core/service/api/device/accelerometer.js",
[
[
"/platforms/h5/service/api/device/accelerometer.js",
"enableAccelerometer"
]
]
],
"onCompassChange": [
"/platforms/h5/service/api/device/compass.js",
[]
],
"startCompass": [
"/platforms/h5/service/api/device/compass.js",
[]
],
"stopCompass": [
"/platforms/h5/service/api/device/compass.js",
[]
],
"makePhoneCall": [
"/platforms/h5/service/api/device/make-phone-call.js",
[
[
"/core/helpers/protocol/device/make-phone-call.js",
"makePhoneCall"
]
]
],
"vibrateLong": [
"/platforms/h5/service/api/device/vibrate.js",
[]
],
"vibrateShort": [
"/platforms/h5/service/api/device/vibrate.js",
[]
],
"onBluetoothDeviceFound": [
"/core/service/api/device/bluetooth.js",
[]
],
"onBluetoothAdapterStateChange": [
"/core/service/api/device/bluetooth.js",
[]
],
"onBLEConnectionStateChange": [
"/core/service/api/device/bluetooth.js",
[]
],
"onBLECharacteristicValueChange": [
"/core/service/api/device/bluetooth.js",
[]
],
"hideKeyboard": [
"/platforms/h5/service/api/device/hide-keyboard.js",
[]
],
"showToast": [
"/platforms/h5/service/api/ui/popup.js",
[
[
"/core/helpers/protocol/ui/popup.js",
"showToast"
],
[
"/platforms/h5/components/app/popup/toast.vue",
"Toast"
],
[
"/platforms/h5/components/app/popup/mixins/toast.js",
"ToastMixin"
]
]
],
"hideToast": [
"/platforms/h5/service/api/ui/popup.js",
[
[
"/platforms/h5/components/app/popup/toast.vue",
"Toast"
],
[
"/platforms/h5/components/app/popup/mixins/toast.js",
"ToastMixin"
]
]
],
"showLoading": [
"/platforms/h5/service/api/ui/popup.js",
[
[
"/core/helpers/protocol/ui/popup.js",
"showLoading"
],
[
"/platforms/h5/components/app/popup/toast.vue",
"Toast"
],
[
"/platforms/h5/components/app/popup/mixins/toast.js",
"ToastMixin"
]
]
],
"hideLoading": [
"/platforms/h5/service/api/ui/popup.js",
[
[
"/platforms/h5/components/app/popup/toast.vue",
"Toast"
],
[
"/platforms/h5/components/app/popup/mixins/toast.js",
"ToastMixin"
]
]
],
"showModal": [
"/platforms/h5/service/api/ui/popup.js",
[
[
"/core/helpers/protocol/ui/popup.js",
"showModal"
],
[
"/platforms/h5/components/app/popup/modal.vue",
"Modal"
],
[
"/platforms/h5/components/app/popup/mixins/modal.js",
"ModalMixin"
]
]
],
"showActionSheet": [
"/platforms/h5/service/api/ui/popup.js",
[
[
"/core/helpers/protocol/ui/popup.js",
"showActionSheet"
],
[
"/platforms/h5/components/app/popup/actionSheet.vue",
"ActionSheet"
],
[
"/platforms/h5/components/app/popup/mixins/action-sheet.js",
"ActionSheetMixin"
]
]
],
"setNavigationBarTitle": [
"/platforms/h5/service/api/ui/navigation-bar.js",
[
[
"/core/helpers/protocol/ui/navigation-bar.js",
"setNavigationBarTitle"
]
]
],
"setNavigationBarColor": [
"/platforms/h5/service/api/ui/navigation-bar.js",
[
[
"/core/helpers/protocol/ui/navigation-bar.js",
"setNavigationBarColor"
]
]
],
"showNavigationBarLoading": [
"/platforms/h5/service/api/ui/navigation-bar.js",
[]
],
"hideNavigationBarLoading": [
"/platforms/h5/service/api/ui/navigation-bar.js",
[]
],
"setTabBarItem": [
"/platforms/h5/service/api/ui/tab-bar.js",
[
[
"/core/helpers/protocol/ui/tab-bar.js",
"setTabBarItem"
]
]
],
"setTabBarStyle": [
"/platforms/h5/service/api/ui/tab-bar.js",
[
[
"/core/helpers/protocol/ui/tab-bar.js",
"setTabBarStyle"
]
]
],
"hideTabBar": [
"/platforms/h5/service/api/ui/tab-bar.js",
[
[
"/core/helpers/protocol/ui/tab-bar.js",
"hideTabBar"
]
]
],
"showTabBar": [
"/platforms/h5/service/api/ui/tab-bar.js",
[
[
"/core/helpers/protocol/ui/tab-bar.js",
"showTabBar"
]
]
],
"setTabBarBadge": [
"/platforms/h5/service/api/ui/tab-bar.js",
[
[
"/core/helpers/protocol/ui/tab-bar.js",
"setTabBarBadge"
]
]
],
"removeTabBarBadge": [
"/platforms/h5/service/api/ui/tab-bar.js",
[
[
"/core/helpers/protocol/ui/tab-bar.js",
"removeTabBarBadge"
]
]
],
"showTabBarRedDot": [
"/platforms/h5/service/api/ui/tab-bar.js",
[
[
"/core/helpers/protocol/ui/tab-bar.js",
"showTabBarRedDot"
]
]
],
"hideTabBarRedDot": [
"/platforms/h5/service/api/ui/tab-bar.js",
[
[
"/core/helpers/protocol/ui/tab-bar.js",
"hideTabBarRedDot"
]
]
],
"createAnimation": [
"/platforms/h5/service/api/ui/create-animation.js",
[]
],
"pageScrollTo": [
"/core/service/api/ui/page-scroll-to.js",
[
[
"/core/helpers/protocol/ui/page-scroll-to.js",
"pageScrollTo"
]
]
],
"onWindowResize": [
"/platforms/h5/service/api/ui/window.js",
[]
],
"offWindowResize": [
"/platforms/h5/service/api/ui/window.js",
[]
],
"startPullDownRefresh": [
"/platforms/h5/service/api/ui/pull-down-refresh.js",
[]
],
"stopPullDownRefresh": [
"/platforms/h5/service/api/ui/pull-down-refresh.js",
[]
],
"createSelectorQuery": [
"/platforms/h5/service/api/ui/create-selector-query.js",
[
[
"/core/view/bridge/subscribe/api/request-component-info.js",
"requestComponentInfo"
]
]
],
"createIntersectionObserver": [
"/platforms/h5/service/api/ui/create-intersection-observer.js",
[
[
"/core/view/bridge/subscribe/api/request-component-observer.js",
"requestComponentObserver"
],
[
"/core/view/bridge/subscribe/api/request-component-observer.js",
"destroyComponentObserver"
]
]
],
"$emit": [
"/platforms/h5/service/api/base/event-bus.js",
[
[
"/core/helpers/protocol/base/event-bus.js",
"$emit"
]
]
],
"$on": [
"/platforms/h5/service/api/base/event-bus.js",
[
[
"/core/helpers/protocol/base/event-bus.js",
"$on"
]
]
],
"$once": [
"/platforms/h5/service/api/base/event-bus.js",
[
[
"/core/helpers/protocol/base/event-bus.js",
"$once"
]
]
],
"$off": [
"/platforms/h5/service/api/base/event-bus.js",
[
[
"/core/helpers/protocol/base/event-bus.js",
"$off"
]
]
],
"openDocument": [
"/platforms/h5/service/api/file/open-document.js",
[
[
"/core/helpers/protocol/file/open-document.js",
"openDocument"
]
]
],
"createCanvasContext": [
"/platforms/h5/service/api/context/canvas.js",
[
[
"/core/helpers/protocol/context/context.js",
"createCanvasContext"
]
]
],
"canvasToTempFilePath": [
"/platforms/h5/service/api/context/canvas.js",
[
[
"/core/helpers/protocol/context/canvas.js",
"canvasToTempFilePath"
]
]
],
"canvasPutImageData": [
"/platforms/h5/service/api/context/canvas.js",
[
[
"/core/helpers/protocol/context/canvas.js",
"canvasPutImageData"
]
]
],
"canvasGetImageData": [
"/platforms/h5/service/api/context/canvas.js",
[
[
"/core/helpers/protocol/context/canvas.js",
"canvasGetImageData"
]
]
],
"getProvider": [
"/platforms/h5/service/api/plugin/get-provider.js",
[
[
"/core/helpers/protocol/plugin/get-provider.js",
"getProvider"
]
]
],
"upx2px": [
"/core/service/api/base/upx2px.js",
[
[
"/core/helpers/protocol/base/upx2px.js",
"upx2px"
]
],
true
]
}
\ No newline at end of file
{
"name": "@dcloudio/uni-h5",
"version": "0.7.3",
"version": "0.7.1",
"description": "uni-app h5",
"main": "dist/index.umd.min.js",
"scripts": {
......
......@@ -231,7 +231,7 @@ const promiseInterceptor = {
};
const SYNC_API_RE =
/^\$|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
/^\$|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
......@@ -258,8 +258,8 @@ function handlePromise (promise) {
function shouldPromise (name) {
if (
isContextApi(name) ||
isSyncApi(name) ||
isCallbackApi(name)
isSyncApi(name) ||
isCallbackApi(name)
) {
return false
}
......@@ -891,8 +891,6 @@ function $emit () {
return apply(getEmitter(), '$emit', [...arguments])
}
var eventApi = /*#__PURE__*/Object.freeze({
$on: $on,
$off: $off,
......@@ -1028,8 +1026,8 @@ function hasHook (hook, vueOptions) {
return true
}
if (vueOptions.super &&
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
return true
}
return false
......@@ -1054,14 +1052,14 @@ function initHooks (mpOptions, hooks, vueOptions) {
});
}
function initVueComponent (Vue$$1, vueOptions) {
function initVueComponent (Vue, vueOptions) {
vueOptions = vueOptions.default || vueOptions;
let VueComponent;
if (isFn(vueOptions)) {
VueComponent = vueOptions;
vueOptions = VueComponent.extendOptions;
} else {
VueComponent = Vue$$1.extend(vueOptions);
VueComponent = Vue.extend(vueOptions);
}
return [VueComponent, vueOptions]
}
......@@ -1218,7 +1216,7 @@ function initProperties (props, isBehavior = false, file = '') {
value = value();
}
opts.type = parsePropType(key, opts.type, value, file);
opts.type = parsePropType(key, opts.type);
properties[key] = {
type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
......@@ -1226,7 +1224,7 @@ function initProperties (props, isBehavior = false, file = '') {
observer: createObserver(key)
};
} else { // content:String
const type = parsePropType(key, opts, null, file);
const type = parsePropType(key, opts);
properties[key] = {
type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
observer: createObserver(key)
......@@ -1301,16 +1299,16 @@ function processEventExtra (vm, extra, event) {
if (Array.isArray(extra) && extra.length) {
/**
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
extra.forEach((dataPath, index) => {
if (typeof dataPath === 'string') {
if (!dataPath) { // model,prop.sync
......@@ -1346,8 +1344,8 @@ function processEventArgs (vm, event, args = [], extra = [], isCustom, methodNam
let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
if (isCustom) { // 自定义事件
isCustomMPEvent = event.currentTarget &&
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
if (!args.length) { // 无参数,直接传入 event 或 detail 数组
if (isCustomMPEvent) {
return [event]
......@@ -1389,30 +1387,33 @@ const CUSTOM = '^';
function isMatchEventType (eventType, optType) {
return (eventType === optType) ||
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
}
function handleEvent (event) {
event = wrapper$1(event);
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
}
const eventOpts = dataset.eventOpts || dataset['event-opts'];// 支付宝 web-view 组件 dataset 非驼峰
const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
if (!eventOpts) {
return console.warn(`事件信息不存在`)
}
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
const eventType = event.type;
const ret = [];
eventOpts.forEach(eventOpt => {
let type = eventOpt[0];
const eventsArray = eventOpt[1];
......@@ -1429,8 +1430,8 @@ function handleEvent (event) {
let handlerCtx = this.$vm;
if (
handlerCtx.$options.generic &&
handlerCtx.$parent &&
handlerCtx.$parent.$parent
handlerCtx.$parent &&
handlerCtx.$parent.$parent
) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
handlerCtx = handlerCtx.$parent.$parent;
}
......@@ -1444,18 +1445,26 @@ function handleEvent (event) {
}
handler.once = true;
}
handler.apply(handlerCtx, processEventArgs(
ret.push(handler.apply(handlerCtx, processEventArgs(
this.$vm,
event,
eventArray[1],
eventArray[2],
isCustom,
methodName
));
)));
}
});
}
});
if (
eventType === 'input' &&
ret.length === 1 &&
typeof ret[0] !== 'undefined'
) {
return ret[0]
}
}
const hooks = [
......@@ -1617,13 +1626,13 @@ const customize = cached((str) => {
const isComponent2 = my.canIUse('component2');
const mocks$1 = ['$id'];
const mocks = ['$id'];
function initRefs$1 () {
function initRefs () {
}
function initBehavior$1 ({
function initBehavior ({
properties
}) {
const props = {};
......@@ -1637,7 +1646,7 @@ function initBehavior$1 ({
}
}
function initRelation$1 (detail) {
function initRelation (detail) {
this.props.onVueInit(detail);
}
......@@ -1760,13 +1769,13 @@ function createObserver$1 (isDidUpdate) {
const handleLink$1 = (function () {
if (isComponent2) {
return function handleLink$$1 (detail) {
return function handleLink$1 (detail) {
return handleLink.call(this, {
detail
})
}
}
return function handleLink$$1 (detail) {
return function handleLink$1 (detail) {
if (this.$vm && this.$vm._isMounted) { // 父已初始化
return handleLink.call(this, {
detail: {
......@@ -1799,8 +1808,8 @@ function parseApp (vm) {
});
return parseBaseApp(vm, {
mocks: mocks$1,
initRefs: initRefs$1
mocks,
initRefs
})
}
......@@ -1825,7 +1834,7 @@ function parsePage (vuePageOptions) {
let [VueComponent, vueOptions] = initVueComponent(Vue, vuePageOptions);
const pageOptions = {
mixins: initBehaviors(vueOptions, initBehavior$1),
mixins: initBehaviors(vueOptions, initBehavior),
data: initData(vueOptions, Vue.prototype),
onLoad (args) {
const properties = this.props;
......@@ -1889,7 +1898,7 @@ function initVm (VueComponent) {
if (isComponent2) {
// 处理父子关系
initRelation$1.call(this, {
initRelation.call(this, {
vuePid: this._$vuePid,
vueOptions: options
});
......@@ -1901,7 +1910,7 @@ function initVm (VueComponent) {
this.$vm.$mount();
} else {
// 处理父子关系
initRelation$1.call(this, {
initRelation.call(this, {
vuePid: this._$vuePid,
vueOptions: options,
VueComponent,
......@@ -1940,7 +1949,7 @@ function parseComponent (vueComponentOptions) {
});
const componentOptions = {
mixins: initBehaviors(vueOptions, initBehavior$1),
mixins: initBehaviors(vueOptions, initBehavior),
data: initData(vueOptions, Vue.prototype),
props,
didMount () {
......@@ -2000,6 +2009,9 @@ let uni = {};
if (typeof Proxy !== 'undefined' && "mp-alipay" !== 'app-plus') {
uni = new Proxy({}, {
get (target, name) {
if (target[name]) {
return target[name]
}
if (baseApi[name]) {
return baseApi[name]
}
......@@ -2021,9 +2033,13 @@ if (typeof Proxy !== 'undefined' && "mp-alipay" !== 'app-plus') {
return
}
return promisify(name, wrapper(name, my[name]))
},
set (target, name, value) {
target[name] = value;
return true
}
});
} else {
} else {
Object.keys(baseApi).forEach(name => {
uni[name] = baseApi[name];
});
......@@ -2059,4 +2075,4 @@ my.createComponent = createComponent;
var uni$1 = uni;
export default uni$1;
export { createApp, createPage, createComponent };
export { createApp, createComponent, createPage };
{
"name": "@dcloudio/uni-mp-alipay",
"version": "0.0.822",
"version": "0.0.826",
"description": "uni-app mp-alipay",
"main": "dist/index.js",
"scripts": {
......
......@@ -231,7 +231,7 @@ const promiseInterceptor = {
};
const SYNC_API_RE =
/^\$|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
/^\$|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
......@@ -258,8 +258,8 @@ function handlePromise (promise) {
function shouldPromise (name) {
if (
isContextApi(name) ||
isSyncApi(name) ||
isCallbackApi(name)
isSyncApi(name) ||
isCallbackApi(name)
) {
return false
}
......@@ -426,6 +426,16 @@ function createTodoMethod (contextName, methodName) {
console.error(`百度小程序 ${contextName}暂不支持${methodName}`);
}
}
function _handleEnvInfo (result) {
result.miniProgram = {
appId: result.appKey
};
result.plugin = {
version: result.sdkVersion
};
}
// 需要做转换的 API 列表
const protocols = {
request: {
......@@ -479,6 +489,10 @@ const protocols = {
},
showShareMenu: {
name: 'openShare'
},
getAccountInfoSync: {
name: 'getEnvInfoSync',
returnValue: _handleEnvInfo
}
};
......@@ -653,8 +667,6 @@ function $emit () {
return apply(getEmitter(), '$emit', [...arguments])
}
var eventApi = /*#__PURE__*/Object.freeze({
$on: $on,
$off: $off,
......@@ -758,8 +770,8 @@ function hasHook (hook, vueOptions) {
return true
}
if (vueOptions.super &&
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
return true
}
return false
......@@ -784,14 +796,14 @@ function initHooks (mpOptions, hooks, vueOptions) {
});
}
function initVueComponent (Vue$$1, vueOptions) {
function initVueComponent (Vue, vueOptions) {
vueOptions = vueOptions.default || vueOptions;
let VueComponent;
if (isFn(vueOptions)) {
VueComponent = vueOptions;
vueOptions = VueComponent.extendOptions;
} else {
VueComponent = Vue$$1.extend(vueOptions);
VueComponent = Vue.extend(vueOptions);
}
return [VueComponent, vueOptions]
}
......@@ -921,10 +933,10 @@ function parsePropType (key, type, defaultValue, file) {
{
if (
defaultValue === false &&
Array.isArray(type) &&
type.length === 2 &&
type.indexOf(String) !== -1 &&
type.indexOf(Boolean) !== -1
Array.isArray(type) &&
type.length === 2 &&
type.indexOf(String) !== -1 &&
type.indexOf(Boolean) !== -1
) { // [String,Boolean]=>Boolean
if (file) {
console.warn(
......@@ -1011,8 +1023,8 @@ function wrapper$1 (event) {
{ // mp-baidu,checked=>value
if (
isPlainObject(event.detail) &&
hasOwn(event.detail, 'checked') &&
!hasOwn(event.detail, 'value')
hasOwn(event.detail, 'checked') &&
!hasOwn(event.detail, 'value')
) {
event.detail.value = event.detail.checked;
}
......@@ -1067,16 +1079,16 @@ function processEventExtra (vm, extra, event) {
if (Array.isArray(extra) && extra.length) {
/**
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
extra.forEach((dataPath, index) => {
if (typeof dataPath === 'string') {
if (!dataPath) { // model,prop.sync
......@@ -1112,8 +1124,8 @@ function processEventArgs (vm, event, args = [], extra = [], isCustom, methodNam
let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
if (isCustom) { // 自定义事件
isCustomMPEvent = event.currentTarget &&
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
if (!args.length) { // 无参数,直接传入 event 或 detail 数组
if (isCustomMPEvent) {
return [event]
......@@ -1155,30 +1167,33 @@ const CUSTOM = '^';
function isMatchEventType (eventType, optType) {
return (eventType === optType) ||
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
}
function handleEvent (event) {
event = wrapper$1(event);
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
}
const eventOpts = dataset.eventOpts || dataset['event-opts'];// 支付宝 web-view 组件 dataset 非驼峰
const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
if (!eventOpts) {
return console.warn(`事件信息不存在`)
}
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
const eventType = event.type;
const ret = [];
eventOpts.forEach(eventOpt => {
let type = eventOpt[0];
const eventsArray = eventOpt[1];
......@@ -1195,8 +1210,8 @@ function handleEvent (event) {
let handlerCtx = this.$vm;
if (
handlerCtx.$options.generic &&
handlerCtx.$parent &&
handlerCtx.$parent.$parent
handlerCtx.$parent &&
handlerCtx.$parent.$parent
) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
handlerCtx = handlerCtx.$parent.$parent;
}
......@@ -1210,18 +1225,26 @@ function handleEvent (event) {
}
handler.once = true;
}
handler.apply(handlerCtx, processEventArgs(
ret.push(handler.apply(handlerCtx, processEventArgs(
this.$vm,
event,
eventArray[1],
eventArray[2],
isCustom,
methodName
));
)));
}
});
}
});
if (
eventType === 'input' &&
ret.length === 1 &&
typeof ret[0] !== 'undefined'
) {
return ret[0]
}
}
const hooks = [
......@@ -1353,20 +1376,20 @@ function handleLink (event) {
vueOptions.parent = parentVm;
}
const mocks$1 = ['nodeId', 'componentName'];
const mocks = ['nodeId', 'componentName'];
function isPage$1 () {
function isPage () {
return !this.ownerId
}
function initRelation$1 (detail) {
function initRelation (detail) {
this.dispatch('__l', detail);
}
function parseApp (vm) {
// 百度 onShow 竟然会在 onLaunch 之前
const appOptions = parseBaseApp(vm, {
mocks: mocks$1,
mocks,
initRefs
});
appOptions.onShow = function onShow (args) {
......@@ -1384,8 +1407,8 @@ function createApp (vm) {
}
function parseBaseComponent (vueComponentOptions, {
isPage: isPage$$1,
initRelation: initRelation$$1
isPage,
initRelation
} = {}) {
let [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
......@@ -1402,7 +1425,7 @@ function parseBaseComponent (vueComponentOptions, {
const properties = this.properties;
const options = {
mpType: isPage$$1.call(this) ? 'page' : 'component',
mpType: isPage.call(this) ? 'page' : 'component',
mpInstance: this,
propsData: properties
};
......@@ -1410,7 +1433,7 @@ function parseBaseComponent (vueComponentOptions, {
initVueIds(properties.vueId, this);
// 处理父子关系
initRelation$$1.call(this, {
initRelation.call(this, {
vuePid: this._$vuePid,
vueOptions: options
});
......@@ -1454,7 +1477,7 @@ function parseBaseComponent (vueComponentOptions, {
}
};
if (isPage$$1) {
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
......@@ -1462,15 +1485,15 @@ function parseBaseComponent (vueComponentOptions, {
function parseComponent (vueOptions) {
const componentOptions = parseBaseComponent(vueOptions, {
isPage: isPage$1,
initRelation: initRelation$1
isPage,
initRelation
});
const oldAttached = componentOptions.lifetimes.attached;
componentOptions.lifetimes.attached = function attached () {
oldAttached.call(this);
if (isPage$1.call(this)) { // 百度 onLoad 在 attached 之前触发
if (isPage.call(this)) { // 百度 onLoad 在 attached 之前触发
// 百度 当组件作为页面时 pageinstancce 不是原来组件的 instance
this.pageinstance.$vm = this.$vm;
......@@ -1504,10 +1527,7 @@ function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent(vuePageOptions, {
isPage,
initRelation
});
const pageOptions = parseComponent(vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
......@@ -1535,8 +1555,8 @@ function onPageUnload ($vm) {
function parsePage (vuePageOptions) {
const pageOptions = parseBasePage(vuePageOptions, {
isPage: isPage$1,
initRelation: initRelation$1
isPage,
initRelation
});
pageOptions.methods.onLoad = function onLoad (args) {
......@@ -1586,6 +1606,9 @@ let uni = {};
if (typeof Proxy !== 'undefined' && "mp-baidu" !== 'app-plus') {
uni = new Proxy({}, {
get (target, name) {
if (target[name]) {
return target[name]
}
if (baseApi[name]) {
return baseApi[name]
}
......@@ -1607,9 +1630,13 @@ if (typeof Proxy !== 'undefined' && "mp-baidu" !== 'app-plus') {
return
}
return promisify(name, wrapper(name, swan[name]))
},
set (target, name, value) {
target[name] = value;
return true
}
});
} else {
} else {
Object.keys(baseApi).forEach(name => {
uni[name] = baseApi[name];
});
......@@ -1645,4 +1672,4 @@ swan.createComponent = createComponent;
var uni$1 = uni;
export default uni$1;
export { createApp, createPage, createComponent };
export { createApp, createComponent, createPage };
{
"name": "@dcloudio/uni-mp-baidu",
"version": "0.0.852",
"version": "0.0.856",
"description": "uni-app mp-baidu",
"main": "dist/index.js",
"scripts": {
......
......@@ -231,7 +231,7 @@ const promiseInterceptor = {
};
const SYNC_API_RE =
/^\$|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
/^\$|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
......@@ -258,8 +258,8 @@ function handlePromise (promise) {
function shouldPromise (name) {
if (
isContextApi(name) ||
isSyncApi(name) ||
isCallbackApi(name)
isSyncApi(name) ||
isCallbackApi(name)
) {
return false
}
......@@ -402,23 +402,11 @@ const todos = [
'canIUse',
'onMemoryWarning',
'onNetworkStatusChange',
'onAccelerometerChange',
'startAccelerometer',
'stopAccelerometer',
'onCompassChange',
'startCompass',
'scanCode',
'startBeaconDiscovery',
'stopBeaconDiscovery',
'getBeacons',
'onBeaconUpdate',
'onBeaconServiceChange',
'setScreenBrightness',
'getScreenBrightness',
'setKeepScreenOn',
'onUserCaptureScreen',
'vibrateLong',
'vibrateShort',
'addPhoneContact',
'getHCEState',
'startHCE',
......@@ -449,13 +437,25 @@ const todos = [
'checkIsSupportSoterAuthentication',
'startSoterAuthentication',
'checkIsSoterEnrolledInDevice',
'createWorker',
'reportMonitor',
'getLogManager',
'onUserCaptureScreen',
'reportAnalytics'
];
const canIUses = [];
const canIUses = [
'scanCode',
'startAccelerometer',
'stopAccelerometer',
'onAccelerometerChange',
'startCompass',
'onCompassChange',
'setScreenBrightness',
'getScreenBrightness',
'setKeepScreenOn',
'onUserCaptureScreen',
'vibrateLong',
'vibrateShort',
'createWorker'
];
const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];
......@@ -628,8 +628,6 @@ function $emit () {
return apply(getEmitter(), '$emit', [...arguments])
}
var eventApi = /*#__PURE__*/Object.freeze({
$on: $on,
$off: $off,
......@@ -717,8 +715,8 @@ function hasHook (hook, vueOptions) {
return true
}
if (vueOptions.super &&
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
return true
}
return false
......@@ -743,14 +741,14 @@ function initHooks (mpOptions, hooks, vueOptions) {
});
}
function initVueComponent (Vue$$1, vueOptions) {
function initVueComponent (Vue, vueOptions) {
vueOptions = vueOptions.default || vueOptions;
let VueComponent;
if (isFn(vueOptions)) {
VueComponent = vueOptions;
vueOptions = VueComponent.extendOptions;
} else {
VueComponent = Vue$$1.extend(vueOptions);
VueComponent = Vue.extend(vueOptions);
}
return [VueComponent, vueOptions]
}
......@@ -917,7 +915,7 @@ function initProperties (props, isBehavior = false, file = '') {
value = value();
}
opts.type = parsePropType(key, opts.type, value, file);
opts.type = parsePropType(key, opts.type);
properties[key] = {
type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
......@@ -925,7 +923,7 @@ function initProperties (props, isBehavior = false, file = '') {
observer: createObserver(key)
};
} else { // content:String
const type = parsePropType(key, opts, null, file);
const type = parsePropType(key, opts);
properties[key] = {
type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
observer: createObserver(key)
......@@ -1000,16 +998,16 @@ function processEventExtra (vm, extra, event) {
if (Array.isArray(extra) && extra.length) {
/**
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
extra.forEach((dataPath, index) => {
if (typeof dataPath === 'string') {
if (!dataPath) { // model,prop.sync
......@@ -1045,8 +1043,8 @@ function processEventArgs (vm, event, args = [], extra = [], isCustom, methodNam
let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
if (isCustom) { // 自定义事件
isCustomMPEvent = event.currentTarget &&
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
if (!args.length) { // 无参数,直接传入 event 或 detail 数组
if (isCustomMPEvent) {
return [event]
......@@ -1088,30 +1086,33 @@ const CUSTOM = '^';
function isMatchEventType (eventType, optType) {
return (eventType === optType) ||
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
}
function handleEvent (event) {
event = wrapper$1(event);
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
}
const eventOpts = dataset.eventOpts || dataset['event-opts'];// 支付宝 web-view 组件 dataset 非驼峰
const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
if (!eventOpts) {
return console.warn(`事件信息不存在`)
}
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
const eventType = event.type;
const ret = [];
eventOpts.forEach(eventOpt => {
let type = eventOpt[0];
const eventsArray = eventOpt[1];
......@@ -1128,8 +1129,8 @@ function handleEvent (event) {
let handlerCtx = this.$vm;
if (
handlerCtx.$options.generic &&
handlerCtx.$parent &&
handlerCtx.$parent.$parent
handlerCtx.$parent &&
handlerCtx.$parent.$parent
) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
handlerCtx = handlerCtx.$parent.$parent;
}
......@@ -1143,18 +1144,26 @@ function handleEvent (event) {
}
handler.once = true;
}
handler.apply(handlerCtx, processEventArgs(
ret.push(handler.apply(handlerCtx, processEventArgs(
this.$vm,
event,
eventArray[1],
eventArray[2],
isCustom,
methodName
));
)));
}
});
}
});
if (
eventType === 'input' &&
ret.length === 1 &&
typeof ret[0] !== 'undefined'
) {
return ret[0]
}
}
const hooks = [
......@@ -1313,8 +1322,8 @@ function createApp (vm) {
}
function parseBaseComponent (vueComponentOptions, {
isPage: isPage$$1,
initRelation: initRelation$$1
isPage,
initRelation
} = {}) {
let [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
......@@ -1331,7 +1340,7 @@ function parseBaseComponent (vueComponentOptions, {
const properties = this.properties;
const options = {
mpType: isPage$$1.call(this) ? 'page' : 'component',
mpType: isPage.call(this) ? 'page' : 'component',
mpInstance: this,
propsData: properties
};
......@@ -1339,7 +1348,7 @@ function parseBaseComponent (vueComponentOptions, {
initVueIds(properties.vueId, this);
// 处理父子关系
initRelation$$1.call(this, {
initRelation.call(this, {
vuePid: this._$vuePid,
vueOptions: options
});
......@@ -1383,7 +1392,7 @@ function parseBaseComponent (vueComponentOptions, {
}
};
if (isPage$$1) {
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
......@@ -1412,10 +1421,7 @@ function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent$1(vuePageOptions, {
isPage,
initRelation
});
const pageOptions = parseComponent$1(vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
......@@ -1467,6 +1473,9 @@ let uni = {};
if (typeof Proxy !== 'undefined' && "mp-qq" !== 'app-plus') {
uni = new Proxy({}, {
get (target, name) {
if (target[name]) {
return target[name]
}
if (baseApi[name]) {
return baseApi[name]
}
......@@ -1488,9 +1497,13 @@ if (typeof Proxy !== 'undefined' && "mp-qq" !== 'app-plus') {
return
}
return promisify(name, wrapper(name, wx[name]))
},
set (target, name, value) {
target[name] = value;
return true
}
});
} else {
} else {
Object.keys(baseApi).forEach(name => {
uni[name] = baseApi[name];
});
......@@ -1526,4 +1539,4 @@ wx.createComponent = createComponent;
var uni$1 = uni;
export default uni$1;
export { createApp, createPage, createComponent };
export { createApp, createComponent, createPage };
{
"name": "@dcloudio/uni-mp-qq",
"version": "0.0.106",
"version": "0.0.110",
"description": "uni-app mp-qq",
"main": "dist/index.js",
"scripts": {
......
......@@ -231,7 +231,7 @@ const promiseInterceptor = {
};
const SYNC_API_RE =
/^\$|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
/^\$|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
......@@ -258,8 +258,8 @@ function handlePromise (promise) {
function shouldPromise (name) {
if (
isContextApi(name) ||
isSyncApi(name) ||
isCallbackApi(name)
isSyncApi(name) ||
isCallbackApi(name)
) {
return false
}
......@@ -709,8 +709,6 @@ function $emit () {
return apply(getEmitter(), '$emit', [...arguments])
}
var eventApi = /*#__PURE__*/Object.freeze({
$on: $on,
$off: $off,
......@@ -798,8 +796,8 @@ function hasHook (hook, vueOptions) {
return true
}
if (vueOptions.super &&
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
return true
}
return false
......@@ -824,14 +822,14 @@ function initHooks (mpOptions, hooks, vueOptions) {
});
}
function initVueComponent (Vue$$1, vueOptions) {
function initVueComponent (Vue, vueOptions) {
vueOptions = vueOptions.default || vueOptions;
let VueComponent;
if (isFn(vueOptions)) {
VueComponent = vueOptions;
vueOptions = VueComponent.extendOptions;
} else {
VueComponent = Vue$$1.extend(vueOptions);
VueComponent = Vue.extend(vueOptions);
}
return [VueComponent, vueOptions]
}
......@@ -998,7 +996,7 @@ function initProperties (props, isBehavior = false, file = '') {
value = value();
}
opts.type = parsePropType(key, opts.type, value, file);
opts.type = parsePropType(key, opts.type);
properties[key] = {
type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
......@@ -1006,7 +1004,7 @@ function initProperties (props, isBehavior = false, file = '') {
observer: createObserver(key)
};
} else { // content:String
const type = parsePropType(key, opts, null, file);
const type = parsePropType(key, opts);
properties[key] = {
type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
observer: createObserver(key)
......@@ -1081,16 +1079,16 @@ function processEventExtra (vm, extra, event) {
if (Array.isArray(extra) && extra.length) {
/**
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
extra.forEach((dataPath, index) => {
if (typeof dataPath === 'string') {
if (!dataPath) { // model,prop.sync
......@@ -1126,8 +1124,8 @@ function processEventArgs (vm, event, args = [], extra = [], isCustom, methodNam
let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
if (isCustom) { // 自定义事件
isCustomMPEvent = event.currentTarget &&
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
if (!args.length) { // 无参数,直接传入 event 或 detail 数组
if (isCustomMPEvent) {
return [event]
......@@ -1169,30 +1167,33 @@ const CUSTOM = '^';
function isMatchEventType (eventType, optType) {
return (eventType === optType) ||
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
}
function handleEvent (event) {
event = wrapper$1(event);
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
}
const eventOpts = dataset.eventOpts || dataset['event-opts'];// 支付宝 web-view 组件 dataset 非驼峰
const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
if (!eventOpts) {
return console.warn(`事件信息不存在`)
}
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
const eventType = event.type;
const ret = [];
eventOpts.forEach(eventOpt => {
let type = eventOpt[0];
const eventsArray = eventOpt[1];
......@@ -1209,8 +1210,8 @@ function handleEvent (event) {
let handlerCtx = this.$vm;
if (
handlerCtx.$options.generic &&
handlerCtx.$parent &&
handlerCtx.$parent.$parent
handlerCtx.$parent &&
handlerCtx.$parent.$parent
) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
handlerCtx = handlerCtx.$parent.$parent;
}
......@@ -1224,18 +1225,26 @@ function handleEvent (event) {
}
handler.once = true;
}
handler.apply(handlerCtx, processEventArgs(
ret.push(handler.apply(handlerCtx, processEventArgs(
this.$vm,
event,
eventArray[1],
eventArray[2],
isCustom,
methodName
));
)));
}
});
}
});
if (
eventType === 'input' &&
ret.length === 1 &&
typeof ret[0] !== 'undefined'
) {
return ret[0]
}
}
const hooks = [
......@@ -1344,13 +1353,13 @@ function handleLink (event) {
vueOptions.parent = parentVm;
}
const mocks$1 = ['__route__', '__webviewId__', '__nodeid__', '__nodeId__'];
const mocks = ['__route__', '__webviewId__', '__nodeid__', '__nodeId__'];
function isPage$1 () {
function isPage () {
return this.__nodeid__ === 0 || this.__nodeId__ === 0
}
function initRefs$1 (vm) {
function initRefs (vm) {
const mpInstance = vm.$scope;
mpInstance.selectAllComponents('.vue-ref', (components) => {
components.forEach(component => {
......@@ -1371,7 +1380,7 @@ function initRefs$1 (vm) {
const instances = Object.create(null);
function initRelation$1 ({
function initRelation ({
vuePid,
mpInstance
}) {
......@@ -1435,7 +1444,7 @@ function parseApp (vm) {
this.$scope.route = this.$scope.__route__;
}
initRefs$1(this);
initRefs(this);
this.__init_injections(this);
this.__init_provide(this);
......@@ -1444,7 +1453,7 @@ function parseApp (vm) {
});
return parseBaseApp(vm, {
mocks: mocks$1,
mocks,
initRefs: function () {} // attached 时,可能查询不到
})
}
......@@ -1455,8 +1464,8 @@ function createApp (vm) {
}
function parseBaseComponent (vueComponentOptions, {
isPage: isPage$$1,
initRelation: initRelation$$1
isPage,
initRelation
} = {}) {
let [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
......@@ -1473,7 +1482,7 @@ function parseBaseComponent (vueComponentOptions, {
const properties = this.properties;
const options = {
mpType: isPage$$1.call(this) ? 'page' : 'component',
mpType: isPage.call(this) ? 'page' : 'component',
mpInstance: this,
propsData: properties
};
......@@ -1481,7 +1490,7 @@ function parseBaseComponent (vueComponentOptions, {
initVueIds(properties.vueId, this);
// 处理父子关系
initRelation$$1.call(this, {
initRelation.call(this, {
vuePid: this._$vuePid,
vueOptions: options
});
......@@ -1525,7 +1534,7 @@ function parseBaseComponent (vueComponentOptions, {
}
};
if (isPage$$1) {
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
......@@ -1538,7 +1547,7 @@ function parseComponent (vueOptions) {
const properties = this.properties;
const options = {
mpType: isPage$1.call(this) ? 'page' : 'component',
mpType: isPage.call(this) ? 'page' : 'component',
mpInstance: this,
propsData: properties
};
......@@ -1552,7 +1561,7 @@ function parseComponent (vueOptions) {
initSlots(this.$vm, properties.vueSlots);
// 处理父子关系
initRelation$1.call(this, {
initRelation.call(this, {
vuePid: this._$vuePid,
mpInstance: this
});
......@@ -1581,10 +1590,7 @@ function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent(vuePageOptions, {
isPage,
initRelation
});
const pageOptions = parseComponent(vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
......@@ -1598,8 +1604,8 @@ function parseBasePage (vuePageOptions, {
function parsePage (vuePageOptions) {
const pageOptions = parseBasePage(vuePageOptions, {
isPage: isPage$1,
initRelation: initRelation$1
isPage,
initRelation
});
// 页面需要在 ready 中触发,其他组件是在 handleLink 中触发
pageOptions.lifetimes.ready = function ready () {
......@@ -1646,6 +1652,9 @@ let uni = {};
if (typeof Proxy !== 'undefined' && "mp-toutiao" !== 'app-plus') {
uni = new Proxy({}, {
get (target, name) {
if (target[name]) {
return target[name]
}
if (baseApi[name]) {
return baseApi[name]
}
......@@ -1667,9 +1676,13 @@ if (typeof Proxy !== 'undefined' && "mp-toutiao" !== 'app-plus') {
return
}
return promisify(name, wrapper(name, tt[name]))
},
set (target, name, value) {
target[name] = value;
return true
}
});
} else {
} else {
Object.keys(baseApi).forEach(name => {
uni[name] = baseApi[name];
});
......@@ -1705,4 +1718,4 @@ tt.createComponent = createComponent;
var uni$1 = uni;
export default uni$1;
export { createApp, createPage, createComponent };
export { createApp, createComponent, createPage };
{
"name": "@dcloudio/uni-mp-toutiao",
"version": "0.0.346",
"version": "0.0.350",
"description": "uni-app mp-toutiao",
"main": "dist/index.js",
"scripts": {
......
......@@ -231,7 +231,7 @@ const promiseInterceptor = {
};
const SYNC_API_RE =
/^\$|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
/^\$|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/;
const CONTEXT_API_RE = /^create|Manager$/;
......@@ -258,8 +258,8 @@ function handlePromise (promise) {
function shouldPromise (name) {
if (
isContextApi(name) ||
isSyncApi(name) ||
isCallbackApi(name)
isSyncApi(name) ||
isCallbackApi(name)
) {
return false
}
......@@ -561,8 +561,6 @@ function $emit () {
return apply(getEmitter(), '$emit', [...arguments])
}
var eventApi = /*#__PURE__*/Object.freeze({
$on: $on,
$off: $off,
......@@ -655,8 +653,8 @@ function hasHook (hook, vueOptions) {
return true
}
if (vueOptions.super &&
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
vueOptions.super.options &&
Array.isArray(vueOptions.super.options[hook])) {
return true
}
return false
......@@ -681,14 +679,14 @@ function initHooks (mpOptions, hooks, vueOptions) {
});
}
function initVueComponent (Vue$$1, vueOptions) {
function initVueComponent (Vue, vueOptions) {
vueOptions = vueOptions.default || vueOptions;
let VueComponent;
if (isFn(vueOptions)) {
VueComponent = vueOptions;
vueOptions = VueComponent.extendOptions;
} else {
VueComponent = Vue$$1.extend(vueOptions);
VueComponent = Vue.extend(vueOptions);
}
return [VueComponent, vueOptions]
}
......@@ -855,7 +853,7 @@ function initProperties (props, isBehavior = false, file = '') {
value = value();
}
opts.type = parsePropType(key, opts.type, value, file);
opts.type = parsePropType(key, opts.type);
properties[key] = {
type: PROP_TYPES.indexOf(opts.type) !== -1 ? opts.type : null,
......@@ -863,7 +861,7 @@ function initProperties (props, isBehavior = false, file = '') {
observer: createObserver(key)
};
} else { // content:String
const type = parsePropType(key, opts, null, file);
const type = parsePropType(key, opts);
properties[key] = {
type: PROP_TYPES.indexOf(type) !== -1 ? type : null,
observer: createObserver(key)
......@@ -938,16 +936,16 @@ function processEventExtra (vm, extra, event) {
if (Array.isArray(extra) && extra.length) {
/**
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*[
* ['data.items', 'data.id', item.data.id],
* ['metas', 'id', meta.id]
*],
*'test'
*/
extra.forEach((dataPath, index) => {
if (typeof dataPath === 'string') {
if (!dataPath) { // model,prop.sync
......@@ -983,8 +981,8 @@ function processEventArgs (vm, event, args = [], extra = [], isCustom, methodNam
let isCustomMPEvent = false; // wxcomponent 组件,传递原始 event 对象
if (isCustom) { // 自定义事件
isCustomMPEvent = event.currentTarget &&
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
event.currentTarget.dataset &&
event.currentTarget.dataset.comType === 'wx';
if (!args.length) { // 无参数,直接传入 event 或 detail 数组
if (isCustomMPEvent) {
return [event]
......@@ -1026,30 +1024,33 @@ const CUSTOM = '^';
function isMatchEventType (eventType, optType) {
return (eventType === optType) ||
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
(
optType === 'regionchange' &&
(
eventType === 'begin' ||
eventType === 'end'
)
)
}
function handleEvent (event) {
event = wrapper$1(event);
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
// [['tap',[['handle',[1,2,a]],['handle1',[1,2,a]]]]]
const dataset = (event.currentTarget || event.target).dataset;
if (!dataset) {
return console.warn(`事件信息不存在`)
}
const eventOpts = dataset.eventOpts || dataset['event-opts'];// 支付宝 web-view 组件 dataset 非驼峰
const eventOpts = dataset.eventOpts || dataset['event-opts']; // 支付宝 web-view 组件 dataset 非驼峰
if (!eventOpts) {
return console.warn(`事件信息不存在`)
}
// [['handle',[1,2,a]],['handle1',[1,2,a]]]
const eventType = event.type;
const ret = [];
eventOpts.forEach(eventOpt => {
let type = eventOpt[0];
const eventsArray = eventOpt[1];
......@@ -1066,8 +1067,8 @@ function handleEvent (event) {
let handlerCtx = this.$vm;
if (
handlerCtx.$options.generic &&
handlerCtx.$parent &&
handlerCtx.$parent.$parent
handlerCtx.$parent &&
handlerCtx.$parent.$parent
) { // mp-weixin,mp-toutiao 抽象节点模拟 scoped slots
handlerCtx = handlerCtx.$parent.$parent;
}
......@@ -1081,18 +1082,26 @@ function handleEvent (event) {
}
handler.once = true;
}
handler.apply(handlerCtx, processEventArgs(
ret.push(handler.apply(handlerCtx, processEventArgs(
this.$vm,
event,
eventArray[1],
eventArray[2],
isCustom,
methodName
));
)));
}
});
}
});
if (
eventType === 'input' &&
ret.length === 1 &&
typeof ret[0] !== 'undefined'
) {
return ret[0]
}
}
const hooks = [
......@@ -1252,8 +1261,8 @@ function createApp (vm) {
}
function parseBaseComponent (vueComponentOptions, {
isPage: isPage$$1,
initRelation: initRelation$$1
isPage,
initRelation
} = {}) {
let [VueComponent, vueOptions] = initVueComponent(Vue, vueComponentOptions);
......@@ -1270,7 +1279,7 @@ function parseBaseComponent (vueComponentOptions, {
const properties = this.properties;
const options = {
mpType: isPage$$1.call(this) ? 'page' : 'component',
mpType: isPage.call(this) ? 'page' : 'component',
mpInstance: this,
propsData: properties
};
......@@ -1278,7 +1287,7 @@ function parseBaseComponent (vueComponentOptions, {
initVueIds(properties.vueId, this);
// 处理父子关系
initRelation$$1.call(this, {
initRelation.call(this, {
vuePid: this._$vuePid,
vueOptions: options
});
......@@ -1322,7 +1331,7 @@ function parseBaseComponent (vueComponentOptions, {
}
};
if (isPage$$1) {
if (isPage) {
return componentOptions
}
return [componentOptions, VueComponent]
......@@ -1347,10 +1356,7 @@ function parseBasePage (vuePageOptions, {
isPage,
initRelation
}) {
const pageOptions = parseComponent(vuePageOptions, {
isPage,
initRelation
});
const pageOptions = parseComponent(vuePageOptions);
initHooks(pageOptions.methods, hooks$1, vuePageOptions);
......@@ -1398,6 +1404,9 @@ let uni = {};
if (typeof Proxy !== 'undefined' && "mp-weixin" !== 'app-plus') {
uni = new Proxy({}, {
get (target, name) {
if (target[name]) {
return target[name]
}
if (baseApi[name]) {
return baseApi[name]
}
......@@ -1419,9 +1428,13 @@ if (typeof Proxy !== 'undefined' && "mp-weixin" !== 'app-plus') {
return
}
return promisify(name, wrapper(name, wx[name]))
},
set (target, name, value) {
target[name] = value;
return true
}
});
} else {
} else {
Object.keys(baseApi).forEach(name => {
uni[name] = baseApi[name];
});
......@@ -1457,4 +1470,4 @@ wx.createComponent = createComponent;
var uni$1 = uni;
export default uni$1;
export { createApp, createPage, createComponent };
export { createApp, createComponent, createPage };
{
"name": "@dcloudio/uni-mp-weixin",
"version": "0.0.967",
"version": "0.0.972",
"description": "uni-app mp-weixin",
"main": "dist/index.js",
"scripts": {
......
module.exports = {
plugins: [
require('autoprefixer')({ browsers: ['iOS >= 8', 'Android >= 4'] })
require('autoprefixer')({ overrideBrowserslist: ['iOS >= 8', 'Android >= 4'] })
]
}
......@@ -14,7 +14,7 @@ import {
isCallbackApi
} from './promise'
import protocol from './protocol/index'
import protocol from 'uni-api-protocol'
import validateParam from './params'
......@@ -159,6 +159,15 @@ function createApiCallback (apiName, params = {}, extras = {}) {
const invokeCallback = function (res) {
res.errMsg = res.errMsg || apiName + ':ok'
// 部分 api 可能返回的 errMsg 的 api 名称部分不一致,格式化为正确的
if (res.errMsg.indexOf(':ok') !== -1) {
res.errMsg = apiName + ':ok'
} else if (res.errMsg.indexOf(':cancel') !== -1) {
res.errMsg = apiName + ':cancel'
} else if (res.errMsg.indexOf(':fail') !== -1) {
res.errMsg = apiName + ':fail'
}
const errMsg = res.errMsg
if (errMsg.indexOf(apiName + ':ok') === 0) {
......@@ -234,7 +243,7 @@ export function invokeCallbackHandler (invokeCallbackId, res) {
}
export function wrapperUnimplemented (name) {
return function (args) {
return function todo (args) {
console.error('API `' + name + '` is not yet implemented')
}
}
......
......@@ -8,7 +8,7 @@ import {
} from './interceptor'
const SYNC_API_RE =
/^\$|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
/^\$|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/
const CONTEXT_API_RE = /^create|Manager$/
......@@ -41,8 +41,8 @@ function handlePromise (promise) {
export function shouldPromise (name) {
if (
isContextApi(name) ||
isSyncApi(name) ||
isCallbackApi(name)
isSyncApi(name) ||
isCallbackApi(name)
) {
return false
}
......
const protocol = Object.create(null)
const modules = require.context('./', true, /\.js$/)
const modules = require.context('./protocol', true, /\.js$/)
modules.keys().forEach(function (key) {
if (key !== './index.js') {
Object.assign(protocol, modules(key))
}
Object.assign(protocol, modules(key))
})
export default protocol
export const $on = [{
name: 'event',
type: [String, Array],
required: true
}, {
name: 'callback',
type: Function,
required: true
}]
export const $once = $on
export const $off = [{
name: 'event',
type: [String, Array]
}, {
name: 'callback',
type: Function
}]
export const $emit = [{
name: 'event',
type: String,
required: true
}]
export const addInterceptor = [{
name: 'method',
type: [String, Object],
required: true
}]
export const removeInterceptor = addInterceptor
export const upx2px = [{
name: 'upx',
type: [Number, String],
required: true
}]
export const chooseLocation = {
keyword: {
type: String
}
}
const type = {
WGS84: 'WGS84',
GCJ02: 'GCJ02'
}
export const getLocation = {
type: {
type: String,
validator (value, params) {
value = (value || '').toUpperCase()
params.type = Object.values(type).indexOf(value) < 0 ? type.WGS84 : value
},
default: type.WGS84
},
altitude: {
altitude: Boolean,
default: false
}
}
const type = {
WGS84: 'WGS84',
GCJ02: 'GCJ02'
}
export const getLocation = {
type: {
type: String,
validator (value, params) {
value = (value || '').toUpperCase()
params.type = Object.values(type).indexOf(value) < 0 ? type.WGS84 : value
},
default: type.WGS84
},
altitude: {
altitude: Boolean,
default: false
}
}
export const openLocation = {
latitude: {
type: Number,
......
export const getStorage = {
'key': {
type: String,
required: true
}
}
export const getStorageSync = [{
name: 'key',
type: String,
required: true
}]
export const setStorage = {
'key': {
type: String,
......@@ -15,4 +28,7 @@ export const setStorageSync = [{
}, {
name: 'data',
required: true
}]
}]
export const removeStorage = getStorage
export const removeStorageSync = getStorageSync
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册