基于微信小程序的CMS内容管理系统开发笔记

背景调研

内容管理CMS小程序的帮助运营者创建和管理小程序内容,提供一个直观的操作界面,能够轻松地添加、编辑和发布内容,而无需了解复杂的编程知识。可以进行栏目管理,文章管理,编辑文章内容,包括文字、图片等操作

功能设计

管理端:
  • 分类管理:提供一级分类,二级分类管理
  • 文章管理:方便的进行文章录入和修改,提供适应小程序排版的图文混排编辑器。
  • 首页轮播图:可设置首页轮播图,支持链接到本地文章或者外部文章
用户端:
  • 分类展示:按一级,二级分类展示
  • 文章展示:文章检索,文章点赞,评论,分享(海报,卡片),
  • 排行榜:可按评论,浏览数,点赞数,收藏数进行排行
  • 个人中心:可修改个人资料,查看自己的点赞,浏览,收藏,评论记录等。

结构图

数据设计

bash 复制代码
ProductModel.DB_STRUCTURE = {
	_pid: 'string|true',
	PRODUCT_ID: 'string|true',

	PRODUCT_TITLE: 'string|false|comment=标题',
	PRODUCT_STATUS: 'int|true|default=1|comment=状态 0/1',

	PRODUCT_CATE_ID: 'array|true|comment=分类编号',
	PRODUCT_CATE_NAME: 'array|true|comment=分类冗余',

	PRODUCT_ORDER: 'int|true|default=9999',
	PRODUCT_VOUCH: 'int|true|default=0',

	PRODUCT_COMMENT_CNT: 'int|true|default=0',

	PRODUCT_QR: 'string|false',
	PRODUCT_VIEW_CNT: 'int|true|default=0|comment=访问次数',

	PRODUCT_COMMENT_CNT: 'int|true|default=0|comment=评论数',
	PRODUCT_FAV_CNT: 'int|true|default=0|comment=收藏数',
	
	PRODUCT_LIKE_CNT: 'int|true|default=0|comment=点赞数',
	PRODUCT_LIKE_LIST: 'array|true|default=[]|comment=点赞记录',

	PRODUCT_FORMS: 'array|true|default=[]',
	PRODUCT_OBJ: 'object|true|default={}',

	PRODUCT_ADD_TIME: 'int|true',
	PRODUCT_EDIT_TIME: 'int|true',
	PRODUCT_ADD_IP: 'string|false',
	PRODUCT_EDIT_IP: 'string|false',
};

Cate1Model.DB_STRUCTURE = {
	_pid: 'string|true',
	CATE1_ID: 'string|true',

	CATE1_ORDER: 'int|true|default=9999',
	CATE1_VOUCH: 'int|true|default=0',

	CATE1_TITLE: 'string|false|comment=标题',
	CATE1_STATUS: 'int|true|default=1|comment=状态 0/1',

	CATE1_CNT: 'int|true|default=0',

	CATE1_FORMS: 'array|true|default=[]',
	CATE1_OBJ: 'object|true|default={}',

	CATE1_ADD_TIME: 'int|true',
	CATE1_EDIT_TIME: 'int|true',
	CATE1_ADD_IP: 'string|false',
	CATE1_EDIT_IP: 'string|false',
};

Cate2Model.DB_STRUCTURE = {
	_pid: 'string|true',
	CATE2_ID: 'string|true',

	CATE2_ORDER: 'int|true|default=9999',

	CATE2_CATE1_ID: 'string|true',
	CATE2_TITLE: 'string|false|comment=标题',
	CATE2_STATUS: 'int|true|default=1|comment=状态 0/1',

	CATE2_CNT: 'int|true|default=0',

	CATE2_FORMS: 'array|true|default=[]',
	CATE2_OBJ: 'object|true|default={}',

	CATE2_ADD_TIME: 'int|true',
	CATE2_EDIT_TIME: 'int|true',
	CATE2_ADD_IP: 'string|false',
	CATE2_EDIT_IP: 'string|false',
};

核心实现

