1
0
mirror of https://shylinux.com/x/volcanos synced 2025-04-25 16:58:06 +08:00
volcanos/pane/Login.js
2020-02-23 06:35:23 +08:00

84 lines
4.0 KiB
JavaScript

Volcanos("onimport", {help: "导入数据", list: [],
_init: function(can, conf, output, action, option, field) {
can.user.login = function(cb) {
can.user.Cookie("sessid")? can.onaction.check(event, can, cb, "check", output):
can.onaction.login(event, can, cb, "login", output)
}
},
share: function(event, can, value, cmd, target) {var msg = can.Event(event)
var list = [];
switch (value) {
case "storm": list.push("river", msg.Conf("river")); break
case "action": list.push("river", msg.Conf("river")), list.push("storm", msg.Conf("storm")); break
}
can.run(event, ["share", value, msg.Option("name"), msg.Option("text")].concat(list), function(msg) {
var p = "/share/" + msg.Result(); can.user.toast({title: msg.Option("name"),
text: [{text: can.user.Share(can, {path: p}, true)}, {img: p+"/qrcode"}],
width: 300, height: 400, duration: 300000,
})
})
},
})
Volcanos("onaction", {help: "组件交互", list: [],
check: function(event, can, cb, cmd, target) {
can.run(event||{}, ["check"], function(msg) {var user = msg.nickname && msg.nickname[0] || msg.Result()
user? typeof cb == "function" && cb({name: user}): can.onaction.login(event, can, cb, "login", target)
})
},
login: function(event, can, cb, cmd, target) {
var ui = can.page.Appends(can, target, [
{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}
can.run(event, ["login", ui.username.value, ui.password.value], function(msg) {
if (msg.result && msg.result.length > 0) {
can.Hide(), can.onaction.check(event, can, cb, "check", target)
return
}
can.user.toast("用户或密码错误")
})
}]},
{button: ["扫码登录", function(event, cmd) {
can.onaction.socket(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(), typeof cb == "function" && cb({name: msg["user.name"]})
can.user.toast("")
return true
}
})
}]},
{type: "br"},
])
can.Show(event, -1, -1)
},
socket: function(event, can, value, cmd, output) {can._username = value
return can._socket = can._socket || can.misc.WSS(can, "wss://shylinux.com/space/", {node: "active", name: ""}, 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)}
switch (msg.detail[0]) {
case "space": can._share = msg.detail[2]; break
case "pwd": msg.Echo("hello world"); break
}
msg.Reply(msg)
})
},
})
Volcanos("onchoice", {help: "组件菜单", list: []})
Volcanos("ondetail", {help: "组件详情", list: []})
Volcanos("onexport", {help: "导出数据", list: []})