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 (
"shylinux.com/x/ice"
kit "shylinux.com/x/toolkits"
"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) {
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:
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"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/education/src/jiaowuxitong/model"
"shylinux.com/x/mysql-story/src/db"
)
type Table struct {
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) {
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.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...)
}
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 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; }
$output div.item.card div.status { white-space:pre; }

View File

@ -2,30 +2,34 @@ package jiaowuxitong
import (
"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"
)
type homework struct {
Table
Class Class
user gonganxitong.User
portal string `data:"true"`
create string `name:"create class_uid* content*"`
list string `name:"list class_uid uid auto"`
create string `name:"create content*" role:"void"`
}
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) {
if len(arg) == 0 {
s.Table.List(m, arg...)
return
if m.IsTech() {
s.Table.Select(m)
}
} 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 {
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))
m.Display("").DisplayCSS("")
s.SelectJoin(m, s.user, "name", "avatar").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"
Volcanos(chat.ONIMPORT, {
_init: function(can, msg) {
if (msg.IsDetail()) { var value = msg.TableDetail(), time = can.base.TimeTrim(value.created_at)
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, [{view: html.ITEM, list: [
{view: [html.TITLE, "", time]},
{view: [html.CONTENT, "", value.content]},
]}]), can.onmotion.delay(can, function() { can.user.agent.init(can, value.content) })
if (msg.IsDetail()) { var value = msg.TableDetail()
can.page.Append(can, can._output, [can.onimport.itemcard(can, value, [
{view: html.TITLE, list: [{text: value.user_name}, {text: can.base.TimeTrim(value.created_at)}]},
{view: html.STATUS, list: [{text: 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 {
can.user.title([can.ConfHelp(), msg.Option(CLASS_NAME)].join(" "))
can.page.Append(can, can._output, msg.Table(function(value) { var time = can.base.TimeTrim(value.created_at)
return {view: html.ITEM, list: [
{view: [html.TITLE, "", time]},
{view: [html.CONTENT, "", value.content]},
], onclick: function(event) {
can.Option(UID, value.uid), can.Update(event)
}}
})), can.onmotion.delay(can, function() { can.user.agent.init(can, can.user.info.titles) })
can.page.Append(can, can._output, msg.Table(function(value) {
return can.onimport.itemcard(can, value, [
{view: html.TITLE, list: [{text: value.user_name}, {text: can.base.TimeTrim(value.created_at)}]},
{view: html.STATUS, list: [{text: value.content}]},
])
}))
can.user.title([can.ConfHelp(), can.sup.Conf(CLASS_NAME)].join(" "))
}
},
})

View File

@ -1,14 +1,12 @@
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"
GRADE = "grade"
CREATED_AT = "created_at"
USER_UID = "user_uid"
CLASS_UID = "class_uid"
CLASS_NAME = "class_name"
@ -19,7 +17,7 @@ const (
type UserClass struct {
db.Model
UserUID string `gorm:"type:char(32);index"`
ClassUID string `gorm:"type:char(32)"`
ClassUID string `gorm:"type:char(32)";index`
}
type Class struct {
db.ModelWithUID
@ -29,20 +27,15 @@ type Class struct {
}
type School struct {
db.ModelWithUID
CityUID string `gorm:"type:char(32);index"`
Name string `gorm:"type:varchar(256)"`
Address string `gorm:"type:varchar(4096)"`
Info string
}
type Homework struct {
db.ModelWithUID
ClassUID 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, "jiaowuxitong", &UserClass{}, &Class{}, &School{}, &Homework{})
}
func init() { ice.Cmd("web.team.education.jiaowuxitong.models", models{}) }
func init() { db.CmdModels("", &UserClass{}, &Class{}, &School{}, &Homework{}) }

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/icebergs/base/ctx"
"shylinux.com/x/icebergs/base/mdb"
"shylinux.com/x/toolkits"
kit "shylinux.com/x/toolkits"
"shylinux.com/x/community/src/gonganxitong"
"shylinux.com/x/education/src/jiaowuxitong/model"
@ -12,55 +12,67 @@ import (
type portal struct {
gonganxitong.Portal
city gonganxitong.City
user gonganxitong.User
userClass userClass
Class Class
class Class
school school
inputs string `name:"inputs" 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"`
}
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) {
if m.Option("form") == "table" {
s.Hash.List(m, arg...).SortInt(mdb.ORDER)
return
}
if len(arg) == 0 {
m.Cmdy(s.userClass, s.userClass.MyClass, s.user.UserUID(m)).Action(s.ClassCreate).PushAction(s.ClassRemove)
kit.If(m.Length() == 0, func() { m.EchoInfoButton(m.Trans("Please Create Your Class", "请创建班级"), s.ClassCreate) })
m.Display("").DisplayCSS("")
m.Cmdy(s.userClass, m.Option(model.USER_UID)).PushAction(s.ClassRemove).Action(s.ClassCreate)
kit.If(!m.IsErr() && m.Length() == 0, func() { m.EchoInfoButton(m.Trans("Please Create Your Class", "请创建班级"), s.ClassCreate) })
} 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 {
s.Portal.List(m, arg...)
}
m.Display("").DisplayCSS("")
}
func (s portal) ClassCreate(m *ice.Message, arg ...string) {
m.ToastProcess()
msg := m.Cmd(s.school, s.school.Select, model.UID, m.Option(model.SCHOOL_UID))
if !m.WarnNotFound(msg.Length() == 0, "school") {
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())
m.Cmd(s.userClass, s.userClass.Create, args)
m.Event(EVENT_CLASS_CREATE, args, model.CLASS_NAME, m.Option(mdb.NAME))
m.ProcessRefresh().ToastSuccess()
}
defer m.ToastProcess()()
if s.city.FindOrCreateByName(m, arg...); m.IsErr() {
return
}
if s.school.FindOrCreateByName(m, arg...); m.IsErr() {
return
}
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) {
m.ToastProcess()
args := kit.Simple(model.USER_UID, s.user.UserUID(m), m.OptionSimple(model.CLASS_UID))
defer m.ToastProcess()()
args := m.OptionSimple(model.USER_UID, model.CLASS_UID)
msg := m.Cmd(s.userClass, s.userClass.Select, args)
if !m.WarnNotFound(msg.Length() == 0, "class") {
m.Cmdy(s.userClass, s.userClass.Delete, args)
m.Cmdy(s.Class, s.Class.Delete, model.UID, m.Option(model.CLASS_UID))
m.Event(EVENT_CLASS_REMOVE, args)
m.ProcessRefresh().ToastSuccess()
m.Cmdy(s.class, s.class.Delete, model.UID, m.Option(model.CLASS_UID))
m.ProcessRefresh()
}
}
func init() { ice.Cmd(prefixKey(), portal{}) }
func init() { ice.TeamCtxCmd(portal{}) }
func (s portal) Show(m *ice.Message, arg ...string) {
cmd := m.GetCommand()
m.Cmd(s, s.Create, mdb.NAME, cmd.Help, mdb.ICONS, cmd.Icon, ctx.INDEX, m.PrefixKey())
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,8 @@
var UID = "uid", CLASS_UID = "class_uid", CLASS_NAME = "class_name"
Volcanos(chat.ONIMPORT, {
_init: function(can, msg) {
_init: function(can, msg) { can.user.isMobile && can.isCmdMode() && can.onappend.style(can, html.OUTPUT)
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, CLASS_UID, CLASS_NAME, "我的班级")
})

View File

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

View File

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

View File

@ -1,10 +1,23 @@
package jiaowuxitong
import "shylinux.com/x/ice"
import (
"shylinux.com/x/ice"
"shylinux.com/x/education/src/jiaowuxitong/model"
)
type school struct {
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*"`
}
func (s userClass) MyClass(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)
func (s userClass) List(m *ice.Message, arg ...string) {
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])
}
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/education/src/jiaowuxitong"
_ "shylinux.com/x/mysql-story/src/db/mysql"
)
func main() { print(ice.Run()) }

View File

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