主要更新uniapp相关功能

This commit is contained in:
hero920103 committed 2026-10-07 00:59:05 +08:00
1 parent aa92ca40a2
commit 5b4dbb2b46
65 files changed
+8532 -1921

No files matched your search

+92 -15
View File
@@ -1,6 +1,7 @@
package controllers
import (
"encoding/json"
"errors"
"sort"
"strings"
@@ -10,6 +11,7 @@ import (
"server/pkg/jwtutil"
"server/services"
"github.com/beego/beego/v2/client/orm"
beego "github.com/beego/beego/v2/server/web"
)
@@ -53,9 +55,9 @@ type appMenuItem struct {
Icon string `json:"icon,omitempty"`
Type int8 `json:"type"`
Sort int64 `json:"sort"`
Module string `json:"module"` // 归属模块 code(crm/erp/oa/cms/ai),公共菜单为空
Locked bool `json:"locked"` // true = 不在租户套餐内,前端置灰并引导升级
Leaf bool `json:"leaf"` // true = 叶子菜单(无下级),可直接跳转
Module string `json:"module"` // 归属模块 code(crm/erp/oa/cms/ai),公共菜单为空
Locked bool `json:"locked"` // true = 不在租户套餐内,前端置灰并引导升级
Leaf bool `json:"leaf"` // true = 叶子菜单(无下级),可直接跳转
Docs int `json:"docs,omitempty"` // 该节点下可见的子菜单数量
}
@@ -128,25 +130,100 @@ func (c *AppAggregateController) Home() {
"code": 200,
"msg": "success",
"data": map[string]interface{}{
"user": c.appUser(claims, uid, tid),
"modules": modules,
"menus": menus,
"stats": c.appStats(claims, tid),
"user": c.appUser(claims, uid, tid),
"modules": modules,
"menus": menus,
"stats": c.appStats(claims, tid),
"quick_menu_ids": c.appQuickMenuIds(tid, uint64(claims.UserID)),
},
})
}
// appQuickMenuIds 读取当前用户自定义的常用功能菜单 ID 列表(有序)。
// 未设置或解析失败一律返回空数组,前端据此回落到默认取前 N 个叶子菜单。
func (c *AppAggregateController) appQuickMenuIds(tid, uid uint64) []uint64 {
out := []uint64{}
var row models.UniappUserQuickMenu
if err := models.Orm.QueryTable(new(models.UniappUserQuickMenu)).
Filter("tid", tid).Filter("uid", uid).One(&row); err != nil {
return out
}
raw := strings.TrimSpace(row.MenuIds)
if raw == "" {
return out
}
var ids []uint64
if err := json.Unmarshal([]byte(raw), &ids); err != nil {
return out
}
if ids == nil {
return out
}
return ids
}
// SaveQuickMenus POST /app/quick-menus
//
// 全量覆盖保存当前用户的常用功能菜单 ID 列表。请求体:{ "menu_ids": [81,102,...] }。
// 顺序即展示顺序;传空数组表示清空自定义(前端回落到默认)。
func (c *AppAggregateController) SaveQuickMenus() {
claims, err := c.appClaims()
if err != nil {
c.fail(err.Error())
return
}
tid := uint64(claims.TenantId)
uid := uint64(claims.UserID)
var body struct {
MenuIds []uint64 `json:"menu_ids"`
}
if err := json.Unmarshal(c.Ctx.Input.RequestBody, &body); err != nil {
c.Ctx.Output.SetStatus(400)
c.serveJSON(map[string]interface{}{"code": 400, "msg": "请求体格式错误"})
return
}
if body.MenuIds == nil {
body.MenuIds = []uint64{}
}
raw, _ := json.Marshal(body.MenuIds)
now := time.Now()
var row models.UniappUserQuickMenu
if err := models.Orm.QueryTable(new(models.UniappUserQuickMenu)).
Filter("tid", tid).Filter("uid", uid).One(&row); err == nil {
_, _ = models.Orm.QueryTable(new(models.UniappUserQuickMenu)).
Filter("id", row.ID).Update(orm.Params{
"menu_ids": string(raw),
"update_time": now,
})
} else {
_, _ = models.Orm.Insert(&models.UniappUserQuickMenu{
Tid: tid,
Uid: uid,
MenuIds: string(raw),
CreateTime: now,
UpdateTime: &now,
})
}
c.serveJSON(map[string]interface{}{
"code": 200,
"msg": "success",
"data": map[string]interface{}{"menu_ids": body.MenuIds},
})
}
// appUser 当前登录用户的展示信息(含企业名,供首页问候语使用)
func (c *AppAggregateController) appUser(claims *jwtutil.Claims, uid, tid uint64) map[string]interface{} {
out := map[string]interface{}{
"uid": uid,
"tid": tid,
"name": "用户",
"account": "",
"role_name": "",
"tenant": "",
"tenant_id": tid,
"avatar": "",
"uid": uid,
"tid": tid,
"name": "用户",
"account": "",
"role_name": "",
"tenant": "",
"tenant_id": tid,
"avatar": "",
}
if claims.Username != "" {
out["name"] = claims.Username