基于微信小程序的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下载

相关推荐
叼烟扛炮3 小时前
Linux 学习笔记(五十八):IO 多路复用封神——epoll 底层原理揭秘
linux·运维·服务器·网络·笔记·学习·php
陈布衣4 小时前
MySQL(1)_MySQL 5.7.21 Linux 安装笔记
linux·笔记·mysql
律宏阔6 小时前
Taro 4 项目从 npm 迁移到 pnpm 踩坑实录
前端·微信小程序·taro
缘来是你远去是我7 小时前
本地个人笔记exe
笔记
FakeOccupational8 小时前
【电路笔记 STM32】RTC配置:晶振选择+闹钟Configuration+中断设置
笔记·stm32·实时音视频
迪康coolmu8 小时前
企业U盘管控落地实战:基于迪康端点安全一体化管理系统的移动存储安全实践
运维·人工智能·经验分享·笔记·安全·电脑
恩创软件开发9 小时前
自助KTV系统管理员续单功能
经验分享·小程序
Z21-X11 小时前
云原生运维学习笔记:容器技术的演进、底层原理与 Docker 全生命周期管理
运维·笔记·学习·云原生
Rabitebla19 小时前
【Linux 底层原理】进程(十):进程等待详解---从僵尸进程到 wait、waitpid 与 status
linux·c++·笔记·学习·visual studio
小lu飞20 小时前
2026小红书小工具怎么制作:纯前端 ZIP 打包、沙箱限制与笔记挂载流程
前端·笔记·ai·ai编程