项目一共分为两个端,客户端、管理端(管理后台),客户端是用户直接访问的页面,管理端用于整个项目的日常运营和维护,两个端均采用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. - 审核
      • 删查

用户

  • 首页
    • 首页轮播图配置
    • 热点文章展示
    • 热点资源展示
  • 个人空间
    • 个人文章
      • 展示、修改、删除、新建、隐藏
    • 个人资料
      • 编辑、上传头像
    • 退出登录
  • 社区
    • 资源
      • 展示、搜索查看、下载
    • 文章
      • 评论
        • 删除自己的评论
        • 给别人评论点赞
        • 举报别人评论
      • 点赞、收藏
      • 举报
  • 查看其他用户
    • 文章&资源
      • 评论
        • 删除自己的评论
        • 给别人评论点赞
        • 举报别人评论
      • 点赞、收藏
      • 举报

        基础配置

表

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:昵称

核心代码

前端权限认证

  1. router.beforeEach(async (to, from, next) => {
  2. // start progress bar
  3. NProgress.start();
  4. // set page title
  5. const title = (to.meta.title as string) || '';
  6. document.title = getPageTitle(title);
  7. // determine whether the user has logged in
  8. const hasToken = getToken();
  9. if (hasToken) {
  10. if (to.path === loginPath) {
  11. // if is logged in, redirect to the home page
  12. next({ path: '/' });
  13. NProgress.done();
  14. } else {
  15. const store = useStore();
  16. // determine whether the user has obtained his permission roles through getInfo
  17. const hasRoles = store.state.user.roles && store.state.user.roles.length > 0;
  18. if (hasRoles) {
  19. next();
  20. } else {
  21. try {
  22. // get user info
  23. // note: roles must be a object array! such as: ['admin'] or ,['developer','editor']
  24. const { roles } = await store.dispatch(UserActionTypes.ACTION_GET_USER_INFO, undefined);
  25. // generate accessible routes map based on roles
  26. const accessRoutes = await store.dispatch(RouterActionTypes.ACTION_GET_ROUTES, undefined);
  27. // dynamically add accessible routes
  28. accessRoutes.forEach(item => {
  29. router.addRoute(item);
  30. });
  31. // hack method to ensure that addRoutes is complete
  32. // set the replace: true, so the navigation will not leave a history record
  33. next({ ...to, replace: true });
  34. } catch (error: SafeAny) {
  35. // remove token and go to login page to re-login
  36. // await store.dispatch('user/resetToken')
  37. message.error(typeof error === 'object' ? error.msg : 'Has Error');
  38. next(`${loginPath}`);
  39. NProgress.done();
  40. }
  41. }
  42. }
  43. } else {
  44. /* has no token*/
  45. if (whiteList.indexOf(to.path) !== -1) {
  46. // in the free login whitelist, go directly
  47. next();
  48. } else {
  49. // other pages that do not have permission to access are redirected to the login page.
  50. next(`${loginPath}`);
  51. NProgress.done();
  52. }
  53. }
  54. });

动态路由

  1. export function reuseView({
  2. viewName,
  3. metaKey,
  4. metaKeyVal,
  5. routePath,
  6. metaFields = {},
  7. query = {}
  8. }: {
  9. viewName: string;
  10. metaKey: MetaMultipleField;
  11. metaKeyVal: SafeAny;
  12. routePath: string;
  13. metaFields?: RouteMetaMultiple;
  14. query?: { [key: string]: SafeAny };
  15. }) {
  16. const store = useStore();
  17. const repeated = store.state.tabs.visitedViews.filter(item => item.name === viewName && item[metaKey] === metaKeyVal);
  18. if (repeated.length > 0) {
  19. const view = repeated[0];
  20. Array.from(Object.entries(metaFields)).forEach(([field, val]) => {
  21. view.meta[field] = val;
  22. });
  23. view.meta._refresh = new Date().getTime();
  24. store.dispatch(TabsActionTypes.ACTION_UPDATE_VISITED_VIEW, view);
  25. router.push({ path: view.path, query: view.query });
  26. } else {
  27. router.push({
  28. path: `${routePath}${new Date().getTime()}`,
  29. query
  30. });
  31. }
  32. }

