mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 16:58:06 +08:00
mix github
This commit is contained in:
commit
4420a9910d
@ -2,6 +2,12 @@ Volcanos("base", {help: "基础模块",
|
||||
isNone: function(c) {return c === undefined || c === null},
|
||||
isSpace: function(c) {return c == " " || c == "Enter"},
|
||||
|
||||
Args: function(obj) {var res = [];
|
||||
for (var k in obj) {
|
||||
res.push(encodeURIComponent(k)+"="+encodeURIComponent(obj[k]))
|
||||
}
|
||||
return res.join("&")
|
||||
},
|
||||
Int: function(value) {return parseInt(value)||0},
|
||||
Duration: function(n) {var res = "", h = 0;
|
||||
h = parseInt(n/3600000), h > 0 && (res += h+"h"), n = n % 3600000;
|
||||
|
30
lib/misc.js
30
lib/misc.js
@ -62,36 +62,44 @@ Volcanos("misc", {help: "工具模块",
|
||||
}), delete(event.msg)
|
||||
}),
|
||||
WSS: shy("请求后端", {order: 0}, function(can, cb, onerror, onclose, onopen) {var meta = arguments.callee.meta
|
||||
var s = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/space/?node=active&name=some&wssid="+can._wssid)
|
||||
can._socket = s
|
||||
s.onerror = onerror || function() {
|
||||
delete(can._socket), setTimeout(function() {
|
||||
can._socket = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/space/?"+can.base.Args({
|
||||
node: "active", name: can._share||"", user: can._username||"", share: can._share||"",
|
||||
}))
|
||||
|
||||
var timer = can.Timer(30000, function() {
|
||||
can._socket.send("{}")
|
||||
})
|
||||
can._socket.onerror = onerror || function() {
|
||||
can._socket.close()
|
||||
}, can._socket.onclose = onclose || function() {
|
||||
timer.stop = true, can.user.toast("wss redial")
|
||||
can.Log("wss", "close"), delete(can._socket), setTimeout(function() {
|
||||
can.misc.WSS(can, cb, onerror, onclose, onopen)
|
||||
}, 1000)
|
||||
}, s.onclose = onclose, s.onopen = onopen
|
||||
s.onmessage = function(event) {var order = ++meta.order
|
||||
}, can._socket.onopen = onopen
|
||||
can._socket.onmessage = function(event) {var order = ++meta.order
|
||||
try {
|
||||
var msg = JSON.parse(event.data||'{}')
|
||||
} catch (e) {
|
||||
var msg = {"result": [event.data]}
|
||||
}
|
||||
|
||||
// Event入口 -1.0
|
||||
msg = can.Event(event, msg)
|
||||
msg.Reply = function() {
|
||||
msg = can.Event(event, msg), msg.Reply = function() {
|
||||
msg.Option("_handle", true)
|
||||
msg.Option("_target", msg.Option("_source"))
|
||||
can.Log(["wss", order, "result"].concat(msg.result).concat([msg]))
|
||||
delete(msg.detail)
|
||||
delete(msg.event), s.send(JSON.stringify(msg))
|
||||
delete(msg.event), can._socket.send(JSON.stringify(msg))
|
||||
}
|
||||
|
||||
try {
|
||||
can.Log(["wss", order].concat(msg.detail).concat([msg]))
|
||||
typeof cb == "function" && cb(event, msg)
|
||||
} catch (e) {
|
||||
msg.Option("_handle", true)
|
||||
msg.Reply(can.Log("err", e))
|
||||
}
|
||||
}
|
||||
return can._socket
|
||||
}),
|
||||
})
|
||||
|
||||
|
@ -1,10 +1,9 @@
|
||||
fieldset.Login {
|
||||
font-size:28px;
|
||||
font-size:24px;
|
||||
z-index:20;
|
||||
}
|
||||
fieldset.Login>form.option input {
|
||||
font-size:18px;
|
||||
height:28px;
|
||||
height:24px;
|
||||
}
|
||||
fieldset.Login>form.option button {
|
||||
font-size:18px;
|
||||
|
@ -1,9 +1,9 @@
|
||||
Volcanos("onimport", {help: "导入数据", list: [],
|
||||
_init: function(can, conf, output, action, option, field) {
|
||||
var ui = can.page.Appends(can, option, [
|
||||
{text: ["username: ", "label"]}, {username: []}, {type: "br"},
|
||||
{text: ["password: ", "label"]}, {password: []}, {type: "br"},
|
||||
{button: ["login", function(event, cmd) {
|
||||
{text: ["账号: ", "label"]}, {username: []}, {type: "br"},
|
||||
{text: ["密码: ", "label"]}, {password: []}, {type: "br"},
|
||||
{button: ["密码登录", function(event, cmd) {
|
||||
if (!ui.username.value) {ui.username.focus(); return}
|
||||
if (!ui.password.value) {ui.password.focus(); return}
|
||||
|
||||
@ -17,33 +17,47 @@ Volcanos("onimport", {help: "导入数据", list: [],
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
return true
|
||||
}]}, {type: "br"},
|
||||
}]},
|
||||
{button: ["扫码登录", function(event, cmd) {
|
||||
can.onimport.username(event, can, "", function(event, msg) {
|
||||
switch (msg.detail[0]) {
|
||||
case "space":
|
||||
if (msg.detail[1] == "share") {can._share = msg.detail[2]
|
||||
can.user.toast({title: "请用微信扫描", list: [{img: [can.user.Share(can, {
|
||||
path: "/share/"+msg.detail[2],
|
||||
}, true)]}]})
|
||||
return true
|
||||
}
|
||||
break
|
||||
case "sessid":
|
||||
can.user.Cookie(can, "sessid", msg.detail[1])
|
||||
can.Hide(), can.Export(event, "", "login")
|
||||
can.user.toast("")
|
||||
return true
|
||||
}
|
||||
})
|
||||
event.stopPropagation()
|
||||
event.preventDefault()
|
||||
return true
|
||||
}]},
|
||||
{type: "br"},
|
||||
])
|
||||
},
|
||||
username: function(event, can, value, cmd, output) {
|
||||
return can._socket || (can._socket = can.misc.WSS(can, function(event, m) {
|
||||
if (m.detail) {
|
||||
switch (m.detail[0]) {
|
||||
case "share":
|
||||
case "pwd":
|
||||
m.Echo("hello world")
|
||||
username: function(event, can, value, cmd, output) {can._username = value
|
||||
return can._socket = can._socket || can.misc.WSS(can, function(event, msg) {
|
||||
if (msg.Option("_handle")) {return can.user.toast(msg.result.join(""))}
|
||||
if (typeof cmd == "function" && cmd(event, msg)) {return msg.Reply(msg)}
|
||||
|
||||
}
|
||||
m.Reply(m)
|
||||
} else {
|
||||
page.toast.Pane.Show(m.result.join(""))
|
||||
switch (msg.detail[0]) {
|
||||
case "space": can._share = msg.detail[2]; break
|
||||
case "pwd": msg.Echo("hello world"); break
|
||||
}
|
||||
|
||||
}, function() {
|
||||
can._socket.close()
|
||||
|
||||
}, null, function() {
|
||||
can.user.toast("WSS Open")
|
||||
}))
|
||||
msg.Reply(msg)
|
||||
})
|
||||
},
|
||||
login: function(event, can, value, cmd, output) {
|
||||
if (!can.user.Cookie("sessid")) {can.Show(event, 400, 400); return}
|
||||
can.run(event||{}, ["check"], function(msg) {var user = msg.Result()
|
||||
can.run(event||{}, ["check"], function(msg) {var user = msg.nickname && msg.nickname[0] || msg.Result()
|
||||
user? can.Export(event, user, "username"): can.Show(event, -1, -1)
|
||||
})
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user