feat: add run.ps1 script to start projects easily

add a powershell script that supports starting MES, WMS, WMSClient, Workstation and Dashboard projects with one command, includes build and run logic for backend services and npm dev for dashboard
This commit is contained in:
SunYF
2026-08-28 17:03:03 +08:00
parent a9c3fbeb41
commit cbd55338f1
30 changed files with 592 additions and 61 deletions
+37 -2
View File
@@ -3,8 +3,10 @@ package handler
import (
"net/http"
"strconv"
"strings"
"bj_power_mes/common/httpx"
tokenx "bj_power_mes/common/token"
"bj_power_mes/internal/logic"
"bj_power_mes/internal/svc"
@@ -27,6 +29,22 @@ func ctxUserId(r *http.Request) int {
return 0
}
// uidFromRequest 取当前登录用户ID:优先 context,缺失时回退解析 Authorization Bearer token(更稳健)
func uidFromRequest(r *http.Request, svcCtx *svc.ServiceContext) int {
if uid := ctxUserId(r); uid > 0 {
return uid
}
auth := strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer ")
if auth == "" || auth == r.Header.Get("Authorization") {
return 0
}
claims, err := tokenx.Parse(svcCtx.Config.Auth.AccessSecret, auth)
if err == nil && claims.UserId > 0 {
return claims.UserId
}
return 0
}
// ctxOperator 当前操作人:优先取 name,其次 username
func ctxOperator(r *http.Request) string {
if v, ok := r.Context().Value("name").(string); ok && v != "" {
@@ -82,7 +100,7 @@ func RefreshHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
func UserInfoHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
data, err := logic.New(svcCtx).UserInfo(r.Context(), ctxUserId(r))
data, err := logic.New(svcCtx).UserInfo(r.Context(), uidFromRequest(r, svcCtx))
if err != nil {
httpx.Fail(w, 1003, err.Error())
return
@@ -154,6 +172,23 @@ func DeleteUserHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
}
// ---------- 修改自己的密码 ----------
func ChangePasswordHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
var req logic.ChangePasswordReq
if err := httpx.ParseJSON(r, &req); err != nil {
httpx.BadRequest(w, "请求体解析失败")
return
}
if err := logic.New(svcCtx).ChangePassword(r.Context(), uidFromRequest(r, svcCtx), req); err != nil {
httpx.Fail(w, 1017, err.Error())
return
}
httpx.OkMessage(w, "密码修改成功", nil)
}
}
// ---------- 角色管理 ----------
func ListRolesHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
@@ -258,4 +293,4 @@ func DeletePermissionHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
}
httpx.OkMessage(w, "删除成功", nil)
}
}
}