mirror of
https://shylinux.com/x/community
synced 2025-04-25 17:48:06 +08:00
102 lines
3.6 KiB
Go
102 lines
3.6 KiB
Go
package gonganxitong
|
|
|
|
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/model"
|
|
)
|
|
|
|
type Portal struct {
|
|
ice.Hash
|
|
Table
|
|
user user
|
|
city city
|
|
export string `data:"true"`
|
|
short string `data:"index"`
|
|
field string `data:"time,name,icons,index,order,enable,type,role"`
|
|
inputs string `name:"inputs" role:"void"`
|
|
list string `name:"list place_uid index uid auto" role:"void"`
|
|
placeCreate string `name:"placeCreate city_name* street_name* place_type*:select name* address*" role:"void" icon:"bi bi-plus-square-dotted"`
|
|
placeRemove string `name:"placeRemove uid*" role:"void" style:"danger"`
|
|
scanQRCode string `name:"scanQRCode type text" role:"void" icon:"bi bi-qr-code-scan"`
|
|
}
|
|
|
|
func (s Portal) BeforeMigrate(m *ice.Message, arg ...string) {
|
|
|
|
}
|
|
func (s Portal) Inputs(m *ice.Message, arg ...string) {
|
|
m.Cmdy(s.Place, m.ActionKey(), 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.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.Select, model.UID, arg[0])
|
|
m.Option(s.Key(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.Display(m)
|
|
}
|
|
func (s Portal) PlaceCreate(m *ice.Message, arg ...string) {
|
|
defer m.ToastProcess()()
|
|
if s.city.FindOrCreateByName(m, arg...); m.IsErr() {
|
|
return
|
|
}
|
|
if s.Street.FindOrCreateByName(m, arg...); m.IsErr() {
|
|
return
|
|
}
|
|
arg = kit.TransArgKeys(arg, s.Keys(s.Place, model.TYPE), model.TYPE)
|
|
if m.Cmdy(s.Place, s.Create, arg[2:]).IsErr() {
|
|
return
|
|
}
|
|
args := kit.Simple(m.OptionSimple(model.USER_UID), s.Keys(s.Place, model.UID), m.Result(), model.ROLE, UserPlaceCreator)
|
|
m.Cmdy(s.UserPlace, s.Create, args).ProcessRefresh()
|
|
}
|
|
func (s Portal) PlaceRemove(m *ice.Message, arg ...string) {
|
|
defer m.ToastProcess()()
|
|
m.Cmdy(s.UserPlace, s.Delete, m.OptionSimple(model.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), s.Key(s.Place, model.UID), m.Option(mdb.TEXT))
|
|
m.Cmdy(s.UserPlace, s.Create, args, model.ROLE, UserPlaceVisitor)
|
|
}
|
|
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.Key(s.Place, model.UID), args[0])
|
|
m.Cmdy(s.UserPlace, s.Create, args, model.ROLE, UserPlaceVisitor)
|
|
}
|
|
}
|
|
}
|
|
|
|
func init() { ice.TeamCtxCmd(Portal{Table: newTable()}) }
|
|
|
|
func (s Portal) Show(m *ice.Message, arg ...string) {
|
|
m.GoSleep("30ms", func() {
|
|
cmd := m.GetCommand()
|
|
m.Cmd(m.Prefix(web.PORTAL), s.Create, mdb.NAME, cmd.Help, mdb.ICONS, cmd.Icon, ctx.INDEX, m.PrefixKey())
|
|
})
|
|
}
|
|
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)}, ":"), ":")
|
|
}
|