From 1198bbdb08fb80ba89ecb5b197c405642ce12e4e Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Thu, 9 May 2019 13:59:25 +0800 Subject: [PATCH] build uni runtime(refactor previewImage) --- packages/uni-mp-baidu/dist/index.js | 68 +++++++++---------- packages/uni-mp-baidu/package.json | 2 +- packages/uni-mp-toutiao/dist/index.js | 68 +++++++++---------- packages/uni-mp-toutiao/package.json | 2 +- packages/uni-mp-weixin/dist/index.js | 62 +++++++++-------- packages/uni-mp-weixin/package.json | 2 +- .../mp-baidu/service/api/protocols.js | 12 +--- .../mp-toutiao/service/api/protocols.js | 12 +--- .../helpers/normalize-preview-image-args.js | 27 -------- .../helpers/normalize-preview-image.js | 33 +++++++++ .../mp-weixin/service/api/protocols.js | 12 +--- 11 files changed, 141 insertions(+), 159 deletions(-) delete mode 100644 src/platforms/mp-weixin/helpers/normalize-preview-image-args.js create mode 100644 src/platforms/mp-weixin/helpers/normalize-preview-image.js diff --git a/packages/uni-mp-baidu/dist/index.js b/packages/uni-mp-baidu/dist/index.js index db93ea19..6bdf4e3c 100644 --- a/packages/uni-mp-baidu/dist/index.js +++ b/packages/uni-mp-baidu/dist/index.js @@ -144,33 +144,39 @@ function upx2px (number, newDeviceWidth) { return number < 0 ? -result : result } -function normalize (fromArgs) { - let currentIndex = parseInt(fromArgs.current); - if (isNaN(currentIndex)) { - return - } - const urls = fromArgs.urls; - if (!Array.isArray(urls)) { - return - } - const len = urls.length; - if (!len) { - return - } - if (currentIndex < 0) { - currentIndex = 0; - } else if (currentIndex >= len) { - currentIndex = len - 1; - } - if (currentIndex > 0) { - fromArgs.current = urls[currentIndex]; - fromArgs.urls = urls.filter( - (item, index) => index < currentIndex ? item !== urls[currentIndex] : true - ); - } else { - fromArgs.current = urls[0]; +var previewImage = { + args (fromArgs) { + let currentIndex = parseInt(fromArgs.current); + if (isNaN(currentIndex)) { + return + } + const urls = fromArgs.urls; + if (!Array.isArray(urls)) { + return + } + const len = urls.length; + if (!len) { + return + } + if (currentIndex < 0) { + currentIndex = 0; + } else if (currentIndex >= len) { + currentIndex = len - 1; + } + if (currentIndex > 0) { + fromArgs.current = urls[currentIndex]; + fromArgs.urls = urls.filter( + (item, index) => index < currentIndex ? item !== urls[currentIndex] : true + ); + } else { + fromArgs.current = urls[0]; + } + return { + indicator: false, + loop: false + } } -} +}; // 不支持的 API 列表 const todos = [ @@ -232,15 +238,7 @@ const protocols = { method: false } }, - previewImage: { - args (fromArgs) { - normalize(fromArgs); - return { - indicator: false, - loop: false - } - } - }, + previewImage, getRecorderManager: { returnValue (fromRet) { fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded'); diff --git a/packages/uni-mp-baidu/package.json b/packages/uni-mp-baidu/package.json index aada5ec9..7f1254f5 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": "0.0.829", + "version": "0.0.830", "description": "uni-app mp-baidu", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-toutiao/dist/index.js b/packages/uni-mp-toutiao/dist/index.js index d56308da..6add7ff2 100644 --- a/packages/uni-mp-toutiao/dist/index.js +++ b/packages/uni-mp-toutiao/dist/index.js @@ -144,33 +144,39 @@ function upx2px (number, newDeviceWidth) { return number < 0 ? -result : result } -function normalize (fromArgs) { - let currentIndex = parseInt(fromArgs.current); - if (isNaN(currentIndex)) { - return - } - const urls = fromArgs.urls; - if (!Array.isArray(urls)) { - return - } - const len = urls.length; - if (!len) { - return - } - if (currentIndex < 0) { - currentIndex = 0; - } else if (currentIndex >= len) { - currentIndex = len - 1; - } - if (currentIndex > 0) { - fromArgs.current = urls[currentIndex]; - fromArgs.urls = urls.filter( - (item, index) => index < currentIndex ? item !== urls[currentIndex] : true - ); - } else { - fromArgs.current = urls[0]; +var previewImage = { + args (fromArgs) { + let currentIndex = parseInt(fromArgs.current); + if (isNaN(currentIndex)) { + return + } + const urls = fromArgs.urls; + if (!Array.isArray(urls)) { + return + } + const len = urls.length; + if (!len) { + return + } + if (currentIndex < 0) { + currentIndex = 0; + } else if (currentIndex >= len) { + currentIndex = len - 1; + } + if (currentIndex > 0) { + fromArgs.current = urls[currentIndex]; + fromArgs.urls = urls.filter( + (item, index) => index < currentIndex ? item !== urls[currentIndex] : true + ); + } else { + fromArgs.current = urls[0]; + } + return { + indicator: false, + loop: false + } } -} +}; // 不支持的 API 列表 const todos = [ @@ -265,15 +271,7 @@ const protocols = { sizeType: false } }, - previewImage: { - args (fromArgs) { - normalize(fromArgs); - return { - indicator: false, - loop: false - } - } - }, + previewImage, connectSocket: { args: { method: false diff --git a/packages/uni-mp-toutiao/package.json b/packages/uni-mp-toutiao/package.json index 6a934b8a..88e1d85d 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": "0.0.327", + "version": "0.0.328", "description": "uni-app mp-toutiao", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-weixin/dist/index.js b/packages/uni-mp-weixin/dist/index.js index 63da3c6f..e6eab42a 100644 --- a/packages/uni-mp-weixin/dist/index.js +++ b/packages/uni-mp-weixin/dist/index.js @@ -144,38 +144,42 @@ function upx2px (number, newDeviceWidth) { return number < 0 ? -result : result } -function normalize (fromArgs) { - let currentIndex = parseInt(fromArgs.current); - if (isNaN(currentIndex)) { - return - } - const urls = fromArgs.urls; - if (!Array.isArray(urls)) { - return - } - const len = urls.length; - if (!len) { - return - } - if (currentIndex < 0) { - currentIndex = 0; - } else if (currentIndex >= len) { - currentIndex = len - 1; - } - if (currentIndex > 0) { - fromArgs.current = urls[currentIndex]; - fromArgs.urls = urls.filter( - (item, index) => index < currentIndex ? item !== urls[currentIndex] : true - ); - } else { - fromArgs.current = urls[0]; +var previewImage = { + args (fromArgs) { + let currentIndex = parseInt(fromArgs.current); + if (isNaN(currentIndex)) { + return + } + const urls = fromArgs.urls; + if (!Array.isArray(urls)) { + return + } + const len = urls.length; + if (!len) { + return + } + if (currentIndex < 0) { + currentIndex = 0; + } else if (currentIndex >= len) { + currentIndex = len - 1; + } + if (currentIndex > 0) { + fromArgs.current = urls[currentIndex]; + fromArgs.urls = urls.filter( + (item, index) => index < currentIndex ? item !== urls[currentIndex] : true + ); + } else { + fromArgs.current = urls[0]; + } + return { + indicator: false, + loop: false + } } -} +}; const protocols = { - previewImage: { - args: normalize - } + previewImage }; const todos = []; const canIUses = []; diff --git a/packages/uni-mp-weixin/package.json b/packages/uni-mp-weixin/package.json index c574a5ab..f22169b4 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": "0.0.951", + "version": "0.0.952", "description": "uni-app mp-weixin", "main": "dist/index.js", "scripts": { diff --git a/src/platforms/mp-baidu/service/api/protocols.js b/src/platforms/mp-baidu/service/api/protocols.js index 08fb92fc..43ee0a26 100644 --- a/src/platforms/mp-baidu/service/api/protocols.js +++ b/src/platforms/mp-baidu/service/api/protocols.js @@ -1,4 +1,4 @@ -import normalizePreviewImageArgs from '../../../mp-weixin/helpers/normalize-preview-image-args' +import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' // 不支持的 API 列表 const todos = [ 'hideKeyboard', @@ -59,15 +59,7 @@ const protocols = { method: false } }, - previewImage: { - args (fromArgs) { - normalizePreviewImageArgs(fromArgs) - return { - indicator: false, - loop: false - } - } - }, + previewImage, getRecorderManager: { returnValue (fromRet) { fromRet.onFrameRecorded = createTodoMethod('RecorderManager', 'onFrameRecorded') diff --git a/src/platforms/mp-toutiao/service/api/protocols.js b/src/platforms/mp-toutiao/service/api/protocols.js index 9ff4f8de..205e4dc1 100644 --- a/src/platforms/mp-toutiao/service/api/protocols.js +++ b/src/platforms/mp-toutiao/service/api/protocols.js @@ -1,4 +1,4 @@ -import normalizePreviewImageArgs from '../../../mp-weixin/helpers/normalize-preview-image-args' +import previewImage from '../../../mp-weixin/helpers/normalize-preview-image' // 不支持的 API 列表 const todos = [ @@ -93,15 +93,7 @@ const protocols = { sizeType: false } }, - previewImage: { - args (fromArgs) { - normalizePreviewImageArgs(fromArgs) - return { - indicator: false, - loop: false - } - } - }, + previewImage, connectSocket: { args: { method: false diff --git a/src/platforms/mp-weixin/helpers/normalize-preview-image-args.js b/src/platforms/mp-weixin/helpers/normalize-preview-image-args.js deleted file mode 100644 index 6c0f499a..00000000 --- a/src/platforms/mp-weixin/helpers/normalize-preview-image-args.js +++ /dev/null @@ -1,27 +0,0 @@ -export default function normalize (fromArgs) { - let currentIndex = parseInt(fromArgs.current) - if (isNaN(currentIndex)) { - return - } - const urls = fromArgs.urls - if (!Array.isArray(urls)) { - return - } - const len = urls.length - if (!len) { - return - } - if (currentIndex < 0) { - currentIndex = 0 - } else if (currentIndex >= len) { - currentIndex = len - 1 - } - if (currentIndex > 0) { - fromArgs.current = urls[currentIndex] - fromArgs.urls = urls.filter( - (item, index) => index < currentIndex ? item !== urls[currentIndex] : true - ) - } else { - fromArgs.current = urls[0] - } -} diff --git a/src/platforms/mp-weixin/helpers/normalize-preview-image.js b/src/platforms/mp-weixin/helpers/normalize-preview-image.js new file mode 100644 index 00000000..02a65248 --- /dev/null +++ b/src/platforms/mp-weixin/helpers/normalize-preview-image.js @@ -0,0 +1,33 @@ +export default { + args (fromArgs) { + let currentIndex = parseInt(fromArgs.current) + if (isNaN(currentIndex)) { + return + } + const urls = fromArgs.urls + if (!Array.isArray(urls)) { + return + } + const len = urls.length + if (!len) { + return + } + if (currentIndex < 0) { + currentIndex = 0 + } else if (currentIndex >= len) { + currentIndex = len - 1 + } + if (currentIndex > 0) { + fromArgs.current = urls[currentIndex] + fromArgs.urls = urls.filter( + (item, index) => index < currentIndex ? item !== urls[currentIndex] : true + ) + } else { + fromArgs.current = urls[0] + } + return { + indicator: false, + loop: false + } + } +} diff --git a/src/platforms/mp-weixin/service/api/protocols.js b/src/platforms/mp-weixin/service/api/protocols.js index 5786e7e5..3b6cd7a9 100644 --- a/src/platforms/mp-weixin/service/api/protocols.js +++ b/src/platforms/mp-weixin/service/api/protocols.js @@ -1,14 +1,6 @@ -import normalizePreviewImageArgs from '../../helpers/normalize-preview-image-args' +import previewImage from '../../helpers/normalize-preview-image' export const protocols = { - previewImage: { - args (fromArgs) { - normalizePreviewImageArgs(fromArgs) - return { - indicator: false, - loop: false - } - } - } + previewImage } export const todos = [] export const canIUses = [] -- GitLab