Merge pull request #27 from maxbad/v2.0

fix 一些使用的小问题
This commit is contained in:
孟帅 2023-05-29 11:17:13 +08:00 committed by GitHub
commit b353728009
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 101 additions and 20 deletions

View File

@ -39,7 +39,7 @@ type ViewRes struct {
// EditReq 修改/新增
type EditReq struct {
entity.AdminNotice
entity.SysAttachment
g.Meta `path:"/attachment/edit" method:"post" tags:"附件" summary:"修改/新增附件"`
}
type EditRes struct{}
@ -62,7 +62,7 @@ type MaxSortRes struct {
// StatusReq 更新状态
type StatusReq struct {
entity.AdminNotice
entity.SysAttachment
g.Meta `path:"/attachment/status" method:"post" tags:"附件" summary:"更新附件状态"`
}
type StatusRes struct{}

View File

@ -69,7 +69,7 @@ func (l *gCurd) generateLogicSwitchFields(ctx context.Context, in *CurdPreviewIn
if in.options.Step.HasSwitch {
for _, field := range in.masterFields {
if field.FormMode == "Switch" {
buffer.WriteString("\t\tdao." + in.In.DaoName + ".Columns()." + field.GoName + ",\n")
buffer.WriteString("\t\t\"" + field.TsName + "\",\n")
}
}
}

View File

@ -204,6 +204,8 @@ func (l *gCurd) generateWebModelFormSchemaEach(buffer *bytes.Buffer, fields []*s
case FormModeTimeRange:
component = fmt.Sprintf(" {\n field: '%s',\n component: '%s',\n label: '%s',\n componentProps: {\n type: '%s',\n clearable: true,\n shortcuts: %s,\n onUpdateValue: (e: any) => {\n console.log(e);\n },\n },\n },\n", field.TsName, "NDatePicker", field.Dc, "datetimerange", "defRangeShortcuts()")
case FormModeSwitch:
fallthrough
case FormModeRadio:
component = fmt.Sprintf(" {\n field: '%s',\n component: '%s',\n label: '%s',\n giProps: {\n //span: 24,\n },\n componentProps: {\n options: [],\n onUpdateChecked: (e: any) => {\n console.log(e);\n },\n },\n },\n", field.TsName, "NRadioGroup", field.Dc)

View File

@ -7,6 +7,8 @@ package admin
import (
"context"
"fmt"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/errors/gerror"
"github.com/gogf/gf/v2/os/gtime"
"hotgo/internal/consts"
@ -91,7 +93,26 @@ func (s *sAdminDept) Edit(ctx context.Context, in adminin.DeptEditInp) (err erro
// 修改
if in.Id > 0 {
// 获取父级tree
var pTree gdb.Value
pTree, err = dao.AdminDept.Ctx(ctx).Where("id", in.Pid).Fields("tree").Value()
if err != nil {
return
}
in.Tree = fmt.Sprintf("%str_%v ", pTree.String(), in.Id)
err = dao.AdminDept.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
// 更新数据
_, err = dao.AdminDept.Ctx(ctx).Where("id", in.Id).Data(in).Update()
if err != nil {
return err
}
// 如果当前部门有子级,更新子级tree关系树
return updateChildrenTree(ctx, in.Id, in.Level, in.Tree)
})
return
}
@ -100,6 +121,27 @@ func (s *sAdminDept) Edit(ctx context.Context, in adminin.DeptEditInp) (err erro
return
}
func updateChildrenTree(ctx context.Context, _id int64, _level int, _tree string) (err error) {
var list []*entity.AdminDept
err = dao.AdminDept.Ctx(ctx).Where("pid", _id).Scan(&list)
if err != nil {
return
}
for _, child := range list {
child.Level = _level + 1
child.Tree = fmt.Sprintf("%str_%v ", _tree, child.Id)
_, err = dao.AdminDept.Ctx(ctx).Where("id", child.Id).Data("level", child.Level, "tree", child.Tree).Update()
if err != nil {
return err
}
err = updateChildrenTree(ctx, child.Id, child.Level, child.Tree)
if err != nil {
return
}
}
return
}
// Status 更新部门状态
func (s *sAdminDept) Status(ctx context.Context, in adminin.DeptStatusInp) (err error) {
if in.Id <= 0 {

View File

@ -479,6 +479,7 @@ func (s *sAdminMember) Edit(ctx context.Context, in adminin.MemberEditInp) (err
// 新增用户时的额外属性
var data adminin.MemberAddInp
data.MemberEditInp = in
data.Salt = grand.S(6)
data.InviteCode = grand.S(12)
data.PasswordHash = gmd5.MustEncryptString(data.Password + data.Salt)
@ -491,10 +492,9 @@ func (s *sAdminMember) Edit(ctx context.Context, in adminin.MemberEditInp) (err
}
// 默认头像
if in.Avatar == "" {
in.Avatar = config.Avatar
if data.Avatar == "" {
data.Avatar = config.Avatar
}
data.MemberEditInp = in
return g.DB().Transaction(ctx, func(ctx context.Context, tx gdb.TX) (err error) {
id, err := dao.AdminMember.Ctx(ctx).Data(data).InsertAndGetId()

View File

@ -7,6 +7,7 @@ package admin
import (
"context"
"fmt"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/encoding/gjson"
"github.com/gogf/gf/v2/errors/gerror"
@ -217,7 +218,24 @@ func (s *sAdminRole) Edit(ctx context.Context, in *role.EditReq) (err error) {
// 修改
if in.Id > 0 {
// 获取父级tree
var pTree gdb.Value
pTree, err = dao.AdminRole.Ctx(ctx).Where("id", in.Pid).Fields("tree").Value()
if err != nil {
return
}
in.Tree = fmt.Sprintf("%str_%v ", pTree.String(), in.Id)
err = dao.AdminRole.Transaction(ctx, func(ctx context.Context, tx gdb.TX) error {
// 更新数据
_, err = dao.AdminRole.Ctx(ctx).Where("id", in.Id).Data(in).Update()
if err != nil {
return err
}
// 如果当前角色有子级,更新子级tree关系树
return updateRoleChildrenTree(ctx, in.Id, in.Level, in.Tree)
})
return
}
@ -226,6 +244,27 @@ func (s *sAdminRole) Edit(ctx context.Context, in *role.EditReq) (err error) {
return
}
func updateRoleChildrenTree(ctx context.Context, _id int64, _level int, _tree string) (err error) {
var list []*entity.AdminDept
err = dao.AdminRole.Ctx(ctx).Where("pid", _id).Scan(&list)
if err != nil {
return
}
for _, child := range list {
child.Level = _level + 1
child.Tree = fmt.Sprintf("%str_%v ", _tree, child.Id)
_, err = dao.AdminRole.Ctx(ctx).Where("id", child.Id).Data("level", child.Level, "tree", child.Tree).Update()
if err != nil {
return err
}
err = updateRoleChildrenTree(ctx, child.Id, child.Level, child.Tree)
if err != nil {
return
}
}
return
}
func (s *sAdminRole) Delete(ctx context.Context, in *role.DeleteReq) (err error) {
if in.Id <= 0 {
return gerror.New("ID不正确")

View File

@ -197,7 +197,7 @@ func (s *sSysLog) AnalysisLog(ctx context.Context) entity.SysLog {
ipData, err := location.GetLocation(ctx, clientIp)
if err != nil {
g.Log().Debugf(ctx, "location.GetLocation clientIp:%v, err:%+v", clientIp, err)
g.Log().Stdout(false).Debugf(ctx, "location.GetLocation clientIp:%v, err:%+v", clientIp, err)
}
if ipData == nil {

View File

@ -43,15 +43,13 @@
<!--NRadioGroup-->
<template v-else-if="schema.component === 'NRadioGroup'">
<n-radio-group v-model:value="formModel[schema.field]">
<n-space>
<n-radio
<n-radio-button
v-for="item in schema.componentProps.options"
:key="item.value"
:value="item.value"
>
{{ item.label }}
</n-radio>
</n-space>
</n-radio-button>
</n-radio-group>
</template>
<!--动态渲染表单组件-->

View File

@ -196,7 +196,7 @@
createdAt: string;
status: number;
name: string;
index: string;
id: number;
children?: RowData[];
};
const data = ref([]);
@ -318,7 +318,7 @@
},
];
const rowKey = (row: RowData) => row.index;
const rowKey = (row: RowData) => row.id;
function addTable() {
showModal.value = true;