From 6d5d73977870ef3c5fe082ebd8886e670f211280 Mon Sep 17 00:00:00 2001 From: shaoying Date: Fri, 27 Sep 2019 09:00:38 +0800 Subject: [PATCH] add onformat.plugin.js --- src/contexts/cli/version.go | 2 +- src/contexts/ctx/ctx.go | 6 +++++- src/contexts/web/web.go | 2 +- src/plugin/love/index.shy | 12 ++++++------ usr/librarys/context.js | 33 ++++++++++++++++++++------------- usr/librarys/example.js | 15 +++++++++------ usr/template/common.tmpl | 4 ++-- 7 files changed, 44 insertions(+), 30 deletions(-) diff --git a/src/contexts/cli/version.go b/src/contexts/cli/version.go index 5dea56b2..82cf1ba9 100644 --- a/src/contexts/cli/version.go +++ b/src/contexts/cli/version.go @@ -4,5 +4,5 @@ var version = struct { host string self int }{ - "2019-09-26 17:44:10", "centos", 606, + "2019-09-27 08:55:10", "mac", 670, } diff --git a/src/contexts/ctx/ctx.go b/src/contexts/ctx/ctx.go index ebdd0ed1..5db52323 100644 --- a/src/contexts/ctx/ctx.go +++ b/src/contexts/ctx/ctx.go @@ -804,6 +804,10 @@ var Index = &Context{Name: "ctx", Help: "模块中心", Server: &CTX{}, return }}, "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) // 去年尾参 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]) } } - if j < len(msg.Meta["detail"]) { + if !skip && j < len(msg.Meta["detail"]) { args = append(args, msg.Meta["detail"][j:]...) } msg.Cmdy(args) diff --git a/src/contexts/web/web.go b/src/contexts/web/web.go index cf38f438..d58b0d1f 100644 --- a/src/contexts/web/web.go +++ b/src/contexts/web/web.go @@ -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{}{} for _, v := range m.Confv("componet", group).([]interface{}) { diff --git a/src/plugin/love/index.shy b/src/plugin/love/index.shy index 38bcd8c2..e481542a 100644 --- a/src/plugin/love/index.shy +++ b/src/plugin/love/index.shy @@ -1,21 +1,21 @@ fun meet "第一眼" protected \ text "love" name table imports plugin_table \ - text "date" name when \ + text "" name when init date \ text "" name where \ button "操作" if $2 == "" || $3 == "" - copy ssh.data show _ + copy skip ssh.data show _ else - copy ssh.data insert _ when _ where __ + copy ssh.data insert _ when _ where end end kit date "日历" "index.js" "index.css" protected "cli.date" _ nature _ \ \ space true format '%s' "s20060102" \ text "2019-07-08" name "起始时间" \ - text "date" name "date" \ + text "" name "截止时间" init date \ text "love" name "table" imports plugin_table \ text "when" name "when" \ text "where" name "where" \ @@ -24,12 +24,12 @@ kit date "日历" "index.js" "index.css" protected "cli.date" _ nature _ \ fun delay "以后告诉你" protected \ text "delay" name table imports plugin_table \ - text "date" name when \ + text "" name when init date\ text "" name what view long \ button "记下了" if $2 == "" || $3 == "" - copy ssh.data show _ + copy skip ssh.data show _ else copy ssh.data insert _ when _ what __ end diff --git a/usr/librarys/context.js b/usr/librarys/context.js index 568d38da..a61fc7f3 100644 --- a/usr/librarys/context.js +++ b/usr/librarys/context.js @@ -1,7 +1,11 @@ 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} + var meta = arguments.callee + var order = ++meta.order + event.msg = msg = msg || {}, proto = proto || {}, msg.__proto__ = proto, proto.__proto__ = { Push: function(key, value) { msg.append || (msg.append = []) @@ -23,10 +27,12 @@ ctx = context = {__proto__: kit, return s }, }, msg.event = event - kit.Log("event", event.type, proto.name, msg) + kit.Log("event", order, event.type, proto.name, msg) return msg - }, - Run: function(dataset, cmd, cb) { + }, {order: 0}), + 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 option = {"cmds": cmd} @@ -42,14 +48,15 @@ ctx = context = {__proto__: kit, msg.option.push(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])) 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 || {}) }, msg) - }, + }, {order: 0}), Runs: function(form, cb) { var data = {} for (var key in form.dataset) { @@ -274,32 +281,32 @@ ctx = context = {__proto__: kit, page.ontoast("wss open") } s.onmessage = function(event) { + var order = ++meta.order try { var msg = JSON.parse(event.data||'{}') } catch (e) { var msg = {"result": [event.data]} } - meta.order++ // Event入口 -1.0 msg = ctx.Event(event, msg, { - name: meta.order, - Order: meta.order, + name: document.title, + Order: order, 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)) }, }) try { - kit.Log(["wss"].concat(msg.detail).concat([msg])) + kit.Log(["wss", order].concat(msg.detail).concat([msg])) typeof cb == "function" && cb(msg) } catch (e) { msg.reply(kit.Log("err", e)) } } s.onerror = function(event) { - kit.Log(event) + kit.Log("wss", "error", event) typeof onerror == "function" && onerror(event) } s.onclose = function(event) { diff --git a/usr/librarys/example.js b/usr/librarys/example.js index 70d7316e..d5fdd249 100644 --- a/usr/librarys/example.js +++ b/usr/librarys/example.js @@ -541,7 +541,7 @@ function Pane(page, field) { var timer = "" var list = [], last = -1, member = {} - var name = option.dataset.name + var name = option.dataset.names var pane = Meta(field, (page[field.dataset.init] || function() { })(page, field, option, output) || {}, { Append: function(type, line, key, which, cb) { @@ -742,11 +742,7 @@ function Plugin(page, pane, field, runs) { } }: cb) }); - switch (item.value) { - case "date": - item.name == "date" && (item.value = kit.format_date(new Date())) - break - } + item.value = plugin.onformat(item.init)(item.value) !item.title && item.name && (item.title = item.name) !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)+"%") }) }, + 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: { inner: function(msg, cb) { output.style.maxWidth = pane.target.clientWidth-20+"px" diff --git a/usr/template/common.tmpl b/usr/template/common.tmpl index 7c94b635..8b793391 100644 --- a/usr/template/common.tmpl +++ b/usr/template/common.tmpl @@ -14,13 +14,13 @@
-
+
{{end}} {{define "fieldset"}}
-
+