自学uniapp开发一个文案句子小程序(2)

服务端使用uniapp 云开发 uniCloud.

使用云开发的好处:

  • 费用低甚至免费,uniCloud 有免费版本,一个账号貌似只可以申请一个,不过开发一个小程序足够用了。
  • 使用uniClound 免去了申请域名以及 HTTPS证书的购买。微信小程序 要进行服务端 请求的地址必须是 HTTPS 证书的。按照传统开发的话,要购买服务器,购买域名,还要购买ssl证书。全套下来 还没开始就已经 被坑了。
  • 数据库管理、云函数、触发器等服务端需要的功能完全满足使用,且简单易学有很多的官方模板。

数据库表设计:

  • 笔记表:专门一个表来保存所有的句子记录,我这个称它为笔记。这个表里面信息包括,笔记内容,笔记类型,发布状态(来管理或者下架文章),创建用户等信息。
  • 互动记录:其实官方有一个完整的 后端模板,这里因为是学习还是自己做一个互动记录表。这个表主要存 用户对笔记的所有操作记录。如:用户id,笔记id,操作类型(收藏、点赞、查看等),文章分变化(计入文章的评估分数,可以理解为热度),用户分变化(计入用户的成长分)

示例:
在这里插入图片描述
笔记表:


// ainotes-echo.schema.json 
// 笔记表字段,只需要创建这样一个 json,就可以创建表和字段,以及权限设置 ,清晰的一目了然,非常好用。
{
	"bsonType": "object",
	"required": [
		"user_id",
		"users_type"
	],
	"permission": {
	    "read": "auth.uid != null || doc.echo_content_type == '系统'", // 登录用户可读,或者 非用户创建的 任何人都刻度
	    "create": "auth.uid != null", // 登录用户才可以新增(admin权限用户不受限)
	    "update": "auth.uid == doc.user_id", // 用户只可以修改自己的(admin权限用户不受限)
	    "delete": false, // 禁止删除数据(admin权限用户不受限)
	    "count": false // 禁止查询数据条数(admin权限用户不受限),新增于HBuilderX 3.1.0
	},
	"properties": {
		"_id": {
			"description": "ID,系统自动生成"
		},
		"user_id": {
			"bsonType": "string",
			"description": "用户id,参考uni-id-users表",
			"foreignKey": "uni-id-users._id",
			"forceDefaultValue":{
				"$env": "uid"
			}
		},
		"note": {
			"bsonType": "string",
			"description": "笔记内容"
		},
		"result": {
			"bsonType": "bool",
			"description": "发布结果,true:成功,false:失败"
		},
		"note_type": {
			"bsonType": "int",
			"title": "记录种类",
			"description": "记录种类:1 冷笑话 2 普通笑话 3浪漫情话 4 土味情话 5 心灵鸡汤 6 贡献",
			"enum": [1,2,3,4,5,6]
		},
		"look_count":{
			"bsonType": "int",
			"description": "查看数量",
			"defaultValue":0
		},
		"like_count":{
			"bsonType": "int",
			"description": "喜欢数量",
			"defaultValue":0
		},
		"save_count":{
			"bsonType": "int",
			"description": "收藏数量",
			"defaultValue":0
		},
		"copy_count":{
			"bsonType": "int",
			"description": "复制数量",
			"defaultValue":0
		},
		"note_count":{
			"bsonType": "int",
			"description": "笔记数量",
			"defaultValue":0
		},
		"total_score":{
			"bsonType": "int",
			"description": "总分",
			"defaultValue":0
		},
		
		"echo_content_type": {
			"bsonType": "string",
			"title": "内容来源",
			"description": "内容来源:系统 作者 共鸣",
			"enum": ["系统","作者","共鸣"]
		},
		"sign":{
			"bsonType": "string",
			"description": "署名",
			"defaultValue":"系统"
		},
		"ip": {
			"bsonType": "string",
			"description": "IP 地址",
			"forceDefaultValue": {
				"$env": "clientIP"
			}
		},
		"language":{
			"bsonType": "json",
			"description": "多语言",
			"defaultValue": "未知区域",
			// {
			// 	text:'简体中文',
			// 	value:'zh_CN'
			// },{
			// 	text:'中文(HK)',
			// 	value:'zh_HK'
			// },{
			// 	text:'英语',
			// 	value:'en'
			// },{
			// 	text:'日语',
			// 	value:'ja'
			// },
		},
		"area": {
			"bsonType": "json",
			"description": "IP 地址",
			"defaultValue": "未知区域"
			
		},
		"result_json": {
			"bsonType": "json",
			"title": "结果json",
			"description": "记录请求详情"
		},
		"create_date": {
			"bsonType": "timestamp",
			"description": "创建时间",
			"forceDefaultValue": {
				"$env": "now"
			}
		}
	},
	"version": "0.0.1"
}

