This commit is contained in:
jingganjiaoyu 2024-08-03 09:20:30 +08:00
parent 6746ab1c88
commit 060809dd84
13 changed files with 202 additions and 89 deletions

View File

@ -1,10 +1,7 @@
package guanlixitong
import (
"strings"
"shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits"
@ -12,18 +9,25 @@ import (
"shylinux.com/x/mysql-story/src/db"
)
type Table struct{ db.Table }
type Table struct {
db.Table
inputs string `name"inputs" role:"void"`
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() { m.GoSleep("30ms", func() { portal{}.Show(m) }) })
kit.If(m.Config(web.PORTAL) == ice.TRUE, func() { portal{}.Show(m) })
}
func (s Table) Inputs(m *ice.Message, arg ...string) {
switch arg[0] {
case model.USER_UID, model.COMPANY_UID:
m.Optionv(mdb.SELECT, model.UID, model.NAME)
m.Cmdy(m.Prefix(strings.TrimSuffix(arg[0], "_uid"))).RenameAppend(model.UID, arg[0])
m.DisplayInputKeyNameIconTitle()
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)
}
} else if len(arg) == 2 {
s.Table.Select(m.FieldsSetDetail(), model.UID, arg[1])
}
return m
}
func prefixKey() string { return kit.Keys("web.team", kit.PathName(-1), kit.FileName(-1)) }

View File

@ -1,7 +1,20 @@
package guanlixitong
import "shylinux.com/x/ice"
import (
"shylinux.com/x/ice"
"shylinux.com/x/enterprise/src/guanlixitong/model"
)
type company struct{ Table }
func init() { ice.Cmd(prefixKey(), company{}) }
func (s company) FindOrCreateByName(m *ice.Message, arg ...string) {
if msg := m.Cmd(s, s.Select, model.NAME, arg[3], arg[0], arg[1]); msg.Length() == 0 {
msg := m.Cmd(s, s.Create, model.NAME, arg[3], arg[0], arg[1])
arg[2], arg[3] = model.COMPANY_UID, msg.Result()
} else {
arg[2], arg[3] = model.COMPANY_UID, msg.Append(model.UID)
}
}
func init() { ice.TeamCtxCmd(company{}) }

View File

