This commit is contained in:
IT 老营长 @云轩领航-创始人 2024-08-02 18:41:39 +08:00
parent 48bedf9b2c
commit 921f638b8d
16 changed files with 121 additions and 131 deletions

View File

@ -2,14 +2,24 @@ package jiaowuxitong
import ( import (
"shylinux.com/x/ice" "shylinux.com/x/ice"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/education/src/jiaowuxitong/model" "shylinux.com/x/education/src/jiaowuxitong/model"
) )
type Class struct{ Table } type Class struct {
Table
school school
}
func (s Class) Inputs(m *ice.Message, arg ...string) { func (s Class) Inputs(m *ice.Message, arg ...string) {
switch arg[0] { switch arg[0] {
case model.GRADE:
y := kit.Int(kit.Split(m.Time(), "-")[0])
for i := 0; i < 10; i++ {
m.Push(arg[0], kit.Format("%d级", y))
y--
}
case model.NAME: case model.NAME:
m.Push(arg[0], "高一二班") m.Push(arg[0], "高一二班")
m.Push(arg[0], "高二三班") m.Push(arg[0], "高二三班")
@ -21,4 +31,4 @@ func (s Class) Inputs(m *ice.Message, arg ...string) {
} }
} }
func init() { ice.Cmd(prefixKey(), Class{}) } func init() { ice.TeamCtxCmd(Class{}) }

View File

@ -5,28 +5,18 @@ import (
"shylinux.com/x/icebergs/base/web" "shylinux.com/x/icebergs/base/web"
kit "shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
"shylinux.com/x/education/src/jiaowuxitong/model"
"shylinux.com/x/mysql-story/src/db" "shylinux.com/x/mysql-story/src/db"
) )
type Table struct { type Table struct {
db.Table db.Table
inputs string `name"inputs" role:"void"`
list string `name:"list class_uid uid auto" role:"void"`
} }
func (s Table) Init(m *ice.Message, arg ...string) { 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) { func (s Table) Inputs(m *ice.Message, arg ...string) {
switch arg[0] { s.Table.Inputs(m, arg...)
case model.GRADE:
y := kit.Int(kit.Split(m.Time(), "-")[0])
for i := 0; i < 10; i++ {
m.Push(arg[0], kit.Format("%d级", y))
y--
}
default:
s.Table.Inputs(m, arg...)
}
} }
func prefixKey() string { return kit.Keys("web.team", kit.PathName(-1), kit.FileName(-1)) }

View File

@ -1,31 +0,0 @@
package jiaowuxitong
import (
"shylinux.com/x/ice"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/community/src/gonganxitong"
"shylinux.com/x/education/src/jiaowuxitong/model"
)
const (
EVENT_CLASS_CREATE = "web.team.education.class.create"
EVENT_CLASS_REMOVE = "web.team.education.class.remove"
)
type events struct {
user gonganxitong.User
portal portal
classCreate string `name:"classCreate" event:"web.team.education.class.create"`
classRemove string `name:"classRemove" event:"web.team.education.class.remove"`
}
func (s events) ClassCreate(m *ice.Message, arg ...string) { s.classEvent(m, "班级创建成功") }
func (s events) ClassRemove(m *ice.Message, arg ...string) { s.classEvent(m, "班级删除成功") }
func init() { ice.Cmd(prefixKey(), events{}) }
func (s events) classEvent(m *ice.Message, arg ...string) {
m.Cmd(s.user, s.user.SendTemplate, m.MergePodCmd("", ice.GetTypeKey(s.portal))+"#"+m.Option(model.CLASS_UID),
m.Trans(m.ActionKey(), arg[0]), m.Option(model.CLASS_NAME), kit.Cut(m.Option(model.CLASS_UID), 8))
}

View File

@ -1,4 +1 @@
$output div.item { padding:20px; } $output div.item.card div.status { white-space:pre; }
$output div.item div.title { border-left: var(--box-notice3); padding-left:10px; }
$output div.item div.content { white-space:pre; padding:10px; }
$input.create tr.class_uid { display:none; }

View File

