1.在uni-id目录下创建hooks,在hooks里面创建index.js(作用看https://doc.dcloud.net.cn/uniCloud/uni-id/summary.html#hooks)
然后修改成这样填入里面,userRecord是返回到数据库插入的值,而这个钩子是在创建用户之前有效,
Math.random().toString(36).substring(3,9);这个是后面加上随机值tostring(36)是转换为36进制的文本,substring是截取3到9个
// 钩子函数示例 hooks/index.js
function beforeRegister({
userRecord,
clientInfo
} = {}) {
userRecord.username='游客'+(Math.random().toString(36).substring(3,9));
}
return userRecord // 务必返回处理后的userRecord
}
module.exports = {
beforeRegister
}