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

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

...@@ -35,8 +35,8 @@ function getPagesJson () { ...@@ -35,8 +35,8 @@ function getPagesJson () {
return processPagesJson(getJson('pages.json', true)) return processPagesJson(getJson('pages.json', true))
} }
function parsePagesJson (content) { function parsePagesJson (content, loader) {
return processPagesJson(parseJson(content, true)) return processPagesJson(parseJson(content, true), loader)
} }
function filterPages (pages = [], root) { function filterPages (pages = [], root) {
...@@ -48,7 +48,25 @@ function filterPages (pages = [], root) { ...@@ -48,7 +48,25 @@ function filterPages (pages = [], root) {
} }
} }
function processPagesJson (pagesJson) { const pagesJsonJsFileName = 'pages.js'
function processPagesJson (pagesJson, loader = {
addDependency: function () {}
}) {
const pagesJsonJsPath = path.resolve(process.env.UNI_INPUT_DIR, pagesJsonJsFileName)
if (fs.existsSync(pagesJsonJsPath)) {
delete require.cache[pagesJsonJsPath]
const pagesJsonJsFn = require(pagesJsonJsPath)
if (typeof pagesJsonJsFn === 'function') {
pagesJson = pagesJsonJsFn(pagesJson, loader)
if (!pagesJson) {
console.error(`${pagesJsonJsFileName} 必须返回一个 json 对象`)
}
} else {
console.error(`${pagesJsonJsFileName} 必须导出 function`)
}
}
let uniNVueEntryPagePath let uniNVueEntryPagePath
if (pagesJson.pages && pagesJson.pages.length) { // 如果首页是 nvue if (pagesJson.pages && pagesJson.pages.length) { // 如果首页是 nvue
if (isNVuePage(pagesJson.pages[0])) { if (isNVuePage(pagesJson.pages[0])) {
...@@ -193,7 +211,6 @@ function parseEntry (pagesJson) { ...@@ -193,7 +211,6 @@ function parseEntry (pagesJson) {
process.UNI_NVUE_ENTRY = {} process.UNI_NVUE_ENTRY = {}
if (process.env.UNI_USING_NATIVE) { if (process.env.UNI_USING_NATIVE) {
// TODO 考虑 pages.json.js
process.UNI_NVUE_ENTRY['app-config'] = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json') process.UNI_NVUE_ENTRY['app-config'] = path.resolve(process.env.UNI_INPUT_DIR, 'pages.json')
process.UNI_NVUE_ENTRY['app-service'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry()) process.UNI_NVUE_ENTRY['app-service'] = path.resolve(process.env.UNI_INPUT_DIR, getMainEntry())
} }
...@@ -231,5 +248,6 @@ module.exports = { ...@@ -231,5 +248,6 @@ module.exports = {
parsePages, parsePages,
parseEntry, parseEntry,
getPagesJson, getPagesJson,
parsePagesJson parsePagesJson,
pagesJsonJsFileName
} }
...@@ -238,7 +238,7 @@ const PLATFORMS = { ...@@ -238,7 +238,7 @@ const PLATFORMS = {
vue: megaloRuntime, vue: megaloRuntime,
compiler: megaloCompiler, compiler: megaloCompiler,
megalo: 'alipay', megalo: 'alipay',
filterTag: 'import-sjs', filterTag: 'sjs',
subPackages: true, subPackages: true,
cssVars: { cssVars: {
'--status-bar-height': '25px', '--status-bar-height': '25px',
......
...@@ -1829,6 +1829,33 @@ function parseApp (vm) { ...@@ -1829,6 +1829,33 @@ function parseApp (vm) {
} }
}); });
Vue.prototype.$onAliGetAuthorize = function onAliGetAuthorize (method, $event) {
my.getPhoneNumber({
success: (res) => {
$event.type = 'getphonenumber';
const response = JSON.parse(res.response).response;
if (response.code === '10000') { // success
$event.detail.errMsg = 'getPhoneNumber:ok';
$event.detail.encryptedData = res.response;
} else {
$event.detail.errMsg = 'getPhoneNumber:fail Error: ' + res.response;
}
this[method]($event);
},
fail: (res) => {
$event.type = 'getphonenumber';
$event.detail.errMsg = 'getPhoneNumber:fail';
this[method]($event);
}
});
};
Vue.prototype.$onAliAuthError = function $onAliAuthError (method, $event) {
$event.type = 'getphonenumber';
$event.detail.errMsg = 'getPhoneNumber:fail Error: ' + $event.detail.errorMessage;
this[method]($event);
};
return parseBaseApp(vm, { return parseBaseApp(vm, {
mocks, mocks,
initRefs initRefs
......
...@@ -415,7 +415,8 @@ const todos = [ ...@@ -415,7 +415,8 @@ const todos = [
'stopBeaconDiscovery', 'stopBeaconDiscovery',
'hideShareMenu', 'hideShareMenu',
'onWindowResize', 'onWindowResize',
'offWindowResize' 'offWindowResize',
'vibrate'
]; ];
// 存在兼容性的 API 列表 // 存在兼容性的 API 列表
......
...@@ -428,7 +428,8 @@ const todos = [ ...@@ -428,7 +428,8 @@ const todos = [
'checkIsSoterEnrolledInDevice', 'checkIsSoterEnrolledInDevice',
'reportMonitor', 'reportMonitor',
'getLogManager', 'getLogManager',
'reportAnalytics' 'reportAnalytics',
'vibrate'
]; ];
const canIUses = [ const canIUses = [
'scanCode', 'scanCode',
......
...@@ -451,7 +451,8 @@ const todos = [ ...@@ -451,7 +451,8 @@ const todos = [
'onWindowResize', 'onWindowResize',
'offWindowResize', 'offWindowResize',
'compressImage', 'compressImage',
'createOffscreenCanvas' 'createOffscreenCanvas',
'vibrate'
]; ];
// 存在兼容性的 API 列表 // 存在兼容性的 API 列表
......
...@@ -387,7 +387,9 @@ var previewImage = { ...@@ -387,7 +387,9 @@ var previewImage = {
const protocols = { const protocols = {
previewImage previewImage
}; };
const todos = []; const todos = [
'vibrate'
];
const canIUses = []; const canIUses = [];
const CALLBACKS = ['success', 'fail', 'cancel', 'complete']; const CALLBACKS = ['success', 'fail', 'cancel', 'complete'];
......
...@@ -104,6 +104,13 @@ describe('mp:compiler-mp-alipay', () => { ...@@ -104,6 +104,13 @@ describe('mp:compiler-mp-alipay', () => {
) )
}) })
it('generate getPhoneNumber', () => {
assertCodegen(
'<button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取手机号</button>',
`<button open-type="getAuthorize" scope="phoneNumber" data-event-opts="{{[['getAuthorize',[['$onAliGetAuthorize',['getPhoneNumber','$event']]]],['error',[['$onAliAuthError',['getPhoneNumber','$event']]]]]}}" onGetAuthorize="__e" onError="__e">获取手机号</button>`
)
})
it('generate events with v-on directive', () => { it('generate events with v-on directive', () => {
assertCodegen( assertCodegen(
`<uni-list-item title="标题文字" note="描述信息" show-extra-icon="true" :extra-icon="{color: '#4cd964',size: '22',type: 'spinner'}"></uni-list-item>`, `<uni-list-item title="标题文字" note="描述信息" show-extra-icon="true" :extra-icon="{color: '#4cd964',size: '22',type: 'spinner'}"></uni-list-item>`,
......
const compiler = require('../lib') const compiler = require('../lib')
const res = compiler.compile( const res = compiler.compile(
` `
<view @/> <button open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">获取手机号</button>
`, { `, {
resourcePath: '/User/fxy/Documents/test.wxml', resourcePath: '/User/fxy/Documents/test.wxml',
mp: { mp: {
......
...@@ -18,6 +18,8 @@ const generateTemplate = require('./template/generate') ...@@ -18,6 +18,8 @@ const generateTemplate = require('./template/generate')
const compilerModule = require('./module') const compilerModule = require('./module')
const compilerAlipayModule = require('./module-alipay')
const generateCodeFrame = require('./codeframe') const generateCodeFrame = require('./codeframe')
module.exports = { module.exports = {
...@@ -28,6 +30,10 @@ module.exports = { ...@@ -28,6 +30,10 @@ module.exports = {
(options.modules || (options.modules = [])).push(compilerModule) (options.modules || (options.modules = [])).push(compilerModule)
if (options.mp.platform === 'mp-alipay') {
options.modules.push(compilerAlipayModule)
}
const res = compile(source, Object.assign(options, { const res = compile(source, Object.assign(options, {
optimize: false optimize: false
})) }))
......
module.exports = {
postTransformNode (el) {
const attrsMap = el.attrsMap
if (attrsMap['open-type'] !== 'getPhoneNumber') {
return
}
const getPhoneNumberValue = attrsMap['@getphonenumber'] || attrsMap['v-on:getphonenumber']
if (!getPhoneNumberValue) {
return
}
el.attrs.find(attr => attr.name === 'open-type').value = '"getAuthorize"'
el.attrs.push({
name: 'scope',
value: '"phoneNumber"'
})
delete el.events['getphonenumber']
el.events['getAuthorize'] = {
value: '$onAliGetAuthorize(\'' + getPhoneNumberValue + '\',$event)'
}
el.events['error'] = {
value: '$onAliAuthError(\'' + getPhoneNumberValue + '\',$event)'
}
}
}
...@@ -45,7 +45,7 @@ module.exports = { ...@@ -45,7 +45,7 @@ module.exports = {
createFilterTag (filterTag, { createFilterTag (filterTag, {
attrs attrs
}) { }) {
return `<${filterTag} name="${attrs.module}" from="${attrs.src}"></${filterTag}>` return `<import-sjs name="${attrs.module}" from="${attrs.src}"></import-sjs>`
}, },
getEventType (eventType) { getEventType (eventType) {
return EVENTS[eventType] || eventType return EVENTS[eventType] || eventType
......
...@@ -92,7 +92,9 @@ const rules = [{ ...@@ -92,7 +92,9 @@ const rules = [{
}, },
jsPreprocessorLoader jsPreprocessorLoader
], ],
exclude: excludeModuleReg exclude (modulePath) {
return excludeModuleReg.test(modulePath) && modulePath.indexOf('@dcloudio') === -1
}
}, },
{ {
test: /\.nvue(\?[^?]+)?$/, test: /\.nvue(\?[^?]+)?$/,
...@@ -171,7 +173,7 @@ if (process.env.UNI_USING_NATIVE) { ...@@ -171,7 +173,7 @@ if (process.env.UNI_USING_NATIVE) {
module.exports = function (entry) { module.exports = function (entry) {
return { return {
target: 'node', // 激活 vue-loader 的 isServer 逻辑 target: 'node', // 激活 vue-loader 的 isServer 逻辑
mode: 'development', // process.env.NODE_ENV, mode: process.env.NODE_ENV,
devtool: process.env.NODE_ENV === 'development' ? 'inline-source-map' : false, devtool: process.env.NODE_ENV === 'development' ? 'inline-source-map' : false,
watch: process.env.NODE_ENV === 'development', watch: process.env.NODE_ENV === 'development',
entry, entry,
......
...@@ -132,10 +132,10 @@ module.exports = { ...@@ -132,10 +132,10 @@ module.exports = {
resourceQuery: [ resourceQuery: [
/lang=wxs/, /lang=wxs/,
/lang=filter/, /lang=filter/,
/lang=import-sjs/, /lang=sjs/,
/blockType=wxs/, /blockType=wxs/,
/blockType=filter/, /blockType=filter/,
/blockType=import-sjs/ /blockType=sjs/
], ],
use: [{ use: [{
loader: require.resolve( loader: require.resolve(
......
...@@ -12,6 +12,13 @@ module.exports = function getSplitChunks () { ...@@ -12,6 +12,13 @@ module.exports = function getSplitChunks () {
} }
} }
} }
const {
normalizePath
} = require('@dcloudio/uni-cli-shared')
const mainPath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, 'main.'))
if (!process.env.UNI_OPT_SUBPACKAGES) { if (!process.env.UNI_OPT_SUBPACKAGES) {
return { return {
chunks (chunk) { // 防止 node_modules 内 vue 组件被 split chunks (chunk) { // 防止 node_modules 内 vue 组件被 split
...@@ -27,7 +34,8 @@ module.exports = function getSplitChunks () { ...@@ -27,7 +34,8 @@ module.exports = function getSplitChunks () {
} }
if (module.resource && ( if (module.resource && (
module.resource.indexOf('.vue') !== -1 || module.resource.indexOf('.vue') !== -1 ||
module.resource.indexOf('.nvue') !== -1 module.resource.indexOf('.nvue') !== -1 ||
module.resource.indexOf(mainPath) === 0 // main.js
)) { )) {
return false return false
} }
...@@ -40,11 +48,6 @@ module.exports = function getSplitChunks () { ...@@ -40,11 +48,6 @@ module.exports = function getSplitChunks () {
} }
} }
} }
const {
normalizePath
} = require('@dcloudio/uni-cli-shared')
const mainPath = normalizePath(path.resolve(process.env.UNI_INPUT_DIR, 'main.'))
function baseTest (module) { function baseTest (module) {
if (module.type === 'css/mini-extract') { if (module.type === 'css/mini-extract') {
......
...@@ -48,7 +48,7 @@ module.exports = function(source) { ...@@ -48,7 +48,7 @@ module.exports = function(source) {
descriptor.customBlocks = descriptor.customBlocks.filter(block => { descriptor.customBlocks = descriptor.customBlocks.filter(block => {
if ( if (
block.attrs.module || block.attrs.module &&
( (
block.type === FILTER_TAG || block.type === FILTER_TAG ||
block.attrs.lang === FILTER_TAG block.attrs.lang === FILTER_TAG
......
...@@ -6,6 +6,10 @@ const { ...@@ -6,6 +6,10 @@ const {
normalizePath normalizePath
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
const {
pagesJsonJsFileName
} = require('@dcloudio/uni-cli-shared/lib/pages')
const generateApp = require('./generate-app') const generateApp = require('./generate-app')
const generateJson = require('./generate-json') const generateJson = require('./generate-json')
const generateComponent = require('./generate-component') const generateComponent = require('./generate-component')
...@@ -43,7 +47,8 @@ function addSubPackagesRequire (compilation) { ...@@ -43,7 +47,8 @@ function addSubPackagesRequire (compilation) {
name.indexOf(root) === 0 && name.indexOf(root) === 0 &&
name !== subPackageVendorPath name !== subPackageVendorPath
) { ) {
const source = `require('${normalizePath(path.relative(path.dirname(name), subPackageVendorPath))}');` + const source =
`require('${normalizePath(path.relative(path.dirname(name), subPackageVendorPath))}');` +
compilation.assets[name].source() compilation.assets[name].source()
compilation.assets[name] = { compilation.assets[name] = {
...@@ -82,13 +87,24 @@ class WebpackUniMPPlugin { ...@@ -82,13 +87,24 @@ class WebpackUniMPPlugin {
}) })
compiler.hooks.invalid.tap('webpack-uni-mp-invalid', (fileName, changeTime) => { compiler.hooks.invalid.tap('webpack-uni-mp-invalid', (fileName, changeTime) => {
if (fileName && typeof fileName === 'string' && path.basename(fileName) === 'pages.json') { // 重新解析 entry if (
fileName &&
typeof fileName === 'string'
) { // 重新解析 entry
const basename = path.basename(fileName)
const deps = process.UNI_PAGES_DEPS || new Set()
if (
basename === 'pages.json' ||
basename === pagesJsonJsFileName ||
deps.has(normalizePath(fileName))
) {
try { try {
parseEntry() parseEntry()
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
} }
}
}) })
} }
} }
......
...@@ -2,9 +2,14 @@ const path = require('path') ...@@ -2,9 +2,14 @@ const path = require('path')
const { const {
md5, md5,
parseEntry parseEntry,
normalizePath
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
const {
pagesJsonJsFileName
} = require('@dcloudio/uni-cli-shared/lib/pages')
const { const {
getPages, getPages,
getSubPages, getSubPages,
...@@ -93,13 +98,24 @@ class WebpackUniMPPlugin { ...@@ -93,13 +98,24 @@ class WebpackUniMPPlugin {
}) })
compiler.hooks.invalid.tap('webpack-uni-mp-invalid', (fileName, changeTime) => { compiler.hooks.invalid.tap('webpack-uni-mp-invalid', (fileName, changeTime) => {
if (fileName && typeof fileName === 'string' && path.basename(fileName) === 'pages.json') { // 重新解析 entry if (
fileName &&
typeof fileName === 'string'
) { // 重新解析 entry
const basename = path.basename(fileName)
const deps = process.UNI_PAGES_DEPS || new Set()
if (
basename === 'pages.json' ||
basename === pagesJsonJsFileName ||
deps.has(normalizePath(fileName))
) {
try { try {
parseEntry() parseEntry()
} catch (e) { } catch (e) {
console.error(e) console.error(e)
} }
} }
}
}) })
} }
} }
......
...@@ -14,6 +14,10 @@ const { ...@@ -14,6 +14,10 @@ const {
updateProjectJson updateProjectJson
} = require('@dcloudio/uni-cli-shared/lib/cache') } = require('@dcloudio/uni-cli-shared/lib/cache')
const {
pagesJsonJsFileName
} = require('@dcloudio/uni-cli-shared/lib/pages')
const parseStyle = require('./util').parseStyle const parseStyle = require('./util').parseStyle
// 将开发者手动设置的 usingComponents 调整名称,方便与自动解析到的 usingComponents 做最后合并 // 将开发者手动设置的 usingComponents 调整名称,方便与自动解析到的 usingComponents 做最后合并
...@@ -28,12 +32,19 @@ function renameUsingComponents (jsonObj) { ...@@ -28,12 +32,19 @@ function renameUsingComponents (jsonObj) {
module.exports = function (content) { module.exports = function (content) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
const pagesJsonJsPath = path.resolve(process.env.UNI_INPUT_DIR, pagesJsonJsFileName)
const manifestJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'manifest.json') const manifestJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'manifest.json')
const manifestJson = parseManifestJson(fs.readFileSync(manifestJsonPath, 'utf8')) const manifestJson = parseManifestJson(fs.readFileSync(manifestJsonPath, 'utf8'))
this.addDependency(pagesJsonJsPath)
this.addDependency(manifestJsonPath) this.addDependency(manifestJsonPath)
const pagesJson = parsePagesJson(content) const pagesJson = parsePagesJson(content, {
addDependency: (file) => {
(process.UNI_PAGES_DEPS || (process.UNI_PAGES_DEPS = new Set())).add(normalizePath(file))
this.addDependency(file)
}
})
// TODO 与 usingComponents 放在一块读取设置 // TODO 与 usingComponents 放在一块读取设置
if (manifestJson.transformPx === false) { if (manifestJson.transformPx === false) {
process.UNI_TRANSFORM_PX = false process.UNI_TRANSFORM_PX = false
......
...@@ -13,6 +13,10 @@ const { ...@@ -13,6 +13,10 @@ const {
getPagesJson getPagesJson
} = require('@dcloudio/uni-cli-shared/lib/cache') } = require('@dcloudio/uni-cli-shared/lib/cache')
const {
pagesJsonJsFileName
} = require('@dcloudio/uni-cli-shared/lib/pages')
const parseStyle = require('./util').parseStyle const parseStyle = require('./util').parseStyle
const emitFileCaches = {} const emitFileCaches = {}
...@@ -44,11 +48,18 @@ module.exports = function (content) { ...@@ -44,11 +48,18 @@ module.exports = function (content) {
this.cacheable && this.cacheable() this.cacheable && this.cacheable()
const manifestJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'manifest.json') const manifestJsonPath = path.resolve(process.env.UNI_INPUT_DIR, 'manifest.json')
const pagesJsonJsPath = path.resolve(process.env.UNI_INPUT_DIR, pagesJsonJsFileName)
const manifestJson = parseManifestJson(fs.readFileSync(manifestJsonPath, 'utf8')) const manifestJson = parseManifestJson(fs.readFileSync(manifestJsonPath, 'utf8'))
this.addDependency(manifestJsonPath) this.addDependency(manifestJsonPath)
this.addDependency(pagesJsonJsPath)
const pagesJson = parsePagesJson(content) const pagesJson = parsePagesJson(content, {
addDependency: (file) => {
(process.UNI_PAGES_DEPS || (process.UNI_PAGES_DEPS = new Set())).add(normalizePath(file))
this.addDependency(file)
}
})
if (manifestJson.transformPx === false) { if (manifestJson.transformPx === false) {
process.UNI_TRANSFORM_PX = false process.UNI_TRANSFORM_PX = false
......
...@@ -2,6 +2,10 @@ const { ...@@ -2,6 +2,10 @@ const {
parsePages parsePages
} = require('@dcloudio/uni-cli-shared') } = require('@dcloudio/uni-cli-shared')
const {
updateAppJsonUsingComponents
} = require('@dcloudio/uni-cli-shared/lib/cache')
const { const {
hasOwn, hasOwn,
parseStyle, parseStyle,
...@@ -60,6 +64,10 @@ module.exports = function (pagesJson, manifestJson) { ...@@ -60,6 +64,10 @@ module.exports = function (pagesJson, manifestJson) {
copyToJson(app, pagesJson, pagesJson2AppJson) copyToJson(app, pagesJson, pagesJson2AppJson)
if (app.usingComponents) {
updateAppJsonUsingComponents(app.usingComponents)
}
return [{ return [{
name: 'app', name: 'app',
content: app content: app
......
...@@ -12,7 +12,8 @@ import { ...@@ -12,7 +12,8 @@ import {
} from '../../constants' } from '../../constants'
import { import {
registerPlusMessage registerPlusMessage,
consumePlusMessage
} from '../../framework/plus-message' } from '../../framework/plus-message'
export const SCAN_ID = '__UNIAPP_SCAN' export const SCAN_ID = '__UNIAPP_SCAN'
...@@ -98,11 +99,11 @@ export function scanCode ({ ...@@ -98,11 +99,11 @@ export function scanCode ({
if (isDark) { if (isDark) {
plus.navigator.setStatusBarStyle('isDark') plus.navigator.setStatusBarStyle('isDark')
} }
webview.close('auto')
result = { result = {
type, type,
code code
} }
webview.close('auto')
}, () => { }, () => {
plus.nativeUI.toast('识别失败') plus.nativeUI.toast('识别失败')
}, filters) }, filters)
...@@ -143,7 +144,7 @@ export function scanCode ({ ...@@ -143,7 +144,7 @@ export function scanCode ({
}) })
}) })
webview.addEventListener('close', () => { webview.addEventListener('close', () => {
if (result && 'code' in result) { if (result) {
invoke(callbackId, { invoke(callbackId, {
result: result.code, result: result.code,
scanType: SCAN_MAPS[result.type] || '', scanType: SCAN_MAPS[result.type] || '',
...@@ -156,6 +157,7 @@ export function scanCode ({ ...@@ -156,6 +157,7 @@ export function scanCode ({
errMsg: 'scanCode:fail cancel' errMsg: 'scanCode:fail cancel'
}) })
} }
consumePlusMessage(MESSAGE_TYPE)
}) })
if (isDark) { // 状态栏前景色 if (isDark) { // 状态栏前景色
plus.navigator.setStatusBarStyle('light') plus.navigator.setStatusBarStyle('light')
...@@ -170,15 +172,10 @@ export function scanCode ({ ...@@ -170,15 +172,10 @@ export function scanCode ({
} }
}) })
} }
// fixed by hxy 注册扫码事件
registerPlusMessage(MESSAGE_TYPE, function (res) { registerPlusMessage(MESSAGE_TYPE, function (res) {
if (res && !res.errMsg) { if (res && 'code' in res) {
result = res result = res
} else {
const errMsg = res && res.errMsg ? ' ' + res.errMsg : ''
result = {
errMsg: 'scanCode:fail' + errMsg
}
} }
}, false) }, false)
} }
...@@ -11,11 +11,14 @@ import { ...@@ -11,11 +11,14 @@ import {
} from '../../constants' } from '../../constants'
import { import {
registerPlusMessage registerPlusMessage,
consumePlusMessage
} from '../../framework/plus-message' } from '../../framework/plus-message'
const CHOOSE_LOCATION_PATH = '_www/__uniappchooselocation.html' const CHOOSE_LOCATION_PATH = '_www/__uniappchooselocation.html'
const MESSAGE_TYPE = 'chooseLocation'
export function chooseLocation (params, callbackId) { export function chooseLocation (params, callbackId) {
const statusBarStyle = plus.navigator.getStatusBarStyle() const statusBarStyle = plus.navigator.getStatusBarStyle()
const webview = plus.webview.create( const webview = plus.webview.create(
...@@ -57,26 +60,38 @@ export function chooseLocation (params, callbackId) { ...@@ -57,26 +60,38 @@ export function chooseLocation (params, callbackId) {
} }
}) })
} }
let index = 0
webview.show('slide-in-bottom', ANI_DURATION, () => { let onShow = function () {
index++
if (index === 2) {
webview.evalJS(`__chooseLocation__(${JSON.stringify(params)})`) webview.evalJS(`__chooseLocation__(${JSON.stringify(params)})`)
}) }
}
webview.addEventListener('loaded', onShow)
webview.show('slide-in-bottom', ANI_DURATION, onShow)
// fixed by hxy let result
registerPlusMessage('chooseLocation', function (res) {
if (res && !res.errMsg) { webview.addEventListener('close', () => {
if (result) {
invoke(callbackId, { invoke(callbackId, {
name: res.poiname, name: result.poiname,
address: res.poiaddress, address: result.poiaddress,
latitude: res.latlng.lat, latitude: result.latlng.lat,
longitude: res.latlng.lng, longitude: result.latlng.lng,
errMsg: 'chooseLocation:ok' errMsg: 'chooseLocation:ok'
}) })
} else { } else {
const errMsg = res && res.errMsg ? ' ' + res.errMsg : '' consumePlusMessage(MESSAGE_TYPE)
invoke(callbackId, { invoke(callbackId, {
errMsg: 'chooseLocation:fail' + errMsg errMsg: 'chooseLocation:fail cancel'
})
}
}) })
registerPlusMessage(MESSAGE_TYPE, function (res) {
if (res && 'latlng' in res) {
result = res
} }
}, false) }, false)
} }
...@@ -9,7 +9,8 @@ import { ...@@ -9,7 +9,8 @@ import {
} from './page' } from './page'
import { import {
registerPlusMessage registerPlusMessage,
consumePlusMessage
} from './plus-message' } from './plus-message'
import { import {
...@@ -69,6 +70,16 @@ function initGlobalListeners () { ...@@ -69,6 +70,16 @@ function initGlobalListeners () {
height: event.height height: event.height
}) })
}) })
plus.globalEvent.addEventListener('plusMessage', function (e) {
if (process.env.NODE_ENV !== 'production') {
console.log('UNIAPP[plusMessage]:[' + Date.now() + ']' + JSON.stringify(e.data))
}
if (e.data && e.data.type) {
const type = e.data.type
consumePlusMessage(type, e.data.args || {})
}
})
} }
function initAppLaunch (appVm) { function initAppLaunch (appVm) {
......
...@@ -25,6 +25,33 @@ export default function parseApp (vm) { ...@@ -25,6 +25,33 @@ export default function parseApp (vm) {
} }
}) })
Vue.prototype.$onAliGetAuthorize = function onAliGetAuthorize (method, $event) {
my.getPhoneNumber({
success: (res) => {
$event.type = 'getphonenumber'
const response = JSON.parse(res.response).response
if (response.code === '10000') { // success
$event.detail.errMsg = 'getPhoneNumber:ok'
$event.detail.encryptedData = res.response
} else {
$event.detail.errMsg = 'getPhoneNumber:fail Error: ' + res.response
}
this[method]($event)
},
fail: (res) => {
$event.type = 'getphonenumber'
$event.detail.errMsg = 'getPhoneNumber:fail'
this[method]($event)
}
})
}
Vue.prototype.$onAliAuthError = function $onAliAuthError (method, $event) {
$event.type = 'getphonenumber'
$event.detail.errMsg = 'getPhoneNumber:fail Error: ' + $event.detail.errorMessage
this[method]($event)
}
return parseBaseApp(vm, { return parseBaseApp(vm, {
mocks, mocks,
initRefs initRefs
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册