diff --git a/packages/uni-mp-alipay/dist/index.js b/packages/uni-mp-alipay/dist/index.js index 8a2f32ea447468107a2034d487184fdc7f0afb7d..b1318cefd1a9e7559bf13efed2a9ec28b7798f1a 100644 --- a/packages/uni-mp-alipay/dist/index.js +++ b/packages/uni-mp-alipay/dist/index.js @@ -1,55 +1,55 @@ -import Vue from 'vue'; - -function b64DecodeUnicode (str) { - return decodeURIComponent(atob(str).split('').map(function (c) { - return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2) - }).join('')) -} - -function getCurrentUserInfo () { - const token = ( my).getStorageSync('uni_id_token') || ''; - const tokenArr = token.split('.'); - if (!token || tokenArr.length !== 3) { - return { - uid: null, - role: [], - permission: [], - tokenExpired: 0 - } - } - let userInfo; - try { - userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1])); - } catch (error) { - throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message) - } - userInfo.tokenExpired = userInfo.exp * 1000; - delete userInfo.exp; - delete userInfo.iat; - return userInfo -} - -function uniIdMixin (Vue) { - Vue.prototype.uniIDHasRole = function (roleId) { - const { - role - } = getCurrentUserInfo(); - return role.indexOf(roleId) > -1 - }; - Vue.prototype.uniIDHasPermission = function (permissionId) { - const { - permission - } = getCurrentUserInfo(); - return this.uniIDHasRole('admin') || permission.indexOf(permissionId) > -1 - }; - Vue.prototype.uniIDTokenValid = function () { - const { - tokenExpired - } = getCurrentUserInfo(); - return tokenExpired > Date.now() - }; -} - +import Vue from 'vue'; + +function b64DecodeUnicode (str) { + return decodeURIComponent(atob(str).split('').map(function (c) { + return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2) + }).join('')) +} + +function getCurrentUserInfo () { + const token = ( my).getStorageSync('uni_id_token') || ''; + const tokenArr = token.split('.'); + if (!token || tokenArr.length !== 3) { + return { + uid: null, + role: [], + permission: [], + tokenExpired: 0 + } + } + let userInfo; + try { + userInfo = JSON.parse(b64DecodeUnicode(tokenArr[1])); + } catch (error) { + throw new Error('获取当前用户信息出错,详细错误信息为:' + error.message) + } + userInfo.tokenExpired = userInfo.exp * 1000; + delete userInfo.exp; + delete userInfo.iat; + return userInfo +} + +function uniIdMixin (Vue) { + Vue.prototype.uniIDHasRole = function (roleId) { + const { + role + } = getCurrentUserInfo(); + return role.indexOf(roleId) > -1 + }; + Vue.prototype.uniIDHasPermission = function (permissionId) { + const { + permission + } = getCurrentUserInfo(); + return this.uniIDHasRole('admin') || permission.indexOf(permissionId) > -1 + }; + Vue.prototype.uniIDTokenValid = function () { + const { + tokenExpired + } = getCurrentUserInfo(); + return tokenExpired > Date.now() + }; +} + const _toString = Object.prototype.toString; const hasOwnProperty = Object.prototype.hasOwnProperty; @@ -88,8 +88,8 @@ function cached (fn) { const camelizeRE = /-(\w)/g; const camelize = cached((str) => { return str.replace(camelizeRE, (_, c) => c ? c.toUpperCase() : '') -}); - +}); + const HOOKS = [ 'invoke', 'success', @@ -240,15 +240,15 @@ function getApiInterceptorHooks (method) { if (hook !== 'returnValue') { interceptor[hook] = globalInterceptors[hook].slice(); } - }); - const scopedInterceptor = scopedInterceptors[method]; - if (scopedInterceptor) { - Object.keys(scopedInterceptor).forEach(hook => { - if (hook !== 'returnValue') { - interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook]); - } - }); - } + }); + const scopedInterceptor = scopedInterceptors[method]; + if (scopedInterceptor) { + Object.keys(scopedInterceptor).forEach(hook => { + if (hook !== 'returnValue') { + interceptor[hook] = (interceptor[hook] || []).concat(scopedInterceptor[hook]); + } + }); + } return interceptor } @@ -278,8 +278,8 @@ const promiseInterceptor = { return res[0] }) } -}; - +}; + const SYNC_API_RE = /^\$|Window$|WindowStyle$|sendNativeEvent|restoreGlobal|getCurrentSubNVue|getMenuButtonBoundingClientRect|^report|interceptors|Interceptor$|getSubNVueById|requireNativePlugin|upx2px|hideKeyboard|canIUse|^create|Sync$|Manager$|base64ToArrayBuffer|arrayBufferToBase64/; @@ -350,8 +350,8 @@ function promisify (name, api) { }), ...params); }))) } -} - +} + const EPS = 1e-4; const BASE_DEVICE_WIDTH = 750; let isIOS = false; @@ -392,20 +392,20 @@ function upx2px (number, newDeviceWidth) { } } return number < 0 ? -result : result -} - +} + const interceptors = { promiseInterceptor -}; - -var baseApi = /*#__PURE__*/Object.freeze({ - __proto__: null, - upx2px: upx2px, - addInterceptor: addInterceptor, - removeInterceptor: removeInterceptor, - interceptors: interceptors -}); - +}; + +var baseApi = /*#__PURE__*/Object.freeze({ + __proto__: null, + upx2px: upx2px, + addInterceptor: addInterceptor, + removeInterceptor: removeInterceptor, + interceptors: interceptors +}); + class EventChannel { constructor (id, events) { this.id = id; @@ -472,8 +472,8 @@ class EventChannel { type }); } -} - +} + const eventChannels = {}; const eventChannelStack = []; @@ -509,8 +509,8 @@ var navigateTo = { returnValue (fromRes, toRes) { fromRes.eventChannel = getEventChannel(); } -}; - +}; + function findExistsPageIndex (url) { const pages = getCurrentPages(); let len = pages.length; @@ -521,8 +521,8 @@ function findExistsPageIndex (url) { } } return -1 -} - +} + var redirectTo = { name (fromArgs) { if (fromArgs.exists === 'back' && fromArgs.delta) { @@ -541,69 +541,69 @@ var redirectTo = { } } } -}; - -function setStorageSync (key, data) { - return my.setStorageSync({ - key, - data - }) -} -function getStorageSync (key) { - const result = my.getStorageSync({ - key - }); - // 支付宝平台会返回一个 success 值,但是目前测试的结果这个始终是 true。当没有存储数据的时候,其它平台会返回空字符串。 - return result.data !== null ? result.data : '' -} -function removeStorageSync (key) { - return my.removeStorageSync({ - key - }) -} - -const UUID_KEY = '__DC_STAT_UUID'; -let deviceId; -function addUuid (result) { - deviceId = deviceId || getStorageSync(UUID_KEY); - if (!deviceId) { - deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7); - my.setStorage({ - key: UUID_KEY, - data: deviceId - }); - } - result.deviceId = deviceId; -} - -function addSafeAreaInsets (result) { - if (result.safeArea) { - const safeArea = result.safeArea; - result.safeAreaInsets = { - top: safeArea.top, - left: safeArea.left, - right: result.windowWidth - safeArea.right, - bottom: result.windowHeight - safeArea.bottom - }; - } -} - -function normalizePlatform (result) { - let platform = result.platform ? result.platform.toLowerCase() : 'devtools'; - if (!~['android', 'ios'].indexOf(platform)) { - platform = 'devtools'; - } - result.platform = platform; -} - -var getSystemInfo = { - returnValue: function (result) { - addUuid(result); - addSafeAreaInsets(result); - normalizePlatform(result); - } -}; - +}; + +function setStorageSync (key, data) { + return my.setStorageSync({ + key, + data + }) +} +function getStorageSync (key) { + const result = my.getStorageSync({ + key + }); + // 支付宝平台会返回一个 success 值,但是目前测试的结果这个始终是 true。当没有存储数据的时候,其它平台会返回空字符串。 + return result.data !== null ? result.data : '' +} +function removeStorageSync (key) { + return my.removeStorageSync({ + key + }) +} + +const UUID_KEY = '__DC_STAT_UUID'; +let deviceId; +function addUuid (result) { + deviceId = deviceId || getStorageSync(UUID_KEY); + if (!deviceId) { + deviceId = Date.now() + '' + Math.floor(Math.random() * 1e7); + my.setStorage({ + key: UUID_KEY, + data: deviceId + }); + } + result.deviceId = deviceId; +} + +function addSafeAreaInsets (result) { + if (result.safeArea) { + const safeArea = result.safeArea; + result.safeAreaInsets = { + top: safeArea.top, + left: safeArea.left, + right: result.windowWidth - safeArea.right, + bottom: result.windowHeight - safeArea.bottom + }; + } +} + +function normalizePlatform (result) { + let platform = result.platform ? result.platform.toLowerCase() : 'devtools'; + if (!~['android', 'ios'].indexOf(platform)) { + platform = 'devtools'; + } + result.platform = platform; +} + +var getSystemInfo = { + returnValue: function (result) { + addUuid(result); + addSafeAreaInsets(result); + normalizePlatform(result); + } +}; + // 不支持的 API 列表 const todos = [ 'preloadPage', @@ -850,8 +850,17 @@ const protocols = { // 需要做转换的 API 列表 // TODO 有没有返回值还需要测试下 }, chooseImage: { - returnValue: { - apFilePaths: 'tempFilePaths' + returnValue (result) { + const hasTempFilePaths = hasOwn(result,'tempFilePaths') && result.tempFilePaths + if (hasOwn(result,'apFilePaths') && !hasTempFilePaths) { + result.tempFilePaths = result.apFilePaths + delete result.apFilePaths + } + if (!hasOwn(result,'tempFiles') && hasTempFilePaths) { + result.tempFiles = [] + result.tempFilePaths.forEach(tempFilePath => result.tempFiles.push({path: tempFilePath})) + } + return {} } }, previewImage: { @@ -1079,8 +1088,8 @@ const protocols = { // 需要做转换的 API 列表 result.errMsg = result.resultStatus; } } -}; - +}; + const CALLBACKS = ['success', 'fail', 'cancel', 'complete']; function processCallback (methodName, method, returnValue) { @@ -1165,8 +1174,8 @@ function wrapper (methodName, method) { } } return method -} - +} + const todoApis = Object.create(null); const TODOS = [ @@ -1193,15 +1202,15 @@ function createTodoApi (name) { TODOS.forEach(function (name) { todoApis[name] = createTodoApi(name); -}); - +}); + var providers = { oauth: ['alipay'], share: ['alipay'], payment: ['alipay'], push: ['alipay'] -}; - +}; + function getProvider ({ service, success, @@ -1223,18 +1232,18 @@ function getProvider ({ isFn(fail) && fail(res); } isFn(complete) && complete(res); -} - -var extraApi = /*#__PURE__*/Object.freeze({ - __proto__: null, - getProvider: getProvider -}); - +} + +var extraApi = /*#__PURE__*/Object.freeze({ + __proto__: null, + getProvider: getProvider +}); + const getEmitter = (function () { let Emitter; - return function getUniEmitter () { - if (!Emitter) { - Emitter = new Vue(); + return function getUniEmitter () { + if (!Emitter) { + Emitter = new Vue(); } return Emitter } @@ -1255,202 +1264,202 @@ function $once () { } function $emit () { return apply(getEmitter(), '$emit', [...arguments]) -} - -var eventApi = /*#__PURE__*/Object.freeze({ - __proto__: null, - $on: $on, - $off: $off, - $once: $once, - $emit: $emit -}); - -function createMediaQueryObserver () { - const mediaQueryObserver = {}; - const { - windowWidth, - windowHeight - } = my.getSystemInfoSync(); - - const orientation = windowWidth < windowHeight ? 'portrait' : 'landscape'; - - mediaQueryObserver.observe = (options, callback) => { - let matches = true; - for (const item in options) { - const itemValue = item === 'orientation' ? options[item] : Number(options[item]); - if (options[item] !== '') { - if (item === 'width') { - if (itemValue === windowWidth) { - matches = true; - } else { - matches = false; - callback(matches); - return matches - } - } - if (item === 'minWidth') { - if (windowWidth >= itemValue) { - matches = true; - } else { - matches = false; - callback(matches); - return matches - } - } - if (item === 'maxWidth') { - if (windowWidth <= itemValue) { - matches = true; - } else { - matches = false; - callback(matches); - return matches - } - } - - if (item === 'height') { - if (itemValue === windowHeight) { - matches = true; - } else { - matches = false; - callback(matches); - return matches - } - } - if (item === 'minHeight') { - if (windowHeight >= itemValue) { - matches = true; - } else { - matches = false; - callback(matches); - return matches - } - } - if (item === 'maxHeight') { - if (windowHeight <= itemValue) { - matches = true; - } else { - matches = false; - callback(matches); - return matches - } - } - - if (item === 'orientation') { - if (options[item] === orientation) { - matches = true; - } else { - matches = false; - callback(matches); - return matches - } - } - } - } - callback(matches); - - return matches - }; - - mediaQueryObserver.disconnect = () => { - }; - - return mediaQueryObserver -} - -function startGyroscope (params) { - if (hasOwn(params, 'interval')) { - console.warn('支付宝小程序 startGyroscope暂不支持interval'); - } - params.success && params.success({ - errMsg: 'startGyroscope:ok' - }); - params.complete && params.complete({ - errMsg: 'startGyroscope:ok' - }); -} - -function createExecCallback (execCallback) { - return function wrapperExecCallback (res) { - this.actions.forEach((action, index) => { - (action._$callbacks || []).forEach(callback => { - callback(res[index]); - }); - }); - if (isFn(execCallback)) { - execCallback(res); - } - } -} - -function addCallback (callback) { - if (isFn(callback)) { - const action = this.actions[this.actions.length - 1]; - if (action) { - (action._$callbacks || (action._$callbacks = [])).push(callback); - } - } -} - -function createSelectorQuery () { - const query = my.createSelectorQuery(); - - const oldExec = query.exec; - const oldScrollOffset = query.scrollOffset; - const oldBoundingClientRect = query.boundingClientRect; - query.exec = function exec (callback) { - return oldExec.call(this, createExecCallback(callback).bind(this)) - }; - query.scrollOffset = function scrollOffset (callback) { - const ret = oldScrollOffset.call(this); - addCallback.call(this, callback); - return ret - }; - query.boundingClientRect = function boundingClientRect (callback) { - const ret = oldBoundingClientRect.call(this); - addCallback.call(this, callback); - return ret - }; - - if (!query.fields) { - query.fields = function ({ rect, size, scrollOffset } = {}, callback) { - if (rect || size) { - this.boundingClientRect(); - } - if (scrollOffset) { - this.scrollOffset(); - } - addCallback.call(this, callback); - return this - }; - } - - if (!query.in) { - query.in = function () { - return this - }; - } - return query -} - -function createIntersectionObserver (component, options) { - if (options && options.observeAll) { - options.selectAll = options.observeAll; - delete options.observeAll; - } - return my.createIntersectionObserver(options) -} - -var api = /*#__PURE__*/Object.freeze({ - __proto__: null, - startGyroscope: startGyroscope, - createSelectorQuery: createSelectorQuery, - createIntersectionObserver: createIntersectionObserver, - createMediaQueryObserver: createMediaQueryObserver, - setStorageSync: setStorageSync, - getStorageSync: getStorageSync, - removeStorageSync: removeStorageSync -}); - +} + +var eventApi = /*#__PURE__*/Object.freeze({ + __proto__: null, + $on: $on, + $off: $off, + $once: $once, + $emit: $emit +}); + +function createMediaQueryObserver () { + const mediaQueryObserver = {}; + const { + windowWidth, + windowHeight + } = my.getSystemInfoSync(); + + const orientation = windowWidth < windowHeight ? 'portrait' : 'landscape'; + + mediaQueryObserver.observe = (options, callback) => { + let matches = true; + for (const item in options) { + const itemValue = item === 'orientation' ? options[item] : Number(options[item]); + if (options[item] !== '') { + if (item === 'width') { + if (itemValue === windowWidth) { + matches = true; + } else { + matches = false; + callback(matches); + return matches + } + } + if (item === 'minWidth') { + if (windowWidth >= itemValue) { + matches = true; + } else { + matches = false; + callback(matches); + return matches + } + } + if (item === 'maxWidth') { + if (windowWidth <= itemValue) { + matches = true; + } else { + matches = false; + callback(matches); + return matches + } + } + + if (item === 'height') { + if (itemValue === windowHeight) { + matches = true; + } else { + matches = false; + callback(matches); + return matches + } + } + if (item === 'minHeight') { + if (windowHeight >= itemValue) { + matches = true; + } else { + matches = false; + callback(matches); + return matches + } + } + if (item === 'maxHeight') { + if (windowHeight <= itemValue) { + matches = true; + } else { + matches = false; + callback(matches); + return matches + } + } + + if (item === 'orientation') { + if (options[item] === orientation) { + matches = true; + } else { + matches = false; + callback(matches); + return matches + } + } + } + } + callback(matches); + + return matches + }; + + mediaQueryObserver.disconnect = () => { + }; + + return mediaQueryObserver +} + +function startGyroscope (params) { + if (hasOwn(params, 'interval')) { + console.warn('支付宝小程序 startGyroscope暂不支持interval'); + } + params.success && params.success({ + errMsg: 'startGyroscope:ok' + }); + params.complete && params.complete({ + errMsg: 'startGyroscope:ok' + }); +} + +function createExecCallback (execCallback) { + return function wrapperExecCallback (res) { + this.actions.forEach((action, index) => { + (action._$callbacks || []).forEach(callback => { + callback(res[index]); + }); + }); + if (isFn(execCallback)) { + execCallback(res); + } + } +} + +function addCallback (callback) { + if (isFn(callback)) { + const action = this.actions[this.actions.length - 1]; + if (action) { + (action._$callbacks || (action._$callbacks = [])).push(callback); + } + } +} + +function createSelectorQuery () { + const query = my.createSelectorQuery(); + + const oldExec = query.exec; + const oldScrollOffset = query.scrollOffset; + const oldBoundingClientRect = query.boundingClientRect; + query.exec = function exec (callback) { + return oldExec.call(this, createExecCallback(callback).bind(this)) + }; + query.scrollOffset = function scrollOffset (callback) { + const ret = oldScrollOffset.call(this); + addCallback.call(this, callback); + return ret + }; + query.boundingClientRect = function boundingClientRect (callback) { + const ret = oldBoundingClientRect.call(this); + addCallback.call(this, callback); + return ret + }; + + if (!query.fields) { + query.fields = function ({ rect, size, scrollOffset } = {}, callback) { + if (rect || size) { + this.boundingClientRect(); + } + if (scrollOffset) { + this.scrollOffset(); + } + addCallback.call(this, callback); + return this + }; + } + + if (!query.in) { + query.in = function () { + return this + }; + } + return query +} + +function createIntersectionObserver (component, options) { + if (options && options.observeAll) { + options.selectAll = options.observeAll; + delete options.observeAll; + } + return my.createIntersectionObserver(options) +} + +var api = /*#__PURE__*/Object.freeze({ + __proto__: null, + startGyroscope: startGyroscope, + createSelectorQuery: createSelectorQuery, + createIntersectionObserver: createIntersectionObserver, + createMediaQueryObserver: createMediaQueryObserver, + setStorageSync: setStorageSync, + getStorageSync: getStorageSync, + removeStorageSync: removeStorageSync +}); + const PAGE_EVENT_HOOKS = [ 'onPullDownRefresh', 'onReachBottom', @@ -1966,8 +1975,8 @@ function handleEvent (event) { ) { return ret[0] } -} - +} + const hooks = [ 'onShow', 'onHide', @@ -2127,8 +2136,8 @@ function parseBaseApp (vm, { initHooks(appOptions, hooks); return appOptions -} - +} + function findVmByVueId (vm, vuePid) { const $children = vm.$children; // 优先查找直属(反向查找:https://github.com/dcloudio/uni-app/issues/1200) @@ -2165,8 +2174,8 @@ function handleLink (event) { } vueOptions.parent = parentVm; -} - +} + const isArray = Array.isArray; const keyList = Object.keys; @@ -2214,8 +2223,8 @@ function equal (a, b) { } return false -} - +} + const customizeRE = /:/g; const customize = cached((str) => { @@ -2409,8 +2418,8 @@ const handleLink$1 = (function () { // 支付宝通过 didMount 来实现,先子后父,故等父 ready 之后,统一初始化 (this._$childVues || (this._$childVues = [])).unshift(detail); } -})(); - +})(); + function parseApp (vm) { Object.defineProperty(Vue.prototype, '$slots', { get () { @@ -2460,13 +2469,13 @@ function parseApp (vm) { mocks, initRefs }) -} - +} + function createApp (vm) { App(parseApp(vm)); return vm -} - +} + const encodeReserveRE = /[!'()*]/g; const encodeReserveReplacer = c => '%' + c.charCodeAt(0).toString(16); const commaRE = /%2C/g; @@ -2508,8 +2517,8 @@ function stringifyQuery (obj, encodeStr = encode) { return encodeStr(key) + '=' + encodeStr(val) }).filter(x => x.length > 0).join('&') : null; return res ? `?${res}` : '' -} - +} + const hooks$1 = [ 'onShow', 'onHide', @@ -2589,14 +2598,14 @@ function parsePage (vuePageOptions) { } return pageOptions -} - +} + function createPage (vuePageOptions) { { return Page(parsePage(vuePageOptions)) } -} - +} + function initVm (VueComponent) { if (this.$vm) { return @@ -2702,25 +2711,25 @@ function parseComponent (vueComponentOptions) { componentOptions.deriveDataFromProps = createObserver$1(); } else { componentOptions.didUpdate = createObserver$1(true); - } - - if (Array.isArray(vueOptions.wxsCallMethods)) { - vueOptions.wxsCallMethods.forEach(callMethod => { - componentOptions.methods[callMethod] = function (args) { - return this.$vm[callMethod](args) - }; - }); + } + + if (Array.isArray(vueOptions.wxsCallMethods)) { + vueOptions.wxsCallMethods.forEach(callMethod => { + componentOptions.methods[callMethod] = function (args) { + return this.$vm[callMethod](args) + }; + }); } return componentOptions -} - +} + function createComponent (vueOptions) { { return my.defineComponent(parseComponent(vueOptions)) } -} - +} + function createSubpackageApp (vm) { const appOptions = parseApp(vm); const app = getApp({ @@ -2755,27 +2764,27 @@ function createSubpackageApp (vm) { vm.__call_hook('onLaunch', args); } return vm -} - -function createPlugin (vm) { - const appOptions = parseApp(vm); - if (isFn(appOptions.onShow) && my.onAppShow) { - my.onAppShow((...args) => { - appOptions.onShow.apply(vm, args); - }); - } - if (isFn(appOptions.onHide) && my.onAppHide) { - my.onAppHide((...args) => { - appOptions.onHide.apply(vm, args); - }); - } - if (isFn(appOptions.onLaunch)) { - const args = my.getLaunchOptionsSync && my.getLaunchOptionsSync(); - appOptions.onLaunch.call(vm, args); - } - return vm -} - +} + +function createPlugin (vm) { + const appOptions = parseApp(vm); + if (isFn(appOptions.onShow) && my.onAppShow) { + my.onAppShow((...args) => { + appOptions.onShow.apply(vm, args); + }); + } + if (isFn(appOptions.onHide) && my.onAppHide) { + my.onAppHide((...args) => { + appOptions.onHide.apply(vm, args); + }); + } + if (isFn(appOptions.onLaunch)) { + const args = my.getLaunchOptionsSync && my.getLaunchOptionsSync(); + appOptions.onLaunch.call(vm, args); + } + return vm +} + todos.forEach(todoApi => { protocols[todoApi] = false; }); @@ -2858,7 +2867,7 @@ my.createComponent = createComponent; my.createSubpackageApp = createSubpackageApp; my.createPlugin = createPlugin; -var uni$1 = uni; - -export default uni$1; -export { createApp, createComponent, createPage, createPlugin, createSubpackageApp }; +var uni$1 = uni; + +export default uni$1; +export { createApp, createComponent, createPage, createPlugin, createSubpackageApp }; diff --git a/src/platforms/mp-alipay/runtime/api/protocols.js b/src/platforms/mp-alipay/runtime/api/protocols.js index 658459e0bcd525f7826758e672c437eabb481484..f9584e89dfd69b8eb0c0a7c90e01f157ae277e4a 100644 --- a/src/platforms/mp-alipay/runtime/api/protocols.js +++ b/src/platforms/mp-alipay/runtime/api/protocols.js @@ -1,5 +1,6 @@ import { - isPlainObject + isPlainObject, + hasOwn } from 'uni-shared' import navigateTo from 'uni-helpers/navigate-to' import redirectTo from '../../../mp-weixin/helpers/redirect-to' @@ -251,8 +252,17 @@ const protocols = { // 需要做转换的 API 列表 // TODO 有没有返回值还需要测试下 }, chooseImage: { - returnValue: { - apFilePaths: 'tempFilePaths' + returnValue (result) { + const hasTempFilePaths = hasOwn(result,'tempFilePaths') && result.tempFilePaths + if (hasOwn(result,'apFilePaths') && !hasTempFilePaths) { + result.tempFilePaths = result.apFilePaths + delete result.apFilePaths + } + if (!hasOwn(result,'tempFiles') && hasTempFilePaths) { + result.tempFiles = [] + result.tempFilePaths.forEach(tempFilePath => result.tempFiles.push({path: tempFilePath})) + } + return {} } }, previewImage: {