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},
|
isNone: function(c) {return c === undefined || c === null},
|
||||||
isSpace: function(c) {return c == " " || c == "Enter"},
|
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},
|
Int: function(value) {return parseInt(value)||0},
|
||||||
Duration: function(n) {var res = "", h = 0;
|
Duration: function(n) {var res = "", h = 0;
|
||||||
h = parseInt(n/3600000), h > 0 && (res += h+"h"), n = n % 3600000;
|
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)
|
}), delete(event.msg)
|
||||||
}),
|
}),
|
||||||
WSS: shy("请求后端", {order: 0}, function(can, cb, onerror, onclose, onopen) {var meta = arguments.callee.meta
|
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 = new WebSocket(location.protocol.replace("http", "ws")+"//"+location.host+"/space/?"+can.base.Args({
|
||||||
can._socket = s
|
node: "active", name: can._share||"", user: can._username||"", share: can._share||"",
|
||||||
s.onerror = onerror || function() {
|
}))
|
||||||
delete(can._socket), setTimeout(function() {
|
|
||||||
|
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)
|
can.misc.WSS(can, cb, onerror, onclose, onopen)
|
||||||
}, 1000)
|
}, 1000)
|
||||||
}, s.onclose = onclose, s.onopen = onopen
|
}, can._socket.onopen = onopen
|
||||||
s.onmessage = function(event) {var order = ++meta.order
|
can._socket.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]}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Event入口 -1.0
|
msg = can.Event(event, msg), msg.Reply = function() {
|
||||||
msg = can.Event(event, msg)
|
msg.Option("_handle", true)
|
||||||
msg.Reply = function() {
|
|
||||||
msg.Option("_target", msg.Option("_source"))
|
msg.Option("_target", msg.Option("_source"))
|
||||||
can.Log(["wss", order, "result"].concat(msg.result).concat([msg]))
|
can.Log(["wss", order, "result"].concat(msg.result).concat([msg]))
|
||||||
delete(msg.detail)
|
delete(msg.event), can._socket.send(JSON.stringify(msg))
|
||||||
delete(msg.event), s.send(JSON.stringify(msg))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
can.Log(["wss", order].concat(msg.detail).concat([msg]))
|
can.Log(["wss", order].concat(msg.detail).concat([msg]))
|
||||||
typeof cb == "function" && cb(event, msg)
|
typeof cb == "function" && cb(event, msg)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
msg.Option("_handle", true)
|
||||||
msg.Reply(can.Log("err", e))
|
msg.Reply(can.Log("err", e))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return can._socket
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
fieldset.Login {
|
fieldset.Login {
|
||||||
font-size:28px;
|
font-size:24px;
|
||||||
z-index:20;
|
z-index:20;
|
||||||
}
|
}
|
||||||
fieldset.Login>form.option input {
|
fieldset.Login>form.option input {
|
||||||
font-size:18px;
|
height:24px;
|
||||||
height:28px;
|
|
||||||
}
|
}
|
||||||
fieldset.Login>form.option button {
|
fieldset.Login>form.option button {
|
||||||
font-size:18px;
|
font-size:18px;
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
Volcanos("onimport", {help: "导入数据", list: [],
|
Volcanos("onimport", {help: "导入数据", list: [],
|
||||||
_init: function(can, conf, output, action, option, field) {
|
_init: function(can, conf, output, action, option, field) {
|
||||||
var ui = can.page.Appends(can, option, [
|
var ui = can.page.Appends(can, option, [
|
||||||
{text: ["username: ", "label"]}, {username: []}, {type: "br"},
|
{text: ["账号: ", "label"]}, {username: []}, {type: "br"},
|
||||||
{text: ["password: ", "label"]}, {password: []}, {type: "br"},
|
{text: ["密码: ", "label"]}, {password: []}, {type: "br"},
|
||||||
{button: ["login", function(event, cmd) {
|
{button: ["密码登录", function(event, cmd) {
|
||||||
if (!ui.username.value) {ui.username.focus(); return}
|
if (!ui.username.value) {ui.username.focus(); return}
|
||||||
if (!ui.password.value) {ui.password.focus(); return}
|
if (!ui.password.value) {ui.password.focus(); return}
|
||||||
|
|
||||||
@ -17,33 +17,47 @@ Volcanos("onimport", {help: "导入数据", list: [],
|
|||||||
event.stopPropagation()
|
event.stopPropagation()
|
||||||
event.preventDefault()
|
event.preventDefault()
|
||||||
return true
|
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) {
|
username: function(event, can, value, cmd, output) {can._username = value
|
||||||
return can._socket || (can._socket = can.misc.WSS(can, function(event, m) {
|
return can._socket = can._socket || can.misc.WSS(can, function(event, msg) {
|
||||||
if (m.detail) {
|
if (msg.Option("_handle")) {return can.user.toast(msg.result.join(""))}
|
||||||
switch (m.detail[0]) {
|
if (typeof cmd == "function" && cmd(event, msg)) {return msg.Reply(msg)}
|
||||||
case "share":
|
|
||||||
case "pwd":
|
|
||||||
m.Echo("hello world")
|
|
||||||
|
|
||||||
|
switch (msg.detail[0]) {
|
||||||
|
case "space": can._share = msg.detail[2]; break
|
||||||
|
case "pwd": msg.Echo("hello world"); break
|
||||||
}
|
}
|
||||||
m.Reply(m)
|
msg.Reply(msg)
|
||||||
} else {
|
})
|
||||||
page.toast.Pane.Show(m.result.join(""))
|
|
||||||
}
|
|
||||||
|
|
||||||
}, function() {
|
|
||||||
can._socket.close()
|
|
||||||
|
|
||||||
}, null, function() {
|
|
||||||
can.user.toast("WSS Open")
|
|
||||||
}))
|
|
||||||
},
|
},
|
||||||
login: function(event, can, value, cmd, output) {
|
login: function(event, can, value, cmd, output) {
|
||||||
if (!can.user.Cookie("sessid")) {can.Show(event, 400, 400); return}
|
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)
|
user? can.Export(event, user, "username"): can.Show(event, -1, -1)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user