@ -2,30 +2,34 @@ package jiaowuxitong
import ( import (
"shylinux.com/x/ice" "shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/mdb" kit "shylinux.com/x/toolkits"
"shylinux.com/x/community/src/gonganxitong"
"shylinux.com/x/education/src/jiaowuxitong/model" "shylinux.com/x/education/src/jiaowuxitong/model"
) )
type homework struct { type homework struct {
Table Table
Class Class Class Class
user gonganxitong.User
portal string `data:"true"` portal string `data:"true"`
create string `name:"create class_uid* content*"` create string `name:"create content*" role:"void"`
list string `name:"list class_uid uid auto"`
} }
func (s homework) Create(m *ice.Message, arg ...string) {
s.Table.Create(m, kit.Simple(arg, m.OptionSimple(model.USER_UID, model.CLASS_UID))...)
}
func (s homework) List(m *ice.Message, arg ...string) { func (s homework) List(m *ice.Message, arg ...string) {
if len(arg) == 0 { if len(arg) == 0 {
s.Table.List(m, arg...) if m.IsTech() {
return s.Table.Select(m)
}
} else if len(arg) == 1 { } else if len(arg) == 1 {
s.Table.Select(m, model.CLASS_UID, arg[0]).PushAction(s.Remove).Action(s.Create) s.Table.Select(m, model.CLASS_UID, arg[0])
} else { } else {
s.Table.Select(m.FieldsSetDetail(), model.UID, arg[1]).PushAction(s.Remove) s.Table.Select(m.FieldsSetDetail(), model.UID, arg[1])
} }
m.Option(model.CLASS_NAME, m.Cmd(s.Class, s.Class.Select, model.UID, arg[0]).Append(mdb.NAME)) s.SelectJoin(m, s.user, "name", "avatar").Display("").DisplayCSS("")
m.Display("").DisplayCSS("")
} }
func init() { ice.Cmd(prefixKey(), homework{}) } func init() { ice.TeamCtxCmd(homework{}) }

View File

@ -1,22 +1,21 @@
var UID = "uid", CLASS_NAME = "class_name" var UID = "uid", CLASS_NAME = "class_name"
Volcanos(chat.ONIMPORT, { Volcanos(chat.ONIMPORT, {
_init: function(can, msg) { _init: function(can, msg) {
if (msg.IsDetail()) { var value = msg.TableDetail(), time = can.base.TimeTrim(value.created_at) if (msg.IsDetail()) { var value = msg.TableDetail()
can.user.title([can.ConfHelp(), msg.Option(CLASS_NAME), can.base.trimPrefix(value.created_at.split(" ")[0], can.base.Time(null, "%y-"))].join(" ")) can.page.Append(can, can._output, [can.onimport.itemcard(can, value, [
can.page.Append(can, can._output, [{view: html.ITEM, list: [ {view: html.TITLE, list: [{text: value.user_name}, {text: can.base.TimeTrim(value.created_at)}]},
{view: [html.TITLE, "", time]}, {view: html.STATUS, list: [{text: value.content}]},
{view: [html.CONTENT, "", value.content]}, ])])
]}]), can.onmotion.delay(can, function() { can.user.agent.init(can, value.content) }) msg.Option("_share_content", value.content)
can.user.title([can.ConfHelp(), can.sup.Conf(CLASS_NAME), can.base.trimPrefix(value.created_at.split(" ")[0], can.base.Time(null, "%y-"))].join(" "))
} else { } else {
can.user.title([can.ConfHelp(), msg.Option(CLASS_NAME)].join(" ")) can.page.Append(can, can._output, msg.Table(function(value) {
can.page.Append(can, can._output, msg.Table(function(value) { var time = can.base.TimeTrim(value.created_at) return can.onimport.itemcard(can, value, [
return {view: html.ITEM, list: [ {view: html.TITLE, list: [{text: value.user_name}, {text: can.base.TimeTrim(value.created_at)}]},
{view: [html.TITLE, "", time]}, {view: html.STATUS, list: [{text: value.content}]},
{view: [html.CONTENT, "", value.content]}, ])
], onclick: function(event) { }))
can.Option(UID, value.uid), can.Update(event) can.user.title([can.ConfHelp(), can.sup.Conf(CLASS_NAME)].join(" "))
}}
})), can.onmotion.delay(can, function() { can.user.agent.init(can, can.user.info.titles) })
} }
}, },
}) })

