杨成耀
杨成耀
  • 发布:2022-09-29 00:02
  • 更新:2022-09-29 00:02
  • 阅读:404

【报Bug】uni-id-users.schema.json和uni-user-profile.vue相关的错误

分类:uni-app

产品分类: uniapp/小程序/微信

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: 正式

HBuilderX版本号: 3.5.3

第三方开发者工具版本号: 1.06

基础库版本号: 1.06

项目创建方式: HBuilderX

操作步骤:

微信小程序登录 控制台输出 数据库权限错误

预期结果:

修正错误,数据库能正常写入用户昵称

实际结果:

目前bug没有修改

bug描述:

这是用户表的

{  
    "bsonType": "object",  
    "required": ["username", "password"],  
    "permission": {  
        "read": "'READ_UNI_ID_USERS' in auth.permission",  
        "create": "'CREATE_UNI_ID_USERS' in auth.permission",  
        "update": "'UPDATE_UNI_ID_USERS' in auth.permission",  配置了这个权限,小程序端微信登录的时候,无法更改用户昵称  
        "delete": "'DELETE_UNI_ID_USERS' in auth.permission"  
    },  
    "properties": {  
        "_id": {  
            "description": "存储文档 ID(用户 ID),系统自动生成"  
        },  
        "username": {  
            "bsonType": "string",  
            "title": "用户名",  
            "description": "用户名,不允许重复",  
            "trim": "both",  
            "minLength": 2  
        },  
        "password": {  
            "bsonType": "password",  
            "title": "密码",  
            "description": "密码,加密存储",  
            "trim": "both",  
            "minLength": 6  
        },  
        "password_secret_version": {  
            "bsonType": "int",  
            "title": "passwordSecret",  
            "description": "密码使用的passwordSecret版本"  
        },  
        "nickname": {  
            "bsonType": "string",  
            "title": "昵称",  
            "description": "用户昵称",  
            "trim": "both"  
        },  
        "gender": {  
            "bsonType": "int",  
            "title": "性别",  
            "description": "用户性别:0 未知 1 男性 2 女性",  
            "defaultValue": 0,  
            "enum": [{  
                "text": "未知",  
                "value": 0  
            }, {  
                "text": "男",  
                "value": 1  
            }, {  
                "text": "女",  
                "value": 2  
            }]  
        },  
        "status": {  
            "bsonType": "int",  
            "description": "用户状态:0 正常 1 禁用 2 审核中 3 审核拒绝",  
            "title": "用户状态",  
            "defaultValue": 0,  
            "enum": [{  
                "text": "正常",  
                "value": 0  
            }, {  
                "text": "禁用",  
                "value": 1  
            }, {  
                "text": "审核中",  
                "value": 2  
            }, {  
                "text": "审核拒绝",  
                "value": 3  
            }]  
        },  
        "mobile": {  
            "bsonType": "string",  
            "title": "手机号码",  
            "description": "手机号码",  
            "pattern": "^\\+?[0-9-]{3,20}$",  
            "trim": "both"  
        },  
        "mobile_confirmed": {  
            "bsonType": "int",  
            "description": "手机号验证状态:0 未验证 1 已验证",  
            "title": "手机号验证状态",  
            "defaultValue": 0,  
            "enum": [{  
                "text": "未验证",  
                "value": 0  
            }, {  
                "text": "已验证",  
                "value": 1  
            }]  
        },  
        "email": {  
            "bsonType": "string",  
            "format": "email",  
            "title": "邮箱",  
            "description": "邮箱地址",  
            "trim": "both"  
        },  
        "email_confirmed": {  
            "bsonType": "int",  
            "description": "邮箱验证状态:0 未验证 1 已验证",  
            "title": "邮箱验证状态",  
            "defaultValue": 0,  
            "enum": [{  
                "text": "未验证",  
                "value": 0  
            }, {  
                "text": "已验证",  
                "value": 1  
            }]  
        },  
        "avatar": {  
            "bsonType": "string",  
            "title": "头像地址",  
            "description": "头像地址",  
            "trim": "both"  
        },  
        "role": {  
            "bsonType": "array",  
            "title": "角色",  
            "description": "用户角色",  
            "enum": {  
                "collection": "uni-id-roles",  
                "field": "role_id as value, role_name as text"  
            },  
            "foreignKey": "uni-id-roles.role_id",  
            "permission": {  
                "write": false  
            }  
        },  
        "dcloud_appid": {  
            "bsonType": "array",  
            "title": "可登陆应用appid",  
            "description": "可登陆应用appid",  
            "enum": {  
                "collection": "opendb-app-list",  
                "field": "appid as value, name as text"  
            },  
            "foreignKey": "opendb-app-list.appid",  
            "permission": {  
                "write": false  
            }  
        },  
        "tags": {  
            "bsonType": "array",  
            "title": "用户标签tagid",  
            "description": "用户标签tagid",  
            "enum": {  
                "collection": "uni-id-tag",  
                "field": "tagid as value, name as text"  
            },  
            "foreignKey": "uni-id-tag.tagid",  
            "permission": {  
                "write": false  
            }  
        },  
        "wx_unionid": {  
            "bsonType": "string",  
            "description": "微信unionid"  
        },  
        "wx_openid": {  
            "bsonType": "object",  
            "description": "微信各个平台openid",  
            "properties": {  
                "app-plus": {  
                    "bsonType": "string",  
                    "description": "app平台微信openid"  
                },  
                "mp-weixin": {  
                    "bsonType": "string",  
                    "description": "微信小程序平台openid"  
                }  
            }  
        },  
        "ali_openid": {  
            "bsonType": "string",  
            "description": "支付宝平台openid"  
        },  
        "comment": {  
            "bsonType": "string",  
            "title": "备注",  
            "description": "备注",  
            "trim": "both"  
        },  
        "realname_auth": {  
            "bsonType": "object",  
            "description": "实名认证信息",  
            "required": ["type", "auth_status"],  
            "properties": {  
                "type": {  
                    "bsonType": "int",  
                    "minimum": 0,  
                    "maximum": 1,  
                    "description": "用户类型:0 个人用户 1 企业用户"  
                },  
                "auth_status": {  
                    "bsonType": "int",  
                    "minimum": 0,  
                    "maximum": 3,  
                    "description": "认证状态:0 未认证 1 等待认证 2 认证通过 3 认证失败"  
                },  
                "auth_date": {  
                    "bsonType": "timestamp",  
                    "description": "认证通过时间"  
                },  
                "real_name": {  
                    "bsonType": "string",  
                    "description": "真实姓名\/企业名称"  
                },  
                "identity": {  
                    "bsonType": "string",  
                    "description": "身份证号码\/营业执照号码"  
                },  
                "id_card_front": {  
                    "bsonType": "string",  
                    "description": "身份证正面照 URL"  
                },  
                "id_card_back": {  
                    "bsonType": "string",  
                    "description": "身份证反面照 URL"  
                },  
                "in_hand": {  
                    "bsonType": "string",  
                    "description": "手持身份证照片 URL"  
                },  
                "license": {  
                    "bsonType": "string",  
                    "description": "营业执照 URL"  
                },  
                "contact_person": {  
                    "bsonType": "string",  
                    "description": "联系人姓名"  
                },  
                "contact_mobile": {  
                    "bsonType": "string",  
                    "description": "联系人手机号码"  
                },  
                "contact_email": {  
                    "bsonType": "string",  
                    "description": "联系人邮箱"  
                }  
            }  
        },  
        "register_date": {  
            "bsonType": "timestamp",  
            "description": "注册时间",  
            "forceDefaultValue": {  
                "$env": "now"  
            },  
            "title": "注册时间"  
        },  
        "register_ip": {  
            "bsonType": "string",  
            "description": "注册时 IP 地址",  
            "forceDefaultValue": {  
                "$env": "clientIP"  
            }  
        },  
        "last_login_date": {  
            "bsonType": "timestamp",  
            "description": "最后登录时间"  
        },  
        "last_login_ip": {  
            "bsonType": "string",  
            "description": "最后登录时 IP 地址"  
        },  
        "token": {  
            "bsonType": "array",  
            "description": "用户token"  
        },  
        "inviter_uid": {  
            "bsonType": "array",  
            "description": "用户全部上级邀请者",  
            "trim": "both"  
        },  
        "my_invite_code": {  
            "bsonType": "string",  
            "description": "用户自身邀请码"  
        }  
    }  
}  

