diff --git a/lerna.json b/lerna.json index 6853d2d2db3566bd14020720e86ef2f6a514880b..48ac07667cbbc5c2b912bf2595bcca2afb0642a9 100644 --- a/lerna.json +++ b/lerna.json @@ -12,5 +12,5 @@ "message": "chore(release): publish %s" } }, - "version": "3.0.0-alpha-24020191018029" + "version": "3.0.0-alpha-24020191018043" } diff --git a/packages/uni-app-plus-nvue/package.json b/packages/uni-app-plus-nvue/package.json index 88f0ceb93a61a069986a2246037122eb7fd61b60..cc0c377f7073741ed33c2d56bb3d8a3b5027bad1 100644 --- a/packages/uni-app-plus-nvue/package.json +++ b/packages/uni-app-plus-nvue/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-app-plus-nvue", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app app-plus-nvue", "main": "dist/index.js", "repository": { @@ -13,5 +13,5 @@ }, "author": "fxy060608", "license": "Apache-2.0", - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/uni-app-plus/dist/index.v3.js b/packages/uni-app-plus/dist/index.v3.js index 732974b40124be2f494ebe6fa4e9f9618cda553a..fb465805d711ce1f281477bbaaa5291d120548cc 100644 --- a/packages/uni-app-plus/dist/index.v3.js +++ b/packages/uni-app-plus/dist/index.v3.js @@ -4044,19 +4044,19 @@ var serviceContext = (function () { const buttons = []; if (!onlyFromCamera) { buttons.push({ - 'float': 'right', - 'text': '相册', - 'fontSize': '17px', - 'width': '60px', - 'onclick': function () { + float: 'right', + text: '相册', + fontSize: '17px', + width: '60px', + onclick: function () { plus.gallery.pick(file => { barcode.scan(file, (type, code) => { if (isDark) { plus.navigator.setStatusBarStyle('isDark'); - } - result = { - type, - code + } + result = { + type, + code }; webview.close('auto'); }, () => { @@ -4107,10 +4107,10 @@ var serviceContext = (function () { path: '', errMsg: 'scanCode:ok' }); - } else { - invoke(callbackId, { - errMsg: 'scanCode:fail cancel' - }); + } else { + invoke(callbackId, { + errMsg: 'scanCode:fail cancel' + }); } consumePlusMessage(MESSAGE_TYPE); }); @@ -4135,6 +4135,245 @@ var serviceContext = (function () { }, false); } + var webview = /*#__PURE__*/Object.freeze({ + SCAN_ID: SCAN_ID, + SCAN_PATH: SCAN_PATH, + scanCode: scanCode + }); + + let plus_; + let weex_; + let uni_; + + let runtime; + + function getRuntime () { + return runtime || (runtime = typeof window === 'object' && typeof navigator === 'object' && typeof document === + 'object' + ? 'webview' : 'v8') + } + + function setRuntime (value) { + runtime = value; + } + + function getPageId () { + return plus_.webview.currentWebview().id + } + + let initedEventListener = false; + const callbacks$1 = {}; + + function addEventListener (pageId, callback) { + const runtime = getRuntime(); + + function onPlusMessage (res) { + const message = res.data && res.data.__message; + if (!message || !message.__page) { + return + } + const pageId = message.__page; + const callback = callbacks$1[pageId]; + callback && callback(message); + if (!message.keep) { + delete callbacks$1[pageId]; + } + } + if (!initedEventListener) { + if (runtime === 'v8') { + const globalEvent = weex_.requireModule('globalEvent'); + globalEvent.addEventListener('plusMessage', onPlusMessage); + } else if (runtime === 'v8-native') { + uni_.$on(getPageId(), onPlusMessage); + } else { + window.__plusMessage = onPlusMessage; + } + initedEventListener = true; + } + callbacks$1[pageId] = callback; + } + + class Page { + constructor (webview) { + this.webview = webview; + } + sendMessage (data) { + const runtime = getRuntime(); + const message = { + __message: { + data + } + }; + if (runtime === 'v8-native') { + uni_.$emit(this.webview.id, { + data: JSON.parse(JSON.stringify(message)) + }); + } else { + plus_.webview.postMessageToUniNView(message, this.webview.id); + } + } + close () { + this.webview.close(); + } + } + + function showPage ({ + context, + runtime, + url, + data = {}, + style = {}, + onMessage, + onClose + }) { + if (context) { + plus_ = context.plus; + weex_ = context.weex; + uni_ = context.uni; + } else { + // eslint-disable-next-line + plus_ = typeof plus === 'object' ? plus : null; + // eslint-disable-next-line + weex_ = typeof weex === 'object' ? weex : null; + // eslint-disable-next-line + uni_ = typeof uni === 'object' ? uni : null; + } + if (runtime) { + setRuntime(runtime); + } else { + runtime = getRuntime(); + } + const titleNView = { + autoBackButton: true, + titleSize: '17px' + }; + const pageId = `page${Date.now()}`; + style = Object.assign({}, style); + if (style.titleNView !== false && style.titleNView !== 'none') { + style.titleNView = Object.assign(titleNView, style.titleNView); + } + const defaultStyle = { + top: 0, + bottom: 0, + usingComponents: {}, + popGesture: 'close', + scrollIndicator: 'none', + animationType: 'pop-in', + animationDuration: 200, + uniNView: { + path: `${(typeof process === 'object' && process.env && process.env.VUE_APP_TEMPLATE_PATH) || ''}/${url}.js`, + defaultFontSize: plus_.screen.resolutionWidth / 20, + viewport: plus_.screen.resolutionWidth + } + }; + style = Object.assign(defaultStyle, style); + const page = plus_.webview.create('', pageId, style, { + extras: { + from: getPageId(), + runtime: runtime, + data + } + }); + page.addEventListener('close', onClose); + addEventListener(pageId, message => { + if (typeof onMessage === 'function') { + onMessage(message.data); + } + if (!message.keep) { + page.close('auto'); + } + }); + page.show(style.animationType, style.animationDuration); + return new Page(page) + } + + function getStatusBarStyle$1 () { + let style = plus.navigator.getStatusBarStyle(); + if (style === 'UIStatusBarStyleBlackTranslucent' || style === 'UIStatusBarStyleBlackOpaque' || style === 'null') { + style = 'light'; + } else if (style === 'UIStatusBarStyleDefault') { + style = 'dark'; + } + return style + } + + function scanCode$1 (options, callbackId) { + const statusBarStyle = getStatusBarStyle$1(); + const isDark = statusBarStyle !== 'light'; + + let result; + const page = showPage({ + url: '__uniappscan', + data: { + scanType: options.scanType + }, + style: { + animationType: options.animationType || 'pop-in', + titleNView: { + autoBackButton: true, + type: 'float', + titleText: options.titleText || '扫码', + titleColor: '#ffffff', + backgroundColor: 'rgba(0,0,0,0)', + buttons: !options.onlyFromCamera ? [{ + text: options.albumText || '相册', + fontSize: '17px', + width: '60px', + onclick: () => { + page.sendMessage({ + type: 'gallery' + }); + } + }] : [] + }, + popGesture: 'close', + backButtonAutoControl: 'close' + }, + onMessage ({ + event, + detail + }) { + result = detail; + if (event === 'marked') { + result.errMsg = 'scanCode:ok'; + } else { + result.errMsg = 'scanCode:fail ' + detail.message; + } + }, + onClose () { + if (isDark) { + plus.navigator.setStatusBarStyle('dark'); + } + invoke(callbackId, result || { + errMsg: 'scanCode:fail cancel' + }); + } + }); + + if (isDark) { + plus.navigator.setStatusBarStyle('light'); + page.webview.addEventListener('popGesture', ({ + type, + result + }) => { + if (type === 'start') { + plus.navigator.setStatusBarStyle('dark'); + } else if (type === 'end' && !result) { + plus.navigator.setStatusBarStyle('light'); + } + }); + } + } + + var weex$1 = /*#__PURE__*/Object.freeze({ + scanCode: scanCode$1 + }); + + function scanCode$2 (...array) { + const api = __uniConfig.nvueCompiler === 'uni-app' ? weex$1 : webview; + return api.scanCode(...array) + } + function checkIsSupportFaceID () { const platform = plus.os.name.toLowerCase(); if (platform !== 'ios') { @@ -4168,50 +4407,33 @@ var serviceContext = (function () { if (checkAuthMode === 'fingerPrint') { if (checkIsSupportFingerPrint()) { const isEnrolled = plus.fingerprint.isKeyguardSecure() && plus.fingerprint.isEnrolledFingerprints(); - if (isEnrolled) { - return { - isEnrolled, - errMsg: 'checkIsSoterEnrolledInDevice:ok' - } - } else { - return { - isEnrolled, - errMsg: 'checkIsSoterEnrolledInDevice:ok' - } - } - } else { return { - isEnrolled: false, - errMsg: 'checkIsSoterEnrolledInDevice:fail not support' + isEnrolled, + errMsg: 'checkIsSoterEnrolledInDevice:ok' } } + return { + isEnrolled: false, + errMsg: 'checkIsSoterEnrolledInDevice:fail not support' + } } else if (checkAuthMode === 'facial') { if (checkIsSupportFaceID()) { const faceID = requireNativePlugin('faceID'); const isEnrolled = faceID && faceID.isKeyguardSecure() && faceID.isEnrolledFaceID(); - if (isEnrolled) { - return { - isEnrolled, - errMsg: 'checkIsSoterEnrolledInDevice:ok' - } - } else { - return { - isEnrolled, - errMsg: 'checkIsSoterEnrolledInDevice:ok' - } - } - } else { return { - isEnrolled: false, - errMsg: 'checkIsSoterEnrolledInDevice:fail not support' + isEnrolled, + errMsg: 'checkIsSoterEnrolledInDevice:ok' } } - } else { return { isEnrolled: false, errMsg: 'checkIsSoterEnrolledInDevice:fail not support' } } + return { + isEnrolled: false, + errMsg: 'checkIsSoterEnrolledInDevice:fail not support' + } } function startSoterAuthentication ({ @@ -4219,6 +4441,24 @@ var serviceContext = (function () { challenge = false, authContent } = {}, callbackId) { + /* + 以手机不支持facial未录入fingerPrint为例 + requestAuthModes:['facial','fingerPrint']时,微信小程序返回值里的authMode为"fingerPrint" + requestAuthModes:['fingerPrint','facial']时,微信小程序返回值里的authMode为"fingerPrint" + 即先过滤不支持的方式之后再判断是否录入 + 微信小程序errCode(从企业号开发者中心查到如下文档): + 0:识别成功 'startSoterAuthentication:ok' + 90001:本设备不支持SOTER 'startSoterAuthentication:fail not support soter' + 90002:用户未授权微信使用该生物认证接口 注:APP端暂不支持 + 90003:请求使用的生物认证方式不支持 'startSoterAuthentication:fail no corresponding mode' + 90004:未传入challenge或challenge长度过长(最长512字符)注:APP端暂不支持 + 90005:auth_content长度超过限制(最长42个字符)注:微信小程序auth_content指纹识别时无效果,faceID暂未测试 + 90007:内部错误 'startSoterAuthentication:fail auth key update error' + 90008:用户取消授权 'startSoterAuthentication:fail cancel' + 90009:识别失败 'startSoterAuthentication:fail' + 90010:重试次数过多被冻结 'startSoterAuthentication:fail authenticate freeze. please try again later' + 90011:用户未录入所选识别方式 'startSoterAuthentication:fail no fingerprint enrolled' + */ const supportMode = checkIsSupportSoterAuthentication().supportMode; if (supportMode.length === 0) { return { @@ -4314,7 +4554,7 @@ var serviceContext = (function () { faceID.authenticate({ message: authContent }, (e) => { - if (e.type === 'success' && e.code === 1) { + if (e.type === 'success' && e.code === 0) { invoke(callbackId, { authMode: realAuthMode, errCode: 0, @@ -4784,8 +5024,8 @@ var serviceContext = (function () { }); } - const CHOOSE_LOCATION_PATH = '_www/__uniappchooselocation.html'; - + const CHOOSE_LOCATION_PATH = '_www/__uniappchooselocation.html'; + const MESSAGE_TYPE$1 = 'chooseLocation'; function chooseLocation$1 (params, callbackId) { @@ -4803,6 +5043,7 @@ var serviceContext = (function () { float: 'right', text: '完成', fontSize: '17px', + width: '60px', onclick: function () { webview.evalJS('__chooseLocationConfirm__()'); } @@ -4828,41 +5069,138 @@ var serviceContext = (function () { plus.navigator.setStatusBarStyle('light'); } }); - } - let index = 0; - let onShow = function () { - index++; - if (index === 2) { - webview.evalJS(`__chooseLocation__(${JSON.stringify(params)})`); - } + } + 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); + 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$1); + invoke(callbackId, { + errMsg: 'chooseLocation:fail cancel' + }); + } + }); + + registerPlusMessage(MESSAGE_TYPE$1, function (res) { + if (res && 'latlng' in res) { + result = res; + } + }, false); + } + + var webview$1 = /*#__PURE__*/Object.freeze({ + chooseLocation: chooseLocation$1 + }); + + function getStatusBarStyle$2 () { + let style = plus.navigator.getStatusBarStyle(); + if (style === 'UIStatusBarStyleBlackTranslucent' || style === 'UIStatusBarStyleBlackOpaque' || style === 'null') { + style = 'light'; + } else if (style === 'UIStatusBarStyleDefault') { + style = 'dark'; + } + return style + } + + function chooseLocation$2 (options, callbackId) { + const statusBarStyle = getStatusBarStyle$2(); + const isDark = statusBarStyle !== 'light'; let result; + const page = showPage({ + url: '__uniappchooselocation', + data: { + keyword: options.keyword + }, + style: { + animationType: options.animationType || 'slide-in-bottom', + titleNView: { + autoBackButton: false, + titleText: options.titleText || '选择位置', + titleColor: '#ffffff', + backgroundColor: 'rgba(0,0,0,1)', + buttons: [{ + // text: options.cancelText || "取消", + // fontSize: "17px", + type: 'close', + float: 'left', + onclick: () => { + page.close(); + } + }, { + text: options.doneText || '完成', + fontSize: '17px', + width: '60px', + onclick: () => { + page.sendMessage({ + type: 'done' + }); + } + }] + }, + popGesture: 'close', + scrollIndicator: 'none' + }, + onMessage ({ + event, + detail + }) { + if (event === 'selected') { + result = detail; + result.errMsg = 'chooseLocation:ok'; + } + }, + onClose () { + if (isDark) { + plus.navigator.setStatusBarStyle('dark'); + } - 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$1); - invoke(callbackId, { + invoke(callbackId, result || { errMsg: 'chooseLocation:fail cancel' }); } }); - - registerPlusMessage(MESSAGE_TYPE$1, function (res) { - if (res && 'latlng' in res) { - result = res; - } - }, false); + + if (isDark) { + plus.navigator.setStatusBarStyle('light'); + page.webview.addEventListener('popGesture', ({ + type, + result + }) => { + if (type === 'start') { + plus.navigator.setStatusBarStyle('dark'); + } else if (type === 'end' && !result) { + plus.navigator.setStatusBarStyle('light'); + } + }); + } + } + + var weex$2 = /*#__PURE__*/Object.freeze({ + chooseLocation: chooseLocation$2 + }); + + function chooseLocation$3 (...array) { + const api = __uniConfig.nvueCompiler === 'uni-app' ? weex$2 : webview$1; + return api.chooseLocation(...array) } function getLocationSuccess (type, position, callbackId) { @@ -4976,6 +5314,34 @@ var serviceContext = (function () { } } + var webview$2 = /*#__PURE__*/Object.freeze({ + openLocation: openLocation$1 + }); + + function openLocation$2 (data) { + showPage({ + url: '__uniappopenlocation', + data, + style: { + titleNView: { + type: 'transparent' + } + } + }); + return { + errMsg: 'openLocation:ok' + } + } + + var weex$3 = /*#__PURE__*/Object.freeze({ + openLocation: openLocation$2 + }); + + function openLocation$3 (...array) { + const api = __uniConfig.nvueCompiler === 'uni-app' ? weex$3 : webview$2; + return api.openLocation(...array) + } + const RECORD_TIME = 60 * 60 * 1000; let recorder; @@ -6169,9 +6535,8 @@ var serviceContext = (function () { }); } else { plus.payment.request(service, params.orderInfo, res => { - invoke(callbackId, { - errMsg: 'requestPayment:ok' - }); + res.errMsg = 'requestPayment:ok'; + invoke(callbackId, res); }, err => { invoke(callbackId, { errMsg: 'requestPayment:fail:' + err.message @@ -7876,23 +8241,23 @@ var serviceContext = (function () { }); } - let webview; + let webview$3; function setPullDownRefreshPageId (pullDownRefreshWebview) { if (typeof pullDownRefreshWebview === 'number') { - webview = plus.webview.getWebviewById(String(pullDownRefreshWebview)); + webview$3 = plus.webview.getWebviewById(String(pullDownRefreshWebview)); } else { - webview = pullDownRefreshWebview; + webview$3 = pullDownRefreshWebview; } } function startPullDownRefresh () { - if (webview) { - webview.endPullToRefresh(); + if (webview$3) { + webview$3.endPullToRefresh(); } - webview = getLastWebview(); - if (webview) { - webview.beginPullToRefresh(); + webview$3 = getLastWebview(); + if (webview$3) { + webview$3.beginPullToRefresh(); return { errMsg: 'startPullDownRefresh:ok' } @@ -7903,12 +8268,12 @@ var serviceContext = (function () { } function stopPullDownRefresh () { - if (!webview) { - webview = getLastWebview(); + if (!webview$3) { + webview$3 = getLastWebview(); } - if (webview) { - webview.endPullToRefresh(); - webview = null; + if (webview$3) { + webview$3.endPullToRefresh(); + webview$3 = null; return { errMsg: 'stopPullDownRefresh:ok' } @@ -8011,16 +8376,16 @@ var serviceContext = (function () { } } - const callbacks$1 = {}; + const callbacks$2 = {}; function createCallbacks (namespace) { - let scopedCallbacks = callbacks$1[namespace]; + let scopedCallbacks = callbacks$2[namespace]; if (!scopedCallbacks) { scopedCallbacks = { id: 1, callbacks: Object.create(null) }; - callbacks$1[namespace] = scopedCallbacks; + callbacks$2[namespace] = scopedCallbacks; } return { get (id) { @@ -8181,9 +8546,7 @@ var serviceContext = (function () { startBeaconDiscovery: startBeaconDiscovery, stopBeaconDiscovery: stopBeaconDiscovery, makePhoneCall: makePhoneCall$1, - SCAN_ID: SCAN_ID, - SCAN_PATH: SCAN_PATH, - scanCode: scanCode, + scanCode: scanCode$2, checkIsSupportSoterAuthentication: checkIsSupportSoterAuthentication, checkIsSoterEnrolledInDevice: checkIsSoterEnrolledInDevice, startSoterAuthentication: startSoterAuthentication, @@ -8197,9 +8560,9 @@ var serviceContext = (function () { getSavedFileInfo: getSavedFileInfo, removeSavedFile: removeSavedFile, openDocument: openDocument$1, - chooseLocation: chooseLocation$1, + chooseLocation: chooseLocation$3, getLocation: getLocation$1, - openLocation: openLocation$1, + openLocation: openLocation$3, startRecord: startRecord, stopRecord: stopRecord, playVoice: playVoice, @@ -8475,9 +8838,9 @@ var serviceContext = (function () { 'error', 'waiting' ]; - const callbacks$2 = {}; + const callbacks$3 = {}; eventNames$1.forEach(name => { - callbacks$2[name] = []; + callbacks$3[name] = []; }); const props$1 = [ @@ -8541,7 +8904,7 @@ var serviceContext = (function () { errMsg, errCode }) => { - callbacks$2[state].forEach(callback => { + callbacks$3[state].forEach(callback => { if (typeof callback === 'function') { callback(state === 'error' ? { errMsg, @@ -8593,7 +8956,7 @@ var serviceContext = (function () { eventNames$1.forEach(item => { const name = item[0].toUpperCase() + item.substr(1); BackgroundAudioManager.prototype[`on${name}`] = function (callback) { - callbacks$2[item].push(callback); + callbacks$3[item].push(callback); }; }); @@ -9557,10 +9920,10 @@ var serviceContext = (function () { createVideoContext: createVideoContext$1 }); - const callbacks$3 = []; + const callbacks$4 = []; onMethod('onAccelerometerChange', function (res) { - callbacks$3.forEach(callbackId => { + callbacks$4.forEach(callbackId => { invoke(callbackId, res); }); }); @@ -9572,7 +9935,7 @@ var serviceContext = (function () { */ function onAccelerometerChange (callbackId) { // TODO 当没有 start 时,添加 on 需要主动 start? - callbacks$3.push(callbackId); + callbacks$4.push(callbackId); if (!isEnable) { startAccelerometer(); } @@ -9627,10 +9990,10 @@ var serviceContext = (function () { onBLECharacteristicValueChange: onBLECharacteristicValueChange$1 }); - const callbacks$4 = []; + const callbacks$5 = []; onMethod('onCompassChange', function (res) { - callbacks$4.forEach(callbackId => { + callbacks$5.forEach(callbackId => { invoke(callbackId, res); }); }); @@ -9642,7 +10005,7 @@ var serviceContext = (function () { */ function onCompassChange (callbackId) { // TODO 当没有 start 时,添加 on 需要主动 start? - callbacks$4.push(callbackId); + callbacks$5.push(callbackId); if (!isEnable$1) { startCompass(); } @@ -9673,23 +10036,23 @@ var serviceContext = (function () { stopCompass: stopCompass }); - const callbacks$5 = []; + const callbacks$6 = []; onMethod('onNetworkStatusChange', res => { - callbacks$5.forEach(callbackId => { + callbacks$6.forEach(callbackId => { invoke(callbackId, res); }); }); function onNetworkStatusChange (callbackId) { - callbacks$5.push(callbackId); + callbacks$6.push(callbackId); } var require_context_module_1_12 = /*#__PURE__*/Object.freeze({ onNetworkStatusChange: onNetworkStatusChange }); - const callbacks$6 = { + const callbacks$7 = { pause: [], resume: [], start: [], @@ -9703,7 +10066,7 @@ var serviceContext = (function () { const state = res.state; delete res.state; delete res.errMsg; - callbacks$6[state].forEach(callback => { + callbacks$7[state].forEach(callback => { if (typeof callback === 'function') { callback(res); } @@ -9711,7 +10074,7 @@ var serviceContext = (function () { }); } onError (callback) { - callbacks$6.error.push(callback); + callbacks$7.error.push(callback); } onFrameRecorded (callback) { @@ -9723,16 +10086,16 @@ var serviceContext = (function () { } onPause (callback) { - callbacks$6.pause.push(callback); + callbacks$7.pause.push(callback); } onResume (callback) { - callbacks$6.resume.push(callback); + callbacks$7.resume.push(callback); } onStart (callback) { - callbacks$6.start.push(callback); + callbacks$7.start.push(callback); } onStop (callback) { - callbacks$6.stop.push(callback); + callbacks$7.stop.push(callback); } pause () { invokeMethod('operateRecorder', { @@ -10033,7 +10396,7 @@ var serviceContext = (function () { const socketTasks$1 = Object.create(null); const socketTasksArray = []; - const callbacks$7 = Object.create(null); + const callbacks$8 = Object.create(null); onMethod('onSocketTaskStateChange', ({ socketTaskId, state, @@ -10054,8 +10417,8 @@ var serviceContext = (function () { if (state === 'open') { socketTask.readyState = socketTask.OPEN; } - if (socketTask === socketTasksArray[0] && callbacks$7[state]) { - invoke(callbacks$7[state], state === 'message' ? { + if (socketTask === socketTasksArray[0] && callbacks$8[state]) { + invoke(callbacks$8[state], state === 'message' ? { data } : {}); } @@ -10114,19 +10477,19 @@ var serviceContext = (function () { } function onSocketOpen (callbackId) { - callbacks$7.open = callbackId; + callbacks$8.open = callbackId; } function onSocketError (callbackId) { - callbacks$7.error = callbackId; + callbacks$8.error = callbackId; } function onSocketMessage (callbackId) { - callbacks$7.message = callbackId; + callbacks$8.message = callbackId; } function onSocketClose (callbackId) { - callbacks$7.close = callbackId; + callbacks$8.close = callbackId; } var require_context_module_1_16 = /*#__PURE__*/Object.freeze({ @@ -10599,16 +10962,16 @@ var serviceContext = (function () { createSelectorQuery: createSelectorQuery }); - const callbacks$8 = []; + const callbacks$9 = []; onMethod('onKeyboardHeightChange', res => { - callbacks$8.forEach(callbackId => { + callbacks$9.forEach(callbackId => { invoke(callbackId, res); }); }); function onKeyboardHeightChange (callbackId) { - callbacks$8.push(callbackId); + callbacks$9.push(callbackId); } var require_context_module_1_22 = /*#__PURE__*/Object.freeze({ @@ -10647,16 +11010,16 @@ var serviceContext = (function () { const hideTabBarRedDot$1 = removeTabBarBadge$1; - const callbacks$9 = []; + const callbacks$a = []; onMethod('onTabBarMidButtonTap', res => { - callbacks$9.forEach(callbackId => { + callbacks$a.forEach(callbackId => { invoke(callbackId, res); }); }); function onTabBarMidButtonTap (callbackId) { - callbacks$9.push(callbackId); + callbacks$a.push(callbackId); } var require_context_module_1_24 = /*#__PURE__*/Object.freeze({ @@ -10666,22 +11029,22 @@ var serviceContext = (function () { onTabBarMidButtonTap: onTabBarMidButtonTap }); - const callbacks$a = []; + const callbacks$b = []; onMethod('onViewDidResize', res => { - callbacks$a.forEach(callbackId => { + callbacks$b.forEach(callbackId => { invoke(callbackId, res); }); }); function onWindowResize (callbackId) { - callbacks$a.push(callbackId); + callbacks$b.push(callbackId); } function offWindowResize (callbackId) { // TODO 目前 on 和 off 即使传入同一个 function,获取到的 callbackId 也不会一致,导致不能 off 掉指定 // 后续修复 // 此处和微信平台一致查询不到去掉最后一个 - callbacks$a.splice(callbacks$a.indexOf(callbackId), 1); + callbacks$b.splice(callbacks$b.indexOf(callbackId), 1); } var require_context_module_1_25 = /*#__PURE__*/Object.freeze({ @@ -11291,6 +11654,56 @@ var serviceContext = (function () { }; } + const isAndroid = plus.os.name.toLowerCase() === 'android'; + const FOCUS_TIMEOUT = isAndroid ? 300 : 700; + const HIDE_TIMEOUT = 300; + let keyboardHeight = 0; + let onKeyboardShow; + let focusTimer; + let hideKeyboardTimeout; + + function hookKeyboardEvent (event, callback) { + onKeyboardShow = null; + focusTimer && clearTimeout(focusTimer); + if (event.type === 'focus') { + if (keyboardHeight > 0) { + event.detail.height = keyboardHeight; + } else { + focusTimer = setTimeout(function () { + event.detail.height = keyboardHeight; + callback(event); + }, FOCUS_TIMEOUT); + onKeyboardShow = function () { + clearTimeout(focusTimer); + event.detail.height = keyboardHeight; + callback(event); + }; + return + } + } + callback(event); + } + + onMethod('onKeyboardHeightChange', res => { + keyboardHeight = res.height; + if (keyboardHeight > 0) { + onKeyboardShow && onKeyboardShow(); + if (hideKeyboardTimeout) { + clearTimeout(hideKeyboardTimeout); + hideKeyboardTimeout = null; + } + } else { + // 仅安卓收起键盘时通知view层失去焦点 + if (isAndroid) { + hideKeyboardTimeout = setTimeout(function () { + hideKeyboardTimeout = null; + var pageId = getCurrentPageId(); + UniServiceJSBridge.publishHandler('hideKeyboard', {}, pageId); + }, HIDE_TIMEOUT); + } + } + }); + function wrapperEvent (event) { event.preventDefault = noop; event.stopPropagation = noop; @@ -11308,7 +11721,15 @@ var serviceContext = (function () { if (!target) { return console.error(`event handler[${cid}][${nid}] not found`) } - target.dispatchEvent(event.type, wrapperEvent(event)); + const type = event.type; + const mpEvent = wrapperEvent(event); + if (type === 'focus' || type === 'blur') { + hookKeyboardEvent(mpEvent, event => { + target.dispatchEvent(type, event); + }); + } else { + target.dispatchEvent(type, mpEvent); + } }); } }; diff --git a/packages/uni-app-plus/package.json b/packages/uni-app-plus/package.json index 1cf9e0c8375be6258870cee1762139769b8977cd..e26568d5a08ceedfbf4a6e02f11c688c84ee3e11 100644 --- a/packages/uni-app-plus/package.json +++ b/packages/uni-app-plus/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-app-plus", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app app-plus", "main": "dist/index.js", "repository": { @@ -13,5 +13,5 @@ }, "author": "fxy060608", "license": "Apache-2.0", - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/uni-cli-shared/package.json b/packages/uni-cli-shared/package.json index ee47a6686e8ef31047e405c0ea74287bf9d53495..6ddebf061e65a774dc5b247eaddbb7a170288129 100644 --- a/packages/uni-cli-shared/package.json +++ b/packages/uni-cli-shared/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-cli-shared", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-cli-shared", "main": "lib/index.js", "repository": { @@ -21,5 +21,5 @@ "hash-sum": "^1.0.2", "strip-json-comments": "^2.0.1" }, - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/uni-h5-ui/package.json b/packages/uni-h5-ui/package.json index 4b88836d6c6c3f40506fc966682db4e44a9a707f..bbb4150163ba15d4a699df487125dbe58060cca7 100644 --- a/packages/uni-h5-ui/package.json +++ b/packages/uni-h5-ui/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-h5-ui", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app h5 ui", "main": "dist/index.umd.min.js", "repository": { @@ -13,5 +13,5 @@ }, "author": "fxy060608", "license": "Apache-2.0", - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/uni-h5/package.json b/packages/uni-h5/package.json index ccf88d19a2e2260bacbe74e1f90cd9bdd291c6d4..aeb87cc07f0d2384a08d39ad5656c656c00f24cc 100644 --- a/packages/uni-h5/package.json +++ b/packages/uni-h5/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-h5", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app h5", "main": "dist/index.umd.min.js", "repository": { @@ -18,5 +18,5 @@ "intersection-observer": "^0.7.0", "safe-area-insets": "^1.4.1" }, - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/uni-migration/package.json b/packages/uni-migration/package.json index 933139b39c307f97b6c73683a5c4a0856f3cde18..5081451eb20fff5c0b346717658ad0c7c68fa718 100644 --- a/packages/uni-migration/package.json +++ b/packages/uni-migration/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-migration", - "version": "3.0.0-alpha-24020191018027", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app migration", "main": "lib/index.js", "repository": { @@ -16,7 +16,7 @@ }, "author": "fxy060608", "license": "Apache-2.0", - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2", + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00", "dependencies": { "mustache": "^3.1.0", "stricter-htmlparser2": "^3.9.6" diff --git a/packages/uni-mp-alipay/package.json b/packages/uni-mp-alipay/package.json index af01f60f3a58c52d0ae0c34eddba967349577cff..7391a0989dc5c00f6f36f4e651fce191b5c997ab 100644 --- a/packages/uni-mp-alipay/package.json +++ b/packages/uni-mp-alipay/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-alipay", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app mp-alipay", "main": "dist/index.js", "repository": { @@ -13,5 +13,5 @@ }, "author": "fxy060608", "license": "Apache-2.0", - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/uni-mp-baidu/dcloudio-uni-mp-baidu-3.0.0-alpha-24020191018043.tgz b/packages/uni-mp-baidu/dcloudio-uni-mp-baidu-3.0.0-alpha-24020191018043.tgz new file mode 100644 index 0000000000000000000000000000000000000000..ce5ad5eefa197d7869942d0607c7ebc9dbcc655c Binary files /dev/null and b/packages/uni-mp-baidu/dcloudio-uni-mp-baidu-3.0.0-alpha-24020191018043.tgz differ diff --git a/packages/uni-mp-baidu/package.json b/packages/uni-mp-baidu/package.json index ca2acdbc441f7b5b80e2dd93abaaf6be0cd38767..206cdbfcca823fbfe00953d99f502795593b2437 100644 --- a/packages/uni-mp-baidu/package.json +++ b/packages/uni-mp-baidu/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-baidu", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app mp-baidu", "main": "dist/index.js", "repository": { @@ -13,5 +13,5 @@ }, "author": "fxy060608", "license": "Apache-2.0", - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/uni-mp-qq/package.json b/packages/uni-mp-qq/package.json index b6cb837dca3780897602abef8aac39179460e22b..7892ed345625e8c40004f6f01a0178cfb6e6dcd0 100644 --- a/packages/uni-mp-qq/package.json +++ b/packages/uni-mp-qq/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-qq", - "version": "3.0.0-alpha-24020191018038", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app mp-qq", "main": "dist/index.js", "repository": { @@ -13,5 +13,5 @@ }, "author": "fxy060608", "license": "Apache-2.0", - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/uni-mp-toutiao/package.json b/packages/uni-mp-toutiao/package.json index a48edc008e1f78f0c936116b504b2daf5a1ef022..d85c99d49d240177d36ba2e485715e133fbae752 100644 --- a/packages/uni-mp-toutiao/package.json +++ b/packages/uni-mp-toutiao/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-toutiao", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app mp-toutiao", "main": "dist/index.js", "repository": { @@ -13,5 +13,5 @@ }, "author": "fxy060608", "license": "Apache-2.0", - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/uni-mp-weixin/package.json b/packages/uni-mp-weixin/package.json index 5d94cbb48946bc836ecc67ee442cdc3082b99748..08a7daab2dcaa9b035013fd095b6f9abf3b17c2a 100644 --- a/packages/uni-mp-weixin/package.json +++ b/packages/uni-mp-weixin/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-mp-weixin", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app mp-weixin", "main": "dist/index.js", "repository": { @@ -13,5 +13,5 @@ }, "author": "fxy060608", "license": "Apache-2.0", - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/uni-stat/package.json b/packages/uni-stat/package.json index cba024b1bc0f89204cbec32e854d78ff00d45786..7fa80783f53db5d5f5fc6d6a9474b4f76107238a 100644 --- a/packages/uni-stat/package.json +++ b/packages/uni-stat/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-stat", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "", "main": "dist/index.js", "repository": { @@ -34,5 +34,5 @@ "rollup-plugin-replace": "^2.2.0", "rollup-plugin-uglify": "^6.0.2" }, - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/uni-template-compiler/package.json b/packages/uni-template-compiler/package.json index 558aa092c53fa23436c229f1b17d75126f6cb710..51b0297ea6f5f2431b1da66ec969860a9b559cc2 100644 --- a/packages/uni-template-compiler/package.json +++ b/packages/uni-template-compiler/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/uni-template-compiler", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-template-compiler", "main": "lib/index.js", "repository": { @@ -22,5 +22,5 @@ "@babel/types": "^7.3.3", "vue-template-compiler": "^2.6.10" }, - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js index f5e070a2cde716308a9bc553d79fcfd5840a1f69..cee4155af172da70d587b8077d5329aa76d62044 100644 --- a/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js +++ b/packages/vue-cli-plugin-hbuilderx/build/webpack.nvue.conf.js @@ -37,13 +37,15 @@ const uniPath = process.env.UNI_USING_V8 : '../packages/uni-app-plus-nvue/dist/index.js' const provide = {} - -if (!process.env.UNI_USING_NATIVE) { - provide['uni'] = [path.resolve(__dirname, uniPath), 'default'] -} - -if (process.env.UNI_USING_V8) { - provide['plus'] = [path.resolve(__dirname, uniPath), 'weexPlus'] + +if (!process.env.UNI_USING_V3) { + if (!process.env.UNI_USING_NATIVE) { + provide['uni'] = [path.resolve(__dirname, uniPath), 'default'] + } + + if (process.env.UNI_USING_V8) { + provide['plus'] = [path.resolve(__dirname, uniPath), 'weexPlus'] + } } if ( diff --git a/packages/vue-cli-plugin-hbuilderx/module-alias.js b/packages/vue-cli-plugin-hbuilderx/module-alias.js index 385c148395f0a81b5be4e79dca624bd3824858f3..f29af64024cec273bda9ac5f9f09ac0eed9a25bb 100644 --- a/packages/vue-cli-plugin-hbuilderx/module-alias.js +++ b/packages/vue-cli-plugin-hbuilderx/module-alias.js @@ -19,19 +19,6 @@ moduleAlias.addAlias('./templateLoader', (fromPath, request, alias) => { } return request }) -// vue cache -if ( // 非 h5 ,非 v3,非 native - process.env.UNI_PLATFORM !== 'h5' && - !process.env.UNI_USING_V3 && - !process.env.UNI_USING_NATIVE -) { - moduleAlias.addAlias('./loaders/pitcher', (fromPath, request, alias) => { - if (fromPath.indexOf('vue-loader') !== -1) { - return path.resolve(__dirname, 'packages/vue-loader/lib/loaders/pitcher') - } - return request - }) -} if (isInHBuilderX) { moduleAlias.addAlias('typescript', path.resolve(process.env.UNI_HBUILDERX_PLUGINS, diff --git a/packages/vue-cli-plugin-hbuilderx/package.json b/packages/vue-cli-plugin-hbuilderx/package.json index 240d0735527c799224fb6adcb55024f0ae9975a7..ace0b987438362a939e0b988f2bafd52e010302e 100644 --- a/packages/vue-cli-plugin-hbuilderx/package.json +++ b/packages/vue-cli-plugin-hbuilderx/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/vue-cli-plugin-hbuilderx", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "HBuilderX plugin for vue-cli 3", "main": "index.js", "repository": { @@ -18,5 +18,5 @@ "css": "~2.2.1", "escodegen": "^1.8.1" }, - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/vue-cli-plugin-uni-optimize/package.json b/packages/vue-cli-plugin-uni-optimize/package.json index a7457ef645e8f161f140f2b442f60ce5275109fc..eaf631342cd37f8bae6d296a62a62571e048cc34 100644 --- a/packages/vue-cli-plugin-uni-optimize/package.json +++ b/packages/vue-cli-plugin-uni-optimize/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/vue-cli-plugin-uni-optimize", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app optimize plugin for vue-cli 3", "main": "index.js", "repository": { @@ -13,5 +13,5 @@ }, "author": "fxy060608", "license": "Apache-2.0", - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/vue-cli-plugin-uni/index.js b/packages/vue-cli-plugin-uni/index.js index 3e1a8cea95cbb5cdb87000a2d1a99102a7bb86b9..e5e3565b0b4e2ec4939204cdc6b77f6ab513354b 100644 --- a/packages/vue-cli-plugin-uni/index.js +++ b/packages/vue-cli-plugin-uni/index.js @@ -26,7 +26,7 @@ module.exports = (api, options) => { require('./lib/options')(options) api.configureWebpack(require('./lib/configure-webpack')(platformOptions, manifestPlatformOptions, options, api)) - api.chainWebpack(require('./lib/chain-webpack')(platformOptions, api)) + api.chainWebpack(require('./lib/chain-webpack')(platformOptions, options, api)) } module.exports.defaultModes = { diff --git a/packages/vue-cli-plugin-uni/lib/app-plus/index.js b/packages/vue-cli-plugin-uni/lib/app-plus/index.js index 3e3ff7c9ef12fae5f9e508a9a356288a1fec43ab..dee8ffd0676d1436b784aa5507387d904f55441c 100644 --- a/packages/vue-cli-plugin-uni/lib/app-plus/index.js +++ b/packages/vue-cli-plugin-uni/lib/app-plus/index.js @@ -7,9 +7,14 @@ const { } = require('@dcloudio/uni-cli-shared') const { - isUnaryTag + isUnaryTag, + getPartialIdentifier } = require('../util') +// const { +// createTemplateCacheLoader +// } = require('../cache-loader') + function getProvides () { return { '__f__': [path.resolve(__dirname, '../format-log.js'), 'default'], @@ -22,7 +27,7 @@ const v3 = { vueConfig: { parallel: false }, - webpackConfig (webpackConfig, vueOptions) { + webpackConfig (webpackConfig, vueOptions, api) { const isAppService = !!vueOptions.pluginOptions['uni-app-plus']['service'] const isAppView = !!vueOptions.pluginOptions['uni-app-plus']['view'] @@ -79,8 +84,8 @@ const v3 = { externals: { vue: 'Vue' }, - entry () { - return entry + entry () { + return entry }, output: { filename: '[name].js', @@ -120,6 +125,12 @@ const v3 = { }] }, ...rules + // v3 暂不支持 cache + // createTemplateCacheLoader(api, + // isAppService + // ? 'uni-template-compiler-service' + // : 'uni-template-compiler-view' + // ) ] }, plugins: [ @@ -127,12 +138,24 @@ const v3 = { ] } }, - chainWebpack (webpackConfig, vueOptions) { + chainWebpack (webpackConfig, vueOptions, api) { webpackConfig.entryPoints.delete('app') const isAppService = !!vueOptions.pluginOptions['uni-app-plus']['service'] const isAppView = !!vueOptions.pluginOptions['uni-app-plus']['view'] + const cacheConfig = { + cacheDirectory: false, + cacheIdentifier: false + } + + if (process.env.UNI_USING_CACHE) { + Object.assign(cacheConfig, api.genCacheConfig( + 'vue-template-compiler/' + process.env.UNI_PLATFORM, + getPartialIdentifier() + )) + } + const compilerOptions = { isUnaryTag, preserveWhitespace: false, @@ -150,20 +173,30 @@ const v3 = { isAppService, isAppView, compiler: getPlatformCompiler(), - compilerOptions, - cacheDirectory: false, - cacheIdentifier: false - })) - .end() - .use('uniapp-custom-block-loader') - .loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/webpack-custom-block-loader')) - .options({ - compiler: getPlatformCompiler() - }) - .end() - .uses - .delete('cache-loader') + compilerOptions + }, cacheConfig)) .end() + .use('uniapp-custom-block-loader') + .loader(require.resolve('@dcloudio/vue-cli-plugin-uni/packages/webpack-custom-block-loader')) + .options({ + compiler: getPlatformCompiler() + }) + + // 是否启用 cache + if (process.env.UNI_USING_CACHE) { + webpackConfig.module + .rule('vue') + .use('cache-loader') + .tap(options => Object.assign(options, api.genCacheConfig( + 'vue-loader/' + process.env.UNI_PLATFORM, + getPartialIdentifier() + ))) + } else { + webpackConfig.module + .rule('vue') + .uses + .delete('cache-loader') + } if (isAppView) { if (process.env.NODE_ENV === 'production') { diff --git a/packages/vue-cli-plugin-uni/lib/cache-loader.js b/packages/vue-cli-plugin-uni/lib/cache-loader.js index 0b659b2aeccebe54f4a626f3c71295bae4c03d6e..af1941c8bb3aedd2760fdcf64cc0cf83b2cb642b 100644 --- a/packages/vue-cli-plugin-uni/lib/cache-loader.js +++ b/packages/vue-cli-plugin-uni/lib/cache-loader.js @@ -62,14 +62,14 @@ function read (key, callback) { } module.exports = { - createTemplateCacheLoader: function (api) { + createTemplateCacheLoader: function (api, id = 'uni-template-compiler') { return { resourceQuery: /type=uni-cache-loader-template/, use: [{ loader: 'cache-loader', ident: 'uni-cache-loader-template-options', options: Object.assign(api.genCacheConfig( - 'uni-template-compiler/' + process.env.UNI_PLATFORM, + id + '/' + process.env.UNI_PLATFORM, getPartialIdentifier() ), { read, diff --git a/packages/vue-cli-plugin-uni/lib/chain-webpack.js b/packages/vue-cli-plugin-uni/lib/chain-webpack.js index 45dc249d4b97bfba714daf2fdaff1a0dbef5ac1e..c4190e9be4c9eedeef479ddbbfc9ff81ec7c2e58 100644 --- a/packages/vue-cli-plugin-uni/lib/chain-webpack.js +++ b/packages/vue-cli-plugin-uni/lib/chain-webpack.js @@ -12,7 +12,7 @@ function resolve (dir) { return path.resolve(__dirname, '..', dir) } -module.exports = function chainWebpack (platformOptions, api) { +module.exports = function chainWebpack (platformOptions, vueOptions, api) { const { runByHBuilderX, // 使用 HBuilderX 运行 cssPreprocessOptions @@ -94,7 +94,7 @@ module.exports = function chainWebpack (platformOptions, api) { }) } - platformOptions.chainWebpack(webpackConfig, api) + platformOptions.chainWebpack(webpackConfig, vueOptions, api) // define webpackConfig .plugin('uni-define') diff --git a/packages/vue-cli-plugin-uni/lib/configure-webpack.js b/packages/vue-cli-plugin-uni/lib/configure-webpack.js index 2873411eaadfbe3adff60cd6bd9a81ee3356cf17..c5e15d163660ca2f70ab0ac043aad4e57035f1df 100644 --- a/packages/vue-cli-plugin-uni/lib/configure-webpack.js +++ b/packages/vue-cli-plugin-uni/lib/configure-webpack.js @@ -23,7 +23,6 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt runByHBuilderX, // 使用 HBuilderX 运行 isInHBuilderX, // 在 HBuilderX 的插件中 hasModule, - getMainEntry, getPlatformVue, jsPreprocessOptions, htmlPreprocessOptions @@ -178,7 +177,7 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt let platformWebpackConfig = platformOptions.webpackConfig if (typeof platformWebpackConfig === 'function') { - platformWebpackConfig = platformWebpackConfig(webpackConfig, api) + platformWebpackConfig = platformWebpackConfig(webpackConfig, vueOptions, api) } // 移除 node_modules 目录,避免受路径上的 node_modules 影响 webpackConfig.resolve.modules = webpackConfig.resolve.modules.filter(module => module !== @@ -207,26 +206,6 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt })) } - let useBuiltIns = 'entry' - if (process.env.UNI_PLATFORM === 'h5') { // 兼容旧版本 h5 - useBuiltIns = 'usage' - try { - const babelConfig = require(path.resolve(process.env.UNI_CLI_CONTEXT, 'babel.config.js')) - useBuiltIns = babelConfig.presets[0][1].useBuiltIns - } catch (e) {} - } - - const statCode = process.env.UNI_USING_STAT ? `import '@dcloudio/uni-stat';` : '' - - let beforeCode = '' - - if (process.env.UNI_PLATFORM === 'h5') { - beforeCode = (useBuiltIns === 'entry' ? `import '@babel/polyfill';` : '') + - `import 'uni-pages';import 'uni-${process.env.UNI_PLATFORM}';` - } else { - beforeCode = `import 'uni-pages';` - } - const rules = [{ test: path.resolve(process.env.UNI_INPUT_DIR, 'pages.json'), use: [{ @@ -236,18 +215,6 @@ module.exports = function configureWebpack (platformOptions, manifestPlatformOpt }], type: 'javascript/auto' }, - { - test: path.resolve(process.env.UNI_INPUT_DIR, getMainEntry()), - // resourceQuery: /type=wrapper/, - use: [{ - loader: 'wrap-loader', - options: { - before: [ - beforeCode + statCode - ] - } - }] - }, { resourceQuery: /vue&type=template/, use: [{ diff --git a/packages/vue-cli-plugin-uni/lib/env.js b/packages/vue-cli-plugin-uni/lib/env.js index 1d12f9207976636cdc3bc30eaae767a077593364..30670dff8c095e4efcb8f87cd5fef093553657ab 100644 --- a/packages/vue-cli-plugin-uni/lib/env.js +++ b/packages/vue-cli-plugin-uni/lib/env.js @@ -125,7 +125,8 @@ if (process.env.UNI_PLATFORM === 'app-plus') { platformOptions.compilerVersion === '3' || platformOptions.compilerVersion === 3 ) - ) { + ) { + delete process.env.UNI_USING_CACHE process.env.UNI_USING_V3 = true platformOptions.usingComponents = true process.env.UNI_OUTPUT_TMP_DIR = '' @@ -256,6 +257,20 @@ const moduleAlias = require('module-alias') moduleAlias.addAlias('vue-template-compiler', '@dcloudio/vue-cli-plugin-uni/packages/vue-template-compiler') moduleAlias.addAlias('@megalo/template-compiler', '@dcloudio/vue-cli-plugin-uni/packages/@megalo/template-compiler') moduleAlias.addAlias('mpvue-template-compiler', '@dcloudio/vue-cli-plugin-uni/packages/mpvue-template-compiler') + +// vue cache +if ( // 非 h5 ,非 v3,非 native + process.env.UNI_PLATFORM !== 'h5' && + !process.env.UNI_USING_V3 && + !process.env.UNI_USING_NATIVE +) { + moduleAlias.addAlias('./loaders/pitcher', (fromPath, request, alias) => { + if (fromPath.indexOf('vue-loader') !== -1) { + return require.resolve('@dcloudio/vue-cli-plugin-hbuilderx/packages/vue-loader/lib/loaders/pitcher') + } + return request + }) +} if (process.env.UNI_PLATFORM === 'mp-toutiao') { // !important 始终带有一个空格 @@ -283,7 +298,7 @@ if (runByHBuilderX) { if ( process.env.UNI_USING_CACHE && - process.env.UNI_PLATFORM !== 'h5' && + process.env.UNI_PLATFORM !== 'h5' && !process.env.UNI_USING_V3 && !process.env.UNI_USING_NATIVE ) { // 使用 cache, 拷贝 cache 的 json diff --git a/packages/vue-cli-plugin-uni/lib/h5/index.js b/packages/vue-cli-plugin-uni/lib/h5/index.js index db9ebde24ae18282255dccf72e6d9fd575def9b9..61ef979b61b333bcc1e9aa73374d58f020af6470 100644 --- a/packages/vue-cli-plugin-uni/lib/h5/index.js +++ b/packages/vue-cli-plugin-uni/lib/h5/index.js @@ -3,8 +3,7 @@ const path = require('path') const { getMainEntry, - getH5Options, - getPlatformCssnano + getH5Options } = require('@dcloudio/uni-cli-shared') const modifyVueLoader = require('../vue-loader') @@ -63,6 +62,18 @@ if (devServer && Object.keys(devServer).length) { module.exports = { vueConfig, webpackConfig (webpackConfig) { + let useBuiltIns = 'usage' + + const statCode = process.env.UNI_USING_STAT ? `import '@dcloudio/uni-stat';` : '' + + try { + const babelConfig = require(path.resolve(process.env.UNI_CLI_CONTEXT, 'babel.config.js')) + useBuiltIns = babelConfig.presets[0][1].useBuiltIns + } catch (e) {} + + const beforeCode = (useBuiltIns === 'entry' ? `import '@babel/polyfill';` : '') + + `import 'uni-pages';import 'uni-${process.env.UNI_PLATFORM}';` + return { devtool: process.env.NODE_ENV === 'production' ? false : 'source-map', resolve: { @@ -74,6 +85,16 @@ module.exports = { }, module: { rules: [{ + test: path.resolve(process.env.UNI_INPUT_DIR, getMainEntry()), + use: [{ + loader: 'wrap-loader', + options: { + before: [ + beforeCode + statCode + ] + } + }] + }, { test: /App\.vue$/, use: { loader: 'wrap-loader', @@ -84,7 +105,7 @@ module.exports = { }, { resourceQuery: /vue&type=template/, use: [{ - loader: resolve('packages/h5-vue-template-loader') + loader: resolve('packages/webpack-uni-app-loader/filter-modules-template.js') }] }, { resourceQuery: [/lang=wxs/, /blockType=wxs/], @@ -101,7 +122,7 @@ module.exports = { plugins } }, - chainWebpack (webpackConfig, api) { + chainWebpack (webpackConfig, vueOptions, api) { webpackConfig.plugins.delete('copy') if (!process.env.UNI_OPT_PREFETCH) { @@ -114,52 +135,7 @@ module.exports = { modifyVueLoader(webpackConfig, require('./compiler-options'), api) if (process.env.NODE_ENV === 'production') { - const module = webpackConfig.module - // TODO 临时 hack calc:false 看看 vue cli 后续是否开放 cssnano 的配置 - const cssnanoOptions = { - sourceMap: false, - plugins: [require('cssnano')({ - preset: ['default', getPlatformCssnano()] - })] - } - - module.rule('css').oneOf('vue-modules').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - module.rule('css').oneOf('vue').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - module.rule('css').oneOf('normal-modules').use('cssnano').loader('postcss-loader').options( - cssnanoOptions) - module.rule('css').oneOf('normal').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - - module.rule('postcss').oneOf('vue-modules').use('cssnano').loader('postcss-loader').options( - cssnanoOptions) - module.rule('postcss').oneOf('vue').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - module.rule('postcss').oneOf('normal-modules').use('cssnano').loader('postcss-loader').options( - cssnanoOptions) - module.rule('postcss').oneOf('normal').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - - module.rule('scss').oneOf('vue-modules').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - module.rule('scss').oneOf('vue').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - module.rule('scss').oneOf('normal-modules').use('cssnano').loader('postcss-loader').options( - cssnanoOptions) - module.rule('scss').oneOf('normal').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - - module.rule('sass').oneOf('vue-modules').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - module.rule('sass').oneOf('vue').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - module.rule('sass').oneOf('normal-modules').use('cssnano').loader('postcss-loader').options( - cssnanoOptions) - module.rule('sass').oneOf('normal').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - - module.rule('less').oneOf('vue-modules').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - module.rule('less').oneOf('vue').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - module.rule('less').oneOf('normal-modules').use('cssnano').loader('postcss-loader').options( - cssnanoOptions) - module.rule('less').oneOf('normal').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - - module.rule('stylus').oneOf('vue-modules').use('cssnano').loader('postcss-loader').options( - cssnanoOptions) - module.rule('stylus').oneOf('vue').use('cssnano').loader('postcss-loader').options(cssnanoOptions) - module.rule('stylus').oneOf('normal-modules').use('cssnano').loader('postcss-loader').options( - cssnanoOptions) - module.rule('stylus').oneOf('normal').use('cssnano').loader('postcss-loader').options(cssnanoOptions) + require('./cssnano-options')(webpackConfig) } } } diff --git a/packages/vue-cli-plugin-uni/lib/mp.js b/packages/vue-cli-plugin-uni/lib/mp.js index 662519596835a1923d6cf15fb1a4b317810ded11..f8fdf9fc9d4e41052dde7b10e9dad1bffd595851 100644 --- a/packages/vue-cli-plugin-uni/lib/mp.js +++ b/packages/vue-cli-plugin-uni/lib/mp.js @@ -62,7 +62,7 @@ module.exports = { vueConfig: { parallel: false }, - webpackConfig (webpackConfig, api) { + webpackConfig (webpackConfig, vueOptions, api) { if (!webpackConfig.optimization) { webpackConfig.optimization = {} } @@ -94,6 +94,9 @@ module.exports = { devtool = 'sourcemap' } } + const statCode = process.env.UNI_USING_STAT ? `import '@dcloudio/uni-stat';` : '' + + const beforeCode = `import 'uni-pages';` return { devtool, @@ -121,6 +124,13 @@ module.exports = { rules: [{ test: path.resolve(process.env.UNI_INPUT_DIR, getMainEntry()), use: [{ + loader: 'wrap-loader', + options: { + before: [ + beforeCode + statCode + ] + } + }, { loader: '@dcloudio/webpack-uni-mp-loader/lib/main' }] }, { @@ -154,7 +164,7 @@ module.exports = { ] } }, - chainWebpack (webpackConfig, api) { + chainWebpack (webpackConfig, vueOptions, api) { if (process.env.UNI_PLATFORM === 'mp-baidu') { webpackConfig.module .rule('js') diff --git a/packages/vue-cli-plugin-uni/lib/util.js b/packages/vue-cli-plugin-uni/lib/util.js index b0112047379ac3a77c985830752cc69909616fc3..fd85fa57024c5892c14dd1b42f9515635e1023c1 100644 --- a/packages/vue-cli-plugin-uni/lib/util.js +++ b/packages/vue-cli-plugin-uni/lib/util.js @@ -16,17 +16,16 @@ module.exports = { 'link,meta,param,source,track,wbr' ), getPartialIdentifier () { - if (partialIdentifier) { - return partialIdentifier - } - partialIdentifier = { - 'UNI_COMPILER_VERSION': require('../package.json').version - } - Object.keys(process.env).forEach(name => { - if (name.indexOf('UNI_') === 0) { - partialIdentifier[name] = process.env[name] + if (!partialIdentifier) { + partialIdentifier = { + 'UNI_COMPILER_VERSION': require('../package.json').version } - }) + Object.keys(process.env).forEach(name => { + if (name.indexOf('UNI_') === 0) { + partialIdentifier[name] = process.env[name] + } + }) + } return partialIdentifier } } diff --git a/packages/vue-cli-plugin-uni/lib/vue-loader.js b/packages/vue-cli-plugin-uni/lib/vue-loader.js index e680c62367b27e0b491b1276d2e19ccd350ebc6b..db5ba5d74e3ce4c9e02511334f97b421db039cd3 100644 --- a/packages/vue-cli-plugin-uni/lib/vue-loader.js +++ b/packages/vue-cli-plugin-uni/lib/vue-loader.js @@ -14,7 +14,6 @@ module.exports = function modifyVueLoader (webpackConfig, compilerOptions, api) cacheDirectory: false, cacheIdentifier: false } - const partialIdentifier = {} if (process.env.UNI_USING_CACHE) { Object.assign(cacheConfig, api.genCacheConfig( @@ -60,7 +59,7 @@ module.exports = function modifyVueLoader (webpackConfig, compilerOptions, api) .use('cache-loader') .tap(options => Object.assign(options, api.genCacheConfig( 'vue-loader/' + process.env.UNI_PLATFORM, - partialIdentifier + getPartialIdentifier() ))) } else { webpackConfig.module diff --git a/packages/vue-cli-plugin-uni/package.json b/packages/vue-cli-plugin-uni/package.json index 34fe2e4c80d9ef4ae873d3dc637b0fc631a691f2..185b255a22e24ec5e84d0b0d65cddb996e05fc16 100644 --- a/packages/vue-cli-plugin-uni/package.json +++ b/packages/vue-cli-plugin-uni/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/vue-cli-plugin-uni", - "version": "2.0.0-23320190923002", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app plugin for vue-cli 3", "main": "index.js", "repository": { @@ -36,5 +36,5 @@ "wrap-loader": "^0.2.0", "xregexp": "4.0.0" }, - "gitHead": "10184426b19cb76e01c93fb25c982c72887557e8" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/webpack-uni-mp-loader/package.json b/packages/webpack-uni-mp-loader/package.json index 6ea30d3cf06730a3f7b4566a61441051c34c8110..5cfc46c340addb940ad11fbb2f4f22151b5ce500 100644 --- a/packages/webpack-uni-mp-loader/package.json +++ b/packages/webpack-uni-mp-loader/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/webpack-uni-mp-loader", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "webpack-uni-mp-loader", "main": "index.js", "repository": { @@ -16,5 +16,5 @@ }, "author": "fxy060608", "license": "Apache-2.0", - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" } diff --git a/packages/webpack-uni-pages-loader/package.json b/packages/webpack-uni-pages-loader/package.json index aac507172b5b8fd065e0331afceef63b0df1ee82..50b3b1923969bc3390517e12c34a3a760a7c6368 100644 --- a/packages/webpack-uni-pages-loader/package.json +++ b/packages/webpack-uni-pages-loader/package.json @@ -1,6 +1,6 @@ { "name": "@dcloudio/webpack-uni-pages-loader", - "version": "3.0.0-alpha-24020191018029", + "version": "3.0.0-alpha-24020191018043", "description": "uni-app pages.json loader", "main": "lib/index.js", "repository": { @@ -21,7 +21,7 @@ "strip-json-comments": "^2.0.1" }, "uni-app": { - "compilerVersion": "2.3.4" + "compilerVersion": "2.4.3" }, - "gitHead": "6b0d55e296028761e3de4b561c1ad7c5fb7a23e2" + "gitHead": "110501ffb0313e417858dec92acf07522d4ded00" }