nx-xcx-login
v1.1.17
Published
农信小程序登录组件
Downloads
25
Readme
nx-xcx-login
农信小程序登录组件:
- 集成手机号登录(微信)
- 集成账号密码登录
- 集成快捷登录,手机号+验证码,未注册时创建用户
前提条件
- 绑定至开放平台
- 报备wxAppId,secret
使用
- 在小程序根目录上执行 npm init 或 yarn init
- 使用 npm install nx-xcx-login --save 安装小程序npm
- 安装utils库:npm install nx-xcx-utils
- 勾选 详情-》本地设置 下的使用npm模块
- 点击菜单 工具-》构建npm
- 在使用的页面的 json 文件 usingComponents 节点下添加 "nx-xcx-login": "nx-xcx-login"
登录参数配置
- 相关文档 https://www.npmjs.com/package/nx-xcx-utils
- 在app.js里
import { configLogin } from 'nx-xcx-utils';
configLogin({
env: 1, //环境信息,根据此配置将请求信息推送至不同的采集站,1:测试 2:预生产 3:正式
loginPage: '登录页地址',
failPage: '授权失败地址,ex:授权取消',
systemId: 1,
channel: '短信通道',
theme: '主题配置'
});
- 页面中配置登录拦截
import { logout, getLoginUser, logout, loginBehavior } from 'nx-xcx-utils';
behaviors: [loginBehavior] // 放置于data同级处,标识页面需要登录
// 获取登录用户
// 如果已经登录,直接从stoge里获取用户信息
// 如果用户未登录,先使用wx.login获取code,然后接口查询,如果用户已经绑定过,根据用户信息进行会话设置并返回,如果flag为false,则返回null,如果flag为true则reject
getLoginUser(flag: boolean = false): Promise<LoginUser>
getLoginUserSync(): LoginUser | null // 获取登录用户信息(同步方法),仅从stoge里获取
// 退出
// flag为false是仅清理stoge中用户信息,flag为true时除清理stoge中用户信息外还将解绑微信, webview中会话信息请自行清理
logout(flag: boolean = false): Promise<boolean>
- theme 主题(可选),可用值及对应色值 theme_sc #ff0023 theme_zx #ff2c71 theme_egg #f5cf49 theme_black #262a2f theme_gray #47525d theme_blue #2d86fe theme_green #22d7bb theme_orange #ff9600
参数说明
- title 授权页标题,请填写小程序所属产品名称
- icon 授权页图标,请使用小程序所属产品图标
- retUrl 授权取消时回退页面,应该配置为小程序登录前页面,由拦截器根据当前地址决定,做为动态参数传入登录页
新增页面web-container,用于小程序内html内容的状态同步(小程序登录后,webview也登录)
- 请在app.json里先进行注册
- 使用wx.redirectTo或wx.reLaunch加载,参数如下
| 参数 | 说明 | | ---- | ---- | | url | 要到的目标页(请编码) | | flag | true/false,是否需要处理登录 |