Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
touchx
uni-app
提交
b4deeaa4
U
uni-app
项目概览
touchx
/
uni-app
与 Fork 源项目一致
Fork自
DCloud / uni-app
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
U
uni-app
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
b4deeaa4
编写于
12月 10, 2018
作者:
fxy060608
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add mp-alipay api wrapper
上级
5fafe127
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
605 addition
and
41 deletion
+605
-41
build/rollup.config.js
build/rollup.config.js
+17
-5
package.json
package.json
+5
-4
packages/uni-mp-alipay/dist/index.js
packages/uni-mp-alipay/dist/index.js
+195
-10
packages/uni-mp-baidu/dist/index.js
packages/uni-mp-baidu/dist/index.js
+90
-6
packages/uni-mp-weixin/dist/index.js
packages/uni-mp-weixin/dist/index.js
+90
-6
src/core/helpers/promise.js
src/core/helpers/promise.js
+1
-1
src/core/runtime/extra.js
src/core/runtime/extra.js
+0
-0
src/core/runtime/index.js
src/core/runtime/index.js
+16
-8
src/core/runtime/wrapper.js
src/core/runtime/wrapper.js
+85
-0
src/platforms/mp-alipay/service/api/protocols.js
src/platforms/mp-alipay/service/api/protocols.js
+98
-0
src/platforms/mp-baidu/service/api/protocols.js
src/platforms/mp-baidu/service/api/protocols.js
+1
-0
src/platforms/mp-weixin/service/api/protocols.js
src/platforms/mp-weixin/service/api/protocols.js
+1
-0
src/shared/util.js
src/shared/util.js
+6
-1
未找到文件。
build/rollup.config.js
浏览文件 @
b4deeaa4
...
@@ -2,11 +2,22 @@ const path = require('path')
...
@@ -2,11 +2,22 @@ const path = require('path')
const
alias
=
require
(
'
rollup-plugin-alias
'
)
const
alias
=
require
(
'
rollup-plugin-alias
'
)
const
replace
=
require
(
'
rollup-plugin-replace
'
)
const
replace
=
require
(
'
rollup-plugin-replace
'
)
const
GLOBAL
=
{
const
PLATFORMS
=
{
'
mp-weixin
'
:
'
wx
'
,
'
mp-weixin
'
:
{
'
mp-alipay
'
:
'
my
'
,
prefix
:
'
wx
'
,
'
mp-baidu
'
:
'
swan
'
title
:
'
微信小程序
'
},
'
mp-alipay
'
:
{
prefix
:
'
my
'
,
title
:
'
支付宝小程序
'
},
'
mp-baidu
'
:
{
prefix
:
'
swan
'
,
title
:
'
百度小程序
'
}
}
}
const
platform
=
PLATFORMS
[
process
.
env
.
UNI_PLATFORM
]
module
.
exports
=
{
module
.
exports
=
{
input
:
'
src/core/runtime/index.js
'
,
input
:
'
src/core/runtime/index.js
'
,
output
:
{
output
:
{
...
@@ -19,7 +30,8 @@ module.exports = {
...
@@ -19,7 +30,8 @@ module.exports = {
'
uni-platform
'
:
path
.
resolve
(
__dirname
,
'
../src/platforms/
'
+
process
.
env
.
UNI_PLATFORM
)
'
uni-platform
'
:
path
.
resolve
(
__dirname
,
'
../src/platforms/
'
+
process
.
env
.
UNI_PLATFORM
)
}),
}),
replace
({
replace
({
__GLOBAL__
:
GLOBAL
[
process
.
env
.
UNI_PLATFORM
]
__GLOBAL__
:
platform
.
prefix
,
__PLATFORM_TITLE__
:
platform
.
title
})
})
]
]
}
}
package.json
浏览文件 @
b4deeaa4
...
@@ -5,9 +5,9 @@
...
@@ -5,9 +5,9 @@
"lint"
:
"eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore build src"
,
"lint"
:
"eslint --fix --config package.json --ext .js --ext .vue --ignore-path .eslintignore build src"
,
"dev:h5"
:
"npm run lint && cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.js"
,
"dev:h5"
:
"npm run lint && cross-env NODE_ENV=production UNI_WATCH=true UNI_PLATFORM=h5 node build/build.js"
,
"build:h5"
:
"npm run lint && cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.js"
,
"build:h5"
:
"npm run lint && cross-env NODE_ENV=production UNI_WATCH=false UNI_PLATFORM=h5 node build/build.js"
,
"build:mp-weixin"
:
"npm run lint && cross-env UNI_PLATFORM=mp-weixin rollup -c build/rollup.config.js"
,
"build:mp-weixin"
:
"npm run lint && cross-env UNI_PLATFORM=mp-weixin rollup -c build/rollup.config.js"
,
"build:mp-baidu"
:
"npm run lint && cross-env UNI_PLATFORM=mp-baidu rollup -c build/rollup.config.js"
,
"build:mp-baidu"
:
"npm run lint && cross-env UNI_PLATFORM=mp-baidu rollup -c build/rollup.config.js"
,
"build:mp-alipay"
:
"npm run lint && cross-env UNI_PLATFORM=mp-alipay rollup -c build/rollup.config.js"
,
"build:mp-alipay"
:
"npm run lint && cross-env UNI_PLATFORM=mp-alipay rollup -c build/rollup.config.js"
,
"test:unit"
:
"cross-env NODE_ENV=test UNI_PLATFORM=h5 mocha-webpack --require tests/unit/setup.js --webpack-config build/webpack.config.test.js tests/unit/**/*.spec.js"
"test:unit"
:
"cross-env NODE_ENV=test UNI_PLATFORM=h5 mocha-webpack --require tests/unit/setup.js --webpack-config build/webpack.config.test.js tests/unit/**/*.spec.js"
},
},
"dependencies"
:
{},
"dependencies"
:
{},
...
@@ -64,7 +64,8 @@
...
@@ -64,7 +64,8 @@
"UniServiceJSBridge"
:
true
,
"UniServiceJSBridge"
:
true
,
"__PLATFORM__"
:
true
,
"__PLATFORM__"
:
true
,
"__VERSION__"
:
true
,
"__VERSION__"
:
true
,
"__GLOBAL__"
:
true
"__GLOBAL__"
:
true
,
"__PLATFORM_TITLE__"
:
true
},
},
"rules"
:
{
"rules"
:
{
"no-tabs"
:
0
,
"no-tabs"
:
0
,
...
...
packages/uni-mp-alipay/dist/index.js
浏览文件 @
b4deeaa4
const
_toString
=
Object
.
prototype
.
toString
;
const
hasOwnProperty
=
Object
.
prototype
.
hasOwnProperty
;
function
isFn
(
fn
)
{
function
isFn
(
fn
)
{
return
typeof
fn
===
'
function
'
return
typeof
fn
===
'
function
'
}
function
isStr
(
str
)
{
return
typeof
str
===
'
string
'
}
function
isPlainObject
(
obj
)
{
return
_toString
.
call
(
obj
)
===
'
[object Object]
'
}
function
hasOwn
(
obj
,
key
)
{
return
hasOwnProperty
.
call
(
obj
,
key
)
}
}
const
SYNC_API_RE
=
/hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/
;
const
SYNC_API_RE
=
/hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/
;
...
@@ -97,9 +112,179 @@ function upx2px (number, newDeviceWidth) {
...
@@ -97,9 +112,179 @@ function upx2px (number, newDeviceWidth) {
return
number
return
number
}
}
const
TODOS
=
[
'
hideTabBar
'
,
'
hideTabBarRedDot
'
,
'
removeTabBarBadge
'
,
'
setTabBarBadge
'
,
'
setTabBarItem
'
,
'
setTabBarStyle
'
,
'
showTabBar
'
,
'
showTabBarRedDot
'
];
const
protocols
=
{
returnValue
(
methodName
,
res
)
{
// 通用 returnValue 解析
if
(
res
.
error
||
res
.
errorMessage
)
{
res
.
errMsg
=
`
${
methodName
}
:fail
${
res
.
errorMessage
||
res
.
error
}
`
;
delete
res
.
error
;
delete
res
.
errorMessage
;
}
return
res
},
setNavigationBarColor
:
{
name
:
'
setNavigationBar
'
,
args
:
{
frontColor
:
false
,
animation
:
false
}
},
setNavigationBarTitle
:
{
name
:
'
setNavigationBar
'
},
showModal
({
showCancel
=
true
}
=
{})
{
if
(
showCancel
)
{
return
{
name
:
'
confirm
'
,
args
:
{
cancelColor
:
false
,
confirmColor
:
false
,
cancelText
:
'
cancelButtonText
'
,
confirmText
:
'
confirmButtonText
'
},
returnValue
(
fromRes
,
toRes
)
{
toRes
.
confirm
=
fromRes
.
confirm
;
toRes
.
cancel
=
!
fromRes
.
confirm
;
}
}
}
return
{
name
:
'
alert
'
,
args
:
{
confirmColor
:
false
,
confirmText
:
'
buttonText
'
},
returnValue
(
fromRes
,
toRes
)
{
toRes
.
confirm
=
true
;
toRes
.
cancel
=
false
;
}
}
},
showToast
({
icon
=
'
success
'
}
=
{})
{
const
args
=
{
title
:
'
content
'
,
icon
:
'
type
'
,
duration
:
false
,
image
:
false
,
mask
:
false
};
if
(
icon
===
'
loading
'
)
{
return
{
name
:
'
showLoading
'
,
args
}
}
return
{
name
:
'
showToast
'
,
args
}
},
showActionSheet
:
{
name
:
'
showActionSheet
'
,
args
:
{
itemList
:
'
items
'
,
itemColor
:
false
},
returnValue
:
{
index
:
'
tapIndex
'
}
}
};
TODOS
.
forEach
(
todoApi
=>
{
protocols
[
todoApi
]
=
false
;
});
const
CALLBACKS
=
[
'
success
'
,
'
fail
'
,
'
cancel
'
,
'
complete
'
];
function
processCallback
(
methodName
,
method
,
returnValue
)
{
return
function
(
res
)
{
return
method
(
processReturnValue
(
methodName
,
res
,
returnValue
))
}
}
function
processArgs
(
methodName
,
fromArgs
,
argsOption
=
{},
returnValue
=
{})
{
if
(
isPlainObject
(
fromArgs
))
{
// 一般 api 的参数解析
const
toArgs
=
{};
if
(
isFn
(
argsOption
))
{
argsOption
=
argsOption
(
fromArgs
,
toArgs
)
||
{};
}
Object
.
keys
(
fromArgs
).
forEach
(
key
=>
{
if
(
hasOwn
(
argsOption
,
key
))
{
let
keyOption
=
argsOption
[
key
];
if
(
isFn
(
keyOption
))
{
keyOption
=
keyOption
(
fromArgs
[
key
],
fromArgs
);
}
if
(
!
keyOption
)
{
// 不支持的参数
console
.
warn
(
`支付宝小程序
${
methodName
}
暂不支持
${
key
}
`
);
}
else
if
(
isStr
(
keyOption
))
{
// 重写参数 key
toArgs
[
keyOption
]
=
fromArgs
[
key
];
}
else
if
(
isPlainObject
(
keyOption
))
{
// {name:newName,value:value}可重新指定参数 key:value
toArgs
[
keyOption
.
name
?
keyOption
.
name
:
key
]
=
keyOption
.
value
;
}
}
else
if
(
CALLBACKS
.
includes
(
key
))
{
toArgs
[
key
]
=
processCallback
(
methodName
,
fromArgs
[
key
],
returnValue
);
}
else
{
toArgs
[
key
]
=
fromArgs
[
key
];
}
});
return
toArgs
}
else
if
(
isFn
(
fromArgs
))
{
fromArgs
=
processCallback
(
methodName
,
fromArgs
,
returnValue
);
}
return
fromArgs
}
function
processReturnValue
(
methodName
,
res
,
returnValue
)
{
if
(
isFn
(
protocols
.
returnValue
))
{
// 处理通用 returnValue
res
=
protocols
.
returnValue
(
methodName
,
res
);
}
return
processArgs
(
methodName
,
res
,
returnValue
)
}
function
wrapper
(
methodName
,
method
)
{
if
(
hasOwn
(
protocols
,
methodName
))
{
const
protocol
=
protocols
[
methodName
];
if
(
!
protocol
)
{
// 暂不支持的 api
return
function
()
{
throw
new
Error
(
`支付宝小程序 暂不支持
${
methodName
}
`
)
}
}
return
function
(
arg1
,
arg2
)
{
// 目前 api 最多两个参数
let
options
=
protocol
;
if
(
isFn
(
protocol
))
{
options
=
protocol
(
arg1
);
}
arg1
=
processArgs
(
methodName
,
arg1
,
options
.
args
,
options
.
returnValue
);
const
returnValue
=
my
[
options
.
name
||
methodName
](
arg1
,
arg2
);
if
(
isSyncApi
(
methodName
))
{
// 同步 api
return
processReturnValue
(
methodName
,
returnValue
,
options
.
returnValue
)
}
return
returnValue
}
}
return
method
}
const
todoApis
=
Object
.
create
(
null
);
const
todoApis
=
Object
.
create
(
null
);
const
TODOS
=
[
const
TODOS
$1
=
[
'
subscribePush
'
,
'
subscribePush
'
,
'
unsubscribePush
'
,
'
unsubscribePush
'
,
'
onPush
'
,
'
onPush
'
,
...
@@ -120,7 +305,7 @@ function createTodoApi (name) {
...
@@ -120,7 +305,7 @@ function createTodoApi (name) {
}
}
}
}
TODOS
.
forEach
(
function
(
name
)
{
TODOS
$1
.
forEach
(
function
(
name
)
{
todoApis
[
name
]
=
createTodoApi
(
name
);
todoApis
[
name
]
=
createTodoApi
(
name
);
});
});
...
@@ -154,7 +339,7 @@ function getProvider ({
...
@@ -154,7 +339,7 @@ function getProvider ({
isFn
(
complete
)
&&
complete
(
res
);
isFn
(
complete
)
&&
complete
(
res
);
}
}
var
base
Api
=
/*#__PURE__*/
Object
.
freeze
({
var
extra
Api
=
/*#__PURE__*/
Object
.
freeze
({
getProvider
:
getProvider
getProvider
:
getProvider
});
});
...
@@ -175,16 +360,16 @@ if (typeof Proxy !== 'undefined') {
...
@@ -175,16 +360,16 @@ if (typeof Proxy !== 'undefined') {
if
(
api
[
name
])
{
if
(
api
[
name
])
{
return
promisify
(
name
,
api
[
name
])
return
promisify
(
name
,
api
[
name
])
}
}
if
(
base
Api
[
name
])
{
if
(
extra
Api
[
name
])
{
return
promisify
(
name
,
base
Api
[
name
])
return
promisify
(
name
,
extra
Api
[
name
])
}
}
if
(
todoApis
[
name
])
{
if
(
todoApis
[
name
])
{
return
promisify
(
name
,
todoApis
[
name
])
return
promisify
(
name
,
todoApis
[
name
])
}
}
if
(
!
my
.
hasOwnProperty
(
name
))
{
if
(
!
hasOwn
(
my
,
name
)
&&
!
hasOwn
(
protocols
,
name
))
{
return
return
}
}
return
promisify
(
name
,
my
[
name
]
)
return
promisify
(
name
,
wrapper
(
name
,
my
[
name
])
)
}
}
});
});
}
else
{
}
else
{
...
@@ -194,7 +379,7 @@ if (typeof Proxy !== 'undefined') {
...
@@ -194,7 +379,7 @@ if (typeof Proxy !== 'undefined') {
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
});
});
Object
.
keys
(
base
Api
).
forEach
(
name
=>
{
Object
.
keys
(
extra
Api
).
forEach
(
name
=>
{
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
});
});
...
@@ -203,8 +388,8 @@ if (typeof Proxy !== 'undefined') {
...
@@ -203,8 +388,8 @@ if (typeof Proxy !== 'undefined') {
});
});
Object
.
keys
(
my
).
forEach
(
name
=>
{
Object
.
keys
(
my
).
forEach
(
name
=>
{
if
(
my
.
hasOwnProperty
(
name
))
{
if
(
hasOwn
(
my
,
name
)
||
hasOwn
(
protocols
,
name
))
{
uni$1
[
name
]
=
promisify
(
name
,
my
[
name
]
);
uni$1
[
name
]
=
promisify
(
name
,
wrapper
(
name
,
my
[
name
])
);
}
}
});
});
}
}
...
...
packages/uni-mp-baidu/dist/index.js
浏览文件 @
b4deeaa4
const
_toString
=
Object
.
prototype
.
toString
;
const
hasOwnProperty
=
Object
.
prototype
.
hasOwnProperty
;
function
isFn
(
fn
)
{
function
isFn
(
fn
)
{
return
typeof
fn
===
'
function
'
return
typeof
fn
===
'
function
'
}
function
isStr
(
str
)
{
return
typeof
str
===
'
string
'
}
function
isPlainObject
(
obj
)
{
return
_toString
.
call
(
obj
)
===
'
[object Object]
'
}
function
hasOwn
(
obj
,
key
)
{
return
hasOwnProperty
.
call
(
obj
,
key
)
}
}
const
SYNC_API_RE
=
/hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/
;
const
SYNC_API_RE
=
/hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/
;
...
@@ -97,6 +112,75 @@ function upx2px (number, newDeviceWidth) {
...
@@ -97,6 +112,75 @@ function upx2px (number, newDeviceWidth) {
return
number
return
number
}
}
var
protocols
=
{};
const
CALLBACKS
=
[
'
success
'
,
'
fail
'
,
'
cancel
'
,
'
complete
'
];
function
processCallback
(
method
,
returnValue
)
{
return
function
(
res
)
{
return
method
(
processReturnValue
(
res
,
returnValue
))
}
}
function
processArgs
(
fromArgs
,
argsOption
=
{},
returnValue
=
{})
{
if
(
isPlainObject
(
fromArgs
))
{
// 一般 api 的参数解析
const
toArgs
=
{};
Object
.
keys
(
fromArgs
).
forEach
(
key
=>
{
if
(
hasOwn
(
argsOption
,
key
))
{
let
keyOption
=
argsOption
[
key
];
if
(
isFn
(
keyOption
))
{
keyOption
=
keyOption
(
fromArgs
[
key
],
fromArgs
);
}
if
(
!
keyOption
)
{
// 不支持的参数
console
.
warn
(
`
${
百度小程序
}
${
name
}
暂不支持
${
key
}
`
);
}
else
if
(
isStr
(
keyOption
))
{
// 重写参数 key
toArgs
[
keyOption
]
=
fromArgs
[
key
];
}
else
if
(
isPlainObject
(
keyOption
))
{
// {name:newName,value:value}可重新指定参数 key:value
toArgs
[
keyOption
.
name
?
keyOption
.
name
:
key
]
=
keyOption
.
value
;
}
}
else
if
(
CALLBACKS
.
includes
(
key
))
{
toArgs
[
key
]
=
processCallback
(
fromArgs
[
key
],
returnValue
);
}
else
{
toArgs
[
key
]
=
fromArgs
[
key
];
}
});
return
toArgs
}
else
if
(
isFn
(
fromArgs
))
{
fromArgs
=
processCallback
(
fromArgs
,
returnValue
);
}
return
fromArgs
}
function
processReturnValue
(
res
,
returnValue
)
{
return
processArgs
(
res
,
returnValue
)
}
function
wrapper
(
name
,
method
)
{
if
(
hasOwn
(
protocols
,
name
))
{
const
protocol
=
protocols
[
name
];
if
(
!
protocol
)
{
// 暂不支持的 api
return
function
()
{
throw
new
Error
(
`
${
百度小程序
}
暂不支持
${
name
}
`
)
}
}
return
function
(
arg1
,
arg2
)
{
// 目前 api 最多两个参数
let
options
=
protocol
;
if
(
isFn
(
protocol
))
{
options
=
protocol
(
arg1
);
}
arg1
=
processArgs
(
arg1
,
options
.
args
,
options
.
returnValue
);
const
returnValue
=
swan
[
options
.
name
||
name
](
arg1
,
arg2
);
if
(
isSyncApi
(
name
))
{
// 同步 api
return
processReturnValue
(
returnValue
,
options
.
returnValue
)
}
return
returnValue
}
}
return
method
}
const
todoApis
=
Object
.
create
(
null
);
const
todoApis
=
Object
.
create
(
null
);
const
TODOS
=
[
const
TODOS
=
[
...
@@ -154,7 +238,7 @@ function getProvider ({
...
@@ -154,7 +238,7 @@ function getProvider ({
isFn
(
complete
)
&&
complete
(
res
);
isFn
(
complete
)
&&
complete
(
res
);
}
}
var
base
Api
=
/*#__PURE__*/
Object
.
freeze
({
var
extra
Api
=
/*#__PURE__*/
Object
.
freeze
({
getProvider
:
getProvider
getProvider
:
getProvider
});
});
...
@@ -175,8 +259,8 @@ if (typeof Proxy !== 'undefined') {
...
@@ -175,8 +259,8 @@ if (typeof Proxy !== 'undefined') {
if
(
api
[
name
])
{
if
(
api
[
name
])
{
return
promisify
(
name
,
api
[
name
])
return
promisify
(
name
,
api
[
name
])
}
}
if
(
base
Api
[
name
])
{
if
(
extra
Api
[
name
])
{
return
promisify
(
name
,
base
Api
[
name
])
return
promisify
(
name
,
extra
Api
[
name
])
}
}
if
(
todoApis
[
name
])
{
if
(
todoApis
[
name
])
{
return
promisify
(
name
,
todoApis
[
name
])
return
promisify
(
name
,
todoApis
[
name
])
...
@@ -184,7 +268,7 @@ if (typeof Proxy !== 'undefined') {
...
@@ -184,7 +268,7 @@ if (typeof Proxy !== 'undefined') {
if
(
!
swan
.
hasOwnProperty
(
name
))
{
if
(
!
swan
.
hasOwnProperty
(
name
))
{
return
return
}
}
return
promisify
(
name
,
swan
[
name
]
)
return
promisify
(
name
,
wrapper
(
name
,
swan
[
name
])
)
}
}
});
});
}
else
{
}
else
{
...
@@ -194,7 +278,7 @@ if (typeof Proxy !== 'undefined') {
...
@@ -194,7 +278,7 @@ if (typeof Proxy !== 'undefined') {
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
});
});
Object
.
keys
(
base
Api
).
forEach
(
name
=>
{
Object
.
keys
(
extra
Api
).
forEach
(
name
=>
{
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
});
});
...
@@ -204,7 +288,7 @@ if (typeof Proxy !== 'undefined') {
...
@@ -204,7 +288,7 @@ if (typeof Proxy !== 'undefined') {
Object
.
keys
(
swan
).
forEach
(
name
=>
{
Object
.
keys
(
swan
).
forEach
(
name
=>
{
if
(
swan
.
hasOwnProperty
(
name
))
{
if
(
swan
.
hasOwnProperty
(
name
))
{
uni$1
[
name
]
=
promisify
(
name
,
swan
[
name
]
);
uni$1
[
name
]
=
promisify
(
name
,
wrapper
(
name
,
swan
[
name
])
);
}
}
});
});
}
}
...
...
packages/uni-mp-weixin/dist/index.js
浏览文件 @
b4deeaa4
const
_toString
=
Object
.
prototype
.
toString
;
const
hasOwnProperty
=
Object
.
prototype
.
hasOwnProperty
;
function
isFn
(
fn
)
{
function
isFn
(
fn
)
{
return
typeof
fn
===
'
function
'
return
typeof
fn
===
'
function
'
}
function
isStr
(
str
)
{
return
typeof
str
===
'
string
'
}
function
isPlainObject
(
obj
)
{
return
_toString
.
call
(
obj
)
===
'
[object Object]
'
}
function
hasOwn
(
obj
,
key
)
{
return
hasOwnProperty
.
call
(
obj
,
key
)
}
}
const
SYNC_API_RE
=
/hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/
;
const
SYNC_API_RE
=
/hideKeyboard|upx2px|canIUse|^create|Sync$|Manager$/
;
...
@@ -97,6 +112,75 @@ function upx2px (number, newDeviceWidth) {
...
@@ -97,6 +112,75 @@ function upx2px (number, newDeviceWidth) {
return
number
return
number
}
}
var
protocols
=
{};
const
CALLBACKS
=
[
'
success
'
,
'
fail
'
,
'
cancel
'
,
'
complete
'
];
function
processCallback
(
method
,
returnValue
)
{
return
function
(
res
)
{
return
method
(
processReturnValue
(
res
,
returnValue
))
}
}
function
processArgs
(
fromArgs
,
argsOption
=
{},
returnValue
=
{})
{
if
(
isPlainObject
(
fromArgs
))
{
// 一般 api 的参数解析
const
toArgs
=
{};
Object
.
keys
(
fromArgs
).
forEach
(
key
=>
{
if
(
hasOwn
(
argsOption
,
key
))
{
let
keyOption
=
argsOption
[
key
];
if
(
isFn
(
keyOption
))
{
keyOption
=
keyOption
(
fromArgs
[
key
],
fromArgs
);
}
if
(
!
keyOption
)
{
// 不支持的参数
console
.
warn
(
`
${
微信小程序
}
${
name
}
暂不支持
${
key
}
`
);
}
else
if
(
isStr
(
keyOption
))
{
// 重写参数 key
toArgs
[
keyOption
]
=
fromArgs
[
key
];
}
else
if
(
isPlainObject
(
keyOption
))
{
// {name:newName,value:value}可重新指定参数 key:value
toArgs
[
keyOption
.
name
?
keyOption
.
name
:
key
]
=
keyOption
.
value
;
}
}
else
if
(
CALLBACKS
.
includes
(
key
))
{
toArgs
[
key
]
=
processCallback
(
fromArgs
[
key
],
returnValue
);
}
else
{
toArgs
[
key
]
=
fromArgs
[
key
];
}
});
return
toArgs
}
else
if
(
isFn
(
fromArgs
))
{
fromArgs
=
processCallback
(
fromArgs
,
returnValue
);
}
return
fromArgs
}
function
processReturnValue
(
res
,
returnValue
)
{
return
processArgs
(
res
,
returnValue
)
}
function
wrapper
(
name
,
method
)
{
if
(
hasOwn
(
protocols
,
name
))
{
const
protocol
=
protocols
[
name
];
if
(
!
protocol
)
{
// 暂不支持的 api
return
function
()
{
throw
new
Error
(
`
${
微信小程序
}
暂不支持
${
name
}
`
)
}
}
return
function
(
arg1
,
arg2
)
{
// 目前 api 最多两个参数
let
options
=
protocol
;
if
(
isFn
(
protocol
))
{
options
=
protocol
(
arg1
);
}
arg1
=
processArgs
(
arg1
,
options
.
args
,
options
.
returnValue
);
const
returnValue
=
wx
[
options
.
name
||
name
](
arg1
,
arg2
);
if
(
isSyncApi
(
name
))
{
// 同步 api
return
processReturnValue
(
returnValue
,
options
.
returnValue
)
}
return
returnValue
}
}
return
method
}
const
todoApis
=
Object
.
create
(
null
);
const
todoApis
=
Object
.
create
(
null
);
const
TODOS
=
[
const
TODOS
=
[
...
@@ -154,7 +238,7 @@ function getProvider ({
...
@@ -154,7 +238,7 @@ function getProvider ({
isFn
(
complete
)
&&
complete
(
res
);
isFn
(
complete
)
&&
complete
(
res
);
}
}
var
base
Api
=
/*#__PURE__*/
Object
.
freeze
({
var
extra
Api
=
/*#__PURE__*/
Object
.
freeze
({
getProvider
:
getProvider
getProvider
:
getProvider
});
});
...
@@ -175,8 +259,8 @@ if (typeof Proxy !== 'undefined') {
...
@@ -175,8 +259,8 @@ if (typeof Proxy !== 'undefined') {
if
(
api
[
name
])
{
if
(
api
[
name
])
{
return
promisify
(
name
,
api
[
name
])
return
promisify
(
name
,
api
[
name
])
}
}
if
(
base
Api
[
name
])
{
if
(
extra
Api
[
name
])
{
return
promisify
(
name
,
base
Api
[
name
])
return
promisify
(
name
,
extra
Api
[
name
])
}
}
if
(
todoApis
[
name
])
{
if
(
todoApis
[
name
])
{
return
promisify
(
name
,
todoApis
[
name
])
return
promisify
(
name
,
todoApis
[
name
])
...
@@ -184,7 +268,7 @@ if (typeof Proxy !== 'undefined') {
...
@@ -184,7 +268,7 @@ if (typeof Proxy !== 'undefined') {
if
(
!
wx
.
hasOwnProperty
(
name
))
{
if
(
!
wx
.
hasOwnProperty
(
name
))
{
return
return
}
}
return
promisify
(
name
,
w
x
[
name
]
)
return
promisify
(
name
,
w
rapper
(
name
,
wx
[
name
])
)
}
}
});
});
}
else
{
}
else
{
...
@@ -194,7 +278,7 @@ if (typeof Proxy !== 'undefined') {
...
@@ -194,7 +278,7 @@ if (typeof Proxy !== 'undefined') {
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
});
});
Object
.
keys
(
base
Api
).
forEach
(
name
=>
{
Object
.
keys
(
extra
Api
).
forEach
(
name
=>
{
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
uni$1
[
name
]
=
promisify
(
name
,
todoApis
[
name
]);
});
});
...
@@ -204,7 +288,7 @@ if (typeof Proxy !== 'undefined') {
...
@@ -204,7 +288,7 @@ if (typeof Proxy !== 'undefined') {
Object
.
keys
(
wx
).
forEach
(
name
=>
{
Object
.
keys
(
wx
).
forEach
(
name
=>
{
if
(
wx
.
hasOwnProperty
(
name
))
{
if
(
wx
.
hasOwnProperty
(
name
))
{
uni$1
[
name
]
=
promisify
(
name
,
w
x
[
name
]
);
uni$1
[
name
]
=
promisify
(
name
,
w
rapper
(
name
,
wx
[
name
])
);
}
}
});
});
}
}
...
...
src/core/helpers/promise.js
浏览文件 @
b4deeaa4
...
@@ -27,7 +27,7 @@ function handlePromise (promise) {
...
@@ -27,7 +27,7 @@ function handlePromise (promise) {
.
catch
(
err
=>
[
err
])
.
catch
(
err
=>
[
err
])
}
}
function
shouldPromise
(
name
)
{
export
function
shouldPromise
(
name
)
{
if
(
isSyncApi
(
name
))
{
if
(
isSyncApi
(
name
))
{
return
false
return
false
}
}
...
...
src/core/runtime/
base
.js
→
src/core/runtime/
extra
.js
浏览文件 @
b4deeaa4
文件已移动
src/core/runtime/index.js
浏览文件 @
b4deeaa4
import
{
hasOwn
}
from
'
uni-shared
'
import
{
import
{
promisify
promisify
}
from
'
../helpers/promise
'
}
from
'
../helpers/promise
'
...
@@ -6,12 +10,16 @@ import {
...
@@ -6,12 +10,16 @@ import {
upx2px
upx2px
}
from
'
../service/api/upx2px
'
}
from
'
../service/api/upx2px
'
import
wrapper
from
'
./wrapper
'
import
todoApi
from
'
./todo
'
import
todoApi
from
'
./todo
'
import
*
as
baseApi
from
'
./base
'
import
*
as
extraApi
from
'
./extra
'
import
*
as
api
from
'
uni-platform/service/api/index.js
'
import
*
as
api
from
'
uni-platform/service/api/index.js
'
import
protocols
from
'
uni-platform/service/api/protocols
'
let
uni
=
{}
let
uni
=
{}
if
(
typeof
Proxy
!==
'
undefined
'
)
{
if
(
typeof
Proxy
!==
'
undefined
'
)
{
...
@@ -23,16 +31,16 @@ if (typeof Proxy !== 'undefined') {
...
@@ -23,16 +31,16 @@ if (typeof Proxy !== 'undefined') {
if
(
api
[
name
])
{
if
(
api
[
name
])
{
return
promisify
(
name
,
api
[
name
])
return
promisify
(
name
,
api
[
name
])
}
}
if
(
base
Api
[
name
])
{
if
(
extra
Api
[
name
])
{
return
promisify
(
name
,
base
Api
[
name
])
return
promisify
(
name
,
extra
Api
[
name
])
}
}
if
(
todoApi
[
name
])
{
if
(
todoApi
[
name
])
{
return
promisify
(
name
,
todoApi
[
name
])
return
promisify
(
name
,
todoApi
[
name
])
}
}
if
(
!
__GLOBAL__
.
hasOwnProperty
(
name
))
{
if
(
!
hasOwn
(
__GLOBAL__
,
name
)
&&
!
hasOwn
(
protocols
,
name
))
{
return
return
}
}
return
promisify
(
name
,
__GLOBAL__
[
name
]
)
return
promisify
(
name
,
wrapper
(
name
,
__GLOBAL__
[
name
])
)
}
}
})
})
}
else
{
}
else
{
...
@@ -42,7 +50,7 @@ if (typeof Proxy !== 'undefined') {
...
@@ -42,7 +50,7 @@ if (typeof Proxy !== 'undefined') {
uni
[
name
]
=
promisify
(
name
,
todoApi
[
name
])
uni
[
name
]
=
promisify
(
name
,
todoApi
[
name
])
})
})
Object
.
keys
(
base
Api
).
forEach
(
name
=>
{
Object
.
keys
(
extra
Api
).
forEach
(
name
=>
{
uni
[
name
]
=
promisify
(
name
,
todoApi
[
name
])
uni
[
name
]
=
promisify
(
name
,
todoApi
[
name
])
})
})
...
@@ -51,8 +59,8 @@ if (typeof Proxy !== 'undefined') {
...
@@ -51,8 +59,8 @@ if (typeof Proxy !== 'undefined') {
})
})
Object
.
keys
(
__GLOBAL__
).
forEach
(
name
=>
{
Object
.
keys
(
__GLOBAL__
).
forEach
(
name
=>
{
if
(
__GLOBAL__
.
hasOwnProperty
(
name
))
{
if
(
hasOwn
(
__GLOBAL__
,
name
)
||
hasOwn
(
protocols
,
name
))
{
uni
[
name
]
=
promisify
(
name
,
__GLOBAL__
[
name
]
)
uni
[
name
]
=
promisify
(
name
,
wrapper
(
name
,
__GLOBAL__
[
name
])
)
}
}
})
})
}
}
...
...
src/core/runtime/wrapper.js
0 → 100644
浏览文件 @
b4deeaa4
import
{
isFn
,
isStr
,
hasOwn
,
isPlainObject
}
from
'
uni-shared
'
import
{
isSyncApi
}
from
'
../helpers/promise
'
import
protocols
from
'
uni-platform/service/api/protocols
'
const
CALLBACKS
=
[
'
success
'
,
'
fail
'
,
'
cancel
'
,
'
complete
'
]
function
processCallback
(
methodName
,
method
,
returnValue
)
{
return
function
(
res
)
{
return
method
(
processReturnValue
(
methodName
,
res
,
returnValue
))
}
}
function
processArgs
(
methodName
,
fromArgs
,
argsOption
=
{},
returnValue
=
{})
{
if
(
isPlainObject
(
fromArgs
))
{
// 一般 api 的参数解析
const
toArgs
=
{}
if
(
isFn
(
argsOption
))
{
argsOption
=
argsOption
(
fromArgs
,
toArgs
)
||
{}
}
Object
.
keys
(
fromArgs
).
forEach
(
key
=>
{
if
(
hasOwn
(
argsOption
,
key
))
{
let
keyOption
=
argsOption
[
key
]
if
(
isFn
(
keyOption
))
{
keyOption
=
keyOption
(
fromArgs
[
key
],
fromArgs
)
}
if
(
!
keyOption
)
{
// 不支持的参数
console
.
warn
(
`__PLATFORM_TITLE__
${
methodName
}
暂不支持
${
key
}
`
)
}
else
if
(
isStr
(
keyOption
))
{
// 重写参数 key
toArgs
[
keyOption
]
=
fromArgs
[
key
]
}
else
if
(
isPlainObject
(
keyOption
))
{
// {name:newName,value:value}可重新指定参数 key:value
toArgs
[
keyOption
.
name
?
keyOption
.
name
:
key
]
=
keyOption
.
value
}
}
else
if
(
CALLBACKS
.
includes
(
key
))
{
toArgs
[
key
]
=
processCallback
(
methodName
,
fromArgs
[
key
],
returnValue
)
}
else
{
toArgs
[
key
]
=
fromArgs
[
key
]
}
})
return
toArgs
}
else
if
(
isFn
(
fromArgs
))
{
fromArgs
=
processCallback
(
methodName
,
fromArgs
,
returnValue
)
}
return
fromArgs
}
function
processReturnValue
(
methodName
,
res
,
returnValue
)
{
if
(
isFn
(
protocols
.
returnValue
))
{
// 处理通用 returnValue
res
=
protocols
.
returnValue
(
methodName
,
res
)
}
return
processArgs
(
methodName
,
res
,
returnValue
)
}
export
default
function
wrapper
(
methodName
,
method
)
{
if
(
hasOwn
(
protocols
,
methodName
))
{
const
protocol
=
protocols
[
methodName
]
if
(
!
protocol
)
{
// 暂不支持的 api
return
function
()
{
throw
new
Error
(
`__PLATFORM_TITLE__ 暂不支持
${
methodName
}
`
)
}
}
return
function
(
arg1
,
arg2
)
{
// 目前 api 最多两个参数
let
options
=
protocol
if
(
isFn
(
protocol
))
{
options
=
protocol
(
arg1
)
}
arg1
=
processArgs
(
methodName
,
arg1
,
options
.
args
,
options
.
returnValue
)
const
returnValue
=
__GLOBAL__
[
options
.
name
||
methodName
](
arg1
,
arg2
)
if
(
isSyncApi
(
methodName
))
{
// 同步 api
return
processReturnValue
(
methodName
,
returnValue
,
options
.
returnValue
)
}
return
returnValue
}
}
return
method
}
src/platforms/mp-alipay/service/api/protocols.js
0 → 100644
浏览文件 @
b4deeaa4
const
TODOS
=
[
'
hideTabBar
'
,
'
hideTabBarRedDot
'
,
'
removeTabBarBadge
'
,
'
setTabBarBadge
'
,
'
setTabBarItem
'
,
'
setTabBarStyle
'
,
'
showTabBar
'
,
'
showTabBarRedDot
'
]
const
protocols
=
{
returnValue
(
methodName
,
res
)
{
// 通用 returnValue 解析
if
(
res
.
error
||
res
.
errorMessage
)
{
res
.
errMsg
=
`
${
methodName
}
:fail
${
res
.
errorMessage
||
res
.
error
}
`
delete
res
.
error
delete
res
.
errorMessage
}
return
res
},
setNavigationBarColor
:
{
name
:
'
setNavigationBar
'
,
args
:
{
frontColor
:
false
,
animation
:
false
}
},
setNavigationBarTitle
:
{
name
:
'
setNavigationBar
'
},
showModal
({
showCancel
=
true
}
=
{})
{
if
(
showCancel
)
{
return
{
name
:
'
confirm
'
,
args
:
{
cancelColor
:
false
,
confirmColor
:
false
,
cancelText
:
'
cancelButtonText
'
,
confirmText
:
'
confirmButtonText
'
},
returnValue
(
fromRes
,
toRes
)
{
toRes
.
confirm
=
fromRes
.
confirm
toRes
.
cancel
=
!
fromRes
.
confirm
}
}
}
return
{
name
:
'
alert
'
,
args
:
{
confirmColor
:
false
,
confirmText
:
'
buttonText
'
},
returnValue
(
fromRes
,
toRes
)
{
toRes
.
confirm
=
true
toRes
.
cancel
=
false
}
}
},
showToast
({
icon
=
'
success
'
}
=
{})
{
const
args
=
{
title
:
'
content
'
,
icon
:
'
type
'
,
duration
:
false
,
image
:
false
,
mask
:
false
}
if
(
icon
===
'
loading
'
)
{
return
{
name
:
'
showLoading
'
,
args
}
}
return
{
name
:
'
showToast
'
,
args
}
},
showActionSheet
:
{
name
:
'
showActionSheet
'
,
args
:
{
itemList
:
'
items
'
,
itemColor
:
false
},
returnValue
:
{
index
:
'
tapIndex
'
}
}
}
TODOS
.
forEach
(
todoApi
=>
{
protocols
[
todoApi
]
=
false
})
export
default
protocols
src/platforms/mp-baidu/service/api/protocols.js
0 → 100644
浏览文件 @
b4deeaa4
export
default
{}
src/platforms/mp-weixin/service/api/protocols.js
0 → 100644
浏览文件 @
b4deeaa4
export
default
{}
src/shared/util.js
浏览文件 @
b4deeaa4
...
@@ -4,6 +4,11 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
...
@@ -4,6 +4,11 @@ const hasOwnProperty = Object.prototype.hasOwnProperty
export
function
isFn
(
fn
)
{
export
function
isFn
(
fn
)
{
return
typeof
fn
===
'
function
'
return
typeof
fn
===
'
function
'
}
}
export
function
isStr
(
str
)
{
return
typeof
str
===
'
string
'
}
export
function
isPlainObject
(
obj
)
{
export
function
isPlainObject
(
obj
)
{
return
_toString
.
call
(
obj
)
===
'
[object Object]
'
return
_toString
.
call
(
obj
)
===
'
[object Object]
'
}
}
...
@@ -26,7 +31,7 @@ export function setProperties (item, props, propsData) {
...
@@ -26,7 +31,7 @@ export function setProperties (item, props, propsData) {
})
})
}
}
export
function
getLen
(
str
=
''
)
{
export
function
getLen
(
str
=
''
)
{
/* eslint-disable no-control-regex */
/* eslint-disable no-control-regex */
return
(
''
+
str
).
replace
(
/
[^\x
00-
\x
ff
]
/g
,
'
**
'
).
length
return
(
''
+
str
).
replace
(
/
[^\x
00-
\x
ff
]
/g
,
'
**
'
).
length
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录