forked from x/ContextOS
zyb enroll
This commit is contained in:
parent
4e5216dfbf
commit
ee2a7e5107
@ -1,7 +1,5 @@
|
||||
~chat
|
||||
config save tmp/flow.json flow
|
||||
~ssh
|
||||
config save tmp/cert.json work trust
|
||||
config save tmp/cert.json work flow trust
|
||||
~aaa
|
||||
config save tmp/auth.json auth
|
||||
~cli
|
||||
|
@ -3,9 +3,7 @@
|
||||
~aaa
|
||||
config load tmp/auth.json auth
|
||||
~ssh
|
||||
config load tmp/cert.json work trust
|
||||
~chat
|
||||
config load tmp/flow.json flow
|
||||
config load tmp/cert.json work flow trust
|
||||
|
||||
source etc/common.shy
|
||||
~ssh
|
||||
|
@ -270,6 +270,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
|
||||
// 检查链接
|
||||
if arg[i] == "check" {
|
||||
m.Log("fuck", "waht %v", p)
|
||||
has := "false"
|
||||
m.Confm("auth", []string{p, "ship"}, func(k string, ship map[string]interface{}) {
|
||||
if i == len(arg)-2 && (ship["meta"] != arg[i+1] && k != arg[i+1]) {
|
||||
@ -331,7 +332,9 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
m.Echo(h)
|
||||
case "node": // 节点操作
|
||||
if i > len(arg)-1 { // 查看节点
|
||||
m.Set("result")
|
||||
m.Cmdy("aaa.config", "auth", p)
|
||||
return
|
||||
} else if arg[i] == "delete" { // 删除节点
|
||||
m.Confm("auth", []string{p, "ship"}, func(ship map[string]interface{}) {
|
||||
for k, _ := range ship {
|
||||
@ -364,7 +367,8 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
return
|
||||
case "data": // 数据操作
|
||||
if i > len(arg)-1 { // 查看数据
|
||||
m.Cmdy("ctx.config", "auth", strings.Join([]string{p, "data"}, "."))
|
||||
m.Set("result").Cmdy("ctx.config", "auth", strings.Join([]string{p, "data"}, "."))
|
||||
return
|
||||
} else if arg[i] == "delete" { // 删除数据
|
||||
m.Confm("auth", []string{s, "data"}, func(data map[string]interface{}) {
|
||||
for _, k := range arg[i+1:] {
|
||||
@ -373,6 +377,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
}
|
||||
})
|
||||
} else if i < len(arg)-1 { // 修改数据
|
||||
m.Set("result")
|
||||
if arg[i] == "option" {
|
||||
m.Confv("auth", []string{p, "data", arg[i+1]}, m.Optionv(arg[i+1]))
|
||||
} else {
|
||||
@ -511,6 +516,9 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
m.Cmdy("aaa.auth", "ship", "username", m.Option("username"), "session", kit.Select("web", arg, 2))
|
||||
m.Cmd("aaa.auth", m.Result(0), "data", "current.ctx", "mdb")
|
||||
}
|
||||
default:
|
||||
m.Option("format", "object")
|
||||
m.Cmdy("aaa.auth", "username", arg[0], "data")
|
||||
}
|
||||
return
|
||||
}},
|
||||
@ -532,6 +540,7 @@ var Index = &ctx.Context{Name: "aaa", Help: "认证中心",
|
||||
|
||||
switch arg[0] {
|
||||
case "user": // 查看用户
|
||||
m.Log("fuck", "what %v", arg)
|
||||
m.Cmdy("aaa.auth", sid, "ship", "username")
|
||||
|
||||
case "current":
|
||||
|
@ -11,6 +11,7 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"plugin"
|
||||
"regexp"
|
||||
"runtime"
|
||||
"strconv"
|
||||
@ -103,6 +104,16 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
"boot": map[string]interface{}{"web_port": ":9094", "ssh_port": ":9090"},
|
||||
}, Help: "运行环境"},
|
||||
|
||||
"plugin": &ctx.Config{Name: "plugin", Value: map[string]interface{}{
|
||||
"go": map[string]interface{}{
|
||||
"build": []interface{}{"go", "build", "-buildmode=plugin"},
|
||||
"next": []interface{}{"so", "load"},
|
||||
},
|
||||
"so": map[string]interface{}{
|
||||
"load": []interface{}{"load"},
|
||||
},
|
||||
}, Help: "免密登录"},
|
||||
|
||||
"system": &ctx.Config{Name: "system", Value: map[string]interface{}{
|
||||
"timeout": "60s",
|
||||
"env": map[string]interface{}{},
|
||||
@ -215,6 +226,49 @@ var Index = &ctx.Context{Name: "cli", Help: "管理中心",
|
||||
return
|
||||
}},
|
||||
|
||||
"plugin": &ctx.Command{Name: "plugin [action] file", Help: "", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
suffix, action, target := "go", "build", path.Join(m.Conf("runtime", "boot.ctx_home"), "src/examples/app/bench.go")
|
||||
if len(arg) == 0 {
|
||||
arg = append(arg, target)
|
||||
}
|
||||
if cs := strings.Split(arg[0], "."); len(cs) > 1 {
|
||||
suffix = cs[len(cs)-1]
|
||||
} else if cs := strings.Split(arg[1], "."); len(cs) > 1 {
|
||||
suffix, action, arg = cs[len(cs)-1], arg[0], arg[1:]
|
||||
}
|
||||
|
||||
if target = m.Cmdx("nfs.path", arg[0]); target == "" {
|
||||
target = m.Cmdx("nfs.path", path.Join("src/plugin/", arg[0]))
|
||||
}
|
||||
|
||||
for suffix != "" && action != "" {
|
||||
m.Log("info", "%v %v %v", suffix, action, target)
|
||||
cook := m.Confv("plugin", suffix)
|
||||
next := strings.Replace(target, "."+suffix, "."+kit.Chains(cook, "next.0"), -1)
|
||||
|
||||
args := []string{}
|
||||
if suffix == "so" {
|
||||
if p, e := plugin.Open(target); m.Assert(e) {
|
||||
s, e := p.Lookup("Index")
|
||||
m.Assert(e)
|
||||
w := *(s.(**ctx.Context))
|
||||
w.Name = kit.Select(w.Name, arg, 1)
|
||||
c.Register(w, nil)
|
||||
m.Spawn(w).Cmd("_init", arg[1:])
|
||||
}
|
||||
} else {
|
||||
if suffix == "go" {
|
||||
args = append(args, "-o", next)
|
||||
}
|
||||
m.Assert(m.Cmd("cli.system", kit.Chain(cook, action), args, target))
|
||||
}
|
||||
|
||||
suffix = kit.Chains(cook, "next.0")
|
||||
action = kit.Chains(cook, "next.1")
|
||||
target = next
|
||||
}
|
||||
return
|
||||
}},
|
||||
"system": &ctx.Command{Name: "system word...", Help: []string{"调用系统命令, word: 命令",
|
||||
"cmd_timeout: 命令超时",
|
||||
"cmd_active(true/false): 是否交互",
|
||||
|
@ -1234,6 +1234,7 @@ func (m *Message) Assert(e interface{}, msg ...string) bool {
|
||||
return true
|
||||
}
|
||||
e = v.Result(1)
|
||||
e = errors.New(v.Result(1))
|
||||
default:
|
||||
if kit.Right(v) {
|
||||
return true
|
||||
|
@ -37,14 +37,25 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
"nnode": &ctx.Cache{Name: "nnode", Value: "0", Help: "节点数量"},
|
||||
},
|
||||
Configs: map[string]*ctx.Config{
|
||||
"node": &ctx.Config{Name: "node", Value: map[string]interface{}{}, Help: "节点信息"},
|
||||
"work": &ctx.Config{Name: "work", Value: map[string]interface{}{}, Help: "用户信息"},
|
||||
"file": &ctx.Config{Name: "file", Value: map[string]interface{}{}, Help: "用户信息"},
|
||||
"node": &ctx.Config{Name: "node", Value: map[string]interface{}{}, Help: "节点信息"},
|
||||
"work": &ctx.Config{Name: "work", Value: map[string]interface{}{}, Help: "用户信息"},
|
||||
"file": &ctx.Config{Name: "file", Value: map[string]interface{}{}, Help: "用户信息"},
|
||||
"flow": &ctx.Config{Name: "flow", Value: map[string]interface{}{}, Help: "聊天记录"},
|
||||
|
||||
"trust": &ctx.Config{Name: "trust", Value: map[string]interface{}{"fresh": false, "user": true, "up": true}, Help: "可信节点"},
|
||||
"timer": &ctx.Config{Name: "timer", Value: map[string]interface{}{"interval": "10s", "timer": ""}, Help: "断线重连"},
|
||||
"componet": &ctx.Config{Name: "componet", Value: map[string]interface{}{
|
||||
"index": []interface{}{
|
||||
map[string]interface{}{"componet_name": "salary", "componet_help": "salary", "componet_tmpl": "componet",
|
||||
"componet_type": "public",
|
||||
"componet_view": "Salary", "componet_init": "",
|
||||
"componet_ctx": "web.chat", "componet_cmd": "salary", "componet_args": []interface{}{"@text", "@total"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"label": "total", "type": "text", "name": "text"},
|
||||
map[string]interface{}{"label": "base", "type": "text", "name": "total"},
|
||||
},
|
||||
},
|
||||
map[string]interface{}{"componet_name": "pwd", "componet_help": "pwd", "componet_tmpl": "componet",
|
||||
"componet_type": "protected",
|
||||
"componet_view": "FlashList", "componet_init": "initFlashList.js",
|
||||
"componet_ctx": "nfs", "componet_cmd": "pwd", "componet_args": []interface{}{"@text"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "button", "value": "当前", "click": "show"},
|
||||
@ -54,13 +65,7 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
"display_result": "", "display_append": "",
|
||||
},
|
||||
map[string]interface{}{"componet_name": "dir", "componet_help": "dir", "componet_tmpl": "componet",
|
||||
"componet_view": "FlashList", "componet_init": "initFlashList.js",
|
||||
"componet_ctx": "nfs", "componet_cmd": "dir", "componet_args": []interface{}{"@text"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "text"},
|
||||
},
|
||||
"display_result": "", "display_append": "",
|
||||
},
|
||||
map[string]interface{}{"componet_name": "dir", "componet_help": "dir", "componet_tmpl": "componet",
|
||||
"componet_type": "private",
|
||||
"componet_view": "FlashList", "componet_init": "initFlashList.js",
|
||||
"componet_ctx": "nfs", "componet_cmd": "dir", "componet_args": []interface{}{"@text"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "text", "name": "text"},
|
||||
@ -164,6 +169,15 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
m.Conf("runtime", "work.route", m.Conf("runtime", "node.route"))
|
||||
m.Conf("work", m.Conf("runtime", "user.name"), map[string]interface{}{"create_time": m.Time(), "user": m.Conf("runtime", "node.route")})
|
||||
|
||||
case "share":
|
||||
user := m.Conf("runtime", "node.route")
|
||||
name := kit.Select(m.Conf("runtime", "user.name"), arg, 1)
|
||||
work := kit.Select(m.Conf("runtime", "work.route"), arg, 2)
|
||||
|
||||
if n := m.Cmdx("ssh._route", work, "_check", "work", name, user); n != "" {
|
||||
m.Echo(n)
|
||||
}
|
||||
|
||||
case "create":
|
||||
user := m.Conf("runtime", "user.route")
|
||||
if user == "" {
|
||||
@ -193,6 +207,10 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
"tool": &ctx.Command{Name: "tool", Help: "用户", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) == 0 {
|
||||
m.Confm("componet", func(key string, index int, value map[string]interface{}) {
|
||||
if kit.Format(value["componet_type"]) != "public" && m.Option("username") != m.Conf("runtime", "work.name") {
|
||||
return
|
||||
}
|
||||
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "index", index)
|
||||
m.Add("append", "name", value["componet_name"])
|
||||
@ -205,8 +223,16 @@ var Index = &ctx.Context{Name: "ssh", Help: "集群中心",
|
||||
switch arg[0] {
|
||||
case "run":
|
||||
tool := m.Confm("componet", []string{arg[1], arg[2]})
|
||||
if kit.Format(tool["componet_type"]) == "private" && m.Option("username") != m.Conf("runtime", "work.name") {
|
||||
m.Echo("private componet of %s", m.Conf("runtime", "work.name"))
|
||||
break
|
||||
}
|
||||
if kit.Format(tool["componet_type"]) == "protected" && !m.Confs("flow", []string{arg[3], "user", m.Option("username")}) {
|
||||
m.Echo("private componet of %s", m.Conf("runtime", "work.name"))
|
||||
break
|
||||
}
|
||||
msg := m.Find(kit.Format(tool["componet_ctx"]))
|
||||
msg.Cmd(tool["componet_cmd"], arg[3:]).CopyTo(m)
|
||||
msg.Cmd(tool["componet_cmd"], arg[4:]).CopyTo(m)
|
||||
|
||||
default:
|
||||
m.Confm("componet", arg[0:], func(value map[string]interface{}) {
|
||||
|
@ -89,9 +89,9 @@ func Merge(m *ctx.Message, client map[string]interface{}, uri string, arg ...str
|
||||
}
|
||||
|
||||
func (web *WEB) Login(msg *ctx.Message, w http.ResponseWriter, r *http.Request) bool {
|
||||
if msg.Confs("skip_login", msg.Option("path")) {
|
||||
return true
|
||||
}
|
||||
// if msg.Confs("skip_login", msg.Option("path")) {
|
||||
// return true
|
||||
// }
|
||||
if msg.Confs("login", "cas") {
|
||||
if !cas.IsAuthenticated(r) {
|
||||
r.URL, _ = r.URL.Parse(r.Header.Get("index_url"))
|
||||
|
@ -47,6 +47,10 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
"componet_view": "Header", "componet_init": "initHeader",
|
||||
"title": "shylinux 天行健,君子以自强不息",
|
||||
},
|
||||
map[string]interface{}{"componet_name": "login", "componet_help": "login", "componet_tmpl": "fieldset",
|
||||
"componet_view": "Login dialog", "componet_init": "initLogin",
|
||||
"componet_ctx": "web.chat", "componet_cmd": "login",
|
||||
},
|
||||
|
||||
map[string]interface{}{"componet_name": "ocean", "componet_tmpl": "fieldset",
|
||||
"componet_view": "Ocean dialog", "componet_init": "initOcean",
|
||||
@ -87,6 +91,18 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
},
|
||||
},
|
||||
}, Help: "组件列表"},
|
||||
"salary": &ctx.Config{Name: "salary", Value: map[string]interface{}{
|
||||
"公基金": 120, "养老": 80, "医疗": 20, "失业": 2,
|
||||
"个税": []interface{}{
|
||||
85000, 45,
|
||||
60000, 35,
|
||||
40000, 30,
|
||||
30000, 25,
|
||||
17000, 20,
|
||||
8000, 10,
|
||||
5000, 3,
|
||||
},
|
||||
}, Help: "聊天记录"},
|
||||
|
||||
"chat_msg": &ctx.Config{Name: "chat_msg", Value: []interface{}{}, Help: "聊天记录"},
|
||||
"default": &ctx.Config{Name: "default", Value: "", Help: "聊天记录"},
|
||||
@ -110,11 +126,25 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
"tool_path": "/Applications/wechatwebdevtools.app/Contents/MacOS/cli",
|
||||
"project_path": "/Users/shaoying/context/usr/client/mp",
|
||||
}, Help: "聊天记录"},
|
||||
|
||||
"flow": &ctx.Config{Name: "flow", Value: map[string]interface{}{}, Help: "聊天记录"},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"login": &ctx.Command{Name: "login [username password]", Help: "登录", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) > 1 {
|
||||
if m.Cmds("ssh.work", "share", arg[0]) {
|
||||
if m.Cmds("aaa.auth", "username", arg[0], "password", arg[1]) {
|
||||
m.Option("username", arg[0])
|
||||
m.Copy(m.Cmd("aaa.user", "session", "select"), "result")
|
||||
}
|
||||
}
|
||||
} else if m.Options("sessid") {
|
||||
m.Echo(m.Option("username"))
|
||||
}
|
||||
return
|
||||
}},
|
||||
"ocean": &ctx.Command{Name: "ocean", Help: "海洋", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if !m.Options("sessid") || !m.Options("username") {
|
||||
return
|
||||
}
|
||||
if len(arg) == 0 {
|
||||
m.Cmdy("ssh.work", "search")
|
||||
return
|
||||
@ -122,6 +152,8 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
|
||||
switch arg[0] {
|
||||
case "spawn":
|
||||
arg = append(arg, m.Conf("runtime", "work.name"))
|
||||
|
||||
h := kit.Select(kit.Hashs("uniq"), arg, 1)
|
||||
user := map[string]interface{}{}
|
||||
for _, v := range arg[3:] {
|
||||
@ -152,8 +184,15 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
return
|
||||
}},
|
||||
"river": &ctx.Command{Name: "river", Help: "河流", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if !m.Options("sessid") || !m.Options("username") {
|
||||
return
|
||||
}
|
||||
if len(arg) == 0 {
|
||||
m.Confm("flow", func(key string, value map[string]interface{}) {
|
||||
if kit.Chain(value, []string{"user", m.Option("username")}) == nil {
|
||||
return
|
||||
}
|
||||
|
||||
m.Add("append", "key", key)
|
||||
m.Add("append", "name", kit.Chains(value, "conf.name"))
|
||||
m.Add("append", "create_user", kit.Chains(value, "conf.create_user"))
|
||||
@ -207,8 +246,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
})
|
||||
|
||||
case "wave":
|
||||
m.Option("username", "shy")
|
||||
m.Cmdy("ssh._route", arg[2], "tool", "run", arg[3], arg[4], arg[5:])
|
||||
m.Cmdy("ssh._route", arg[2], "tool", "run", arg[3], arg[4], arg[1], arg[5:])
|
||||
}
|
||||
return
|
||||
}},
|
||||
@ -231,7 +269,6 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
m.Add("append", "group", tool["group"])
|
||||
m.Add("append", "index", tool["index"])
|
||||
|
||||
m.Option("username", "shy")
|
||||
msg := m.Cmd("ssh._route", tool["node"], "tool", tool["group"], tool["index"])
|
||||
|
||||
m.Add("append", "name", msg.Append("name"))
|
||||
@ -245,8 +282,7 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
}
|
||||
|
||||
if tool := m.Confm("flow", []string{arg[0], "tool", arg[1], "list", arg[2]}); tool != nil {
|
||||
m.Option("username", "shy")
|
||||
m.Cmdy("ssh._route", tool["node"], "tool", "run", tool["group"], tool["index"], arg[3:])
|
||||
m.Cmdy("ssh._route", tool["node"], "tool", "run", tool["group"], tool["index"], arg[0], arg[3:])
|
||||
return
|
||||
}
|
||||
return
|
||||
@ -282,11 +318,31 @@ var Index = &ctx.Context{Name: "chat", Help: "会议中心",
|
||||
})
|
||||
|
||||
default:
|
||||
m.Option("username", "shy")
|
||||
m.Cmdy("ssh._route", m.Conf("flow", []string{arg[0], "user", arg[1], "user"}), "tool")
|
||||
}
|
||||
return
|
||||
}},
|
||||
"salary": &ctx.Command{Name: "salary", Help: "天空", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
arg[0] = kit.Select(arg[1], arg, 0)
|
||||
total := kit.Int64(kit.Select(arg[0], arg, 1))
|
||||
base := kit.Int64(arg[0]) - m.Appendi("公基金", total*kit.Int64(m.Conf("salary", "公基金"))/1000) -
|
||||
m.Appendi("养老", total*kit.Int64(m.Conf("salary", "养老"))/1000) -
|
||||
m.Appendi("医疗", total*kit.Int64(m.Conf("salary", "医疗"))/1000) -
|
||||
m.Appendi("失业", total*kit.Int64(m.Conf("salary", "失业"))/1000)
|
||||
|
||||
list := kit.Trans(m.Confv("salary", "个税"))
|
||||
calc, tax := base, int64(0)
|
||||
for i := 0; i < len(list); i += 2 {
|
||||
if calc > kit.Int64(list[i]) {
|
||||
tax += (calc - kit.Int64(list[i])) * kit.Int64(list[i+1])
|
||||
calc = kit.Int64(list[i])
|
||||
}
|
||||
}
|
||||
m.Append("个税", tax/100)
|
||||
m.Append("结余", (base*100-tax)/100)
|
||||
m.Table()
|
||||
return
|
||||
}},
|
||||
|
||||
"/chat": &ctx.Command{Name: "user", Help: "应用示例", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
// 信息验证
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"math"
|
||||
"math/rand"
|
||||
"os"
|
||||
"strings"
|
||||
"toolkit"
|
||||
)
|
||||
|
||||
@ -60,6 +61,33 @@ var Index = &ctx.Context{Name: "sort", Help: "sort code",
|
||||
}},
|
||||
},
|
||||
Commands: map[string]*ctx.Command{
|
||||
"_init": &ctx.Command{Name: "_init", Help: "_init", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
if len(arg) > 0 {
|
||||
keys := []string{}
|
||||
for key, _ := range c.Commands {
|
||||
if !strings.HasPrefix(key, "_") && !strings.HasPrefix(key, "/") {
|
||||
keys = append(keys, key)
|
||||
}
|
||||
}
|
||||
|
||||
list := []interface{}{}
|
||||
for _, key := range keys {
|
||||
cmd := c.Commands[key]
|
||||
|
||||
list = append(list, map[string]interface{}{"componet_name": cmd.Name, "componet_help": cmd.Help,
|
||||
"componet_tmpl": "componet", "componet_view": "", "componet_init": "",
|
||||
"componet_ctx": "cli." + arg[0], "componet_cmd": key,
|
||||
"componet_args": []interface{}{"@text", "@total"}, "inputs": []interface{}{
|
||||
map[string]interface{}{"type": "input"},
|
||||
map[string]interface{}{"type": "button", "value": "show"},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
m.Confv("ssh.componet", arg[0], list)
|
||||
}
|
||||
return
|
||||
}},
|
||||
"data": &ctx.Command{Name: "data", Help: "data", Hand: func(m *ctx.Message, c *ctx.Context, key string, arg ...string) (e error) {
|
||||
data := []int{}
|
||||
for i := 0; i < kit.Int(kit.Select("10", arg, 0)); i++ {
|
||||
|
@ -94,6 +94,56 @@ func Int(arg ...interface{}) int {
|
||||
}
|
||||
return result
|
||||
}
|
||||
func Int64(arg ...interface{}) int64 {
|
||||
var result int64
|
||||
for _, v := range arg {
|
||||
switch val := v.(type) {
|
||||
case int:
|
||||
result += int64(val)
|
||||
case int8:
|
||||
result += int64(val)
|
||||
case int16:
|
||||
result += int64(val)
|
||||
// case int32:
|
||||
// result += int64(val)
|
||||
case int64:
|
||||
result += int64(val)
|
||||
// case uint8:
|
||||
// result += int64(val)
|
||||
case uint16:
|
||||
result += int64(val)
|
||||
case uint32:
|
||||
result += int64(val)
|
||||
case uint64:
|
||||
result += int64(val)
|
||||
case float64:
|
||||
result += int64(val)
|
||||
case byte: // uint8
|
||||
result += int64(val)
|
||||
case rune: // int32
|
||||
result += int64(val)
|
||||
case string:
|
||||
if i, e := strconv.ParseInt(val, 10, 64); e == nil {
|
||||
result += i
|
||||
}
|
||||
case bool:
|
||||
if val {
|
||||
result += 1
|
||||
}
|
||||
case time.Time:
|
||||
result += int64(val.Unix())
|
||||
case []string:
|
||||
result += int64(len(val))
|
||||
case map[string]string:
|
||||
result += int64(len(val))
|
||||
case []interface{}:
|
||||
result += int64(len(val))
|
||||
case map[string]interface{}:
|
||||
result += int64(len(val))
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
func Right(arg ...interface{}) bool {
|
||||
result := false
|
||||
for _, v := range arg {
|
||||
|
@ -1,6 +1,9 @@
|
||||
fieldset.Ocean div.create pre:hover {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset.Ocean div.create pre:hover {
|
||||
background-color:red;
|
||||
}
|
||||
|
||||
fieldset.River {
|
||||
float:left;
|
||||
@ -24,9 +27,15 @@ fieldset.Steam table.device {
|
||||
margin-left:10px;
|
||||
float:left;
|
||||
}
|
||||
fieldset.Steam div.output tr.select {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset.Steam div.create {
|
||||
clear:both;
|
||||
}
|
||||
fieldset.Steam div.create pre:hover {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset div.output {
|
||||
clear:both;
|
||||
}
|
||||
|
@ -65,23 +65,79 @@ var page = Page({
|
||||
|
||||
}
|
||||
break
|
||||
} else {
|
||||
switch (event.key) {
|
||||
case "Escape":
|
||||
page.dialog && page.dialog.Show()
|
||||
}
|
||||
}
|
||||
break
|
||||
}
|
||||
},
|
||||
|
||||
initLogin: function(page, pane, form, output) {
|
||||
var ui = kit.AppendChild(form, [
|
||||
{label: "username"}, {input: ["username"]}, {type: "br"},
|
||||
{label: "password"}, {password: ["password"]}, {type: "br"},
|
||||
{button: ["login", function(event) {
|
||||
form.Run([ui.username.value, ui.password.value], function(msg) {
|
||||
if (msg.result && msg.result[0]) {
|
||||
pane.ShowDialog(1, 1)
|
||||
ctx.Cookie("sessid", msg.result.join(""))
|
||||
page.header.State("user", ui.username.value)
|
||||
page.river.Show()
|
||||
return
|
||||
}
|
||||
page.alert("用户或密码错误")
|
||||
})
|
||||
}]}
|
||||
])
|
||||
|
||||
form.Run([], function(msg) {
|
||||
if (msg.result && msg.result[0]) {
|
||||
page.header.State("user", msg.result[0])
|
||||
page.river.Show()
|
||||
return
|
||||
}
|
||||
pane.ShowDialog(1, 1)
|
||||
})
|
||||
pane.Exit = function() {
|
||||
ctx.Cookie("sessid", "")
|
||||
page.reload()
|
||||
|
||||
}
|
||||
},
|
||||
initOcean: function(page, pane, form, output) {
|
||||
var table = kit.AppendChild(output, "table")
|
||||
var ui = kit.AppendChild(pane, [{view: ["create ocean"], list: [
|
||||
{input: ["name", function(event) {
|
||||
page.oninput(event, function(event) {
|
||||
switch (event.key) {
|
||||
case "a":
|
||||
case "1":
|
||||
case "2":
|
||||
case "3":
|
||||
case "4":
|
||||
case "5":
|
||||
case "6":
|
||||
case "7":
|
||||
case "8":
|
||||
var tr = table.querySelectorAll("tr.normal")[parseInt(event.key)-1]
|
||||
tr && tr.childNodes[0].click()
|
||||
return true
|
||||
case "9":
|
||||
pane.Action["全选"](event)
|
||||
return
|
||||
case "c":
|
||||
return true
|
||||
case "0":
|
||||
pane.Action["清空"](event)
|
||||
return
|
||||
return true
|
||||
case "-":
|
||||
var pre = ui.list.querySelector("pre")
|
||||
pre && pre.click()
|
||||
return true
|
||||
case "=":
|
||||
var td = table.querySelector("tr.normal td")
|
||||
td && td.click()
|
||||
return true
|
||||
}
|
||||
})
|
||||
event.key == "Enter" && this.nextSibling.click()
|
||||
@ -109,11 +165,11 @@ var page = Page({
|
||||
]}])
|
||||
|
||||
pane.Show = function() {
|
||||
pane.ShowDialog() && (table.innerHTML = "", ui.list.innerHTML = "", ui.name.value = "good", form.Run([], function(msg) {
|
||||
pane.ShowDialog() && (table.innerHTML = "", ui.list.innerHTML = "", ui.name.value = "good", ui.name.focus(), form.Run([], function(msg) {
|
||||
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, row, i, tr, event) {
|
||||
tr.style.display = "none"
|
||||
tr.className = "hidden"
|
||||
var uis = kit.AppendChild(ui.list, [{text: [row.key], click: function(event) {
|
||||
tr.style.display = "", uis.last.parentNode.removeChild(uis.last)
|
||||
tr.className = "normal", uis.last.parentNode.removeChild(uis.last)
|
||||
}}])
|
||||
})
|
||||
}))
|
||||
@ -123,13 +179,13 @@ var page = Page({
|
||||
pane.Show()
|
||||
},
|
||||
"全选": function(event) {
|
||||
ui.list.innerHTML = "", table.querySelectorAll("tr").forEach(function(item) {
|
||||
table.querySelectorAll("tr.normal").forEach(function(item) {
|
||||
item.firstChild.click()
|
||||
})
|
||||
},
|
||||
"清空": function(event) {
|
||||
ui.list.innerHTML = "", table.querySelectorAll("tr").forEach(function(item) {
|
||||
item.style.display = ""
|
||||
ui.list.querySelectorAll("pre").forEach(function(item) {
|
||||
item.click()
|
||||
})
|
||||
},
|
||||
}
|
||||
@ -139,7 +195,6 @@ var page = Page({
|
||||
pane.Show = function() {
|
||||
output.Update([], "text", ["name", "count"], "key", true)
|
||||
}
|
||||
pane.Show()
|
||||
pane.Action = {
|
||||
"创建": function(event) {
|
||||
page.ocean.Show()
|
||||
@ -239,8 +294,8 @@ var page = Page({
|
||||
node: line.node, group: line.group, index: line.index, inputs: line.inputs,
|
||||
})): form.Run([river, storm, index].concat(args), function(msg) {
|
||||
event.ctrlKey && (msg.append && msg.append[0]?
|
||||
page.target.Send("table", JSON.stringify(ctx.Table(msg))):
|
||||
page.target.Send("text", msg.result.join("")))
|
||||
page.target.Send("table", JSON.stringify(ctx.Tables(msg))):
|
||||
page.target.Send("code", msg.result.join("")))
|
||||
cbs(msg)
|
||||
})
|
||||
})
|
||||
@ -250,7 +305,7 @@ var page = Page({
|
||||
output.querySelectorAll("fieldset")[index-1].Select()
|
||||
}
|
||||
|
||||
var toggle = false
|
||||
var toggle = true
|
||||
pane.Action = {
|
||||
"恢复": function(event) {
|
||||
page.onlayout(event, page.conf.layout)
|
||||
@ -315,12 +370,39 @@ var page = Page({
|
||||
{input: ["name", function(event) {
|
||||
page.oninput(event, function(event) {
|
||||
switch (event.key) {
|
||||
case "a":
|
||||
case "i":
|
||||
var prev = table.querySelector("tr.select").previousSibling
|
||||
prev && prev.childNodes[0].click()
|
||||
return true
|
||||
case "o":
|
||||
var next = table.querySelector("tr.select").nextSibling
|
||||
next && next.childNodes[0].click()
|
||||
return true
|
||||
case "1":
|
||||
case "2":
|
||||
case "3":
|
||||
case "4":
|
||||
case "5":
|
||||
case "6":
|
||||
case "7":
|
||||
case "8":
|
||||
var tr = device.querySelectorAll("tr.normal")[parseInt(event.key)-1]
|
||||
tr && tr.childNodes[0].click()
|
||||
return true
|
||||
case "9":
|
||||
pane.Action["全选"](event)
|
||||
return
|
||||
case "c":
|
||||
return true
|
||||
case "0":
|
||||
pane.Action["清空"](event)
|
||||
return
|
||||
return true
|
||||
case "-":
|
||||
var tr = ui.list.querySelectorAll("tr")[1]
|
||||
tr && tr.childNodes[0].click()
|
||||
return true
|
||||
case "=":
|
||||
var td = device.querySelector("tr.normal td")
|
||||
td && td.click()
|
||||
return true
|
||||
}
|
||||
})
|
||||
event.key == "Enter" && this.nextSibling.click()
|
||||
@ -344,10 +426,9 @@ var page = Page({
|
||||
}
|
||||
|
||||
form.Run(cmd, function(msg) {
|
||||
page.storm.Show()
|
||||
page.storm.which.set(ui.name.value)
|
||||
page.action.Show()
|
||||
pane.Show()
|
||||
page.storm.Show()
|
||||
page.storm.which.set(ui.name.value, true)
|
||||
})
|
||||
}]}, {name: "list", view: ["list", "table"]},
|
||||
]}])
|
||||
@ -355,6 +436,8 @@ var page = Page({
|
||||
pane.Show = function() {
|
||||
pane.ShowDialog() && (table.innerHTML = "", ui.name.value = "nice", form.Run([river], function(msg) {
|
||||
kit.AppendTable(table, ctx.Table(msg), ["key", "user.route"], function(value, key, pod, i, tr, event) {
|
||||
var old = table.querySelector("tr.select")
|
||||
tr.className = "select", old && (old.className = "normal")
|
||||
form.Run([river, pod.key], function(msg) {
|
||||
device.innerHTML = "", kit.AppendTable(device, ctx.Table(msg), ["key", "index", "name", "help"], function(value, key, com, i, tr, event) {
|
||||
var last = kit.AppendChild(ui.list, [{type: "tr", list: [
|
||||
@ -433,5 +516,9 @@ var page = Page({
|
||||
page.onlayout(null, page.conf.layout)
|
||||
page.footer.State("action", "")
|
||||
page.footer.Order(["action", "text"])
|
||||
page.header.State("user", "")
|
||||
page.header.Order(["user"], function(event, item, value) {
|
||||
page.confirm("logout?") && page.login.Exit()
|
||||
})
|
||||
},
|
||||
})
|
||||
|
@ -48,6 +48,33 @@ ctx = context = {
|
||||
}
|
||||
return ret
|
||||
},
|
||||
Tables: function(msg, cb) {
|
||||
var ret = []
|
||||
if (!msg || !msg.append || !msg.append.length || !msg[msg.append[0]]) {
|
||||
return ret
|
||||
}
|
||||
ret.push(msg.append)
|
||||
|
||||
var ncol = msg.append.length
|
||||
var nrow = msg[msg.append[0]].length
|
||||
for (var i = 0; i < nrow; i++) {
|
||||
var one = []
|
||||
for (var j = 0; j < ncol; j++) {
|
||||
one.push(msg[msg.append[j]][i])
|
||||
}
|
||||
ret.push(one)
|
||||
}
|
||||
|
||||
var list = []
|
||||
typeof cb == "function" && ret.forEach(function(value, index, array) {
|
||||
var item = cb(value, index, array)
|
||||
item && list.push(item)
|
||||
})
|
||||
if (list.length > 0) {
|
||||
return list
|
||||
}
|
||||
return ret
|
||||
},
|
||||
Share: function(objs) {
|
||||
var args = this.Search()
|
||||
for (var k in objs) {
|
||||
|
@ -15,12 +15,20 @@ legend {
|
||||
fieldset div.output {
|
||||
padding:6px;
|
||||
}
|
||||
fieldset form.option label {
|
||||
margin-right:6px;
|
||||
}
|
||||
fieldset form.option div {
|
||||
margin-right:6px;
|
||||
float:left;
|
||||
}
|
||||
fieldset div.output div.item:hover {
|
||||
background-color:red;
|
||||
}
|
||||
fieldset div.output div.item.select {
|
||||
background-color:red;
|
||||
}
|
||||
|
||||
fieldset.toast {
|
||||
background-color:#ffffff00;
|
||||
position:absolute;
|
||||
@ -57,6 +65,17 @@ fieldset.dialog div.create {
|
||||
margin-left:10px;
|
||||
float:left;
|
||||
}
|
||||
fieldset.Header div.output div.title {
|
||||
float:left;
|
||||
}
|
||||
fieldset.Header div.output div.state {
|
||||
float:right;
|
||||
}
|
||||
fieldset.Header div.output div.state div {
|
||||
margin-left:5px;
|
||||
float:right;
|
||||
cursor:pointer;
|
||||
}
|
||||
fieldset.Footer {
|
||||
clear:both;
|
||||
}
|
||||
@ -71,6 +90,12 @@ fieldset.Footer div.output div.state div {
|
||||
float:right;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display:none;
|
||||
}
|
||||
.normal {
|
||||
}
|
||||
|
||||
fieldset table {
|
||||
font-size:14px;
|
||||
overflow: auto;
|
||||
|
@ -19,8 +19,8 @@ function Page(page) {
|
||||
get: function() {
|
||||
return data
|
||||
},
|
||||
set: function(value) {
|
||||
if (value == data) {
|
||||
set: function(value, force) {
|
||||
if (value == data && !force) {
|
||||
return value
|
||||
}
|
||||
old_value = data, data = value
|
||||
@ -44,14 +44,16 @@ function Page(page) {
|
||||
result = [{view: ["item", "div", key.length>1? line[key[0]]+"("+line[key[1]]+")": (key.length>0? line[key[0]]: "null")], click: cb}]
|
||||
break
|
||||
|
||||
case "code":
|
||||
result = [{type: "code", list: [{text: [key.length>1? line[key[0]]+"("+line[key[1]]+")": (key.length>0? line[key[0]]: "null")], click: cb}]}]
|
||||
break
|
||||
|
||||
case "table":
|
||||
result = [{view: [""], list: [
|
||||
{view: ["", "table"], list: JSON.parse(line.text || "[]").map(function(item, index) {
|
||||
var line = []
|
||||
for (var k in item) {
|
||||
line.push({text: index == 0? [k, "th"]: [item[k], "td"]})
|
||||
}
|
||||
return {type: "tr", list: line}
|
||||
return {type: "tr", list: item.map(function(value) {
|
||||
return {text: [value, index == 0? "th": "td"]}
|
||||
})}
|
||||
})},
|
||||
]}]
|
||||
break
|
||||
@ -74,6 +76,12 @@ function Page(page) {
|
||||
ui.last.Meta = line
|
||||
return ui
|
||||
},
|
||||
alert: function(text) {
|
||||
alert(text)
|
||||
},
|
||||
confirm: function(text) {
|
||||
return confirm(text)
|
||||
},
|
||||
reload: function() {
|
||||
location.reload()
|
||||
},
|
||||
@ -83,7 +91,8 @@ function Page(page) {
|
||||
|
||||
if (event.ctrlKey) {
|
||||
if (typeof local == "function" && local(event)) {
|
||||
return
|
||||
event.stopPropagation()
|
||||
return true
|
||||
}
|
||||
switch (event.key) {
|
||||
case "a":
|
||||
@ -116,16 +125,19 @@ function Page(page) {
|
||||
return false
|
||||
|
||||
}
|
||||
event.stopPropagation()
|
||||
return true
|
||||
}
|
||||
switch (event.key) {
|
||||
case "Escape":
|
||||
target.blur()
|
||||
break
|
||||
event.stopPropagation()
|
||||
return true
|
||||
default:
|
||||
if (kit.HitText(target, "jk")) {
|
||||
kit.DelText(target, target.selectionStart-2, 2)
|
||||
target.blur()
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
@ -180,8 +192,24 @@ function Page(page) {
|
||||
}
|
||||
},
|
||||
|
||||
initHeader: function(page, field, option, output) {
|
||||
return [{"text": ["shycontext", "div", "title"]}]
|
||||
initHeader: function(page, pane, form, output) {
|
||||
var state = {}, list = [], cb = function(event, item, value) {
|
||||
}
|
||||
pane.State = function(name, value) {
|
||||
state[name] = value, pane.Show()
|
||||
}
|
||||
pane.Order = function(value, cbs) {
|
||||
list = value, cb = cbs || cb, pane.Show()
|
||||
}
|
||||
pane.Show = function() {
|
||||
output.innerHTML = "", kit.AppendChild(output, [
|
||||
{"view": ["title", "div", "shycontext"]},
|
||||
{"view": ["state"], list: list.map(function(item) {return {text: [state[item], "div"], click: function(event) {
|
||||
cb(event, item, state[item])
|
||||
}}})},
|
||||
])
|
||||
}
|
||||
return
|
||||
},
|
||||
initBanner: function(page, field, option, output) {
|
||||
field.querySelectorAll("li").forEach(function(item) {
|
||||
@ -226,6 +254,7 @@ function Page(page) {
|
||||
return true
|
||||
}
|
||||
pane.style.display = "none"
|
||||
delete(page.dialog)
|
||||
return false
|
||||
}
|
||||
pane.Size = function(width, height) {
|
||||
@ -235,16 +264,19 @@ function Page(page) {
|
||||
}
|
||||
|
||||
// form init
|
||||
form.Run = function(cmds, cb) {
|
||||
pane.Run = form.Run = function(cmds, cb) {
|
||||
ctx.Run(page, form.dataset, cmds, cb)
|
||||
}
|
||||
form.Runs = function(cmds, cb) {
|
||||
pane.Runs = form.Runs = function(cmds, cb) {
|
||||
ctx.Run(page, form.dataset, cmds, function(msg) {
|
||||
ctx.Table(msg, function(line, index) {
|
||||
cb(line, index, msg)
|
||||
})
|
||||
})
|
||||
}
|
||||
form.onsubmit = function(event) {
|
||||
event.preventDefault()
|
||||
}
|
||||
|
||||
var conf = cb(page[pane.dataset.init], pane, form)
|
||||
})
|
||||
@ -282,7 +314,9 @@ function Plugin(field, inputs, plugin) {
|
||||
})
|
||||
option.Run(event, args.slice(1), function(msg) {
|
||||
(option.ondaemon || function(msg) {
|
||||
output.innerHTML = "", kit.AppendChild(output, [{type: "code", list: [{text: [msg.result.join(""), "pre"]}]}])
|
||||
output.innerHTML = "",
|
||||
msg.append? kit.AppendTable(kit.AppendChild(output, "table"), ctx.Table(msg), msg.append)
|
||||
:kit.AppendChild(output, [{type: "code", list: [{text: [msg.result.join(""), "pre"]}]}])
|
||||
})(msg)
|
||||
})
|
||||
}
|
||||
@ -300,13 +334,11 @@ function Plugin(field, inputs, plugin) {
|
||||
switch (event.key) {
|
||||
case "i":
|
||||
var next = field.nextSibling;
|
||||
// (next? next: field.parentNode.firstChild).querySelectorAll("input")[1].focus()
|
||||
next && (next.querySelectorAll("input")[1].focus(), event.stopPropagation())
|
||||
next && next.Select()
|
||||
break
|
||||
case "o":
|
||||
var prev = field.previousSibling;
|
||||
// (prev? prev: field.parentNode.lastChild).querySelectorAll("input")[1].focus()
|
||||
prev && (prev.querySelectorAll("input")[1].focus(), event.stopPropagation())
|
||||
prev && prev.Select()
|
||||
break
|
||||
case "c":
|
||||
output.innerHTML = ""
|
||||
@ -328,13 +360,13 @@ function Plugin(field, inputs, plugin) {
|
||||
}
|
||||
return true
|
||||
})
|
||||
event.key == "Enter" && (index == inputs.length-1? run(event): event.target.nextSibling.focus())
|
||||
event.key == "Enter" && (index == inputs.length-1? run(event): event.target.parentNode.nextSibling.childNodes[1].focus())
|
||||
}, field.Select = function() {
|
||||
ui.first.focus()
|
||||
ui.last.childNodes[1].focus()
|
||||
})
|
||||
return {type: "input", data: item}
|
||||
return {type: "div", list: [{type: "label", inner: item.label||""}, {type: "input", name: item.name, data: item}]}
|
||||
}))
|
||||
ui.first.focus()
|
||||
ui.last.childNodes[1].focus()
|
||||
|
||||
plugin = plugin || {}, plugin.__proto__ = {
|
||||
show: function() {},
|
||||
|
@ -25,25 +25,50 @@ kit = toolkit = {
|
||||
return args
|
||||
},
|
||||
|
||||
ModifyNode: function(which, html) {
|
||||
var node = typeof which == "string"? document.querySelector(which): which
|
||||
switch (typeof html) {
|
||||
case "string":
|
||||
node.innerHTML = html
|
||||
break
|
||||
case "object":
|
||||
for (var k in html) {
|
||||
if (typeof html[k] == "object") {
|
||||
for (var d in html[k]) {
|
||||
node[k][d] = html[k][d]
|
||||
}
|
||||
continue
|
||||
}
|
||||
node[k] = html[k]
|
||||
ScrollPage: function(event, conf) {
|
||||
switch (event.key) {
|
||||
case "h":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(-conf.scroll_x*10, 0)
|
||||
} else {
|
||||
window.scrollBy(-conf.scroll_x, 0)
|
||||
}
|
||||
break
|
||||
case "H":
|
||||
window.scrollBy(-document.body.scrollWidth, 0)
|
||||
break
|
||||
case "l":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(conf.scroll_x*10, 0)
|
||||
} else {
|
||||
window.scrollBy(conf.scroll_x, 0)
|
||||
}
|
||||
break
|
||||
case "L":
|
||||
window.scrollBy(document.body.scrollWidth, 0)
|
||||
break
|
||||
case "j":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(0, conf.scroll_y*10)
|
||||
} else {
|
||||
window.scrollBy(0, conf.scroll_y)
|
||||
}
|
||||
break
|
||||
case "J":
|
||||
window.scrollBy(0, document.body.scrollHeight)
|
||||
break
|
||||
case "k":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(0, -conf.scroll_y*10)
|
||||
} else {
|
||||
window.scrollBy(0, -conf.scroll_y)
|
||||
}
|
||||
break
|
||||
case "K":
|
||||
window.scrollBy(0, -document.body.scrollHeight)
|
||||
break
|
||||
}
|
||||
return node
|
||||
return true
|
||||
},
|
||||
ModifyView: function(which, args) {
|
||||
var height = document.body.clientHeight-4
|
||||
@ -98,50 +123,25 @@ kit = toolkit = {
|
||||
}
|
||||
return kit.ModifyNode(which, {style: args})
|
||||
},
|
||||
ScrollPage: function(event, conf) {
|
||||
switch (event.key) {
|
||||
case "h":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(-conf.scroll_x*10, 0)
|
||||
} else {
|
||||
window.scrollBy(-conf.scroll_x, 0)
|
||||
ModifyNode: function(which, html) {
|
||||
var node = typeof which == "string"? document.querySelector(which): which
|
||||
switch (typeof html) {
|
||||
case "string":
|
||||
node.innerHTML = html
|
||||
break
|
||||
case "object":
|
||||
for (var k in html) {
|
||||
if (typeof html[k] == "object") {
|
||||
for (var d in html[k]) {
|
||||
node[k][d] = html[k][d]
|
||||
}
|
||||
continue
|
||||
}
|
||||
node[k] = html[k]
|
||||
}
|
||||
break
|
||||
case "H":
|
||||
window.scrollBy(-document.body.scrollWidth, 0)
|
||||
break
|
||||
case "l":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(conf.scroll_x*10, 0)
|
||||
} else {
|
||||
window.scrollBy(conf.scroll_x, 0)
|
||||
}
|
||||
break
|
||||
case "L":
|
||||
window.scrollBy(document.body.scrollWidth, 0)
|
||||
break
|
||||
case "j":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(0, conf.scroll_y*10)
|
||||
} else {
|
||||
window.scrollBy(0, conf.scroll_y)
|
||||
}
|
||||
break
|
||||
case "J":
|
||||
window.scrollBy(0, document.body.scrollHeight)
|
||||
break
|
||||
case "k":
|
||||
if (event.ctrlKey) {
|
||||
window.scrollBy(0, -conf.scroll_y*10)
|
||||
} else {
|
||||
window.scrollBy(0, -conf.scroll_y)
|
||||
}
|
||||
break
|
||||
case "K":
|
||||
window.scrollBy(0, -document.body.scrollHeight)
|
||||
break
|
||||
}
|
||||
return true
|
||||
return node
|
||||
},
|
||||
CreateNode: function(element, html) {
|
||||
return this.ModifyNode(document.createElement(element), html)
|
||||
@ -160,12 +160,12 @@ kit = toolkit = {
|
||||
// dataset
|
||||
// click
|
||||
//
|
||||
// button input
|
||||
// tree, fork, leaf // 树状结构
|
||||
// view, text, code // 普通视图
|
||||
// include require styles // 加载文件
|
||||
// button input label
|
||||
// 树状结构: tree, fork, leaf
|
||||
// 普通视图: view, text, code
|
||||
// 加载文件: include require styles
|
||||
//
|
||||
// type, data, list // 基本结构
|
||||
// 基本结构: type, data, list
|
||||
|
||||
var kit = this
|
||||
|
||||
@ -212,6 +212,17 @@ kit = toolkit = {
|
||||
child.data["name"] = child.input[0]
|
||||
child.name = child.name || child.input[0]
|
||||
|
||||
} else if (child.password) {
|
||||
child.type = "input"
|
||||
child.data["onkeyup"] = child.password[1]
|
||||
child.data["name"] = child.password[0]
|
||||
child.data["type"] = "password"
|
||||
child.name = child.name || child.password[0]
|
||||
|
||||
} else if (child.label) {
|
||||
child.type = "label"
|
||||
child.data["innerText"] = child.label
|
||||
|
||||
} else if (child.tree) {
|
||||
child.type = "ul"
|
||||
child.list = child.tree
|
||||
@ -308,7 +319,7 @@ kit = toolkit = {
|
||||
var td = kit.AppendChild(tr, "th", key)
|
||||
})
|
||||
data.forEach(function(row, i) {
|
||||
var tr = kit.AppendChild(table, "tr")
|
||||
var tr = kit.AppendChild(table, "tr", {className: "normal"})
|
||||
fields.forEach(function(key, j) {
|
||||
var td = kit.AppendChild(tr, "td", row[key])
|
||||
if (typeof cb == "function") {
|
||||
@ -507,6 +518,9 @@ kit = toolkit = {
|
||||
}
|
||||
return true
|
||||
},
|
||||
Selector(target, name) {
|
||||
return target.Selector(name)
|
||||
}
|
||||
}
|
||||
|
||||
function right(arg) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user