@ -4,8 +4,26 @@ import "shylinux.com/x/ice"
type group struct{ Table }
func (s group) List(m *ice.Message, arg ...string) {
s.Table.List(m, arg...)
func init() { ice.TeamCtxCmd(group{}) }
type GroupType int
const (
GroupRD GroupType = iota
GroupOP
GroupSales
GroupFinancial
GroupAdmin
GroupHR
)
var GroupTypeList = map[GroupType]string{
GroupRD: "RD",
GroupOP: "OP",
GroupSales: "sales",
GroupFinancial: "financial",
GroupAdmin: "admin",
GroupHR: "HR",
}
func init() { ice.Cmd(prefixKey(), group{}) }
func (s GroupType) String() string { return GroupTypeList[s] }

View File

@ -1,47 +1,42 @@
package model
import (
"shylinux.com/x/ice"
"shylinux.com/x/mysql-story/src/db"
)
import "shylinux.com/x/mysql-story/src/db"
const (
UID = "uid"
NAME = "name"
OPENID = "openid"
OPEN_ID = "open_id"
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"
)
type UserGroup struct {
db.Model
UserUID string `gorm:"type:char(32);index"`
GroupUID string `gorm:"type:char(32)"`
GroupUID string `gorm:"type:char(32);index"`
}
type Group struct {
db.ModelWithUID
CompanyUID string `gorm:"type:char(32)"`
Name string `gorm:"type:char(32)"`
Name string `gorm:"type:varchar(256)"`
}
type Company struct {
db.ModelWithUID
Name string `gorm:"type:varchar(256)"`
CityUID string `gorm:"type:char(32);index"`
Name string `gorm:"type:varchar(256);index"`
Info string
}
type Target struct {
db.ModelWithUID
Name string `gorm:"type:varchar(256)"`
Info string
GroupUID string `gorm:"type:char(32);index"`
UserUID string `gorm:"type:char(32)"`
Content string
}
type models struct{ db.Models }
func (s models) Init(m *ice.Message, arg ...string) {
s.Models.Register(m, "guanlixitong", &UserGroup{}, &Group{}, &Company{}, &Target{})
}
func init() { ice.Cmd("web.team.enterprise.guanlixitong.models", models{}) }
func init() { db.CmdModels("", &UserGroup{}, &Group{}, &Company{}, &Target{}) }

View File

@ -1 +0,0 @@
CREATE DATABASE IF NOT EXISTS guanlixitong CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

View File

@ -4,70 +4,92 @@ 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"
)
const (
EVENT_GROUP_CREATE = "web.team.enterprise.group.create"
EVENT_GROUP_REMOVE = "web.team.enterprise.group.remove"
)
type portal struct {
gonganxitong.Portal
city gonganxitong.City
user gonganxitong.User
userGroup userGroup
group group
company company
export string `data:"true"`
short string `data:"index"`
field string `data:"time,name,icons,index,order,enable"`
list string `name:"list group_uid index uid auto" role:"void"`
groupCreate string `name:"groupCreate company_uid* name*" role:"void"`
groupRemove string `name:"groupRemove group_uid*" role:"void" style:"danger"`
groupCreate string `name:"groupCreate city_name* company_name* name*" role:"void"`
groupRemove string `name:"groupRemove group_uid*" 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, s.userGroup.MyGroup, s.user.UserUID(m)).Action(s.GroupCreate).PushAction(s.GroupRemove)
kit.If(m.Length() == 0, func() { m.EchoInfoButton(m.Trans("Please Create Your Group", "请创建团队"), s.GroupCreate) })
m.Display("").DisplayCSS("")
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) {
m.ToastProcess()
msg := m.Cmd(s.company, s.company.Select, model.UID, m.Option(model.COMPANY_UID))
if !m.WarnNotFound(msg.Length() == 0, "company") {
if !m.Cmdy(s.group, s.group.Create, arg).IsErr() {
args := kit.Simple(model.USER_UID, s.user.UserUID(m), model.GROUP_UID, m.Result())
m.Cmd(s.userGroup, s.userGroup.Create, args)
m.Event(EVENT_GROUP_CREATE, args, model.GROUP_NAME, m.Option(model.NAME))
m.ProcessRefresh().ToastSuccess()
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) {
m.ToastProcess()
args := kit.Simple(model.USER_UID, s.user.UserUID(m), m.OptionSimple(model.GROUP_UID))
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") {
m.Cmdy(s.userGroup, s.userGroup.Delete, 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.Event(EVENT_GROUP_REMOVE, args)
m.ProcessRefresh().ToastSuccess()
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.Cmd(prefixKey(), portal{}) }
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())
})
}

View File

@ -1,9 +1,9 @@
var UID = "uid", GROUP_UID = "group_uid", GROUP_NAME = "group_name"
Volcanos(chat.ONIMPORT, {
_init: function(can, msg) {
_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(),
"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, "我的团队")
})

View File

@ -1,12 +1,15 @@
{
"user": "用户",
"group": "团队",
"company": "公司",
"portal": "管理系统",
"scanQRCode": "扫码添加",
"groupCreate": "创建团队",
"groupRemove": "解散团队",
"portal": "管理系统",
"qrcode": "团队码",
"target": "目标计划",
"icons": {
"groupCreate": "bi bi-plus-square-dotted"
"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"
@ -22,6 +25,14 @@
"group_name": "团队名称",
"company_uid": "公司",
"company_name": "公司名称"
},
"value": {
"group_type": {
"RD": "研发",
"icons": {
"RD": "https://img.icons8.com/officel/80/code.png"
}
}
}
}

View File

@ -0,0 +1,7 @@
chapter "管理系统"
field web.code.mysql.client
field web.code.mysql.query args `mysql guanlixitong`
field web.code.db.database
field web.code.db.driver
field web.code.db.models

View File

@ -0,0 +1,26 @@
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{}) }

View File

@ -5,7 +5,6 @@ import "shylinux.com/x/ice"
type target struct {
Table
portal string `data:"true"`
list string `name:"list group_uid uid auto" help:"目标管理"`
}
func init() { ice.Cmd(prefixKey(), target{}) }
func init() { ice.TeamCtxCmd(target{}) }

View File

@ -7,14 +7,33 @@ import (
)
type userGroup struct {
Table
group group
company company
Table
}
func (s userGroup) MyGroup(m *ice.Message, arg ...string) {
s.Fields(m, "groups.created_at", model.COMPANY_NAME, model.GROUP_NAME, model.GROUP_UID, model.COMPANY_UID).Tables(m, s.group, s.company)
s.Select(m, model.USER_UID, arg[0])
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])
}
func init() { ice.Cmd(prefixKey(), userGroup{}) }
func init() { ice.TeamCtxCmd(userGroup{}) }
type UserGroupRole int
const (
UserGroupCreator UserGroupRole = iota
UserGroupLeader
UserGroupMember
UserGroupVisitor
)
var UserGroupRoleList = map[UserGroupRole]string{
UserGroupCreator: "creator",
UserGroupLeader: "leader",
UserGroupMember: "member",
UserGroupVisitor: "visitor",
}
func (s UserGroupRole) String() string { return UserGroupRoleList[s] }

View File

@ -10,4 +10,4 @@ func (s {{.Option "name"}}) List(m *ice.Message, arg ...string) {
s.Table.List(m, arg...)
}
func init() { ice.Cmd(prefixKey(), {{.Option "name"}}{}) }
func init() { ice.TeamCtxCmd({{.Option "name"}}{}) }