View File

@ -1,14 +1,12 @@
package model package model
import ( import "shylinux.com/x/mysql-story/src/db"
"shylinux.com/x/ice"
"shylinux.com/x/mysql-story/src/db"
)
const ( const (
UID = "uid" UID = "uid"
NAME = "name" NAME = "name"
GRADE = "grade" GRADE = "grade"
CREATED_AT = "created_at"
USER_UID = "user_uid" USER_UID = "user_uid"
CLASS_UID = "class_uid" CLASS_UID = "class_uid"
CLASS_NAME = "class_name" CLASS_NAME = "class_name"
@ -19,7 +17,7 @@ const (
type UserClass struct { type UserClass struct {
db.Model db.Model
UserUID string `gorm:"type:char(32);index"` UserUID string `gorm:"type:char(32);index"`
ClassUID string `gorm:"type:char(32)"` ClassUID string `gorm:"type:char(32)";index`
} }
type Class struct { type Class struct {
db.ModelWithUID db.ModelWithUID
@ -29,20 +27,15 @@ type Class struct {
} }
type School struct { type School struct {
db.ModelWithUID db.ModelWithUID
CityUID string `gorm:"type:char(32);index"`
Name string `gorm:"type:varchar(256)"` Name string `gorm:"type:varchar(256)"`
Address string `gorm:"type:varchar(4096)"`
Info string Info string
} }
type Homework struct { type Homework struct {
db.ModelWithUID db.ModelWithUID
ClassUID string `gorm:"type:char(32);index"` ClassUID string `gorm:"type:char(32);index"`
UserUID string `gorm:"type:char(32)"`
Content string Content string
} }
type models struct{ db.Models } func init() { db.CmdModels("", &UserClass{}, &Class{}, &School{}, &Homework{}) }
func (s models) Init(m *ice.Message, arg ...string) {
s.Models.Register(m, "jiaowuxitong", &UserClass{}, &Class{}, &School{}, &Homework{})
}
func init() { ice.Cmd("web.team.education.jiaowuxitong.models", models{}) }

View File

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

View File

@ -4,7 +4,7 @@ import (
"shylinux.com/x/ice" "shylinux.com/x/ice"
"shylinux.com/x/icebergs/base/ctx" "shylinux.com/x/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb" "shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/toolkits" kit "shylinux.com/x/toolkits"
"shylinux.com/x/community/src/gonganxitong" "shylinux.com/x/community/src/gonganxitong"
"shylinux.com/x/education/src/jiaowuxitong/model" "shylinux.com/x/education/src/jiaowuxitong/model"
@ -12,55 +12,67 @@ import (
type portal struct { type portal struct {
gonganxitong.Portal gonganxitong.Portal
city gonganxitong.City
user gonganxitong.User user gonganxitong.User
userClass userClass userClass userClass
Class Class class Class
school school school school
inputs string `name:"inputs" role:"void"`
list string `name:"list class_uid index uid auto" role:"void"` list string `name:"list class_uid index uid auto" role:"void"`
classCreate string `name:"classCreate school_uid* grade* name*" role:"void"` classCreate string `name:"classCreate city_name* school_name* grade*:select name*" role:"void"`
classRemove string `name:"classRemove class_uid*" role:"void"` classRemove string `name:"classRemove class_uid*" role:"void"`
} }
func (s portal) Inputs(m *ice.Message, arg ...string) { func (s portal) Inputs(m *ice.Message, arg ...string) {
s.Class.Inputs(m, arg...) s.class.Inputs(m, arg...)
} }
func (s portal) List(m *ice.Message, arg ...string) { 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 { if len(arg) == 0 {
m.Cmdy(s.userClass, s.userClass.MyClass, s.user.UserUID(m)).Action(s.ClassCreate).PushAction(s.ClassRemove) m.Cmdy(s.userClass, m.Option(model.USER_UID)).PushAction(s.ClassRemove).Action(s.ClassCreate)
kit.If(m.Length() == 0, func() { m.EchoInfoButton(m.Trans("Please Create Your Class", "请创建班级"), s.ClassCreate) }) kit.If(!m.IsErr() && m.Length() == 0, func() { m.EchoInfoButton(m.Trans("Please Create Your Class", "请创建班级"), s.ClassCreate) })
m.Display("").DisplayCSS("") } else if len(arg) == 2 {
msg := m.Cmd(s.class, s.class.Select, model.UID, arg[0])
m.Option(model.CLASS_NAME, msg.Append(model.NAME))
m.Cmdy(ctx.COMMAND, arg[1]).Push(ctx.ARGS, arg[0])
} else { } else {
s.Portal.List(m, arg...) s.Portal.List(m, arg...)
} }
m.Display("").DisplayCSS("")
} }
func (s portal) ClassCreate(m *ice.Message, arg ...string) { func (s portal) ClassCreate(m *ice.Message, arg ...string) {
m.ToastProcess() defer m.ToastProcess()()
msg := m.Cmd(s.school, s.school.Select, model.UID, m.Option(model.SCHOOL_UID)) if s.city.FindOrCreateByName(m, arg...); m.IsErr() {
if !m.WarnNotFound(msg.Length() == 0, "school") { return
if !m.Cmdy(s.Class, s.Class.Create, arg).IsErr() { }
args := kit.Simple(model.USER_UID, s.user.UserUID(m), model.CLASS_UID, m.Result()) if s.school.FindOrCreateByName(m, arg...); m.IsErr() {
m.Cmd(s.userClass, s.userClass.Create, args) return
m.Event(EVENT_CLASS_CREATE, args, model.CLASS_NAME, m.Option(mdb.NAME)) }
m.ProcessRefresh().ToastSuccess() if !m.Cmdy(s.class, s.class.Create, arg[2:]).IsErr() {
} args := kit.Simple(model.USER_UID, m.Option(model.USER_UID), model.CLASS_UID, m.Result())
m.Cmdy(s.userClass, s.userClass.Create, args)
m.ProcessRefresh()
} }
} }
func (s portal) ClassRemove(m *ice.Message, arg ...string) { func (s portal) ClassRemove(m *ice.Message, arg ...string) {
m.ToastProcess() defer m.ToastProcess()()
args := kit.Simple(model.USER_UID, s.user.UserUID(m), m.OptionSimple(model.CLASS_UID)) args := m.OptionSimple(model.USER_UID, model.CLASS_UID)
msg := m.Cmd(s.userClass, s.userClass.Select, args) msg := m.Cmd(s.userClass, s.userClass.Select, args)
if !m.WarnNotFound(msg.Length() == 0, "class") { if !m.WarnNotFound(msg.Length() == 0, "class") {
m.Cmdy(s.userClass, s.userClass.Delete, args) m.Cmdy(s.userClass, s.userClass.Delete, args)
m.Cmdy(s.Class, s.Class.Delete, model.UID, m.Option(model.CLASS_UID)) m.Cmdy(s.class, s.class.Delete, model.UID, m.Option(model.CLASS_UID))
m.Event(EVENT_CLASS_REMOVE, args) m.ProcessRefresh()
m.ProcessRefresh().ToastSuccess()
} }
} }
func init() { ice.Cmd(prefixKey(), portal{}) } func init() { ice.TeamCtxCmd(portal{}) }
func (s portal) Show(m *ice.Message, arg ...string) { func (s portal) Show(m *ice.Message, arg ...string) {
cmd := m.GetCommand() m.GoSleep("30ms", func() {
m.Cmd(s, s.Create, mdb.NAME, cmd.Help, mdb.ICONS, cmd.Icon, ctx.INDEX, m.PrefixKey()) 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,8 @@
var UID = "uid", CLASS_UID = "class_uid", CLASS_NAME = "class_name" var UID = "uid", CLASS_UID = "class_uid", CLASS_NAME = "class_name"
Volcanos(chat.ONIMPORT, { Volcanos(chat.ONIMPORT, {
_init: function(can, msg) { _init: function(can, msg) { can.user.isMobile && can.isCmdMode() && can.onappend.style(can, html.OUTPUT)
can.require([ can.require([
"usr/community/src/gonganxitong/portal.js", "usr/community/src/gonganxitong/portal.js", "usr/community/src/gonganxitong/portal.css?render=replace&index="+can.ConfIndex(),
"usr/community/src/gonganxitong/portal.css?render=replace&index="+can.ConfIndex(),
], function() { ], function() {
can.onimport.myPortal(can, msg, CLASS_UID, CLASS_NAME, "我的班级") can.onimport.myPortal(can, msg, CLASS_UID, CLASS_NAME, "我的班级")
}) })

View File

@ -21,6 +21,12 @@
"class_uid": "班级", "class_uid": "班级",
"class_name": "班级名称", "class_name": "班级名称",
"school_uid": "学校", "school_uid": "学校",
"school_name": "学校名称" "school_name": "学校名称",
"place_address": "学校地址",
"city_name": "城市名称"
},
"value": {
} }
} }

View File

@ -1,7 +1,5 @@
chapter "教务系统" chapter "教务系统"
refer `
GORM https://gorm.io/docs/indexes.html
`
field web.code.mysql.client field web.code.mysql.client
field web.code.mysql.query args `mysql jiaowuxitong` field web.code.mysql.query args `mysql jiaowuxitong`
field web.code.db.database field web.code.db.database

View File

@ -1,10 +1,23 @@
package jiaowuxitong package jiaowuxitong
import "shylinux.com/x/ice" import (
"shylinux.com/x/ice"
"shylinux.com/x/education/src/jiaowuxitong/model"
)
type school struct { type school struct {
Table Table
create string `name:"create name* address info"` create string `name:"create city_uid* name info"`
} }
func init() { ice.Cmd(prefixKey(), school{}) } func init() { ice.TeamCtxCmd(school{}) }
func (s school) 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.SCHOOL_UID, msg.Result()
} else {
arg[2], arg[3] = model.SCHOOL_UID, msg.Append(model.UID)
}
}

View File

@ -13,9 +13,9 @@ type userClass struct {
create string `name:"create user_uid* class_uid*"` create string `name:"create user_uid* class_uid*"`
} }
func (s userClass) MyClass(m *ice.Message, arg ...string) { func (s userClass) List(m *ice.Message, arg ...string) {
s.Fields(m, "classes.created_at", model.SCHOOL_NAME, model.GRADE, model.CLASS_NAME, model.CLASS_UID, model.SCHOOL_UID).Tables(m, s.Class, s.school) s.Tables(m, s.Class, s.school).Fields(m, s.Key(s.Class, model.CREATED_AT), model.SCHOOL_NAME, model.GRADE, model.CLASS_NAME, model.CLASS_UID, model.SCHOOL_UID)
s.Select(m, model.USER_UID, arg[0]) s.Select(m, model.USER_UID, arg[0])
} }
func init() { ice.Cmd(prefixKey(), userClass{}) } func init() { ice.TeamCtxCmd(userClass{}) }

View File

@ -4,7 +4,6 @@ import (
"shylinux.com/x/ice" "shylinux.com/x/ice"
_ "shylinux.com/x/education/src/jiaowuxitong" _ "shylinux.com/x/education/src/jiaowuxitong"
_ "shylinux.com/x/mysql-story/src/db/mysql"
) )
func main() { print(ice.Run()) } func main() { print(ice.Run()) }

View File

@ -1,6 +1,8 @@
package main package main
import ( import (
_ "shylinux.com/x/golang-story/src/runtime"
_ "shylinux.com/x/ice/devops" _ "shylinux.com/x/ice/devops"
_ "shylinux.com/x/golang-story/src/runtime"
_ "shylinux.com/x/mysql-story/src/db/mysql"
) )