更新记录

1.2.1(2022-02-25)

更新依赖

1.2.0(2022-01-08)

密码hash使用sha256,打通Meteor生态

1.1.0(2021-12-31)

每次重连成功后都会进行权限校验,从而不会失败一次断开连接再连接时自动重连

查看更多

平台兼容性

Vue2 Vue3
×
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.1.0 app-vue × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × ×

hj-meteor-account

结合hj-ddp使用

import { init } from "../../uni_modules/hj-ddp/js_sdk";
// 导入插件 -------------********************************************
import { useMeteorAccount } from "../../uni_modules/hj-meteor-account/js_sdk";

// #ifdef H5
export const ddp = init('ws://localhost:3002')
// #endif

// #ifndef H5
export const ddp = init('ws://10.0.2.2:3002')
// #endif
// 使用插件 * 去除插件模式,而是返回一个基于ddp连接的封装对象,插件模式不利于类型推断也可能存在属性覆盖。
// 封装对象返回包含独特方法的新对象更灵活

export const Account = useMeteorAccount(ddp);

属性 state表示插件当前状态:离线、已登录、登陆中,info是用户信息可为空,里塞入一个回调函数会在用户登录登出时调用,第一个参数为user.info

user: {
    state: 0 | 1 | 2; // offline logined loging
    user: any; //可以使用watchEffect等来观察变化,所以去掉了onChange方法
};

用户注册 : u 可以是用户名或者邮箱

 createAccount(u: string, password: string): Promise<any>;

密码登录

 loginWithPassword(u: string, password: string): Promise<any>;

退出

logout():void

例子

// 一个vue3的响应式数据,vue2也支持的啦,不过下面的赋值用set 哦

export const Users = ddp.db.collection('users')
export const user = computed(()=>Account.user)
// 登录
export const signin = async (data) => {
    if (!data.username || !data.password) return
    ddp.loginWithPassword(data.username, data.password).catch(err => {
        uni.showToast({
            title: '密码或者用户名错误'
        })
    });
};
// 注册
export const signup = async (data) => {
    if (!data.username || !data.password || data.password !== data.password1) return
    ddp.createAccount(data.username, data.password).catch(err => {
        uni.showToast({
            title: '注册失败'
        })
    });
};

隐私、权限声明

1. 本插件需要申请的系统权限列表:

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

许可协议

MIT协议

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问