CMS content management system development notes based on WeChat applet

Background research

Content management CMS applet helps operators create and manage applet content, providing an intuitive operation interface that can easily add, edit and publish content without knowing complex programming knowledge. You can perform column management, article management, and edit article content, including text, pictures, etc.

feature design

Management side:

  • Classification management: Provide first-level classification and second-level classification management
  • Article management: Conveniently enter and modify articles, and provide an image and text editor that is suitable for mini program layout.
  • Home page carousel: You can set a home page carousel, supporting links to local articles or external articles.

user terminal:

  • Classification display: display by first-level and second-level classification
  • Article display: article retrieval, article likes, comments, sharing (posters, cards),
  • Ranking: You can rank by comments, views, likes, and collections
  • Personal Center: You can modify personal information, view your likes, browsing, collections, comment records, etc.

Structure diagram

data design

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',
};

core implementation

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 design

Management background design

code

git download

Linus took it upon himself to prevent kernel developers from replacing tabs with spaces. His father is one of the few leaders who can write code, his second son is the director of the open source technology department, and his youngest son is an open source core contributor. Robin Li: Natural language will become a new universal programming language. The open source model will fall further and further behind Huawei: It will take 1 year to fully migrate 5,000 commonly used mobile applications to Hongmeng. Java is the language most prone to third-party vulnerabilities. Rich text editor Quill 2.0 has been released with features, reliability and developers. The experience has been greatly improved. Ma Huateng and Zhou Hongyi shook hands to "eliminate grudges." Meta Llama 3 is officially released. Although the open source of Laoxiangji is not the code, the reasons behind it are very heart-warming. Google announced a large-scale restructuring
{{o.name}}
{{m.name}}

Guess you like

Origin my.oschina.net/u/3808186/blog/11048360