Skip to content

Commit 7f91f2f

Browse files
committed
新增:深层级的 API my.ap.xxswan.ai.xxcreateMapContext 之类的 API 处理
1 parent 5dd5e5c commit 7f91f2f

59 files changed

Lines changed: 1440 additions & 8706 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
.DS_Store
22
.AppleDouble
33
.LSOverride
4+
package-lock.json
45

56
._*
67

.npmignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
examples
1+
assets
2+
example
23
node_modules
34
*.js.map
4-
webpack.config.js
5+
webpack.config.js
6+
package-lock.json
7+
CHANGELOG.md

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.2.1
2+
- 新增:深层级的 API `my.ap.xx``swan.ai.xx``createMapContext` 之类的 API 处理
3+
- 修改:example 示例为 `mpvue`
4+
15
## 0.2.0
26
- 新增字节跳动小程序
37
- 重构

README.md

Lines changed: 38 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
> mpapi(miniProgram API),小程序 API 兼容插件,一次编写,多端运行。
44
5-
:alarm_clock: 更新日期: 2019-05-30
5+
:alarm_clock: 更新日期: 2019-05-31
66

77
[![NPM][img-npm-badge]][url-npm] [![Language][img-javascript]][url-github] [![License][img-mit]][url-mit]
88

@@ -32,28 +32,12 @@ api.alert({...}).then((res) => {})
3232
api.confirm({...}).then((res) => {})
3333
api.getLocation().then((res) => {})
3434
...
35-
36-
// 微信小程序的处理
37-
if(api.isWechat){
38-
api.setTopBarText({...}).then((res) => {})
39-
}
40-
41-
// 支付宝小程序的处理
42-
if(api.isAlipay){
43-
api.startZMVerify({...}).then((res) => {})
44-
}
45-
46-
// 百度智能小程序的处理
47-
if(api.isSwan){
48-
api.getSwanId().then((res) => {})
49-
}
5035
```
5136

5237

5338
## 快速查看
5439
- [兼容 API 列表](#兼容api列表)
5540
- [其它包装成 Promise 的 API](#其它包装成promise的api)
56-
- [优化的 API](#优化的api)
5741
- [API 差异](#小程序之间的api差异)
5842
- [使用说明](#使用说明)
5943
- [特殊 API 的事件处理](#特殊api的事件处理)`request``downloadFile``uploadFile`
@@ -119,7 +103,7 @@ if(api.isSwan){
119103
## 其它包装成Promise的API
120104
> 只在特定小程序下才会支持。
121105
122-
微信小程序![wx](./assets/wx.png)、支付宝小程序![my](./assets/my.png)、百度智能小程序![swan](./assets/swan.png)、字节跳动小程序![tt](./assets/tt.png),有图标表示只支持对应小程序,没有图标表示支持所有小程序
106+
微信小程序![wx](./assets/wx.png)、支付宝小程序![my](./assets/my.png)、百度智能小程序![swan](./assets/swan.png)、字节跳动小程序![tt](./assets/tt.png),有图标表示只支持对应小程序,没有图标表示都支持
123107

124108

125109
- 交互
@@ -354,6 +338,41 @@ if(api.isSwan){
354338

355339

356340

341+
- **深层级的 API**
342+
- `api.ap` ![my](./assets/my.png)
343+
- [x] `api.ap.$faceVerify`
344+
- [x] `api.ap.$navigateToAlipayPage`
345+
- [x] `...`
346+
- `api.ai` ![swan](./assets/swan.png)
347+
- [x] `api.ai.$ocrIdCard`
348+
- [x] `api.ai.$ocrBankCard`
349+
- [x] `...`
350+
351+
- **某些新实例的对象上面的 API**
352+
353+
- [x] `createMapContext` ![%= lbl %>](./assets/wx.png) ![%= lbl %>](./assets/my.png) ![%= lbl %>](./assets/swan.png)
354+
- [x] `createVideoContext` ![%= lbl %>](./assets/wx.png) ![%= lbl %>](./assets/swan.png)
355+
- [x] `createAudioContext` ![%= lbl %>](./assets/wx.png)
356+
- [x] `createCameraContext` ![%= lbl %>](./assets/wx.png) ![%= lbl %>](./assets/swan.png)
357+
- [x] `createInnerAudioContext` ![%= lbl %>](./assets/wx.png) ![%= lbl %>](./assets/swan.png) ![%= lbl %>](./assets/tt.png)
358+
- [x] `createLivePusherContext` ![%= lbl %>](./assets/wx.png)
359+
- [x] `createLivePlayerContext` ![%= lbl %>](./assets/wx.png)
360+
- [x] `getBackgroundAudioManager` ![%= lbl %>](./assets/wx.png) ![%= lbl %>](./assets/swan.png)
361+
- [x] `getRecorderManager` ![%= lbl %>](./assets/wx.png) ![%= lbl %>](./assets/swan.png) ![%= lbl %>](./assets/tt.png)
362+
- [x] `createSelectorQuery`
363+
- [x] `getFileSystemManager` ![%= lbl %>](./assets/wx.png)
364+
- [x] `createARCameraContext` ![%= lbl %>](./assets/swan.png)
365+
366+
例如:**注意:方法加了 `$` 前缀**
367+
```javascript
368+
let ctx = api.createMapContext('maper')
369+
370+
ctx.$getCenterLocation().then((res) => {
371+
console.log('createMapContext:getCenterLocation')
372+
console.log(res)
373+
})
374+
```
375+
357376

358377
## 小程序之间的API差异
359378

@@ -492,14 +511,6 @@ api.chooseImage({
492511
})
493512
```
494513

