From 7f4a90210e2a4758fbcc94b4a029b2044d77b263 Mon Sep 17 00:00:00 2001 From: jingganjiaoyu Date: Sun, 4 Aug 2024 14:54:11 +0800 Subject: [PATCH] opt some --- src/guanlixitong/common.go | 41 +++++++++------ src/guanlixitong/groupUser.go | 22 ++++++++ src/guanlixitong/groupUser.js | 12 +++++ src/guanlixitong/model/model.go | 27 +++++----- src/guanlixitong/portal.css | 1 - src/guanlixitong/portal.go | 90 ++------------------------------- src/guanlixitong/portal.js | 17 ------- src/guanlixitong/portal.json | 29 ++++------- src/guanlixitong/portal.shy | 1 - src/guanlixitong/qrcode.go | 26 ---------- src/guanlixitong/userGroup.go | 24 +++++++-- 11 files changed, 108 insertions(+), 182 deletions(-) create mode 100644 src/guanlixitong/groupUser.go create mode 100644 src/guanlixitong/groupUser.js delete mode 100644 src/guanlixitong/portal.css delete mode 100644 src/guanlixitong/portal.js delete mode 100644 src/guanlixitong/qrcode.go diff --git a/src/guanlixitong/common.go b/src/guanlixitong/common.go index 549bc62..97c8c6f 100644 --- a/src/guanlixitong/common.go +++ b/src/guanlixitong/common.go @@ -2,32 +2,41 @@ package guanlixitong import ( "shylinux.com/x/ice" - "shylinux.com/x/icebergs/base/web" kit "shylinux.com/x/toolkits" + "shylinux.com/x/community/src/gonganxitong" "shylinux.com/x/enterprise/src/guanlixitong/model" - "shylinux.com/x/mysql-story/src/db" ) type Table struct { - db.Table - inputs string `name"inputs" role:"void"` - list string `name:"list group_uid uid auto" role:"void"` + gonganxitong.Table + list string `name:"list group_uid uid auto" role:"void"` } -func (s Table) Init(m *ice.Message, arg ...string) { - kit.If(m.Config(web.PORTAL) == ice.TRUE, func() { portal{}.Show(m) }) -} func (s Table) Inputs(m *ice.Message, arg ...string) { - s.Table.Inputs(m, arg...) -} -func (s Table) List(m *ice.Message, arg ...string) *ice.Message { - if len(arg) == 0 || len(arg) == 1 { - if m.IsTech() { - s.Table.List(m) + switch arg[0] { + case model.GROUP_TYPE: + for k, v := range GroupTypeList { + m.Push(arg[0], k).Push(model.NAME, v) } - } else if len(arg) == 2 { - s.Table.Select(m.FieldsSetDetail(), model.UID, arg[1]) + m.SortInt(arg[0]).DisplayInputKeyNameIconTitle() + case model.USER_GROUP_ROLE: + for k, v := range UserGroupRoleList { + if k != UserGroupCreator && k != UserGroupVisitor { + m.Push(arg[0], k).Push(model.NAME, v) + } + } + m.SortInt(arg[0]).DisplayInputKeyNameIconTitle() + default: + s.Table.Inputs(m, arg...) } +} +func (s Table) RewriteAppend(m *ice.Message, arg ...string) *ice.Message { + m.RewriteAppend(func(value, key string, index int) string { + kit.If(key == model.GROUP_TYPE, func() { value = GroupType(kit.Int(value)).String() }) + kit.If(key == model.USER_GROUP_ROLE, func() { value = UserGroupRole(kit.Int(value)).String() }) + return value + }) + s.Table.RewriteAppend(m) return m } diff --git a/src/guanlixitong/groupUser.go b/src/guanlixitong/groupUser.go new file mode 100644 index 0000000..f64f2af --- /dev/null +++ b/src/guanlixitong/groupUser.go @@ -0,0 +1,22 @@ +package guanlixitong + +import ( + "shylinux.com/x/ice" + + "shylinux.com/x/enterprise/src/guanlixitong/model" +) + +type groupUser struct { + portal portal + userGroup userGroup + list string `name:"list group_uid uid auto" role:"void" help:"团队成员" icon:"https://img.icons8.com/officel/80/crowd.png"` +} + +func (s groupUser) Init(m *ice.Message, arg ...string) { + s.portal.Show(m, model.ROLE, "creator,leader") +} +func (s groupUser) List(m *ice.Message, arg ...string) { + m.Cmdy(s.userGroup, s.userGroup.User, arg).Display("") +} + +func init() { ice.TeamCtxCmd(groupUser{}) } diff --git a/src/guanlixitong/groupUser.js b/src/guanlixitong/groupUser.js new file mode 100644 index 0000000..4ee226b --- /dev/null +++ b/src/guanlixitong/groupUser.js @@ -0,0 +1,12 @@ +Volcanos(chat.ONIMPORT, { + _init: function(can, msg) { if (msg.IsDetail()) { return msg.Dump(can) } + can.page.Append(can, can._output, msg.Table(function(value) { value._style = [value.user_group_role] + return can.onimport.itemcard(can, value, [ + {view: html.TITLE, list: [{text: value.user_name}, + {text: [can.user.transValue(can, value, "user_group_role"), "", aaa.ROLE]}, + ]}, + {view: html.STATUS, list: [{text: value.uid.slice(0, 6)}, {text: can.base.TimeTrim(value.created_at)}]}, + ]) + })) + }, +}) diff --git a/src/guanlixitong/model/model.go b/src/guanlixitong/model/model.go index d430473..c415f04 100644 --- a/src/guanlixitong/model/model.go +++ b/src/guanlixitong/model/model.go @@ -3,28 +3,31 @@ package model import "shylinux.com/x/mysql-story/src/db" const ( - UID = "uid" - NAME = "name" - TYPE = "type" - ROLE = "role" - CREATED_AT = "created_at" - USER_UID = "user_uid" - GROUP_UID = "group_uid" - GROUP_NAME = "group_name" - COMPANY_UID = "company_uid" - COMPANY_NAME = "company_name" - CITY_NAME = "city_name" + UID = "uid" + NAME = "name" + TYPE = "type" + ROLE = "role" + USER_UID = "user_uid" + USER_GROUP_ROLE = "user_group_role" + GROUP_UID = "group_uid" + GROUP_NAME = "group_name" + GROUP_TYPE = "group_type" + COMPANY_UID = "company_uid" + COMPANY_NAME = "company_name" + CITY_UID = "city_uid" ) type UserGroup struct { - db.Model + db.ModelWithUID UserUID string `gorm:"type:char(32);index"` GroupUID string `gorm:"type:char(32);index"` + Role uint8 } type Group struct { db.ModelWithUID CompanyUID string `gorm:"type:char(32)"` Name string `gorm:"type:varchar(256)"` + Type uint8 } type Company struct { db.ModelWithUID diff --git a/src/guanlixitong/portal.css b/src/guanlixitong/portal.css deleted file mode 100644 index fbeacba..0000000 --- a/src/guanlixitong/portal.css +++ /dev/null @@ -1 +0,0 @@ -$output { background-color:var(--plugin-bg-color); } \ No newline at end of file diff --git a/src/guanlixitong/portal.go b/src/guanlixitong/portal.go index 70a82d3..f9b720b 100644 --- a/src/guanlixitong/portal.go +++ b/src/guanlixitong/portal.go @@ -1,95 +1,13 @@ package guanlixitong -import ( - "shylinux.com/x/ice" - "shylinux.com/x/icebergs/base/ctx" - "shylinux.com/x/icebergs/base/mdb" - "shylinux.com/x/icebergs/base/web" - "shylinux.com/x/toolkits" - - "shylinux.com/x/community/src/gonganxitong" - "shylinux.com/x/enterprise/src/guanlixitong/model" -) +import "shylinux.com/x/community/src/gonganxitong" type portal struct { gonganxitong.Portal - city gonganxitong.City - user gonganxitong.User - userGroup userGroup - group group - company company list string `name:"list group_uid index uid auto" role:"void"` - groupCreate string `name:"groupCreate city_name* company_name* name*" role:"void"` - groupRemove string `name:"groupRemove group_uid*" role:"void"` + placeCreate string `name:"placeCreate city_name* company_name* name*" role:"void"` } -func (s portal) Inputs(m *ice.Message, arg ...string) { - s.group.Inputs(m, arg...) -} -func (s portal) List(m *ice.Message, arg ...string) { - if m.Option("form") == "table" { - s.Hash.List(m, arg...).SortInt(mdb.ORDER) - return - } - if len(arg) == 0 { - m.Cmdy(s.userGroup, m.Option(model.USER_UID)).PushAction(s.GroupRemove).Action(s.GroupCreate, s.ScanQRCode) - kit.If(!m.IsErr() && m.Length() == 0, func() { - m.EchoInfoButton(m.Trans("Please Create Your Group", "请创建团队"), s.GroupCreate, s.ScanQRCode) - }) - } else if len(arg) == 2 { - msg := m.Cmd(s.group, s.group.Select, model.UID, arg[0]) - m.Option(model.GROUP_NAME, msg.Append(model.NAME)) - m.Cmdy(ctx.COMMAND, arg[1]).Push(ctx.ARGS, arg[0]) - } else { - s.Portal.List(m, arg...) - } - m.Display("").DisplayCSS("") -} -func (s portal) GroupCreate(m *ice.Message, arg ...string) { - defer m.ToastProcess()() - if s.city.FindOrCreateByName(m, arg...); m.IsErr() { - return - } - if s.company.FindOrCreateByName(m, arg...); m.IsErr() { - return - } - if m.Cmdy(s.group, s.group.Create, arg[2:]).IsErr() { - return - } - args := kit.Simple(m.OptionSimple(model.USER_UID), model.GROUP_UID, m.Result()) - m.Cmdy(s.userGroup, s.userGroup.Create, args).ProcessRefresh() -} -func (s portal) GroupRemove(m *ice.Message, arg ...string) { - defer m.ToastProcess()() - args := m.OptionSimple(model.USER_UID, model.GROUP_UID) - msg := m.Cmd(s.userGroup, s.userGroup.Select, args) - if m.WarnNotFound(msg.Length() == 0, "group") { - return - } - m.Cmdy(s.userGroup, s.userGroup.Delete, args, msg.AppendSimple(model.UID)) - m.Cmdy(s.group, s.group.Delete, model.UID, m.Option(model.GROUP_UID)) - m.ProcessRefresh() -} -func (s portal) ScanQRCode(m *ice.Message, arg ...string) { - defer m.ToastProcess()() - if m.Option(mdb.TYPE) == mdb.TEXT { - args := kit.Simple(m.OptionSimple(model.USER_UID), model.GROUP_UID, m.Option(mdb.TEXT)) - m.Cmdy(s.userGroup, s.userGroup.Create, args, model.ROLE, UserGroupVisitor) - } - if m.Option(mdb.TYPE) == web.LINK { - args := m.ParseURL(m.Option(mdb.TEXT)) - if len(args) > 1 && args[1] == m.Prefix("apply") { - args := kit.Simple(m.OptionSimple(model.USER_UID), model.GROUP_UID, args[0]) - m.Cmdy(s.userGroup, s.userGroup.Create, args, model.ROLE, UserGroupVisitor) - } - } -} - -func init() { ice.TeamCtxCmd(portal{}) } - -func (s portal) Show(m *ice.Message, arg ...string) { - m.GoSleep("30ms", func() { - cmd := m.GetCommand() - m.Cmd(s, s.Create, mdb.NAME, cmd.Help, mdb.ICONS, cmd.Icon, ctx.INDEX, m.PrefixKey()) - }) +func init() { + gonganxitong.PortalCmd(portal{Portal: gonganxitong.NewPortal(userGroup{}, group{}, company{})}) } diff --git a/src/guanlixitong/portal.js b/src/guanlixitong/portal.js deleted file mode 100644 index cf26ceb..0000000 --- a/src/guanlixitong/portal.js +++ /dev/null @@ -1,17 +0,0 @@ -var UID = "uid", GROUP_UID = "group_uid", GROUP_NAME = "group_name" -Volcanos(chat.ONIMPORT, { - _init: function(can, msg) { can.user.isMobile && can.isCmdMode() && can.onappend.style(can, html.OUTPUT) - debugger - can.require([ - "usr/community/src/gonganxitong/portal.js", "usr/community/src/gonganxitong/portal.css?render=replace&index="+can.ConfIndex(), - ], function() { - can.onimport.myPortal(can, msg, GROUP_UID, GROUP_NAME, "我的团队") - }) - }, - myValue: function(can, value) { - return [ - {view: html.TITLE, list: [{text: value.group_name}]}, - {view: html.STATUS, list: [{text: value.group_uid.slice(0, 8)}, {text: value.company_name}]}, - ] - }, -}) diff --git a/src/guanlixitong/portal.json b/src/guanlixitong/portal.json index 88d69bc..efc06da 100644 --- a/src/guanlixitong/portal.json +++ b/src/guanlixitong/portal.json @@ -1,30 +1,19 @@ { "portal": "管理系统", "scanQRCode": "扫码添加", - "groupCreate": "创建团队", - "groupRemove": "解散团队", - "qrcode": "团队码", + "placeCreate": "创建团队", + "placeRemove": "解散团队", "target": "目标计划", "icons": { - "scanQRCode": "bi bi-qr-code-scan", - "groupCreate": "bi bi-plus-square-dotted", - "qrcode": "https://img.icons8.com/officel/80/qr-code.png", - "target": "https://img.icons8.com/officel/80/goal--v1.png"" - }, - "style": { - "groupRemove": "danger" + "target": "https://img.icons8.com/officel/80/goal--v1.png" }, "input": { - "migrate": "迁移", - "uid": "主键", - "info": "信息", - "open_id": "外键", - "user_uid": "用户", - "user_name": "用户名", + "My Group": "我的团队", + "user_group_role": "用户角色", "group_uid": "团队", "group_name": "团队名称", - "company_uid": "公司", - "company_name": "公司名称" + "company_name": "公司名称", + "city_name": "城市名称" }, "value": { "group_type": { @@ -32,6 +21,10 @@ "icons": { "RD": "https://img.icons8.com/officel/80/code.png" } + }, + "user_group_role": { + "leader": "领导", + "member": "组员" } } } diff --git a/src/guanlixitong/portal.shy b/src/guanlixitong/portal.shy index b161ec1..a8cd6db 100644 --- a/src/guanlixitong/portal.shy +++ b/src/guanlixitong/portal.shy @@ -1,5 +1,4 @@ chapter "管理系统" - field web.code.mysql.client field web.code.mysql.query args `mysql guanlixitong` field web.code.db.database diff --git a/src/guanlixitong/qrcode.go b/src/guanlixitong/qrcode.go deleted file mode 100644 index a792dee..0000000 --- a/src/guanlixitong/qrcode.go +++ /dev/null @@ -1,26 +0,0 @@ -package guanlixitong - -import ( - "shylinux.com/x/ice" - kit "shylinux.com/x/toolkits" - - "shylinux.com/x/enterprise/src/guanlixitong/model" -) - -type qrcode struct { - portal portal - userGroup userGroup - list string `name:"list group_uid auto" role:"void"` -} - -func (s qrcode) Init(m *ice.Message, arg ...string) { - s.portal.Show(m) -} -func (s qrcode) List(m *ice.Message, arg ...string) { - msg := m.Cmd(s.userGroup, m.Option(model.USER_UID), arg[0]) - m.FieldsSetDetail() - kit.For([]string{model.CITY_NAME, model.COMPANY_NAME, model.GROUP_NAME}, func(key string) { m.Push(key, msg.Append(key)) }) - m.EchoQRCode(s.portal.Link(m, arg[0], m.Prefix("apply"))) -} - -func init() { ice.TeamCtxCmd(qrcode{}) } diff --git a/src/guanlixitong/userGroup.go b/src/guanlixitong/userGroup.go index 3d88e77..5107f01 100644 --- a/src/guanlixitong/userGroup.go +++ b/src/guanlixitong/userGroup.go @@ -12,10 +12,24 @@ type userGroup struct { company company } +func (s userGroup) User(m *ice.Message, arg ...string) { + s.Select(m, model.GROUP_UID, arg[0]).RenameAppend(model.ROLE, model.USER_GROUP_ROLE) + s.SelectJoinUser(m) + s.RewriteAppend(m) +} func (s userGroup) List(m *ice.Message, arg ...string) { - s.Tables(m, s.group, s.company).Fields(m, - s.Key(s.group, model.CREATED_AT), model.COMPANY_NAME, model.GROUP_NAME, model.GROUP_UID, model.COMPANY_UID, - ).Orders(m, s.Desc(model.CREATED_AT)).Select(m, model.USER_UID, arg[0]) + s.Tables(m, s.group, s.company).FieldsWithCreatedAT(m, s, + model.GROUP_NAME, model.GROUP_TYPE, model.USER_GROUP_ROLE, + model.COMPANY_NAME, + model.GROUP_UID, model.CITY_UID, + ) + if len(arg) == 1 { + s.Select(m, model.USER_UID, arg[0]) + } else if len(arg) == 2 { + s.SelectDetail(m, model.USER_UID, arg[0], model.GROUP_UID, arg[1]) + } + s.SelectJoinCity(m) + s.RewriteAppend(m) } func init() { ice.TeamCtxCmd(userGroup{}) } @@ -24,16 +38,16 @@ type UserGroupRole int const ( UserGroupCreator UserGroupRole = iota + UserGroupVisitor UserGroupLeader UserGroupMember - UserGroupVisitor ) var UserGroupRoleList = map[UserGroupRole]string{ UserGroupCreator: "creator", + UserGroupVisitor: "visitor", UserGroupLeader: "leader", UserGroupMember: "member", - UserGroupVisitor: "visitor", } func (s UserGroupRole) String() string { return UserGroupRoleList[s] }