feat: 完成MES工位终端系统全量功能迭代
本次提交包含以下核心变更: 1. 新增按钮级权限控制框架与前端权限校验 2. 新增工位管理、工艺流程、巡检终端等核心业务模块 3. 完善用户体系,支持工位终端专属登录权限 4. 新增文件上传下载、报表查询等配套功能 5. 修复多系统兼容性与交互体验问题 6. 完成所有文档与配置项的规范化更新
This commit is contained in:
@@ -25,13 +25,15 @@ func healthHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
// loginHandler 本地 SQLite + bcrypt 校验登录,返回 {token, expireAt, user}。
|
||||
// 账号自动记录为操作人(前端通过 localStorage 的 user 保存操作人)。
|
||||
// loginHandler 登录代理 MES /api/internal/station/login(块1:用户体系来源于 MES)。
|
||||
// 前端提交 {username, password, stationNo},MES 校验工位终端密码 + 工位权限并签发同密钥 JWT。
|
||||
// 响应体原样透传({code,message,data:{accessToken,expireAt,user,stations,stationNo}})。
|
||||
func loginHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req struct {
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
Username string `json:"username"`
|
||||
Password string `json:"password"`
|
||||
StationNo int `json:"stationNo"`
|
||||
}
|
||||
if err := parseJSON(r, &req); err != nil {
|
||||
fail(w, http.StatusBadRequest, "参数错误")
|
||||
@@ -42,46 +44,27 @@ func loginHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
u, err := ctx.Store.GetUserByUsername(strings.TrimSpace(req.Username))
|
||||
if err != nil {
|
||||
fail(w, http.StatusUnauthorized, "用户名或密码错误")
|
||||
return
|
||||
}
|
||||
if bcrypt.CompareHashAndPassword([]byte(u.PasswordHash), []byte(req.Password)) != nil {
|
||||
fail(w, http.StatusUnauthorized, "用户名或密码错误")
|
||||
return
|
||||
}
|
||||
|
||||
token, expireAt, err := auth.SignToken(
|
||||
ctx.Config.Auth.AccessSecret,
|
||||
ctx.Config.Auth.AccessExpire,
|
||||
auth.TokenInfo{UserID: u.ID, Username: u.Username, RealName: u.RealName, Role: u.Role},
|
||||
)
|
||||
if err != nil {
|
||||
fail(w, http.StatusInternalServerError, "签发 token 失败")
|
||||
return
|
||||
}
|
||||
|
||||
ctx.Store.AddEventLog("", u.RealName, "login", "账号登录")
|
||||
ok(w, map[string]any{
|
||||
"token": token,
|
||||
"expireAt": expireAt,
|
||||
"user": map[string]any{
|
||||
"id": u.ID,
|
||||
"username": u.Username,
|
||||
"realName": u.RealName,
|
||||
"role": u.Role,
|
||||
},
|
||||
body, _, err := ctx.Mes.Post("/api/internal/station/login", map[string]any{
|
||||
"username": strings.TrimSpace(req.Username),
|
||||
"password": req.Password,
|
||||
"stationNo": req.StationNo,
|
||||
})
|
||||
if err != nil {
|
||||
fail(w, http.StatusBadGateway, "MES 服务不可达:"+errString(err))
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
_, _ = w.Write(body)
|
||||
}
|
||||
}
|
||||
|
||||
// configHandler GET /api/config 返回工位配置:
|
||||
// 固定工位号(Station.Code 为空则前端可自选)、本工位需拧紧的螺丝颗数。
|
||||
// 固定工位号 stationNo(Station.Code 为空则前端可自选 1~12)、本工位需拧紧的螺丝颗数。
|
||||
func configHandler(ctx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ok(w, map[string]any{
|
||||
"station": ctx.Config.Station.Code,
|
||||
"stationNo": atoi(ctx.Config.Station.Code, 0),
|
||||
"screwCount": ctx.Config.Station.ScrewCount,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user