495-
3、深层级的 API,也可以通过 `api` 来调用,并且支持 `Promise` 语法(**`success` 回调的才有**
496-
```javascript
497-
// 支付宝小程序支持的
498-
api.ap.imgRisk({...}).then((res) => {})
499-
api.ap.navigateToAlipayPage({...}).then((res) => {})
500-
...
501-
```
502-
503514

504515
## 特殊API的事件处理
505516
某些 API 既要支持 Promise,又要调用它的事件,那么可以采用如下方式:
@@ -544,7 +555,7 @@ downloadTask.$event('onProgressUpdate', (res) => {
544555

545556

546557
## Changelog
547-
[更新日志](./CHANGELOG.md)
558+
[更新日志](./CHANGELOG.md)
548559

549560

550561
## License

TEMPLATE.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -32,28 +32,12 @@ api.alert({...}).then((res) => {})
3232
api.confirm({...}).then((res) => {})
3333
api.getLocation().then((res) => {})
3434
...
35-
36-
// 微信小程序的处理
37-
if(api.isWechat){
38-
api.setTopBarText({...}).then((res) => {})
39-
}
40-
41-
// 支付宝小程序的处理
42-
if(api.isAlipay){
43-
api.startZMVerify({...}).then((res) => {})
44-
}
45-
46-
// 百度智能小程序的处理
47-
if(api.isSwan){
48-
api.getSwanId().then((res) => {})
49-
}
5035
```
5136

5237

5338
## 快速查看
5439
- [兼容 API 列表](#兼容api列表)
5540
- [其它包装成 Promise 的 API](#其它包装成promise的api)
56-
- [优化的 API](#优化的api)
5741
- [API 差异](#小程序之间的api差异)
5842
- [使用说明](#使用说明)
5943
- [特殊 API 的事件处理](#特殊api的事件处理)`request``downloadFile``uploadFile`
@@ -71,14 +55,38 @@ if(api.isSwan){
7155
## 其它包装成Promise的API
7256
> 只在特定小程序下才会支持。
7357
74-
微信小程序![wx](./assets/wx.png)、支付宝小程序![my](./assets/my.png)、百度智能小程序![swan](./assets/swan.png)、字节跳动小程序![tt](./assets/tt.png),有图标表示只支持对应小程序,没有图标表示支持所有小程序
58+
微信小程序![wx](./assets/wx.png)、支付宝小程序![my](./assets/my.png)、百度智能小程序![swan](./assets/swan.png)、字节跳动小程序![tt](./assets/tt.png),有图标表示只支持对应小程序,没有图标表示都支持
7559

7660
<% _.each(obj.normalApi, function(group){ %>
7761
- <%= group.title %>
7862
<% _.each(group.items, function(item){ %> - [x] `<%= item.title %>` <% _.each(item.labels, function(lbl){ %> ![%= lbl %>](./assets/<%= lbl %>.png) <% }) %>
7963
<% }) %>
8064
<% }) %>
8165

66+
- **深层级的 API**
67+
- `api.ap` ![my](./assets/my.png)
68+
- [x] `api.ap.$faceVerify`
69+
- [x] `api.ap.$navigateToAlipayPage`
70+
- [x] `...`
71+
- `api.ai` ![swan](./assets/swan.png)
72+
- [x] `api.ai.$ocrIdCard`
73+
- [x] `api.ai.$ocrBankCard`
74+
- [x] `...`
75+
76+
- **某些新实例的对象上面的 API**
77+
<% _.each(obj.instanceApi, function(group){ %>
78+
- [x] `<%= group.title %>` <% _.each(group.labels, function(lbl){ %>![%= lbl %>](./assets/<%= lbl %>.png) <% }) %><% }) %>
79+
80+
例如:**注意:方法加了 `$` 前缀**
81+
```javascript
82+
let ctx = api.createMapContext('maper')
83+
84+
ctx.$getCenterLocation().then((res) => {
85+
console.log('createMapContext:getCenterLocation')
86+
console.log(res)
87+
})
88+
```
89+
8290

8391
## 小程序之间的API差异
8492

@@ -217,14 +225,6 @@ api.chooseImage({
217225
})
218226
```
219227

220-
3、深层级的 API,也可以通过 `api` 来调用,并且支持 `Promise` 语法(**`success` 回调的才有**
221-
```javascript
222-
// 支付宝小程序支持的
223-
api.ap.imgRisk({...}).then((res) => {})
224-
api.ap.navigateToAlipayPage({...}).then((res) => {})
225-
...
226-
```
227-
228228

229229
## 特殊API的事件处理
230230
某些 API 既要支持 Promise,又要调用它的事件,那么可以采用如下方式:
@@ -269,7 +269,7 @@ downloadTask.$event('onProgressUpdate', (res) => {
269269

270270

271271
## Changelog
272-
[更新日志](./CHANGELOG.md)
272+
[更新日志](./CHANGELOG.md)
273273

274274

275275
## License

doc.js

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ const TEMPLATE = path.join(__dirname, 'TEMPLATE.md')
88
const README = path.join(__dirname, 'README.md')
99

1010
const NORMALAPI_FILE = path.join(__dirname, 'src/api/normalApi.js')
11+
const INSTANCEAPI_FILE = path.join(__dirname, 'src/api/instanceApi.js')
1112
const POLYFILLS_FILE = path.join(__dirname, 'src/polyfills/index.js')
1213

1314
let NORMALAPI_DATA = []
15+
let INSTANCEAPI_DATA = []
1416
let POLYFILLS_DATA = []
1517

1618
// normalApi.js 转换成数组数据
@@ -53,6 +55,43 @@ function handlerNormalApi(){
5355
}
5456

5557

58+
59+
// instanceApi.js 转换成数组数据
60+
function handlerInstanceApi(){
61+
let rl = readline(INSTANCEAPI_FILE, { retainBuffer: true })
62+
63+
let ready = false
64+
65+
return new Promise((resolve) => {
66+
rl.on('line', (data) => {
67+
let content = data.toString()
68+
69+
if(/module\.exports/.test(content)){
70+
ready = true
71+
}
72+
73+
if(ready){
74+
let matchApi = content.match(/'(\w+)',(\s+\/\/\s+([\w\s]+))?/)
75+
if(matchApi && matchApi[1]){
76+
let labels = []
77+
78+
if(matchApi[3]){
79+
labels = matchApi[3].split(/\s/)
80+
}
81+
82+
INSTANCEAPI_DATA.push({
83+
title: matchApi[1],
84+
labels: labels
85+
})
86+
}
87+
}
88+
});
89+
90+
rl.on('end', resolve)
91+
})
92+
}
93+
94+
5695
// polyfills/index.js 转换成数组数据
5796
function handlerPolyfills(){
5897
let rl = readline(POLYFILLS_FILE, { retainBuffer: true })
@@ -102,6 +141,7 @@ function writeMarkdown(){
102141

103142
tplContent = compiled({
104143
updateDate: moment().format('YYYY-MM-DD'),
144+
instanceApi: INSTANCEAPI_DATA,
105145
normalApi: NORMALAPI_DATA,
106146
polyfills: POLYFILLS_DATA
107147
});
@@ -111,6 +151,7 @@ function writeMarkdown(){
111151

112152
async function init(){
113153
await handlerNormalApi()
154+
await handlerInstanceApi()
114155
await handlerPolyfills()
115156

116157
writeMarkdown()

example/mpvue/.babelrc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"presets": [
3+
["env", {
4+
"modules": false,
5+
"targets": {
6+
"browsers": ["> 1%", "last 2 versions", "not ie <= 8"]
7+
}
8+
}],
9+
"stage-2"
10+
],
11+
"plugins": ["transform-runtime"],
12+
"env": {
13+
"test": {
14+
"presets": ["env", "stage-2"],
15+
"plugins": ["istanbul"]
16+
}
17+
}
18+
}

example/mpvue/.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

example/mpvue/.eslintignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/*.js
2+
config/*.js

example/mpvue/.eslintrc.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// http://eslint.org/docs/user-guide/configuring
2+
3+
module.exports = {
4+
root: true,
5+
parser: 'babel-eslint',
6+
parserOptions: {
7+
sourceType: 'module'
8+
},
9+
env: {
10+
browser: false,
11+
node: true,
12+
es6: true
13+
},
14+
// https://github.com/standard/standard/blob/master/docs/RULES-en.md
15+
extends: 'standard',
16+
// required to lint *.vue files
17+
plugins: [
18+
'html'
19+
],
20+
// add your custom rules here
21+
'rules': {
22+
// allow paren-less arrow functions
23+
'arrow-parens': 0,
24+
// allow async-await
25+
'generator-star-spacing': 0,
26+
// allow debugger during development
27+
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
28+
},
29+
globals: {
30+
App: true,
31+
Page: true,
32+
wx: true,
33+
swan: true,
34+
tt: true,
35+
my: true,
36+
getApp: true,
37+
getPage: true,
38+
requirePlugin: true,
39+
mpvue: true,
40+
mpvuePlatform: true
41+
}
42+
}

0 commit comments

Comments
 (0)