Skip to content

Commit

Permalink
fix(taro): 小程序端 api 传参丢失参数,close #420
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Oct 22, 2018
1 parent 24cdfff commit 69ed1cb
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 7 deletions.
12 changes: 9 additions & 3 deletions packages/taro-alipay/src/native-api.js
Expand Up @@ -239,13 +239,16 @@ function processApis (taro) {
const weApis = Object.assign({ }, onAndSyncApis, noPromiseApis, otherApis)
Object.keys(weApis).forEach(key => {
if (!onAndSyncApis[key] && !noPromiseApis[key]) {
taro[key] = options => {
taro[key] = (options, ...args) => {
const result = generateSpecialApis(key, options || {})
key = result.api
options = result.options
let task = null
let obj = Object.assign({}, options)
if (typeof options === 'string') {
if (args.length) {
return my[key](options, ...args)
}
return my[key](options)
}
const p = new Promise((resolve, reject) => {
Expand All @@ -272,8 +275,11 @@ function processApis (taro) {
}
}
})

task = my[key](obj)
if (args.length) {
task = my[key](obj, ...args)
} else {
task = my[key](obj)
}
})
if (key === 'uploadFile' || key === 'downloadFile') {
p.progress = cb => {
Expand Down
11 changes: 9 additions & 2 deletions packages/taro-swan/src/native-api.js
Expand Up @@ -66,7 +66,7 @@ function processApis (taro) {
const weApis = Object.assign({ }, onAndSyncApis, noPromiseApis, otherApis)
Object.keys(weApis).forEach(key => {
if (!onAndSyncApis[key] && !noPromiseApis[key]) {
taro[key] = options => {
taro[key] = (options, ...args) => {
options = options || {}
if (key === 'connectSocket') {
if (options['protocols']) {
Expand All @@ -76,6 +76,9 @@ function processApis (taro) {
let task = null
let obj = Object.assign({}, options)
if (typeof options === 'string') {
if (args.length) {
return swan[key](options, ...args)
}
return swan[key](options)
}
const p = new Promise((resolve, reject) => {
Expand All @@ -94,7 +97,11 @@ function processApis (taro) {
}
}
})
task = swan[key](obj)
if (args.length) {
task = swan[key](obj, ...args)
} else {
task = swan[key](obj)
}
})
if (key === 'uploadFile' || key === 'downloadFile') {
p.progress = cb => {
Expand Down
11 changes: 9 additions & 2 deletions packages/taro-weapp/src/native-api.js
Expand Up @@ -75,11 +75,14 @@ function processApis (taro) {
const preloadInitedComponent = '$preloadComponent'
Object.keys(weApis).forEach(key => {
if (!onAndSyncApis[key] && !noPromiseApis[key]) {
taro[key] = options => {
taro[key] = (options, ...args) => {
options = options || {}
let task = null
let obj = Object.assign({}, options)
if (typeof options === 'string') {
if (args.length) {
return wx[key](options, ...args)
}
return wx[key](options)
}

Expand Down Expand Up @@ -121,7 +124,11 @@ function processApis (taro) {
}
}
})
task = wx[key](obj)
if (args.length) {
task = wx[key](obj, ...args)
} else {
task = wx[key](obj)
}
})
if (key === 'uploadFile' || key === 'downloadFile') {
p.progress = cb => {
Expand Down

0 comments on commit 69ed1cb

Please sign in to comment.