提交 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])) {
...@@ -86,7 +104,7 @@ function isNVuePage (page, root = '') { ...@@ -86,7 +104,7 @@ function isNVuePage (page, root = '') {
} }
function isValidPage (page, root = '') { function isValidPage (page, root = '') {
if (typeof page === 'string') { // 不合法的配置 if (typeof page === 'string') { // 不合法的配置
console.warn(`${page} 配置错误, 已被忽略, 查看文档: https://uniapp.dcloud.io/collocation/pages?id=pages`) console.warn(`${page} 配置错误, 已被忽略, 查看文档: https://uniapp.dcloud.io/collocation/pages?id=pages`)
return false return false
} }
...@@ -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',
......
...@@ -1811,7 +1811,7 @@ const handleLink$1 = (function () { ...@@ -1811,7 +1811,7 @@ const handleLink$1 = (function () {
} }
})(); })();
function parseApp (vm) { function parseApp (vm) {
Object.defineProperty(Vue.prototype, '$slots', { Object.defineProperty(Vue.prototype, '$slots', {
get () { get () {
return this.$scope && this.$scope.props.$slots return this.$scope && this.$scope.props.$slots
...@@ -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'];
......
...@@ -27,24 +27,24 @@ describe('mp:compiler-mp-alipay', () => { ...@@ -27,24 +27,24 @@ describe('mp:compiler-mp-alipay', () => {
'<view><view v-if="show">hello</view><view v-else-if="hide">world</view><view v-else>bye</view></view>', '<view><view v-if="show">hello</view><view v-else-if="hide">world</view><view v-else>bye</view></view>',
`<view><block a:if="{{show}}"><view>hello</view></block><block a:else><block a:if="{{hide}}"><view>world</view></block><block a:else><view>bye</view></block></block></view>` `<view><block a:if="{{show}}"><view>hello</view></block><block a:else><block a:if="{{hide}}"><view>world</view></block><block a:else><view>bye</view></block></block></view>`
) )
}) })
it('generate ref', () => { it('generate ref', () => {
assertCodegen( assertCodegen(
'<component1 ref="c1">text</component1>', '<component1 ref="c1">text</component1>',
`<component1 vue-id="1" ref="__r" data-ref="c1" onVueInit="__l">text</component1>` `<component1 vue-id="1" ref="__r" data-ref="c1" onVueInit="__l">text</component1>`
) )
assertCodegen( assertCodegen(
'<component1 :ref="c2">text<text>123213</text></component1>', '<component1 :ref="c2">text<text>123213</text></component1>',
`<component1 vue-id="1" ref="__r" data-ref="{{c2}}" onVueInit="__l">text<text>123213</text></component1>` `<component1 vue-id="1" ref="__r" data-ref="{{c2}}" onVueInit="__l">text<text>123213</text></component1>`
) )
assertCodegen( assertCodegen(
'<component1 v-for="item in items" ref="c3"></component1>', '<component1 v-for="item in items" ref="c3"></component1>',
`<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'1-'+__i0__}}" ref="__r" data-ref-in-for="c3" onVueInit="__l"></component1></block>` `<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'1-'+__i0__}}" ref="__r" data-ref-in-for="c3" onVueInit="__l"></component1></block>`
) )
assertCodegen( assertCodegen(
'<component1 v-for="item in items" :ref="c4"></component1>', '<component1 v-for="item in items" :ref="c4"></component1>',
`<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'1-'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" onVueInit="__l"></component1></block>` `<block a:for="{{items}}" a:for-item="item" a:for-index="__i0__"><component1 vue-id="{{'1-'+__i0__}}" ref="__r" data-ref-in-for="{{c4}}" onVueInit="__l"></component1></block>`
) )
}) })
it('generate default slot', () => { it('generate default slot', () => {
assertCodegen( assertCodegen(
...@@ -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>`,
...@@ -119,26 +126,26 @@ describe('mp:compiler-mp-alipay', () => { ...@@ -119,26 +126,26 @@ describe('mp:compiler-mp-alipay', () => {
assertCodegen( assertCodegen(
`<form @submit="formSubmit" @reset="formReset"/>`, `<form @submit="formSubmit" @reset="formReset"/>`,
`<form data-event-opts="{{[['submit',[['formSubmit',['$event']]]]]}}" onSubmit="__e" onReset="formReset"></form>` `<form data-event-opts="{{[['submit',[['formSubmit',['$event']]]]]}}" onSubmit="__e" onReset="formReset"></form>`
) )
assertCodegen( assertCodegen(
`<map @callouttap="calloutTap" @controltap="controlTap" @markertap="markerTap" @regionchange="regionChange" @tap="tap"/>`, `<map @callouttap="calloutTap" @controltap="controlTap" @markertap="markerTap" @regionchange="regionChange" @tap="tap"/>`,
`<map data-event-opts="{{[['tap',[['tap',['$event']]]]]}}" onCalloutTap="calloutTap" onControlTap="controlTap" onMarkerTap="markerTap" onRegionChange="regionChange" onTap="__e"></map>` `<map data-event-opts="{{[['tap',[['tap',['$event']]]]]}}" onCalloutTap="calloutTap" onControlTap="controlTap" onMarkerTap="markerTap" onRegionChange="regionChange" onTap="__e"></map>`
) )
assertCodegen( assertCodegen(
`<view @transitionend="transitionEnd" @animationstart="animationStart" @animationiteration="animationIteration" @animationend="animationEnd" @firstappear="firstAppear"/>`, `<view @transitionend="transitionEnd" @animationstart="animationStart" @animationiteration="animationIteration" @animationend="animationEnd" @firstappear="firstAppear"/>`,
`<view data-event-opts="{{[['transitionEnd',[['transitionEnd',['$event']]]],['animationStart',[['animationStart',['$event']]]],['animationIteration',[['animationIteration',['$event']]]],['animationEnd',[['animationEnd',['$event']]]],['firstAppear',[['firstAppear',['$event']]]]]}}" onTransitionEnd="__e" onAnimationStart="__e" onAnimationIteration="__e" onAnimationEnd="__e" onFirstAppear="__e"></view>` `<view data-event-opts="{{[['transitionEnd',[['transitionEnd',['$event']]]],['animationStart',[['animationStart',['$event']]]],['animationIteration',[['animationIteration',['$event']]]],['animationEnd',[['animationEnd',['$event']]]],['firstAppear',[['firstAppear',['$event']]]]]}}" onTransitionEnd="__e" onAnimationStart="__e" onAnimationIteration="__e" onAnimationEnd="__e" onFirstAppear="__e"></view>`
) )
assertCodegen( assertCodegen(
`<scroll-view @scrolltoupper="scrollToUpper" @scrolltolower="scrollToLower"/>`, `<scroll-view @scrolltoupper="scrollToUpper" @scrolltolower="scrollToLower"/>`,
`<scroll-view data-event-opts="{{[['scrollToUpper',[['scrollToUpper',['$event']]]],['scrollToLower',[['scrollToLower',['$event']]]]]}}" onScrollToUpper="__e" onScrollToLower="__e"></scroll-view>` `<scroll-view data-event-opts="{{[['scrollToUpper',[['scrollToUpper',['$event']]]],['scrollToLower',[['scrollToLower',['$event']]]]]}}" onScrollToUpper="__e" onScrollToLower="__e"></scroll-view>`
) )
assertCodegen( assertCodegen(
`<movable-view @changeend="changeEnd"/>`, `<movable-view @changeend="changeEnd"/>`,
`<movable-view data-event-opts="{{[['changeEnd',[['changeEnd',['$event']]]]]}}" onChangeEnd="__e"></movable-view>` `<movable-view data-event-opts="{{[['changeEnd',[['changeEnd',['$event']]]]]}}" onChangeEnd="__e"></movable-view>`
) )
}) })
}) })
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
......
...@@ -91,8 +91,10 @@ const rules = [{ ...@@ -91,8 +91,10 @@ 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,11 +87,22 @@ class WebpackUniMPPlugin { ...@@ -82,11 +87,22 @@ 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 (
try { fileName &&
parseEntry() typeof fileName === 'string'
} catch (e) { ) { // 重新解析 entry
console.error(e) const basename = path.basename(fileName)
const deps = process.UNI_PAGES_DEPS || new Set()
if (
basename === 'pages.json' ||
basename === pagesJsonJsFileName ||
deps.has(normalizePath(fileName))
) {
try {
parseEntry()
} catch (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,11 +98,22 @@ class WebpackUniMPPlugin { ...@@ -93,11 +98,22 @@ 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 (
try { fileName &&
parseEntry() typeof fileName === 'string'
} catch (e) { ) { // 重新解析 entry
console.error(e) const basename = path.basename(fileName)
const deps = process.UNI_PAGES_DEPS || new Set()
if (
basename === 'pages.json' ||
basename === pagesJsonJsFileName ||
deps.has(normalizePath(fileName))
) {
try {
parseEntry()
} catch (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 = {}
...@@ -25,7 +29,7 @@ function checkEmitFile (filePath, jsonObj, changedEmitFiles) { ...@@ -25,7 +29,7 @@ function checkEmitFile (filePath, jsonObj, changedEmitFiles) {
} }
} }
module.exports = function (content) { module.exports = function (content) {
if (this.resourceQuery) { if (this.resourceQuery) {
const params = loaderUtils.parseQuery(this.resourceQuery) const params = loaderUtils.parseQuery(this.resourceQuery)
if (params) { if (params) {
...@@ -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
......
const { 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,
...@@ -59,6 +63,10 @@ module.exports = function (pagesJson, manifestJson) { ...@@ -59,6 +63,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',
......
...@@ -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'
...@@ -97,12 +98,12 @@ export function scanCode ({ ...@@ -97,12 +98,12 @@ export function scanCode ({
barcode.scan(file, (type, code) => { barcode.scan(file, (type, code) => {
if (isDark) { if (isDark) {
plus.navigator.setStatusBarStyle('isDark') plus.navigator.setStatusBarStyle('isDark')
}
result = {
type,
code
} }
webview.close('auto') webview.close('auto')
result = {
type,
code
}
}, () => { }, () => {
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] || '',
...@@ -151,11 +152,12 @@ export function scanCode ({ ...@@ -151,11 +152,12 @@ export function scanCode ({
path: '', path: '',
errMsg: 'scanCode:ok' errMsg: 'scanCode:ok'
}) })
} else { } else {
invoke(callbackId, { invoke(callbackId, {
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,10 +11,13 @@ import { ...@@ -11,10 +11,13 @@ 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()
...@@ -56,27 +59,39 @@ export function chooseLocation (params, callbackId) { ...@@ -56,27 +59,39 @@ export function chooseLocation (params, callbackId) {
plus.navigator.setStatusBarStyle('light') plus.navigator.setStatusBarStyle('light')
} }
}) })
}
let index = 0
let onShow = function () {
index++
if (index === 2) {
webview.evalJS(`__chooseLocation__(${JSON.stringify(params)})`)
}
} }
webview.addEventListener('loaded', onShow)
webview.show('slide-in-bottom', ANI_DURATION, onShow)
let result
webview.addEventListener('close', () => {
if (result) {
invoke(callbackId, {
name: result.poiname,
address: result.poiaddress,
latitude: result.latlng.lat,
longitude: result.latlng.lng,
errMsg: 'chooseLocation:ok'
})
} else {
consumePlusMessage(MESSAGE_TYPE)
invoke(callbackId, {
errMsg: 'chooseLocation:fail cancel'
})
}
})
webview.show('slide-in-bottom', ANI_DURATION, () => { registerPlusMessage(MESSAGE_TYPE, function (res) {
webview.evalJS(`__chooseLocation__(${JSON.stringify(params)})`) if (res && 'latlng' in res) {
}) result = res
// fixed by hxy
registerPlusMessage('chooseLocation', function (res) {
if (res && !res.errMsg) {
invoke(callbackId, {
name: res.poiname,
address: res.poiaddress,
latitude: res.latlng.lat,
longitude: res.latlng.lng,
errMsg: 'chooseLocation:ok'
})
} else {
const errMsg = res && res.errMsg ? ' ' + res.errMsg : ''
invoke(callbackId, {
errMsg: 'chooseLocation:fail' + errMsg
})
} }
}, 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 {
...@@ -68,6 +69,16 @@ function initGlobalListeners () { ...@@ -68,6 +69,16 @@ function initGlobalListeners () {
publish('onKeyboardHeightChange', { publish('onKeyboardHeightChange', {
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 || {})
}
}) })
} }
......
...@@ -7,7 +7,7 @@ import { ...@@ -7,7 +7,7 @@ import {
initRefs initRefs
} from './util' } from './util'
export default function parseApp (vm) { export default function parseApp (vm) {
Object.defineProperty(Vue.prototype, '$slots', { Object.defineProperty(Vue.prototype, '$slots', {
get () { get () {
return this.$scope && this.$scope.props.$slots return this.$scope && this.$scope.props.$slots
...@@ -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.
先完成此消息的编辑!
想要评论请 注册