mirror of
https://shylinux.com/x/community
synced 2025-05-08 14:48:11 +08:00
165 lines
6.2 KiB
Go
165 lines
6.2 KiB
Go
package gonganxitong
|
|
|
|
import (
|
|
"shylinux.com/x/ice"
|
|
"shylinux.com/x/icebergs/base/aaa"
|
|
"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/model"
|
|
)
|
|
|
|
type Portal struct {
|
|
ice.Hash
|
|
Table
|
|
user user
|
|
city city
|
|
service service
|
|
export string `data:"true"`
|
|
short string `data:"index"`
|
|
field string `data:"time,name,icons,index,order,enable,type,role,view"`
|
|
list string `name:"list place_uid index uid auto" role:"void"`
|
|
create string `name:"create index name icons"`
|
|
placeCreate string `name:"placeCreate city_name* street_name* place_type*:select place_name* address*" icon:"bi bi-plus-square-dotted" role:"void"`
|
|
placeRemove string `name:"placeRemove uid*" role:"void"`
|
|
scanQRCode string `name:"scanQRCode type text" icon:"bi bi-qr-code-scan" role:"void"`
|
|
setIcons string `name:"setIcons icons" icon:"bi bi-info-square"`
|
|
}
|
|
|
|
func (s Portal) Init(m *ice.Message, arg ...string) {
|
|
s.Hash.Init(m, arg...)
|
|
m.Design(s.List, "", kit.JoinWord(s.Keys(s.Place, model.UID), ctx.INDEX, model.UID, ice.AUTO))
|
|
}
|
|
func (s Portal) Exit(m *ice.Message, arg ...string) {
|
|
s.Hash.Exit(m, arg...)
|
|
}
|
|
func (s Portal) BeforeMigrate(m *ice.Message, arg ...string) {
|
|
}
|
|
func (s Portal) AfterMigrate(m *ice.Message, arg ...string) {
|
|
m.GoSleep("30ms", func() {
|
|
cmd := m.Target().Commands[m.CommandKey()]
|
|
m.Cmdy(s.service, s.Table.Update, mdb.NAME, cmd.Help, mdb.ICON, kit.Select(ice.Info.NodeIcon, cmd.Icon), ctx.INDEX, m.PrefixKey())
|
|
})
|
|
}
|
|
func (s Portal) Inputs(m *ice.Message, arg ...string) {
|
|
m.Cmdy(s.Place, m.ActionKey(), arg)
|
|
}
|
|
func (s Portal) Run(m *ice.Message, arg ...string) {
|
|
m.Search(arg[0], func(key string, cmd *ice.Command) {
|
|
role := cmd.Role
|
|
if len(arg) > 1 && arg[1] == ctx.ACTION {
|
|
if action, ok := cmd.Actions[arg[2]]; ok {
|
|
role = action.Role
|
|
}
|
|
} else {
|
|
if action, ok := cmd.Actions[arg[1]]; ok {
|
|
role = action.Role
|
|
}
|
|
}
|
|
if kit.IsIn(role, "", aaa.VOID) {
|
|
kit.If(!ctx.PodCmd(m.Message, arg) && aaa.Right(m.Message, arg), func() { m.Cmdy(arg) })
|
|
} else {
|
|
if !m.Cmdy(arg[0], s.CheckRole, role).IsErr() {
|
|
m.Cmdy(arg)
|
|
}
|
|
}
|
|
s.Place.RewriteAppend(m)
|
|
})
|
|
}
|
|
func (s Portal) List(m *ice.Message, arg ...string) {
|
|
if m.Option(mdb.VIEW) == mdb.TABLE {
|
|
s.Hash.List(m, arg...).PushAction(mdb.DETAIL, s.SetIcons, s.Remove).SortInt(mdb.ORDER)
|
|
return
|
|
}
|
|
if len(arg) == 0 {
|
|
m.Cmdy(s.UserPlace, m.Option(model.USER_UID)).PushAction(s.PlaceRemove).Action(s.PlaceCreate, s.ScanQRCode)
|
|
kit.If(!m.IsErr() && m.Length() == 0, func() {
|
|
m.EchoInfoButton(m.Trans("Please Create Your Place", "请添加场所"), s.PlaceCreate, s.ScanQRCode)
|
|
})
|
|
} else if len(arg) == 2 {
|
|
msg := m.Cmd(s.Place, s.Place.Select, model.UID, arg[0])
|
|
m.Option(s.Keys(s.Place, model.NAME), msg.Append(model.NAME))
|
|
m.Cmdy(ctx.COMMAND, arg[1]).Push(ctx.ARGS, arg[0])
|
|
} else if len(arg) == 1 {
|
|
s.Hash.List(m, arg[1:]...).SortInt(mdb.ORDER)
|
|
} else {
|
|
m.FieldsSetDetail().Cmdy(arg[1], mdb.SELECT, model.UID, arg[2]).PushAction().Action()
|
|
}
|
|
s.Place.RewriteAppend(m)
|
|
s.Display(m, "").DisplayCSS("")
|
|
}
|
|
func (s Portal) PlaceCreate(m *ice.Message, arg ...string) {
|
|
defer m.ToastProcess()()
|
|
if s.city.FindOrCreateByName(m, arg...); m.IsErr() {
|
|
return
|
|
} else if s.Street.FindOrCreateByName(m, arg...); m.IsErr() {
|
|
return
|
|
}
|
|
name := m.Option(s.Keys(s.Place, model.NAME))
|
|
arg = kit.TransArgKeys(arg, s.Keys(s.Place, model.TYPE), model.TYPE)
|
|
arg = kit.TransArgKeys(arg, s.Keys(s.Place, model.NAME), model.NAME)
|
|
if m.Cmdy(s.Place, s.Create, arg[2:]).IsErr() {
|
|
return
|
|
}
|
|
s.RecordEvent(m, m.Result(), m.Trans("create place", "创建服务场景")+" "+name, m.Result())
|
|
args := kit.Simple(m.OptionSimple(model.USER_UID), s.Keys(s.Place, model.UID), m.Result(), model.ROLE, UserPlaceCreator)
|
|
m.SetResult().Cmdy(s.UserPlace, s.Create, args).ProcessRefresh()
|
|
m.Cmd(s.user, s.SendTemplate, "", "", s.Link(m, m.Result()), m.Trans("create place", "创建服务场景"), name, m.Result())
|
|
}
|
|
func (s Portal) PlaceRemove(m *ice.Message, arg ...string) {
|
|
defer m.ToastProcess()()
|
|
m.Cmdy(s.UserPlace, s.Delete, m.OptionSimple(model.UID)).ProcessRefresh()
|
|
m.Cmd(s.user, s.SendTemplate, "", "", s.Link(m, m.Result()), m.Trans("remove place", "删除服务场景"), m.Option("_name"), m.Option(model.UID))
|
|
}
|
|
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), s.Key(s.Place, model.UID), m.Option(mdb.TEXT))
|
|
m.Cmdy(s.UserPlace, s.Create, args, model.ROLE, UserPlaceVisitor)
|
|
} else 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), s.Keys(s.Place, model.UID), args[0])
|
|
m.Cmdy(s.UserPlace, s.Create, args, model.ROLE, UserPlaceVisitor)
|
|
}
|
|
}
|
|
}
|
|
func (s Portal) SetIcons(m *ice.Message, arg ...string) {
|
|
s.Hash.Modify(m, arg...)
|
|
}
|
|
|
|
func init() { ice.TeamCtxCmd(Portal{Table: newTable()}) }
|
|
|
|
func (s Portal) Create(m *ice.Message, arg ...string) {
|
|
args := []string{ctx.INDEX, m.Option(ctx.INDEX)}
|
|
msg := s.Hash.Select(m.Spawn(), m.Option(ctx.INDEX))
|
|
if msg.Length() > 0 {
|
|
args = append(args, mdb.TIME, msg.Append(mdb.TIME))
|
|
}
|
|
m.Search(m.Option(ctx.INDEX), func(key string, cmd *ice.Command) {
|
|
args = append(args, mdb.NAME, cmd.Help, mdb.ICONS, cmd.Icon)
|
|
kit.For([]string{mdb.ORDER, mdb.TYPE, aaa.ROLE, mdb.VIEW}, func(key string) {
|
|
value := m.Conf(m.Option(ctx.INDEX), kit.Keym(key))
|
|
args = append(args, key, kit.Select(value, msg.Append(key)))
|
|
})
|
|
})
|
|
s.Hash.Create(m, args...)
|
|
}
|
|
func (s Portal) Show(m *ice.Message, arg ...string) {
|
|
key := m.PrefixKey()
|
|
m.GoSleep("300ms", func() { m.Cmd(m.Prefix(web.PORTAL), s.Create, ctx.INDEX, key) })
|
|
}
|
|
func (s Portal) Link(m *ice.Message, arg ...string) string {
|
|
return m.MergePodCmd("", m.Prefix(web.PORTAL)) + "?debug=true" +
|
|
"#" + kit.TrimSuffix(kit.Join([]string{arg[0], kit.Select(m.Prefix("apply"), arg, 1), kit.Select("", arg, 2)}, ":"), ":")
|
|
}
|
|
|
|
type portal struct {
|
|
Portal
|
|
name string `data:"公安系统"`
|
|
}
|
|
|
|
func init() { ice.TeamCtxCmd(portal{Portal: Portal{Table: newTable()}}) }
|