同时微信小程序获取的用户头像数据字段avatar_file也和用户表字段avatar不对应
以下是小程序调试输出的字段
{nickname: "xxxx", avatar_file: {…}}
avatar_file: {name: "633453340f90b70001accc2a/1664379963863avatarUrl.jpg", extname: "jpg", url: "https://vkceyugu.cdn.bspapp.com/VKCEYUGU-a78a775c-…8ea501ab/6c1b3988-5e13-8-515774dd77ef.jpg"}
nickname: "xxxx"
proto: Object

这里是uni-user-profile.vue内提交用户表修改的方法
doUpdate(data,callback){
console.log('dododo',data);

            // 使用 clientDB 提交数据  
            usersTable.where('_id==$env.uid').update(data).then((res) => {  
                console.log(res);  
                this.setUserInfo(data);  
                callback(res)  
            }).catch((err) => {  
                uni.showModal({  
                    content: err.message ||  
                        '请求服务失败',  
                    showCancel: false  
                })  
                callback(err)  
            }).finally(() => {  
                // console.log("权限错误")  
                this.$emit('next')  
                uni.hideLoading()  
            })  
        }  

最终问题:微信小程序采用微信登录数据库权限报错。
如果把用户表 "update": "'UPDATE_UNI_ID_USERS' in auth.permission", 更改成"update": true 那么报错数据库验证失败:提交的字段["avatar_file"]在云端数据表的schema文件中不存在"

我不知道是我哪里更新错误还是怎么的。但代码的确有问题。

2022-09-29 00:02 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复