# tthg-jssdk

> 用于和 `tthigo App WebView` 通信的 `jssdk`。

Latest version **0.4.0** (published 2018-10-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install tthg-jssdk
pnpm add tthg-jssdk
yarn add tthg-jssdk
bun add tthg-jssdk
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2018-10-20 |
| First published | 2018-05-03 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 75.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | hm910705, jacinoface |

## Links

- npm: https://www.npmjs.com/package/tthg-jssdk
- Repository: http://trgit2/ttHigo/tthg-jssdk
- npm.io page: https://npm.io/package/tthg-jssdk

## Recent versions

- 0.4.0 (latest) — 2018-10-20
- 0.3.1 — 2018-05-26
- 0.3.0 — 2018-05-23
- 0.2.0 — 2018-05-17
- 0.1.0 — 2018-05-03

## README

# tthg-jssdk

用于和 `tthigo App WebView` 通信的 `jssdk`。

# 如何使用tthigo-jssdk?

首先需要在页面中引入 `tthg-jssdk.min.js`，然后初始化代码如下：

```js
// WebView已经准备好交互
ttHigo.ready(async function(){
  // 获取登录状态
  const loginStatus = await ttHigo.checkLoginStatus();
  // 获取登录用户信息
  const customerInfo = await ttHigo.getCustomerInfo();
  // 唤起App登录
  ttHigo.login();
  // 使用App打开商品
  const productNo = ''; // 商品编号
  ttHigo.openProduct(productNo);
});
// 获取App的具体版本号
console.log(ttHigo.higoAppVersion);

// 获取SDK的版本号
console.log(ttHigo.version);

// 如果是在App的WebView中打开，则会输出true
console.log(ttHigo.isInApp); // true
```

# API文档

## 1、ready(fn): void

```js
// Webview通信环境加载完毕后触发，类似JQ的$.ready
ttHigo.ready(function(){
  // do something
});
```

## 2、checkLoginStatus(): Promise<{isLogin: bool}>

```js
// 获取当前用户是否已经登录
ttHigo.checkLoginStatus()
  .then(data => {
    console.log(data.isLogin); // 打印用户是否登录
  });
```

## 3、getCustomerInfo(): Promise<CustomerInfo>

```js
// 获取登录用户信息，如果用户未登录，返回null
ttHigo.getCustomerInfo()
  .then(customerInfo => {
    console.log(customerInfo);
  });
```

**CustomerInfo:**

```js
{
  loginName: string, // 登录名
  nickName: string, // 用户昵称
  contactWith: string, // 姓名
  encryptedCustomerNumber: string, // 加密后的客户ID
  homePhone: string, // 账号绑定的手机号
}
```

## 4、login(): void

```js
// 请求用户登录，如果用户已经登录不会有任何变化
ttHigo.login();
```

## 5、openProduct(productNo: string, extraOptions?: any): void

```js
// 在App上打开指定商品的商品详情页面
ttHigo.openProduct('商品ID');
```

## 6、openSeller(sellerId: string, extraOptions?: any): void

```js
// 在App上打开指定的经销商页面
ttHigo.openSeller('seller ID');
```

## 7、openStore(storeId: number, extraOptions?: any): void

```js
// 在App上打开指定的EventStore页面
ttHigo.openStore('store ID');
```

## 8、openBrand(brandId: number, extraOptions?: any): void

```js
// 在App上打开指定的品牌商页面
ttHigo.openBrand('brand ID');
```

## 9、openShoppingCart(extraOptions?: any): void

```js
// 在APP上打开购物车页面
ttHigo.openShoppingCart();
```

## 10、addProductToCart(itemNumber, extraOptions?: any): Promise<bool>

```js
// 添加商品到购物车
ttHigo.addProductToCart(itemNumber); // itemNumber，为商品编号
```

## 11、close(extraOptions?: any): void

```js
// 关闭Webview（路由goBack）
ttHigo.close();
```

## 12、openUrl(url, extraOptions?: any): void （注：暂未启用）

```js
// 使用UniversalWebview 打开页面
ttHigo.openUrl(url);
```

## 13、openShareModal(shareChannels: string[], extraOptions?: any): void
> 该方法用于自定义分享渠道及分享数据，如果要自定义分享数据 channels为必选参数（可以为空数组）
```js
// 传递分享渠道信息并打开分享弹出窗
// 目前支持的分享渠道有 微信 朋友圈 新浪微博 QQ QQ空间
// 分别对应channel: wechat moments weibo qq qqzone
// 如果没有传递，默认是全部渠道
/**
   * 传递分享渠道信息并打开分享弹出窗
   * @param {Array} channels 渠道列表
   * @param {object} extraOptions 额外参数
   * @param {string} [extraOptions.shareTitle] 分享标题，默认为“TT海购”
   * @param {string} [extraOptions.shareLink] 分享链接，默认为“https://www.tthigo.com”
   * @param {string} [extraOptions.shareImgUrl] 分享图片链接，默认为“https://c9.neweggimages.com.cn/Higo/images/NavyBlueLogo_120.png”
   * @param {string} [extraOptions.shareDescription] 分享描述，默认为“推荐给你tt海购正品精选好物，点开看看吧”
   */
ttHigo.openShareModal(['channel1','channel2'], extraOptions);
```

## 14、openBindPhone(extraOptions?:any): void

```js
// 打开绑定手机号页面
const result = await ttHigo.openBindPhone();
console.log(result);
```

## 15、监控页面前置

```js
document.addEventListener('higoWebviewFocus', ()=>{
  console.log('focus', '当前活动页面为WebView');
});
```

## 16、监控页面后置

```js
document.addEventListener('higoWebviewBlur', ()=>{
  console.log('blur', '已经跳出Webview');
});
```

# 如何开发？

```bash
npm i
# run dev
npm run dev
# run build
npm run build
```

---
_Source: https://npm.io/package/tthg-jssdk · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
