通用 CRUD 项目操作手册

发布时间 2023-11-17 15:52:03作者: Ba11ooner

前言

本操作手册旨在通过列出通用 CRUD 项目的复用流程的待办清单的形式,方便后续实现复用

相关项目文档

项目总结 通用 CRUD 后端项目 stateful-backend

项目总结 通用 CRUD 前端项目 stateful-backend-frontend

相关项目源码

后端项目源码

前端项目源码

操作手册

通用 CRUD 项目复用流程

预备工作
  • cd ~/Project
    mkdir xxx-backend
    git init
    git pull https://github.com/Ba11ooner/stateful-backend.git
    git checkout -b xxx-backend
    
    cd ../
    mkdir xxx-backend-frontend
    git init
    git pull https://github.com/Ba11ooner/stateful-backend-frontend.git
    git checkout -b xxx-backend-frontend
    
    • 注意事项:受技术栈限制,如果不采用以下的额外约束,可能会出现奇怪 Bug

      • 为每一个表都单独增加一个 id 自增主键,方便删除
      • 通过业务控制而非外键控制数据库表之间的属性约束
        即保证 Navicat 生成的 ER 图中所有表都是独立的
后端项目二次开发

前提:完成数据库表的初始化工作

前端项目二次开发

前提:完成后端的二次开发

    • yarn install  --production=false # 参数为必选项,否则会有奇怪 Bug
      
    • yarn openapi
      
      • export function getUrl() {
          // 在此处配置后端接口地址
          const url = 'http://localhost:8080'
          console.log("当前后端 URL:" + url)
          return url
        }
        
        • ...
          import {getUrl} from "@/services/url";
          const url = getUrl()
          
      • // 在登录、获取用户态方法中加入 Cookie 认证
        		...
        		credentials:'include',
            method:'POST'
        		...
        
      • // 与 openapi 自动生成的机制有关,不一定需要这一步,不报错就不用
        // 如果生成的方法就是 getLoginUserUsingGet 和 userLoginUsingPost,就不用再做修改
        // 根据实际经验,有可能会出现生成方法名称是 getLoginUserUsingGET 和 userLoginUsingPOST		这种名字不同的情况下,名字不同就需要这一步
        
        // 将 as 前面的方法修改为 "@/services/stateful-backend/userController" 中生成的方法
        import {
          getLoginUserUsingGet as getLoginUser,
          userLoginUsingPost as login
        } from "@/services/stateful-backend/userController";
        
      • // 与 openapi 自动生成的机制有关,不一定需要这一步,与登入接口的方法配置同理
        import {userLogoutUsingGet as outLogin} from "@/services/stateful-backend/userController";
        
      •  ...
         {name: '查询表格', icon: 'table', path: '/list', component: './TableList'},
         {name: 'Entity 表格', icon: 'table', path: '/list', component: './EntityList'},
         ...