bash 复制代码
async likeProduct(userId, id) {
		// 是否点赞
		let product = await ProductModel.getOne(id, 'PRODUCT_LIKE_LIST');
		if (!product) this.AppError('记录不存在');

		let arr = product.PRODUCT_LIKE_LIST;
		let flag = false;
		if (arr.includes(userId)) {
			arr = arr.filter(item => item != userId);
			flag = false;
		}
		else {
			arr.push(userId);
			flag = true;
		}
		await ProductModel.edit(id, {
			PRODUCT_LIKE_LIST: arr,
			PRODUCT_LIKE_CNT: arr.length
		});

		return flag;
	}

	/** 浏览资讯信息 */
	async viewProduct(userId, id) {

		let fields = '*';

		let where = {
			_id: id,
			PRODUCT_STATUS: 1
		}
		let product = await ProductModel.getOne(where, fields);
		if (!product) return null;

		product.like = product.PRODUCT_LIKE_LIST.includes(userId) ? true : false;

		delete product.PRODUCT_LIKE_LIST;

		ProductModel.inc(id, 'PRODUCT_VIEW_CNT', 1);

		return product;
	}


	/** 取得分页列表 */
	async getProductList({
		cateId,
		search, // 搜索条件
		sortType, // 搜索菜单
		sortVal, // 搜索菜单
		orderBy, // 排序 
		page,
		size,
		isTotal = true,
		oldTotal
	}) {

		orderBy = orderBy || {
			'PRODUCT_ORDER': 'asc',
			'PRODUCT_ADD_TIME': 'desc'
		};
		let fields = 'PRODUCT_LIKE_CNT,PRODUCT_FAV_CNT,PRODUCT_COMMENT_CNT,PRODUCT_VIEW_CNT,PRODUCT_TITLE,PRODUCT_CATE_ID,PRODUCT_ADD_TIME,PRODUCT_ORDER,PRODUCT_STATUS,PRODUCT_CATE_NAME,PRODUCT_OBJ';

		let where = {};
		where.and = {
			_pid: this.getProjectId() //复杂的查询在此处标注PID
		};
		where.and.PRODUCT_STATUS = 1; // 状态 

		if (cateId && cateId !== '0') where.and.PRODUCT_CATE_ID = cateId;

		if (util.isDefined(search) && search) {
			where.or = [
				{ PRODUCT_TITLE: ['like', search] },
			];
		} else if (sortType && util.isDefined(sortVal)) {
			// 搜索菜单
			switch (sortType) {
				case 'sort': {
					orderBy = this.fmtOrderBySort(sortVal, 'PRODUCT_ADD_TIME');
					break;
				}
				case 'cateId': {
					if (sortVal) where.and.PRODUCT_CATE_ID = String(sortVal);
					break;
				}
			}
		}

		return await ProductModel.getList(where, fields, orderBy, page, size, isTotal, oldTotal);
	}

	async getMyLikeProductList(userId, {
		search, // 搜索条件
		sortType, // 搜索菜单
		sortVal, // 搜索菜单
		orderBy, // 排序 
		page,
		size,
		isTotal = true,
		oldTotal
	}) {

		orderBy = orderBy || {
			'PRODUCT_ORDER': 'asc',
			'PRODUCT_ADD_TIME': 'desc'
		};
		let fields = 'PRODUCT_LIKE_CNT,PRODUCT_FAV_CNT,PRODUCT_COMMENT_CNT,PRODUCT_VIEW_CNT,PRODUCT_TITLE,PRODUCT_CATE_ID,PRODUCT_ADD_TIME,PRODUCT_ORDER,PRODUCT_STATUS,PRODUCT_CATE_NAME,PRODUCT_OBJ';

		let where = {};
		where.and = {
			_pid: this.getProjectId() //复杂的查询在此处标注PID
		};
		where.and.PRODUCT_LIKE_LIST = userId; 


		if (util.isDefined(search) && search) {
			where.or = [
				{ PRODUCT_TITLE: ['like', search] },
			];
		} else if (sortType && util.isDefined(sortVal)) {
			// 搜索菜单
			switch (sortType) {
				case 'sort': {
					orderBy = this.fmtOrderBySort(sortVal, 'PRODUCT_ADD_TIME');
					break;
				}
			}
		}

		return await ProductModel.getList(where, fields, orderBy, page, size, isTotal, oldTotal);
	}

UI设计



管理后台设计



代码

git下载

相关推荐
再睡一夏就好15 小时前
【C++闯关笔记】详解多态
c语言·c++·笔记·学习·语法·1024程序员节
断剑zou天涯16 小时前
【算法笔记】暴力递归尝试
java·笔记·算法
摇滚侠18 小时前
全面掌握PostgreSQL关系型数据库,备份和恢复,笔记46和笔记47
java·数据库·笔记·postgresql·1024程序员节
kkkkk02110620 小时前
黑马微服务保险(一)
笔记·微服务·架构
hour_go20 小时前
【知识图谱】图神经网络(GNN)核心概念详解:从消息传递到实战应用
笔记·深度学习·神经网络·1024程序员节
摇滚侠20 小时前
全面掌握PostgreSQL关系型数据库,设置远程连接,笔记05,笔记06
java·数据库·笔记·postgresql
蒙奇D索大21 小时前
【数据结构】数据结构核心考点:AVL树删除操作详解(附平衡旋转实例)
数据结构·笔记·考研·学习方法·改行学it·1024程序员节
开心-开心急了21 小时前
Flask入门教程——李辉 第5章: 数据库 关键知识梳理
笔记·后端·python·flask·1024程序员节
charlie1145141911 天前
HTML 理论笔记
开发语言·前端·笔记·学习·html·1024程序员节
知识分享小能手1 天前
uni-app 入门学习教程,从入门到精通,uni-app 企业项目实战:鲁嗑瓜子项目开发知识点(9)
前端·javascript·学习·微信小程序·小程序·uni-app·vue