Skip to content

Commit

Permalink
feat: choose-image support bytedance
Browse files Browse the repository at this point in the history
  • Loading branch information
siteng.xst committed Apr 25, 2020
1 parent 78428ff commit c94db43
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 15 deletions.
6 changes: 3 additions & 3 deletions packages/choose-image/README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
选取图片

## 支持
<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px">
<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"><img alt="bytedanceMicroApp" src="https://gw.alicdn.com/tfs/TB1jFtVzO_1gK0jSZFqXXcpaXXa-200-200.svg" width="25px" height="25px">

## 安装
```bash
Expand All @@ -28,8 +28,8 @@ chooseImage().then(res => {
| 成员 | 类型 | 描述 | 必选 | 默认值 | 支持 |
| ------------------ | -------- | ---------------- | ---- | --------------- | ---- |
| options | `object` | 选取照片参数 || - | |
| options.count | `number` | 最大可选照片数 || `1` | <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> |
| options.sourceType | `array` | 相册选取或者拍照 || `camera, album` | <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> |
| options.count | `number` | 最大可选照片数 || `1` | <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"><img alt="bytedanceMicroApp" src="https://gw.alicdn.com/tfs/TB1jFtVzO_1gK0jSZFqXXcpaXXa-200-200.svg" width="25px" height="25px"> |
| options.sourceType | `array` | 相册选取或者拍照 || `camera, album` | <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"><img alt="bytedanceMicroApp" src="https://gw.alicdn.com/tfs/TB1jFtVzO_1gK0jSZFqXXcpaXXa-200-200.svg" width="25px" height="25px"> |

#### 返回值
| 成员 | 类型 | 描述 |
Expand Down
6 changes: 3 additions & 3 deletions packages/choose-image/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Choose image.


## Support
<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px">
<img alt="browser" src="https://gw.alicdn.com/tfs/TB1uYFobGSs3KVjSZPiXXcsiVXa-200-200.svg" width="25px" height="25px" /> <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"><img alt="bytedanceMicroApp" src="https://gw.alicdn.com/tfs/TB1jFtVzO_1gK0jSZFqXXcpaXXa-200-200.svg" width="25px" height="25px">

## Install

Expand All @@ -29,8 +29,8 @@ chooseImage().then(res => {
| Property | Type | Description | require | Default | Supported |
| ------------------ | -------- | ------------------------------- | ------- | ----------------- | --------- |
| options | `object` | Options | false | - | |
| options.count | `number` | Maximum number of choices | false | `1` | <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> |
| options.sourceType | `array` | Album selection or photo taking | false | `[camera, album]` | <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"> |
| options.count | `number` | Maximum number of choices | false | `1` | <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"><img alt="bytedanceMicroApp" src="https://gw.alicdn.com/tfs/TB1jFtVzO_1gK0jSZFqXXcpaXXa-200-200.svg" width="25px" height="25px"> |
| options.sourceType | `array` | Album selection or photo taking | false | `[camera, album]` | <img alt="miniApp" src="https://gw.alicdn.com/tfs/TB1bBpmbRCw3KVjSZFuXXcAOpXa-200-200.svg" width="25px" height="25px" /> <img alt="wechatMiniprogram" src="https://img.alicdn.com/tfs/TB1slcYdxv1gK0jSZFFXXb0sXXa-200-200.svg" width="25px" height="25px"><img alt="bytedanceMicroApp" src="https://gw.alicdn.com/tfs/TB1jFtVzO_1gK0jSZFqXXcpaXXa-200-200.svg" width="25px" height="25px"> |

#### Returns
| Property | Type | Description |
Expand Down
6 changes: 3 additions & 3 deletions packages/choose-image/docs-template/README-zh_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
选取图片

## 支持
__icon_web__ __icon_miniapp_mp__ __icon_miniapp_wx__
__icon_web__ __icon_miniapp_mp__ __icon_miniapp_wx__ __icon_miniapp_tt__

## 安装
```bash
Expand All @@ -28,8 +28,8 @@ chooseImage().then(res => {
| 成员 | 类型 | 描述 | 必选 | 默认值 | 支持 |
| ------------------ | -------- | ---------------- | ---- | --------------- | ---- |
| options | `object` | 选取照片参数 || - | |
| options.count | `number` | 最大可选照片数 || `1` | __icon_miniapp_mp__ __icon_miniapp_wx__ |
| options.sourceType | `array` | 相册选取或者拍照 || `camera, album` | __icon_miniapp_mp__ __icon_miniapp_wx__ |
| options.count | `number` | 最大可选照片数 || `1` | __icon_miniapp_mp__ __icon_miniapp_wx__ __icon_miniapp_tt__ |
| options.sourceType | `array` | 相册选取或者拍照 || `camera, album` | __icon_miniapp_mp__ __icon_miniapp_wx__ __icon_miniapp_tt__ |

#### 返回值
| 成员 | 类型 | 描述 |
Expand Down
6 changes: 3 additions & 3 deletions packages/choose-image/docs-template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Choose image.


## Support
__icon_web__ __icon_miniapp_mp__ __icon_miniapp_wx__
__icon_web__ __icon_miniapp_mp__ __icon_miniapp_wx__ __icon_miniapp_tt__

## Install

Expand All @@ -29,8 +29,8 @@ chooseImage().then(res => {
| Property | Type | Description | require | Default | Supported |
| ------------------ | -------- | ------------------------------- | ------- | ----------------- | --------- |
| options | `object` | Options | false | - | |
| options.count | `number` | Maximum number of choices | false | `1` | __icon_miniapp_mp__ __icon_miniapp_wx__ |
| options.sourceType | `array` | Album selection or photo taking | false | `[camera, album]` | __icon_miniapp_mp__ __icon_miniapp_wx__ |
| options.count | `number` | Maximum number of choices | false | `1` | __icon_miniapp_mp__ __icon_miniapp_wx__ __icon_miniapp_tt__ |
| options.sourceType | `array` | Album selection or photo taking | false | `[camera, album]` | __icon_miniapp_mp__ __icon_miniapp_wx__ __icon_miniapp_tt__ |

#### Returns
| Property | Type | Description |
Expand Down
4 changes: 2 additions & 2 deletions packages/choose-image/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "universal-choose-image",
"author": "rax",
"version": "1.0.1",
"version": "1.1.0",
"license": "BSD-3-Clause",
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand All @@ -21,7 +21,7 @@
"npm": ">=3.0.0"
},
"dependencies": {
"universal-env": "^2.0.0"
"universal-env": "^3.0.0"
},
"devDependencies": {
"@types/jest": "^24.0.12",
Expand Down
7 changes: 6 additions & 1 deletion packages/choose-image/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { isWeb, isWeex, isMiniApp, isWeChatMiniprogram } from 'universal-env';
import { isWeb, isWeex, isMiniApp, isWeChatMiniprogram, isByteDanceMicroApp } from 'universal-env';
import webModule from './web/index';
import weexModule from './weex/index';
import miniAppModule from './miniapp/ali/index';
import weChatModule from './miniapp/wechat/index';
import bytedanceModule from './miniapp/bytedance-microapp/index';

import { ChooseImage } from './types';

Expand All @@ -21,6 +22,10 @@ if (isMiniApp) {
chooseImage = miniAppModule;
}

if (isByteDanceMicroApp) {
chooseImage = bytedanceModule;
}

if (isWeChatMiniprogram) {
chooseImage = weChatModule;
}
Expand Down
24 changes: 24 additions & 0 deletions packages/choose-image/src/miniapp/bytedance-microapp/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Options } from '../../types';

declare const tt: any;

const choose = (options: Options = {}): Promise<null> => {
return new Promise((resolve, reject): void => {
const { count = 1, sourceType = ['camera', 'album'], sizeType }: Options = options;
tt.chooseImage({
sourceType,
count,
sizeType,
success: (res) => {
resolve(Object.assign({}, {
data: res.tempFilePaths
}, res));
},
fail: (e) => {
reject(e);
}
});
});
};

export default choose;

0 comments on commit c94db43

Please sign in to comment.