1
0
mirror of https://shylinux.com/x/volcanos synced 2025-04-25 16:58:06 +08:00
This commit is contained in:
harveyshao 2022-11-16 13:13:21 +08:00
parent d5c4ae3971
commit 4ecd492927
4 changed files with 33 additions and 38 deletions

View File

@ -54,7 +54,7 @@ Volcanos(chat.ONENGINE, {_init: function(can, meta, list, cb, target) {
if (can.base.isUndefined(name) || !can.base.isString(name) || name == _name) { return } if (can.base.isUndefined(name) || !can.base.isString(name) || name == _name) { return }
if (can.base.isUndefined(command)) { return arguments.callee.meta[_name] } if (can.base.isUndefined(command)) { return arguments.callee.meta[_name] }
var button = false, type = html.TEXT; command.list = can.core.List(command.list, function(item) { var button = false, type = html.TEXT; command.list = can.core.List(command.list, function(item) {
return can.base.isString(item) && (item = can.core.SplitInput(item, type)), item.type != html.SELECT && (type = item.type), button = button || item.type == html.BUTTON, item return can.base.isString(item) && (item = can.core.SplitInput(item, can.base.isFunc(command.meta[item])? html.BUTTON: type)), item.type != html.SELECT && (type = item.type), button = button || item.type == html.BUTTON, item
}); if (!button) { command.list.push(can.core.SplitInput(ice.LIST, html.BUTTON)) } }); if (!button) { command.list.push(can.core.SplitInput(ice.LIST, html.BUTTON)) }
command.can = can, command.meta.name = name, arguments.callee.meta[_name] = command command.can = can, command.meta.name = name, arguments.callee.meta[_name] = command
}), }),
@ -65,10 +65,10 @@ Volcanos(chat.ONENGINE, {_init: function(can, meta, list, cb, target) {
}, },
}) })
Volcanos(chat.ONDAEMON, {_init: function(can, name) { if (can.user.isLocalFile) { return } Volcanos(chat.ONDAEMON, {_init: function(can, name) { if (can.user.isLocalFile) { return }
can.misc.WSS(can, {type: html.CHROME, name: can.misc.Search(can, cli.DAEMON)||name||"", text: can.user.title()}, function(event, msg, cmd, arg) { if (!msg) { return } can.misc.WSS(can, {type: html.CHROME, name: can.misc.Search(can, cli.DAEMON)||name||"", text: can.user.title()}, function(event, msg, cmd, arg, cb) {
var sub = can.ondaemon._list[msg.Option(ice.MSG_TARGET)]||can; can.base.isFunc(sub.ondaemon[cmd])? var sub = can.ondaemon._list[msg.Option(ice.MSG_TARGET)]||can; can.base.isFunc(sub.ondaemon[cmd])?
can.core.CallFunc(sub.ondaemon[cmd], {can: can, msg: msg, sub: sub, cmd: cmd, arg: arg, cb: function() { msg.Reply() }}): can.core.CallFunc(sub.ondaemon[cmd], {can: can, msg: msg, sub: sub, cmd: cmd, arg: arg, cb: cb}):
can.onengine._search({}, can, msg, can, [chat._SEARCH, cmd].concat(arg), function() { msg.Reply() }) can.onengine._search({}, can, msg, can, [chat._SEARCH, cmd].concat(arg), cb)
}) })
}, _list: [""], }, _list: [""],
pwd: function(can, arg) { can._wss_name = can.ondaemon._list[0] = arg[0] }, pwd: function(can, arg) { can._wss_name = can.ondaemon._list[0] = arg[0] },
@ -118,7 +118,9 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) {
case lang.OBJECT: can.page.style(can, sub._target, style); break case lang.OBJECT: can.page.style(can, sub._target, style); break
} sub.Mode() != meta.type && can.page.ClassList.add(can, field, sub.Mode()) } sub.Mode() != meta.type && can.page.ClassList.add(can, field, sub.Mode())
sub._trans = can.base.Copy(sub._trans||{}, can.core.Value(sub, [chat.ONACTION, chat._TRANS])), meta.inputs && sub.onappend._option(sub, meta, sub._option, meta.msg) sub._trans = can.base.Copy(sub._trans||{}, can.core.Value(sub, [chat.ONACTION, chat._TRANS]))
can.core.Item(meta.feature, function(key, cb) { cb.help && sub.user.trans(sub, kit.Dict(key, cb.help)) })
meta.inputs && sub.onappend._option(sub, meta, sub._option, meta.msg)
if (meta.msg) { var msg = sub.request(); msg.Copy(can.base.Obj(meta.msg)), sub.onappend._output(sub, msg, meta.display||msg.Option(ice.MSG_DISPLAY)||meta.feature.display) } if (meta.msg) { var msg = sub.request(); msg.Copy(can.base.Obj(meta.msg)), sub.onappend._output(sub, msg, meta.display||msg.Option(ice.MSG_DISPLAY)||meta.feature.display) }
can.core.Value(sub._legend, chat.ONMOUSEENTER, function(event) { can.core.Value(sub._legend, chat.ONMOUSEENTER, function(event) {

View File

@ -111,9 +111,7 @@ Volcanos("misc", {Message: function(event, can) { var msg = {}
xhr.open(msg._method||web.POST, url), xhr.onreadystatechange = function() { if (xhr.readyState != 4) { return } xhr.open(msg._method||web.POST, url), xhr.onreadystatechange = function() { if (xhr.readyState != 4) { return }
try { var res = JSON.parse(xhr.responseText) } catch (e) { var res = {result: [xhr.responseText]} } msg.Option("_cost", new Date() - begin) try { var res = JSON.parse(xhr.responseText) } catch (e) { var res = {result: [xhr.responseText]} } msg.Option("_cost", new Date() - begin)
if (xhr.status == 200) { return can.base.isFunc(cb) && cb(msg.Copy(res)) } if (xhr.status == 200) { return can.base.isFunc(cb) && cb(msg.Copy(res)) }
if (xhr.status == 401) { return can.user.toastFailure(can, xhr.response) } can.user.toastFailure(can, xhr.response), can.misc.Warn(xhr.status, res, url, form)
if (xhr.status == 403) { return can.user.toastFailure(can, xhr.response) }
can.misc.Warn(xhr.status, res, url, form)
}, xhr.setRequestHeader(web.Accept, msg._accept||web.ContentJSON) }, xhr.setRequestHeader(web.Accept, msg._accept||web.ContentJSON)
if (msg._upload) { if (msg._upload) {
@ -157,7 +155,7 @@ Volcanos("misc", {Message: function(event, can) { var msg = {}
try { try {
msg.Option(ice.LOG_DISABLE) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_DETAIL, msg.detail, msg) msg.Option(ice.LOG_DISABLE) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_DETAIL, msg.detail, msg)
can.base.isFunc(cb) && cb(event, msg, msg.detail[0], msg.detail.slice(1)) can.core.CallFunc(cb, {event: event, msg: msg, cmd: msg.detail[0], arg: msg.detail.slice(1), cb: function() { msg.Reply() }})
} catch (e) { can.misc.Warn(e), msg.Reply() } } catch (e) { can.misc.Warn(e), msg.Reply() }
} }
}, },

View File

@ -214,43 +214,35 @@ Volcanos("user", {info: {}, agent: {
}) }) }) })
}, },
login: function(can, cb, method, auto) { login: function(can, cb, method, auto) { var trans = kit.Dict(aaa.USERNAME, "用户", aaa.PASSWORD, "密码", aaa.LOGIN, "登录")
function layout() { can.onmotion.delay(can, function() { can.page.Modify(can, ui._target, {className: "input login", style: {left: (window.innerWidth-ui._target.offsetWidth)/2, top: window.innerHeight/6}}) }) } function layout() { can.page.style(can, ui._target, {left: (window.innerWidth-ui._target.offsetWidth)/2, top: window.innerHeight/6}) }
function button(list) { return {view: [html.ITEM, html.TR], list: [{type: html.TD}, {type: html.TD, list: can.core.Item(list, function(key, cb) {
function input(name, type) { return {view: [html.ITEM, html.TR], list: [{type: html.TD, list: [{text: can.user.trans(can, name, { return {type: html.INPUT, value: can.user.trans(can, key, trans), data: {type: html.BUTTON}, onclick: cb}
"username": "用户", "password": "密码", }) }]} }
})}]}, {type: html.TD, list: [{type: html.INPUT, name: name, data: {type: type||html.TEXT}}]}]} } function input(name, type) { return {view: [html.ITEM, html.TR], list: [
{type: html.TD, list: [{text: can.user.trans(can, name, trans)}]},
function button(name, cb) { {type: html.TD, list: [{type: html.INPUT, name: name, data: {type: type||html.TEXT}}]},
return {view: [html.ITEM, html.TR], list: [{type: "td"}, {type: "td", list: [{type: "input", value: can.user.trans(can, "login", "登录"), data: {type: "button"}, onclick: cb}] }]} ]} }
}
var ui = can.onappend.tabview(can, { var ui = can.onappend.tabview(can, {
"扫码授权": function(target) { "扫码授权": function(target) { can.misc.WSS(can, {type: html.CHROME, cmd: cli.PWD}, function(cmd, arg) {
can.misc.WSS(can, {type: html.CHROME, cmd: cli.PWD}, function(event, msg, cmd, arg) { if (cmd == cli.PWD) { return can.page.Modify(can, target, arg[2]), can.page.Append(can, target, [{text: "<br/>请授权: "+arg[0]}]), layout() }
if (cmd == ice.MSG_SESSID) { return can.misc.CookieSessid(can, arg[0]), msg.Reply(), can.user.reload(true) } if (cmd == ice.MSG_SESSID) { return can.misc.CookieSessid(can, arg[0]), can.page.Remove(can, ui._target), can.base.isFunc(cb) && cb() }
if (cmd == cli.PWD) { layout() }) },
return can.page.Modify(can, target, arg[2]), can.page.Append(can, target, [{text: "<br/>请授权: "+arg[0]}])
}
})
},
"密码登录": function(target) { "密码登录": function(target) {
var _ui = can.page.Append(can, target, [input("username"), input("password", "password"), var _ui = can.page.Append(can, target, [input(aaa.USERNAME), input(aaa.PASSWORD, aaa.PASSWORD),
button("login", function(event) { button(kit.Dict(aaa.LOGIN, function(event) {
can.runAction(event, aaa.LOGIN, [_ui.username.value, _ui.password.value], function(msg) { can.runAction(event, aaa.LOGIN, [_ui.username.value, _ui.password.value], function(msg) {
if (!msg.Option(ice.MSG_USERNAME)) { return can.user.toast(can, "用户或密码错误") } if (!msg.Option(ice.MSG_USERNAME)) { return can.user.toastFailure(can, "用户或密码错误") }
can.page.Remove(can, ui._target), can.base.isFunc(cb) && cb() can.page.Remove(can, ui._target), can.base.isFunc(cb) && cb()
}) })
}), })),
]) ])
}, },
"网关授权": function(target) { "网关授权": function(target) { can.misc.WSS(can, {type: html.CHROME, cmd: chat.SSO, back: location.href}, function(cmd, arg) {
can.misc.WSS(can, {type: html.CHROME, cmd: chat.SSO, back: location.href}, function(event, msg, cmd, arg) { if (cmd == cli.PWD) { return can.onmotion.delay(can, function() { location.href = arg[1] }) }
if (cmd == cli.PWD) { return location.href = arg[1] } }) },
}) }, auto? ["网关授权"]: can.base.Obj(method, can.user.isMobile? ["密码登录"]: ["扫码授权"]), can.page.Append(can, document.body, [{view: "input login"}])._target); layout()
},
}, auto? ["网关授权"]: can.base.Obj(method, can.user.isMobile? ["密码登录"]: ["扫码授权"]), can.page.Append(can, document.body, [{view: "input login"}])._target)
layout()
}, },
logout: function(can, force) { if (force||can.user.confirm("logout?")) { can.runAction({}, aaa.LOGOUT, [], function(msg) { logout: function(can, force) { if (force||can.user.confirm("logout?")) { can.runAction({}, aaa.LOGOUT, [], function(msg) {
can.misc.Search(can, chat.SHARE)? can.misc.Search(can, chat.SHARE, ""): can.user.reload(true) can.misc.Search(can, chat.SHARE)? can.misc.Search(can, chat.SHARE, ""): can.user.reload(true)

View File

@ -150,4 +150,7 @@ Volcanos(chat.ONPLUGIN, {
}, ["language:select=zh,en", ice.RUN], function(can, msg, arg) { }, ["language:select=zh,en", ice.RUN], function(can, msg, arg) {
can.runAction(event, aaa.LANGUAGE, [arg[0]], function(msg) { can.user.reload() }) can.runAction(event, aaa.LANGUAGE, [arg[0]], function(msg) { can.user.reload() })
}), }),
logout: shy("退出登录", kit.Dict(
aaa.LOGOUT, shy("退出", function(can) { can.user.logout(can._root.Header, true) })
), [aaa.LOGOUT]),
}) })