From 8516fa702ab5dd7704ead4c20bf614c73903ebcd Mon Sep 17 00:00:00 2001 From: fxy060608 Date: Wed, 8 May 2019 16:59:07 +0800 Subject: [PATCH] build uni runtime(mp previewImage currentIndex) --- packages/uni-mp-alipay/dist/index.js | 11 +++++--- packages/uni-mp-alipay/package.json | 2 +- packages/uni-mp-baidu/dist/index.js | 37 ++++++++++++++++++++++++--- packages/uni-mp-baidu/package.json | 2 +- packages/uni-mp-toutiao/dist/index.js | 37 ++++++++++++++++++++++++--- packages/uni-mp-toutiao/package.json | 2 +- packages/uni-mp-weixin/dist/index.js | 36 ++++++++++++++++++++++++-- packages/uni-mp-weixin/package.json | 2 +- 8 files changed, 114 insertions(+), 15 deletions(-) diff --git a/packages/uni-mp-alipay/dist/index.js b/packages/uni-mp-alipay/dist/index.js index 4f101c80d..c7d3b20eb 100644 --- a/packages/uni-mp-alipay/dist/index.js +++ b/packages/uni-mp-alipay/dist/index.js @@ -361,9 +361,14 @@ const protocols = { // 需要做转换的 API 列表 previewImage: { args (fromArgs) { // 支付宝小程序的 current 是索引值,而非图片地址。 - if (fromArgs.current && Array.isArray(fromArgs.urls)) { - const index = fromArgs.urls.indexOf(fromArgs.current); - fromArgs.current = ~index ? index : 0; + const currentIndex = Number(fromArgs.current); + if (isNaN(currentIndex)) { + if (fromArgs.current && Array.isArray(fromArgs.urls)) { + const index = fromArgs.urls.indexOf(fromArgs.current); + fromArgs.current = ~index ? index : 0; + } + } else { + fromArgs.current = currentIndex; } return { indicator: false, diff --git a/packages/uni-mp-alipay/package.json b/packages/uni-mp-alipay/package.json index 4ec8aa306..17d4cfa93 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": "0.0.802", + "version": "0.0.803", "description": "uni-app mp-alipay", "main": "dist/index.js", "scripts": { diff --git a/packages/uni-mp-baidu/dist/index.js b/packages/uni-mp-baidu/dist/index.js index e144b8358..db93ea193 100644 --- a/packages/uni-mp-baidu/dist/index.js +++ b/packages/uni-mp-baidu/dist/index.js @@ -144,6 +144,34 @@ 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]; + } +} + // 不支持的 API 列表 const todos = [ 'hideKeyboard', @@ -205,9 +233,12 @@ const protocols = { } }, previewImage: { - args: { - indicator: false, - loop: false + args (fromArgs) { + normalize(fromArgs); + return { + indicator: false, + loop: false + } } }, getRecorderManager: { diff --git a/packages/uni-mp-baidu/package.json b/packages/uni-mp-baidu/package.json index 99be9a84b..aada5ec90 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.828", + "version": "0.0.829", "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 833c081be..d56308da3 100644 --- a/packages/uni-mp-toutiao/dist/index.js +++ b/packages/uni-mp-toutiao/dist/index.js @@ -144,6 +144,34 @@ 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]; + } +} + // 不支持的 API 列表 const todos = [ 'hideKeyboard', @@ -238,9 +266,12 @@ const protocols = { } }, previewImage: { - args: { - indicator: false, - loop: false + args (fromArgs) { + normalize(fromArgs); + return { + indicator: false, + loop: false + } } }, connectSocket: { diff --git a/packages/uni-mp-toutiao/package.json b/packages/uni-mp-toutiao/package.json index 6f9e57995..6a934b8a5 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.326", + "version": "0.0.327", "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 f8c8ce162..63da3c6ff 100644 --- a/packages/uni-mp-weixin/dist/index.js +++ b/packages/uni-mp-weixin/dist/index.js @@ -144,8 +144,40 @@ function upx2px (number, newDeviceWidth) { return number < 0 ? -result : result } -const protocols = {}; -const todos = []; +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]; + } +} + +const protocols = { + previewImage: { + args: normalize + } +}; +const todos = []; const canIUses = []; const CALLBACKS = ['success', 'fail', 'cancel', 'complete']; diff --git a/packages/uni-mp-weixin/package.json b/packages/uni-mp-weixin/package.json index 921ee8113..c574a5ab7 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.950", + "version": "0.0.951", "description": "uni-app mp-weixin", "main": "dist/index.js", "scripts": { -- GitLab