公用方法

  1. import extend from 'extend';
  2. import { SafeAny } from '../types/yacommon';
  3. /**
  4. * Gets the value at `path` of `object`, like `_.get` in lodash.
  5. *
  6. * 类似 `_.get`,根据 `path` 获取安全值
  7. */
  8. export function deepGet(obj: SafeAny, path: string | string[] | null | undefined, defaultValue?: unknown): SafeAny {
  9. if (!obj || path == null || path.length === 0) return defaultValue;
  10. if (!Array.isArray(path)) {
  11. path = ~path.indexOf('.') ? path.split('.') : [path];
  12. }
  13. if (path.length === 1) {
  14. const checkObj = obj[path[0]];
  15. return typeof checkObj === 'undefined' ? defaultValue : checkObj;
  16. }
  17. const res = path.reduce((o, k) => (o || {})[k], obj);
  18. return typeof res === 'undefined' ? defaultValue : res;
  19. }
  20. /**
  21. * Base on [extend](https://github.com/justmoon/node-extend) deep copy.
  22. *
  23. * 基于 [extend](https://github.com/justmoon/node-extend) 的深度拷贝
  24. */
  25. export function deepCopy<T extends { [key: string]: SafeAny } = SafeAny>(obj: T | null | undefined): T {
  26. const result = extend(true, {}, { _: obj });
  27. return result._ as T;
  28. }
  29. /**
  30. * Deep merge object.
  31. *
  32. * 深度合并对象
  33. *
  34. * @param original 原始对象
  35. * @param arrayProcessMethod 数组处理方式
  36. * - `true` 表示替换新值,不管新值为哪种类型
  37. * - `false` 表示会合并整个数组(将旧数据与新数据合并成新数组)
  38. * @param objects 要合并的对象
  39. */
  40. export function deepMergeKey(original: unknown, arrayProcessMethod: boolean, ...objects: SafeAny[]): SafeAny {
  41. if (Array.isArray(original) || typeof original !== 'object') return original;
  42. const isObject = (v: unknown): boolean => typeof v === 'object';
  43. const merge = (target: SafeAny, obj: SafeAny): SafeAny => {
  44. Object.keys(obj)
  45. .filter(key => key !== '__proto__' && Object.prototype.hasOwnProperty.call(obj, key))
  46. .forEach(key => {
  47. const fromValue = obj[key];
  48. const toValue = target[key];
  49. if (Array.isArray(toValue)) {
  50. target[key] = arrayProcessMethod ? fromValue : [...toValue, ...fromValue];
  51. } else if (typeof fromValue === 'function') {
  52. target[key] = fromValue;
  53. } else if (fromValue != null && isObject(fromValue) && toValue != null && isObject(toValue)) {
  54. target[key] = merge(toValue, fromValue);
  55. } else {
  56. target[key] = deepCopy(fromValue);
  57. }
  58. });
  59. return target;
  60. };
  61. objects.filter(v => v != null && isObject(v)).forEach(v => merge(original, v));
  62. return original;
  63. }
  64. /**
  65. * Deep merge object.
  66. *
  67. * 深度合并对象
  68. */
  69. export function deepMerge(original: unknown, ...objects: unknown[]): SafeAny {
  70. return deepMergeKey(original, false, ...objects);
  71. }

高并发模拟

  1. export function httpMultiple(httpFun: (data: SafeAny) => Observable<SafeAny>, data: SafeAny, count: number) {
  2. return new Observable(sub => {
  3. const subscription = interval(10)
  4. .pipe(take(count))
  5. .subscribe(() => {
  6. httpFun(data).subscribe({
  7. next: res => {
  8. sub.next(res);
  9. },
  10. error: err => {
  11. sub.error(err);
  12. subscription.unsubscribe();
  13. }
  14. });
  15. });
  16. });
  17. }