笔记互动记录表

{
	"bsonType": "object",
	"required": [
		"user_id","note_id"
	],
	"permission": {
	    "read": "auth.uid != null", // 登录用户
	    "create": "auth.uid != null", // 登录用户(admin权限用户不受限)
	    "update": "auth.uid == doc.user_id", // 禁止更新数据(admin权限用户不受限)
	    "delete": false, // 禁止删除数据(admin权限用户不受限)
	    "count": false // 禁止查询数据条数(admin权限用户不受限),新增于HBuilderX 3.1.0
	},
	"properties": {
		"_id": {
			"description": "ID,系统自动生成"
		},
		"user_id": {
			"bsonType": "string",
			"description": "用户id,参考uni-id-users表",
			"foreignKey": "uni-id-users._id",
			"forceDefaultValue":{
				"$env": "uid"
			}
		},
		"note_id": {
			"bsonType": "string",
			"description": "请求字符串",
			"description": "句子编号",
			"foreignKey": "hiainotes-echo._id"
		},
		"result": {
			"bsonType": "bool",
			"description": "任务执行结果,true:成功,false:失败"
		},
		"echo_type": {
			"bsonType": "string",
			"title": "记录种类",
			"description": "记录种类:摘抄 笔记 共鸣 私藏 心灵鸡汤",
			// "enum": ["摘抄","笔记","共鸣","分享"],
			"enum":["笔记","查看","收藏","喜欢","复制","摘抄","取消喜欢","取消收藏"]
		},
		"note_score":{
			"bsonType": "int",
			"description": "文章分数变动",
			"defaultValue":0
		},
		"user_score":{
			"bsonType": "int",
			"description": "用户分数变动",
			"defaultValue":0
		},
		"emotion":{
			"bsonType": "string",
			"title": "情绪",
			"description": "记录种类:系统 作者 共鸣",
			"enum": ["安静","喜悦","限怒","哀冷","悲痛","忧愁","愤急","烦闷","惊骇","恭敬","抚爱","憎恶","贪欲","嫉妒","傲慢","惭愧","耻辱"]
		},
		"ip": {
			"bsonType": "string",
			"description": "IP 地址",
			"forceDefaultValue": {
				"$env": "clientIP"
			}
		},
		"area": {
			"bsonType": "json",
			"description": "IP 地址",
			"defaultValue": "未知区域"
		},
		"text": {
			"bsonType": "string",
			"title": "结果json",
			"description": "记录请求详情"
		},
		"create_date": {
			"bsonType": "timestamp",
			"description": "创建时间",
			"forceDefaultValue": {
				"$env": "now"
			}
		}
	},
	"version": "0.0.1"
}

用户、登录记录表

这里注意,因为使用了uniCloud ,以上表只是自己功能需要的表。不包含用户、权限、角色 等其他公共表。因为官方提供了 整套开箱即用的模板。所以这些表都用官方的 uni-id-common

链接:uniCloud官方用户体系文档

已经实现的功能截图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你曾记得认识的那家花店吗

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值