mirror of
https://shylinux.com/x/ContextOS
synced 2025-04-25 16:58:06 +08:00
add onformat.plugin.js
This commit is contained in:
parent
a1afe94027
commit
6d5d739778
@ -4,5 +4,5 @@ var version = struct {
|
|||||||
host string
|
host string
|
||||||
self int
|
self int
|
||||||
}{
|
}{
|
||||||
"2019-09-26 17:44:10", "centos", 606,
|
"2019-09-27 08:55:10", "mac", 670,
|
||||||
}
|
}
|
||||||
|
@ -804,6 +804,10 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
|||||||
return
|
return
|
||||||
}},
|
}},
|
||||||
"copy": &Command{Name: "copy", Help: "查看或添加选项", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
"copy": &Command{Name: "copy", Help: "查看或添加选项", Hand: func(m *Message, c *Context, key string, arg ...string) (e error) {
|
||||||
|
skip := false
|
||||||
|
if arg[0] == "skip" {
|
||||||
|
skip, arg = true, arg[1:]
|
||||||
|
}
|
||||||
msg := m.Optionv("bio.msg").(*Message)
|
msg := m.Optionv("bio.msg").(*Message)
|
||||||
// 去年尾参
|
// 去年尾参
|
||||||
for i := len(arg) - 1; i >= 0; i-- {
|
for i := len(arg) - 1; i >= 0; i-- {
|
||||||
@ -828,7 +832,7 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{},
|
|||||||
args = append(args, arg[i])
|
args = append(args, arg[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if j < len(msg.Meta["detail"]) {
|
if !skip && j < len(msg.Meta["detail"]) {
|
||||||
args = append(args, msg.Meta["detail"][j:]...)
|
args = append(args, msg.Meta["detail"][j:]...)
|
||||||
}
|
}
|
||||||
msg.Cmdy(args)
|
msg.Cmdy(args)
|
||||||
|
@ -865,7 +865,7 @@ var Index = &ctx.Context{Name: "web", Help: "应用中心",
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 响应数据
|
// 响应数据
|
||||||
group, order := m.Option("group", kit.Select(m.Conf("route", "componet_index"), m.Option("group"))), m.Option("name")
|
group, order := m.Option("group", kit.Select(m.Conf("route", "componet_index"), m.Option("group"))), m.Option("names")
|
||||||
list := []interface{}{}
|
list := []interface{}{}
|
||||||
|
|
||||||
for _, v := range m.Confv("componet", group).([]interface{}) {
|
for _, v := range m.Confv("componet", group).([]interface{}) {
|
||||||
|
@ -1,21 +1,21 @@
|
|||||||
|
|
||||||
fun meet "第一眼" protected \
|
fun meet "第一眼" protected \
|
||||||
text "love" name table imports plugin_table \
|
text "love" name table imports plugin_table \
|
||||||
text "date" name when \
|
text "" name when init date \
|
||||||
text "" name where \
|
text "" name where \
|
||||||
button "操作"
|
button "操作"
|
||||||
|
|
||||||
if $2 == "" || $3 == ""
|
if $2 == "" || $3 == ""
|
||||||
copy ssh.data show _
|
copy skip ssh.data show _
|
||||||
else
|
else
|
||||||
copy ssh.data insert _ when _ where __
|
copy ssh.data insert _ when _ where
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
kit date "日历" "index.js" "index.css" protected "cli.date" _ nature _ \
|
kit date "日历" "index.js" "index.css" protected "cli.date" _ nature _ \
|
||||||
\ space true format '<span class="%s">%s</span>' "s20060102" \
|
\ space true format '<span class="%s">%s</span>' "s20060102" \
|
||||||
text "2019-07-08" name "起始时间" \
|
text "2019-07-08" name "起始时间" \
|
||||||
text "date" name "date" \
|
text "" name "截止时间" init date \
|
||||||
text "love" name "table" imports plugin_table \
|
text "love" name "table" imports plugin_table \
|
||||||
text "when" name "when" \
|
text "when" name "when" \
|
||||||
text "where" name "where" \
|
text "where" name "where" \
|
||||||
@ -24,12 +24,12 @@ kit date "日历" "index.js" "index.css" protected "cli.date" _ nature _ \
|
|||||||
|
|
||||||
fun delay "以后告诉你" protected \
|
fun delay "以后告诉你" protected \
|
||||||
text "delay" name table imports plugin_table \
|
text "delay" name table imports plugin_table \
|
||||||
text "date" name when \
|
text "" name when init date\
|
||||||
text "" name what view long \
|
text "" name what view long \
|
||||||
button "记下了"
|
button "记下了"
|
||||||
|
|
||||||
if $2 == "" || $3 == ""
|
if $2 == "" || $3 == ""
|
||||||
copy ssh.data show _
|
copy skip ssh.data show _
|
||||||
else
|
else
|
||||||
copy ssh.data insert _ when _ what __
|
copy ssh.data insert _ when _ what __
|
||||||
end
|
end
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
ctx = context = {__proto__: kit,
|
ctx = context = {__proto__: kit,
|
||||||
Event: function(event, msg, proto) {
|
Event: Wrap(function(event, msg, proto) {
|
||||||
|
event = event || document.createEvent("Event")
|
||||||
if (event.msg && !msg) {return event.msg}
|
if (event.msg && !msg) {return event.msg}
|
||||||
|
|
||||||
|
var meta = arguments.callee
|
||||||
|
var order = ++meta.order
|
||||||
|
|
||||||
event.msg = msg = msg || {}, proto = proto || {}, msg.__proto__ = proto, proto.__proto__ = {
|
event.msg = msg = msg || {}, proto = proto || {}, msg.__proto__ = proto, proto.__proto__ = {
|
||||||
Push: function(key, value) {
|
Push: function(key, value) {
|
||||||
msg.append || (msg.append = [])
|
msg.append || (msg.append = [])
|
||||||
@ -23,10 +27,12 @@ ctx = context = {__proto__: kit,
|
|||||||
return s
|
return s
|
||||||
},
|
},
|
||||||
}, msg.event = event
|
}, msg.event = event
|
||||||
kit.Log("event", event.type, proto.name, msg)
|
kit.Log("event", order, event.type, proto.name, msg)
|
||||||
return msg
|
return msg
|
||||||
},
|
}, {order: 0}),
|
||||||
Run: function(dataset, cmd, cb) {
|
Run: Wrap(function(dataset, cmd, cb) {
|
||||||
|
var meta = arguments.callee
|
||||||
|
var order = ++meta.order
|
||||||
var msg = ctx.Event(event||document.createEvent("Event"), null, {name: "ctx.run"})
|
var msg = ctx.Event(event||document.createEvent("Event"), null, {name: "ctx.run"})
|
||||||
|
|
||||||
var option = {"cmds": cmd}
|
var option = {"cmds": cmd}
|
||||||
@ -42,14 +48,15 @@ ctx = context = {__proto__: kit,
|
|||||||
msg.option.push(k)
|
msg.option.push(k)
|
||||||
msg[k] = option[k]
|
msg[k] = option[k]
|
||||||
}
|
}
|
||||||
msg.detail = ["run"].concat(option.group).concat(option.name).concat(option.cmds)
|
msg.detail = ["run", order].concat(option.group).concat(option.names).concat(option.cmds)
|
||||||
|
msg.Order = order
|
||||||
|
|
||||||
kit.Log(msg.detail.concat([msg]))
|
kit.Log(msg.detail.concat([msg]))
|
||||||
this.POST("", option, function(msg) {
|
this.POST("", option, function(msg) {
|
||||||
kit.Log("run", "result", msg.result? msg.result[0]: "", msg)
|
kit.Log("run", order, "result", msg.result? msg.result[0]: "", msg)
|
||||||
typeof cb == "function" && cb(msg || {})
|
typeof cb == "function" && cb(msg || {})
|
||||||
}, msg)
|
}, msg)
|
||||||
},
|
}, {order: 0}),
|
||||||
Runs: function(form, cb) {
|
Runs: function(form, cb) {
|
||||||
var data = {}
|
var data = {}
|
||||||
for (var key in form.dataset) {
|
for (var key in form.dataset) {
|
||||||
@ -274,32 +281,32 @@ ctx = context = {__proto__: kit,
|
|||||||
page.ontoast("wss open")
|
page.ontoast("wss open")
|
||||||
}
|
}
|
||||||
s.onmessage = function(event) {
|
s.onmessage = function(event) {
|
||||||
|
var order = ++meta.order
|
||||||
try {
|
try {
|
||||||
var msg = JSON.parse(event.data||'{}')
|
var msg = JSON.parse(event.data||'{}')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
var msg = {"result": [event.data]}
|
var msg = {"result": [event.data]}
|
||||||
}
|
}
|
||||||
|
|
||||||
meta.order++
|
|
||||||
// Event入口 -1.0
|
// Event入口 -1.0
|
||||||
msg = ctx.Event(event, msg, {
|
msg = ctx.Event(event, msg, {
|
||||||
name: meta.order,
|
name: document.title,
|
||||||
Order: meta.order,
|
Order: order,
|
||||||
Reply: function(msg) {
|
Reply: function(msg) {
|
||||||
kit.Log(["wss", "result"].concat(msg.result))
|
kit.Log(["wss", order, "result"].concat(msg.result).concat([msg]))
|
||||||
delete(msg.event), s.send(JSON.stringify(msg))
|
delete(msg.event), s.send(JSON.stringify(msg))
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
try {
|
try {
|
||||||
kit.Log(["wss"].concat(msg.detail).concat([msg]))
|
kit.Log(["wss", order].concat(msg.detail).concat([msg]))
|
||||||
typeof cb == "function" && cb(msg)
|
typeof cb == "function" && cb(msg)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
msg.reply(kit.Log("err", e))
|
msg.reply(kit.Log("err", e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
s.onerror = function(event) {
|
s.onerror = function(event) {
|
||||||
kit.Log(event)
|
kit.Log("wss", "error", event)
|
||||||
typeof onerror == "function" && onerror(event)
|
typeof onerror == "function" && onerror(event)
|
||||||
}
|
}
|
||||||
s.onclose = function(event) {
|
s.onclose = function(event) {
|
||||||
|
@ -541,7 +541,7 @@ function Pane(page, field) {
|
|||||||
|
|
||||||
var timer = ""
|
var timer = ""
|
||||||
var list = [], last = -1, member = {}
|
var list = [], last = -1, member = {}
|
||||||
var name = option.dataset.name
|
var name = option.dataset.names
|
||||||
var pane = Meta(field, (page[field.dataset.init] || function() {
|
var pane = Meta(field, (page[field.dataset.init] || function() {
|
||||||
})(page, field, option, output) || {}, {
|
})(page, field, option, output) || {}, {
|
||||||
Append: function(type, line, key, which, cb) {
|
Append: function(type, line, key, which, cb) {
|
||||||
@ -742,11 +742,7 @@ function Plugin(page, pane, field, runs) {
|
|||||||
}
|
}
|
||||||
}: cb)
|
}: cb)
|
||||||
});
|
});
|
||||||
switch (item.value) {
|
item.value = plugin.onformat(item.init)(item.value)
|
||||||
case "date":
|
|
||||||
item.name == "date" && (item.value = kit.format_date(new Date()))
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
!item.title && item.name && (item.title = item.name)
|
!item.title && item.name && (item.title = item.name)
|
||||||
!item.placeholder && item.title && (item.placeholder = item.title)
|
!item.placeholder && item.title && (item.placeholder = item.title)
|
||||||
@ -947,6 +943,13 @@ function Plugin(page, pane, field, runs) {
|
|||||||
page.ontoast(), page.ontoast("上传进度 "+parseInt(event.loaded*100/event.total)+"%")
|
page.ontoast(), page.ontoast("上传进度 "+parseInt(event.loaded*100/event.total)+"%")
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
onformat: Wrap(function(which) {
|
||||||
|
var meta = arguments.callee
|
||||||
|
return meta[which]||meta["none"]
|
||||||
|
}, {
|
||||||
|
none: function(value) {return value},
|
||||||
|
date: function(value) {return kit.format_date(new Date())},
|
||||||
|
}),
|
||||||
ondaemon: {
|
ondaemon: {
|
||||||
inner: function(msg, cb) {
|
inner: function(msg, cb) {
|
||||||
output.style.maxWidth = pane.target.clientWidth-20+"px"
|
output.style.maxWidth = pane.target.clientWidth-20+"px"
|
||||||
|
@ -14,13 +14,13 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<fieldset class="toast"><legend></legend>
|
<fieldset class="toast"><legend></legend>
|
||||||
<form class="option" data-name="toast"></form>
|
<form class="option" data-names="toast"></form>
|
||||||
<div class="output"></div>
|
<div class="output"></div>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{define "fieldset"}}
|
{{define "fieldset"}}
|
||||||
<fieldset class="{{options . "view"}}" data-init="{{options . "init"}}">
|
<fieldset class="{{options . "view"}}" data-init="{{options . "init"}}">
|
||||||
<form class="option" data-name="{{options . "name"}}" data-group="{{options . "group"}}">
|
<form class="option" data-names="{{options . "name"}}" data-group="{{options . "group"}}">
|
||||||
<input style="display:none"></input>
|
<input style="display:none"></input>
|
||||||
</form>
|
</form>
|
||||||
<div class="output"></div>
|
<div class="output"></div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user