更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -17,18 +17,10 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// BackendDictController 租户端数据字典:字典列表 + 字典项
|
||||
//
|
||||
// 表:yz_backend_dict / yz_backend_dict_item(建表 SQL:docs/sql/create_dict.sql)。
|
||||
// 按 tenant_id 隔离(取 JWT 里的租户ID,前端不传),与 yz_backend_erp_supplier 一致。
|
||||
// 平台端字典见 PlatformDictController(/platform/dict/*)。
|
||||
type BackendDictController struct {
|
||||
beego.Controller
|
||||
}
|
||||
|
||||
// globalDictTenantID 全局内置字典的租户标记:所有租户可见、只读,
|
||||
// 与 yz_system_admin_role 中 tenant_id=0 的「全局租户角色」同一套约定。
|
||||
// 租户要改动时就按相同 dict_code 建一份自己的字典覆盖它。
|
||||
const globalDictTenantID = "0"
|
||||
|
||||
var backendDictCodeRe = regexp.MustCompile(`^[a-zA-Z][a-zA-Z0-9_]{0,99}$`)
|
||||
@@ -83,18 +75,15 @@ type backendDictItemPayload struct {
|
||||
IsDefault *int8 `json:"is_default"`
|
||||
}
|
||||
|
||||
// backendDictRow 字典列表行:在实体上追加「是否全局内置」,供前端禁用编辑/删除
|
||||
type backendDictRow struct {
|
||||
models.BackendDict
|
||||
IsGlobal bool `json:"is_global"`
|
||||
}
|
||||
|
||||
// dictTenantScope 当前请求可见的字典租户范围:全局内置 + 本租户自己的
|
||||
func dictTenantScope(claims *jwtutil.Claims) []string {
|
||||
return []string{globalDictTenantID, strconv.Itoa(claims.TenantId)}
|
||||
}
|
||||
|
||||
// findVisibleDict 按编码取当前租户可见的字典:优先本租户自己的,没有再回落全局内置
|
||||
func findVisibleDict(tenantID, code string) (*models.BackendDict, error) {
|
||||
var dicts []models.BackendDict
|
||||
if _, err := models.Orm.QueryTable(new(models.BackendDict)).
|
||||
@@ -116,12 +105,8 @@ func findVisibleDict(tenantID, code string) (*models.BackendDict, error) {
|
||||
return nil, orm.ErrNoRows
|
||||
}
|
||||
|
||||
// isGlobalDictRow 全局内置字典:任何租户都不允许修改 / 删除
|
||||
func isGlobalDictRow(tenantID string) bool { return tenantID == globalDictTenantID }
|
||||
|
||||
/* ---------------- 字典列表 ---------------- */
|
||||
|
||||
// ListTypes GET /backend/dict/types
|
||||
func (c *BackendDictController) ListTypes() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -133,7 +118,6 @@ func (c *BackendDictController) ListTypes() {
|
||||
keyword := strings.TrimSpace(c.GetString("keyword"))
|
||||
status := strings.TrimSpace(c.GetString("status"))
|
||||
|
||||
// 可见范围:全局内置 + 本租户自己的(同编码时两条都会出现,各自带 is_global 标记)
|
||||
cond := orm.NewCondition().
|
||||
And("tenant_id__in", dictTenantScope(claims)).
|
||||
And("delete_time__isnull", true)
|
||||
@@ -171,7 +155,6 @@ func (c *BackendDictController) ListTypes() {
|
||||
}, "")
|
||||
}
|
||||
|
||||
// CreateType POST /backend/dict/types
|
||||
func (c *BackendDictController) CreateType() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -232,8 +215,6 @@ func (c *BackendDictController) CreateType() {
|
||||
c.dictOk(row, "新增成功")
|
||||
}
|
||||
|
||||
// UpdateType PUT /backend/dict/types/:id
|
||||
// 编码是业务取值依据,不允许修改。
|
||||
func (c *BackendDictController) UpdateType() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -287,8 +268,6 @@ func (c *BackendDictController) UpdateType() {
|
||||
c.dictOk(row, "保存成功")
|
||||
}
|
||||
|
||||
// DeleteType DELETE /backend/dict/types/:id
|
||||
// 字典下还有字典项时拒绝删除,避免留下孤儿数据。
|
||||
func (c *BackendDictController) DeleteType() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -333,9 +312,6 @@ func (c *BackendDictController) DeleteType() {
|
||||
c.dictOk(nil, "删除成功")
|
||||
}
|
||||
|
||||
/* ---------------- 字典项 ---------------- */
|
||||
|
||||
// ListItems GET /backend/dict/items
|
||||
func (c *BackendDictController) ListItems() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -348,7 +324,6 @@ func (c *BackendDictController) ListItems() {
|
||||
c.dictErr(400, 400, "dict_id 不能为空")
|
||||
return
|
||||
}
|
||||
// 字典必须在本租户可见范围内(自己的或全局内置),避免越权读取他人字典
|
||||
var dict models.BackendDict
|
||||
if err := models.Orm.QueryTable(new(models.BackendDict)).
|
||||
Filter("id", dictID).
|
||||
@@ -363,7 +338,6 @@ func (c *BackendDictController) ListItems() {
|
||||
keyword := strings.TrimSpace(c.GetString("keyword"))
|
||||
status := strings.TrimSpace(c.GetString("status"))
|
||||
|
||||
// 字典项跟随所属字典的租户:全局内置字典的项对所有租户可见
|
||||
cond := orm.NewCondition().
|
||||
And("tenant_id", dict.TenantID).
|
||||
And("dict_id", dictID).
|
||||
@@ -398,7 +372,6 @@ func (c *BackendDictController) ListItems() {
|
||||
}, "")
|
||||
}
|
||||
|
||||
// CreateItem POST /backend/dict/items
|
||||
func (c *BackendDictController) CreateItem() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -488,8 +461,6 @@ func (c *BackendDictController) CreateItem() {
|
||||
c.dictOk(row, "新增成功")
|
||||
}
|
||||
|
||||
// UpdateItem PUT /backend/dict/items/:id
|
||||
// 字典项值是业务入库值,不允许修改,避免存量数据对不上。
|
||||
func (c *BackendDictController) UpdateItem() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -548,7 +519,6 @@ func (c *BackendDictController) UpdateItem() {
|
||||
c.dictOk(row, "保存成功")
|
||||
}
|
||||
|
||||
// ToggleItemStatus POST /backend/dict/items/:id/status
|
||||
func (c *BackendDictController) ToggleItemStatus() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -594,7 +564,6 @@ func (c *BackendDictController) ToggleItemStatus() {
|
||||
c.dictOk(nil, "操作成功")
|
||||
}
|
||||
|
||||
// DeleteItem DELETE /backend/dict/items/:id
|
||||
func (c *BackendDictController) DeleteItem() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -626,11 +595,6 @@ func (c *BackendDictController) DeleteItem() {
|
||||
c.dictOk(nil, "删除成功")
|
||||
}
|
||||
|
||||
/* ---------------- 业务读取 ---------------- */
|
||||
|
||||
// OptionsAll GET /backend/dict/options
|
||||
// 一次取回本租户可见的全部「启用」字典项(全局内置 + 本租户自己的,同编码租户优先),
|
||||
// 供前端登录后预热缓存:之后页面按任意 dict_code 都能同步读到。
|
||||
func (c *BackendDictController) OptionsAll() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -650,7 +614,6 @@ func (c *BackendDictController) OptionsAll() {
|
||||
c.dictErr(500, 500, "查询失败: "+err.Error())
|
||||
return
|
||||
}
|
||||
// 同编码优先本租户:先记录全局,再用租户自己的覆盖
|
||||
chosen := map[string]uint64{}
|
||||
for _, d := range dicts {
|
||||
if _, ok := chosen[d.DictCode]; !ok || d.TenantID == tenantID {
|
||||
@@ -687,9 +650,6 @@ func (c *BackendDictController) OptionsAll() {
|
||||
c.dictOk(map[string]interface{}{"dicts": result}, "")
|
||||
}
|
||||
|
||||
// OptionsBatch POST /backend/dict/options
|
||||
// 一次取多个字典的启用项,供前端预加载(body: {"codes":[...]})。
|
||||
// 同编码时优先本租户自己的字典,没有再回落全局内置字典。
|
||||
func (c *BackendDictController) OptionsBatch() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -736,7 +696,6 @@ func (c *BackendDictController) OptionsBatch() {
|
||||
return
|
||||
}
|
||||
|
||||
// 同编码优先本租户:先记录全局,再用租户自己的覆盖
|
||||
chosen := map[string]uint64{}
|
||||
for _, d := range dicts {
|
||||
if _, ok := chosen[d.DictCode]; !ok || d.TenantID == tenantID {
|
||||
@@ -772,8 +731,6 @@ func (c *BackendDictController) OptionsBatch() {
|
||||
c.dictOk(map[string]interface{}{"dicts": result}, "")
|
||||
}
|
||||
|
||||
// Options GET /backend/dict/options/:code
|
||||
// 业务页面按编码取选项:只返回「字典与字典项都启用」的项,按 sort 升序。
|
||||
func (c *BackendDictController) Options() {
|
||||
claims, err := c.dictClaims()
|
||||
if err != nil {
|
||||
@@ -787,7 +744,6 @@ func (c *BackendDictController) Options() {
|
||||
return
|
||||
}
|
||||
|
||||
// 优先取本租户自己的字典,没有再回落全局内置字典
|
||||
dict, err := findVisibleDict(strconv.Itoa(claims.TenantId), code)
|
||||
if err != nil {
|
||||
c.dictErr(404, 404, "字典不存在或已停用")
|
||||
|
||||
Reference in new issue
Block a user