# nx-xcx-utils

> 农信小程序工具库

Latest version **0.1.16** (published 2025-04-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install nx-xcx-utils
pnpm add nx-xcx-utils
yarn add nx-xcx-utils
bun add nx-xcx-utils
```

## Health

**Score 25/100 (F)** — status: maintenance-mode.

Positive: no vulnerabilities.

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

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.16 |
| Published | 2025-04-14 |
| First published | 2021-03-18 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 52.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | petzold |
| Maintainers | petzold |

## Links

- npm: https://www.npmjs.com/package/nx-xcx-utils
- npm.io page: https://npm.io/package/nx-xcx-utils

## Recent versions

- 0.1.16 (latest) — 2025-04-14
- 0.1.15 — 2022-07-28
- 0.1.14 — 2021-09-28
- 0.1.13 — 2021-09-26
- 0.1.12 — 2021-09-26
- 0.1.11 — 2021-08-19
- 0.1.10 — 2021-08-19
- 0.1.9 — 2021-04-23
- 0.1.8 — 2021-04-21
- 0.1.7 — 2021-04-21
- 0.1.6 — 2021-04-15
- 0.1.5 — 2021-03-31
- 0.1.4 — 2021-03-30
- 0.1.3 — 2021-03-30
- 0.1.2 — 2021-03-30
- … 11 more at https://npm.io/package/nx-xcx-utils/versions

## README

# nx-xcx-utils

小程序 js 库。一些类库的封装。

> 使用此组件需要依赖小程序基础库 2.2.1 以上版本，同时依赖开发者工具的 npm 构建。具体详情可查阅[官方 npm 文档](https://developers.weixin.qq.com/miniprogram/dev/devtools/npm.html)。

## 安装

```bash
npm install --save nx-xcx-utils
```

## 采集站脚本

### configLog配置采集站参数,请在app启动时配置一次即可
### proxyLog包装page属性

```js
import { configLog, proxyLog, gatherBehavior } from 'nx-xcx-utils'

//配置采集信息
configLog({
    env: 1, //环境信息，根据此配置将请求信息推送至不同的采集站，1：测试 2：预生产 3：正式
    code: '采集站分配的码',
    getUid: function() { //登录用户的uid,如未登录返回null
        return 'xx'
    }
});

//上报采集信息,使用代理
Page(proxyLog({
    data: {}, ...
}))

//上报采集信息,使用behaviors

behaviors: [gatherBehavior]

```


## 登录配置

### configLogin配置登录参数,请在app启动时配置一次即可

```js
import { configLogin, login, logout, getLoginUser, loginBehavior } from 'nx-xcx-utils'

//配置登录信息
configLogin({
    env: 1, //环境信息，根据此配置将请求信息推送至不同的采集站，1：测试 2：预生产 3：正式
    domain: 'domain', //一级域名,此配置为支持多个私有化环境,如nxin.com, dbn.cn
    loginPage: '登录页地址',
    failPage: '授权失败地址,ex:授权取消',
    systemId: 1,
    channel: '短信通道',
    theme: '主题配置'
});


interface LoginUser {
    id: string;
    uid: string;
    name: string;
    nickName: string;
    phone: string;
    loginName: string;
    photo: string;
    gender: number;
    ticket: string;
}

login(user: LoginUser): Promise<boolean> //登录,将会话信息写入stoge,用户信息使用/oauth/xcx/wx/get-info-by-code获取

/***
 * @param flag 是否在未登录时通过绑定填充会话
 * @param kfs 是否是小程序开发商模式
 */
getLoginUser(flag: boolean = false, kfs: boolean = false): Promise<LoginUser> //获取登录的用户信息

/***
 * @param flag 是否解绑 
 * @param kfs 是否是小程序开发商模式
 */
logout(flag: boolean = false, kfs: boolean = false)： Promise<boolen> // 清理会话信息

//配置页面需要登录信息,使用behaviors

behaviors: [loginBehavior]

```

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