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 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 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...) } 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() { m.Cmdy(s.service, s.Update, m.ConfigSimple(mdb.NAME), mdb.ICON, kit.Select(ice.Info.NodeIcon, m.Config(mdb.ICON)), ctx.INDEX, m.PrefixKey()) }) } func (s Portal) Inputs(m *ice.Message, arg ...string) { m.Cmdy(s.Place, m.ActionKey(), arg) } func (s Portal) SetIcons(m *ice.Message, arg ...string) { s.Hash.Modify(m, arg...) } 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.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 } 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() s.RecordEvent(m, m.Result(), kit.Format(m.Trans("create", "创建")), arg...) } 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) } 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 init() { ice.TeamCtxCmd(Portal{Table: newTable()}) } type portal struct { Portal name string `data:"公安系统"` } func init() { ice.TeamCtxCmd(portal{Portal: Portal{Table: newTable()}}) } func (s Portal) Create(m *ice.Message, arg ...string) { var _cmd *ice.Command m.Search(m.Option(ctx.INDEX), func(key string, cmd *ice.Command) { _cmd = cmd }) msg := s.Hash.Select(m.Spawn(), m.Option(ctx.INDEX)) s.Hash.Create(m, ctx.INDEX, m.Option(ctx.INDEX), mdb.NAME, _cmd.Help, mdb.ICONS, _cmd.Icon, mdb.TIME, msg.Append(mdb.TIME)) } 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)}, ":"), ":") }