项目一共分为两个端,客户端、管理端(管理后台),客户端是用户直接访问的页面,管理端用于整个项目的日常运营和维护,两个端均采用B/S模式。
前端选用vue3开发,后端选用Java语言开发。
使用到的技术、库或框架
前端:
- html、css、js、ts、vue3.0、sass、vite、axios、elementui
数据库:
- mysql
后端:
- java、springboot、springdatajpa、redis
存储:
- oss
版本控制:
- git
部署发布:
- docker、k8s
管理端主要分为以下几个模块:
- 系统管理
- 配置路由-路由菜单
- 配置主题色
- 配置页面整体布局
- 权限管理
- 管理员管理
- 增删改查
- 权限角色管理
- 增删改查
- 管理员管理
- 用户管理
- 用户增删改查
- 冻结/解冻
- 禁用/解封
- 文章管理
- 删查
- 审核
- 资源管理
- 个人资源
- 删查
- 公共资源
- 审核
- 删查
- 个人资源
用户端主要分为以下几个模块:
- 首页
- 热点文章展示
- 热点资源展示
- 个人空间
- 个人资源
- 展示、搜索查看、上传、删除
- 个人文章
- 展示、修改、删除、新建、隐藏
- 个人资料
- 编辑、上传头像
- 退出登录
- 个人资源
- 社区
- 资源
- 展示、搜索查看、下载
- 文章
- 评论
- 删除自己的评论
- 给别人评论点赞
- 举报别人评论
- 点赞、收藏
- 举报
- 评论
- 资源
- 查看其他用户
- 文章&资源
- 评论
- 删除自己的评论
- 给别人评论点赞
- 举报别人评论
- 点赞、收藏
- 举报
- 评论
- 文章&资源
version1.0
后台
后台通过goadmin搭建起来
基础功能
- 配置菜单
- 权限管理功能
- 管理员管理功能
基础业务(以菜单区分模块)
- 用户管理
- 用户增删改查
- 冻结/解冻
- 禁用/解封
- 文章管理
- 删查
- 审核
- 分类管理
- 资源管理
- 公共资源管理(官方)
- 审核
- 删查
- 公共资源管理(官方)
用户
- 首页
- 首页轮播图配置
- 热点文章展示
- 热点资源展示
- 个人空间
- 个人文章
- 展示、修改、删除、新建、隐藏
- 个人资料
- 编辑、上传头像
- 退出登录
- 个人文章
- 社区
- 资源
- 展示、搜索查看、下载
- 文章
- 评论
- 删除自己的评论
- 给别人评论点赞
- 举报别人评论
- 点赞、收藏
- 举报
- 评论
- 资源
- 查看其他用户
表
1. 新建数据库:pealt
2. 新建查询:init
3. 新建表
admin(管理员):
- id
- email:邮箱
- mobile:电话
- name:名字
- password:密码(base64加密)
- role_id:角色id
- img:图片
- status:状态 0禁用、1启用
- created_at:创建时间
- signin_at:登录时间
admin_session(admin登录记录):
- id
- admin_id:admin的id
- token:登录的token
- signin_at:登录时间
- expire_at:登录过期时间
article(文章)
- id
- title:标题
- content:内容
- cover:封面
- descr:描述
- type:类型 1 官方 2 个人
- user_id:用户id
- status:状态 0 草稿(未发布) 1 上架(发布)2 下架 (不能对状态0进行下架处理)3 审核中
- last_modified: 修改时间
- created_at:创建时间
article_tag(文章标签)
- article_id:文章id
- category_id:分类id
- like_num:点赞数
- collect_num:收藏数
- comment_num:评论数
- pv:浏览数
- tag_ids:标签id列表
- status:状态
- created_at:创建时间
category(文章类型)
- id
- name:名字
- priority:权重
- parent_id:父id
- cover:封面
- icon:图标
- status:状态 0 禁用 1 启用
- created_at:创建时间
comment(评论)
comment_settings(评论设置)
level(等级)
- name:名字
- icon:图标
- empirical_val:经验值
- font_color:文字颜色
- border_color:边框颜色
- created_at:创建时间
role(角色)
- id
- name:名字
- permissions:权限列表
tag(标签)
- name:名字
- priority:权重
- border_color:颜色
- font_color:颜色
- status:状态
- created_at:创建时间
user(用户)
- id
- name:名字
- mobile:电话
- user_info:详细信息
- fan_num:粉丝数
- sex:性别
- avatar:头像
- created_at:创建时间
- password:密码
- signin_at:最后登录时间
- status:状态
- nickname:昵称
核心代码
前端权限认证
router.beforeEach(async (to, from, next) => {// start progress barNProgress.start();// set page titleconst title = (to.meta.title as string) || '';document.title = getPageTitle(title);// determine whether the user has logged inconst hasToken = getToken();if (hasToken) {if (to.path === loginPath) {// if is logged in, redirect to the home pagenext({ path: '/' });NProgress.done();} else {const store = useStore();// determine whether the user has obtained his permission roles through getInfoconst hasRoles = store.state.user.roles && store.state.user.roles.length > 0;if (hasRoles) {next();} else {try {// get user info// note: roles must be a object array! such as: ['admin'] or ,['developer','editor']const { roles } = await store.dispatch(UserActionTypes.ACTION_GET_USER_INFO, undefined);// generate accessible routes map based on rolesconst accessRoutes = await store.dispatch(RouterActionTypes.ACTION_GET_ROUTES, undefined);// dynamically add accessible routesaccessRoutes.forEach(item => {router.addRoute(item);});// hack method to ensure that addRoutes is complete// set the replace: true, so the navigation will not leave a history recordnext({ ...to, replace: true });} catch (error: SafeAny) {// remove token and go to login page to re-login// await store.dispatch('user/resetToken')message.error(typeof error === 'object' ? error.msg : 'Has Error');next(`${loginPath}`);NProgress.done();}}}} else {/* has no token*/if (whiteList.indexOf(to.path) !== -1) {// in the free login whitelist, go directlynext();} else {// other pages that do not have permission to access are redirected to the login page.next(`${loginPath}`);NProgress.done();}}});
动态路由
export function reuseView({viewName,metaKey,metaKeyVal,routePath,metaFields = {},query = {}}: {viewName: string;metaKey: MetaMultipleField;metaKeyVal: SafeAny;routePath: string;metaFields?: RouteMetaMultiple;query?: { [key: string]: SafeAny };}) {const store = useStore();const repeated = store.state.tabs.visitedViews.filter(item => item.name === viewName && item[metaKey] === metaKeyVal);if (repeated.length > 0) {const view = repeated[0];Array.from(Object.entries(metaFields)).forEach(([field, val]) => {view.meta[field] = val;});view.meta._refresh = new Date().getTime();store.dispatch(TabsActionTypes.ACTION_UPDATE_VISITED_VIEW, view);router.push({ path: view.path, query: view.query });} else {router.push({path: `${routePath}${new Date().getTime()}`,query});}}
公用方法
import extend from 'extend';import { SafeAny } from '../types/yacommon';/*** Gets the value at `path` of `object`, like `_.get` in lodash.** 类似 `_.get`,根据 `path` 获取安全值*/export function deepGet(obj: SafeAny, path: string | string[] | null | undefined, defaultValue?: unknown): SafeAny {if (!obj || path == null || path.length === 0) return defaultValue;if (!Array.isArray(path)) {path = ~path.indexOf('.') ? path.split('.') : [path];}if (path.length === 1) {const checkObj = obj[path[0]];return typeof checkObj === 'undefined' ? defaultValue : checkObj;}const res = path.reduce((o, k) => (o || {})[k], obj);return typeof res === 'undefined' ? defaultValue : res;}/*** Base on [extend](https://github.com/justmoon/node-extend) deep copy.** 基于 [extend](https://github.com/justmoon/node-extend) 的深度拷贝*/export function deepCopy<T extends { [key: string]: SafeAny } = SafeAny>(obj: T | null | undefined): T {const result = extend(true, {}, { _: obj });return result._ as T;}/*** Deep merge object.** 深度合并对象** @param original 原始对象* @param arrayProcessMethod 数组处理方式* - `true` 表示替换新值,不管新值为哪种类型* - `false` 表示会合并整个数组(将旧数据与新数据合并成新数组)* @param objects 要合并的对象*/export function deepMergeKey(original: unknown, arrayProcessMethod: boolean, ...objects: SafeAny[]): SafeAny {if (Array.isArray(original) || typeof original !== 'object') return original;const isObject = (v: unknown): boolean => typeof v === 'object';const merge = (target: SafeAny, obj: SafeAny): SafeAny => {Object.keys(obj).filter(key => key !== '__proto__' && Object.prototype.hasOwnProperty.call(obj, key)).forEach(key => {const fromValue = obj[key];const toValue = target[key];if (Array.isArray(toValue)) {target[key] = arrayProcessMethod ? fromValue : [...toValue, ...fromValue];} else if (typeof fromValue === 'function') {target[key] = fromValue;} else if (fromValue != null && isObject(fromValue) && toValue != null && isObject(toValue)) {target[key] = merge(toValue, fromValue);} else {target[key] = deepCopy(fromValue);}});return target;};objects.filter(v => v != null && isObject(v)).forEach(v => merge(original, v));return original;}/*** Deep merge object.** 深度合并对象*/export function deepMerge(original: unknown, ...objects: unknown[]): SafeAny {return deepMergeKey(original, false, ...objects);}
高并发模拟
export function httpMultiple(httpFun: (data: SafeAny) => Observable<SafeAny>, data: SafeAny, count: number) {return new Observable(sub => {const subscription = interval(10).pipe(take(count)).subscribe(() => {httpFun(data).subscribe({next: res => {sub.next(res);},error: err => {sub.error(err);subscription.unsubscribe();}});});});}
