xxx.schema.json文件内容如下
复制代码{
"bsonType": "object",
"required": [],
"permission": {
"read": true,
"create": false,
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"title": {
"bsonType": "string",
"description": "文章题目",
"title": "文章题目"
},
"content": {
"bsonType": "string",
"description": "文章内容",
"title": "文章内容"
},
"create_user": {
"bsonType": "string",
"foreignKey": "uni-id-users._id",
"description": "新建该计划的用户ID",
"forceDefaultValue": {
"$env": "uid"
}
}
}
}
前端代码(使用schema2code生成)
复制代码<template>
<view class="uni-container">
<uni-forms ref="form" :value="formData" validate-trigger="submit" err-show-type="toast">
<uni-forms-item name="title" label="文章题目">
<uni-easyinput placeholder="文章题目" v-model="formData.title"></uni-easyinput>
</uni-forms-item>
<uni-forms-item name="content" label="文章内容">
<uni-easyinput placeholder="文章内容" v-model="formData.content"></uni-easyinput>
</uni-forms-item>
<view class="uni-button-group">
<button type="primary" class="uni-button" @click="submit">提交</button>
</view>
</uni-forms>
</view>
</template>
<script>
import {
validator
} from '../../js_sdk/validator/admin-article-test.js';
const db = uniCloud.database();
const dbCollectionName = 'admin-article-test';
function getValidator(fields) {
let result = {}
for (let key in validator) {
if (fields.indexOf(key) > -1) {
result[key] = validator[key]
}
}
return result
}
export default {
data() {
let formData = {
"title": "",
"content": ""
}
return {
formData,
formOptions: {},
rules: {
...getValidator(Object.keys(formData))
}
}
},
onReady() {
this.$refs.form.setRules(this.rules)
},
methods: {
/**
* 触发表单提交
*/
submit() {
uni.showLoading({
mask: true
})
this.$refs.form.validate().then((res) => {
this.submitForm(res)
}).catch(() => {
uni.hideLoading()
})
},
submitForm(value) {
// 使用 clientDB 提交数据
db.collection(dbCollectionName).add(value).then((res) => {
uni.showToast({
icon: 'none',
title: '新增成功'
})
this.getOpenerEventChannel().emit('refreshData')
setTimeout(() => uni.navigateBack(), 500)
}).catch((err) => {
uni.showModal({
content: err.message || '请求服务失败',
showCancel: false
})
}).finally(() => {
uni.hideLoading()
})
}
}
}
</script>
8***@qq.com (作者)
现在的权限限制又过于强了,false的时候连admin用户都创建不了,只能把false随便改成一个 xxx in auth.permission,这样admin用户才能创建
2021-09-03 10:58
DCloud_uniCloud_WYQ
回复 8***@qq.com: 了解,我们调整下
2021-09-03 15:26
DCloud_uniCloud_WYQ
回复 8***@qq.com: 感谢你的反馈,此问题已修复
2021-09-03 15:48