1
0
mirror of https://shylinux.com/x/volcanos synced 2025-04-25 16:58:06 +08:00

opt wx.ide

This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-11-29 16:10:34 +08:00
parent fd85b603ad
commit ebdd932d40
13 changed files with 152 additions and 94 deletions

View File

@ -382,7 +382,7 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) {
can.page.ClassList.set(can, target, "will", can.page.ClassList.has(can, target, key)) can.page.ClassList.set(can, target, "will", can.page.ClassList.has(can, target, key))
}) })
}, title: can.user.trans(can, can.Option(key) == undefined? key: "click to detail", null, html.INPUT), _init: function(target) { }, title: can.user.trans(can, can.Option(key) == undefined? key: "click to detail", null, html.INPUT), _init: function(target) {
key == ctx.ACTION && can.onappend.mores(can, target, data, can.user.isMobile && !can.user.isLandscape()? 2: can.isCmdMode()? 5: 3) key == ctx.ACTION && can.onappend.mores(can, target, data, can.user.isMobile && !can.user.isLandscape()? 2: can.isCmdMode() || msg.IsDetail()? 5: 3)
can.page.style(can, target, "cursor", key == mdb.KEY? "default": can.Option(key) != undefined? "pointer": "text") can.page.style(can, target, "cursor", key == mdb.KEY? "default": can.Option(key) != undefined? "pointer": "text")
}} }}
}); table && can.onappend.style(can, chat.CONTENT, table), table && msg.IsDetail() && can.onappend.style(can, mdb.DETAIL, table) }); table && can.onappend.style(can, chat.CONTENT, table), table && msg.IsDetail() && can.onappend.style(can, mdb.DETAIL, table)
@ -474,8 +474,7 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) {
if (item.index) { item._index = count++, ui.size[item._index] = item.height||item.width if (item.index) { item._index = count++, ui.size[item._index] = item.height||item.width
can.onmotion.hidden(can, target) can.onmotion.hidden(can, target)
can.onappend.plugin(can, item, function(sub) { can._plugins = (can._plugins||[]).concat([sub]) can.onappend.plugin(can, item, function(sub) { can._plugins = (can._plugins||[]).concat([sub])
item.layout = function(height, width) { item.layout = function(height, width) { sub.onimport.size(sub, height, width) }
sub.onimport.size(sub, height, width) }
sub.onexport._output = function() { can.onmotion.toggle(can, target, true) } sub.onexport._output = function() { can.onmotion.toggle(can, target, true) }
}, target, ui[item._index] = can.onappend.field(can, item.type, {index: item.index, name: item.index.split(nfs.PT).pop(), help: item.help}, target)._target) }, target, ui[item._index] = can.onappend.field(can, item.type, {index: item.index, name: item.index.split(nfs.PT).pop(), help: item.help}, target)._target)
} else { can.page.Append(can, target, [item]) } } else { can.page.Append(can, target, [item]) }
@ -484,15 +483,18 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) {
function calc(item, size, total) { return !ui.size[item]? can.base.isString(size)? parseInt(can.base.trimSuffix(size, "px")): size: ui.size[item] < 1? total*ui.size[item]: ui.size[item] } function calc(item, size, total) { return !ui.size[item]? can.base.isString(size)? parseInt(can.base.trimSuffix(size, "px")): size: ui.size[item] < 1? total*ui.size[item]: ui.size[item] }
var defer = [], content_height, content_width; function layout(type, list, height, width) { var _width = width, _height = height; can.core.List(list, function(item) { var defer = [], content_height, content_width; function layout(type, list, height, width) { var _width = width, _height = height; can.core.List(list, function(item) {
if (can.base.isArray(item)) { return } if (can.base.isObject(item)) { var meta = item; item = item._index } if (can.base.isArray(item)) { return } if (can.base.isObject(item)) { var meta = item; item = item._index }
var target = ui[item]; if (!can.page.isDisplay(target)) { return } var target = ui[item]
if (!can.page.isDisplay(target)) { return }
if (item == html.CONTENT || item == "main") { return defer.push(function() { can.page.style(can, target, html.HEIGHT, content_height = height, html.WIDTH, content_width = width) }) } if (item == html.CONTENT || item == "main") { return defer.push(function() { can.page.style(can, target, html.HEIGHT, content_height = height, html.WIDTH, content_width = width) }) }
if (type == FLOW) { var h = calc(item, target.offsetHeight, height) if (type == FLOW) { var h = calc(item, target.offsetHeight, height)
if (can.base.isObject(meta) && meta.layout) { meta.layout(h, width) } if (can.base.isObject(meta) && meta.layout) { meta.layout(h, width) }
can.page.style(can, target, html.WIDTH, width), height -= h can.page.style(can, target, html.WIDTH, width)
if (can.page.isDisplay(target)) { height -= h }
} else { } else {
var w = calc(item, target.offsetWidth||target.style.width||_width/list.length, _width), h = height var w = calc(item, target.offsetWidth||target.style.width||_width/list.length, _width), h = height
if (can.base.isObject(meta)) { meta.layout(h, w = _width/list.length) } if (can.base.isObject(meta)) { meta.layout(h, w = _width/list.length) }
can.page.style(can, target, html.HEIGHT, h, html.WIDTH, w), width -= w can.page.style(can, target, html.HEIGHT, h, html.WIDTH, w)
if (can.page.isDisplay(target)) { width -= w }
} }
}), can.core.List(list, function(item) { if (can.base.isArray(item)) { layout(type == FLOW? FLEX: FLOW, item, height, width) } }) } }), can.core.List(list, function(item) { if (can.base.isArray(item)) { layout(type == FLOW? FLEX: FLOW, item, height, width) } }) }
ui.profile && can.onmotion.hidden(can, ui.profile), ui.display && can.onmotion.hidden(can, ui.display) ui.profile && can.onmotion.hidden(can, ui.profile), ui.display && can.onmotion.hidden(can, ui.display)

View File

@ -34,7 +34,7 @@ body {
--svg-font-size:24px; --svg-stroke-width:1; --status-font-size:12px; --svg-font-size:24px; --svg-stroke-width:1; --status-font-size:12px;
--legend-padding:20px; --title-margin:var(--legend-padding); --river-margin:80px; --legend-padding:20px; --title-margin:var(--legend-padding); --river-margin:80px;
--textarea-height:96px; --qrcode-height:320px; --iframe-height:420px; --textarea-height:96px; --qrcode-height:360px; --iframe-height:420px;
--action-height:32px; --status-height:var(--action-height); --footer-height:var(--action-height); --header-height:48px; --action-height:32px; --status-height:var(--action-height); --footer-height:var(--action-height); --header-height:48px;
--project-width:230px; --river-width:var(--project-width); --input-width:120px; --button-width:60px; --project-width:230px; --river-width:var(--project-width); --input-width:120px; --button-width:60px;
--plugin-margin:var(--plugin-padding); --button-margin:var(--button-padding); --input-margin:var(--input-padding); --action-margin:200px; --desktop-icon-size:80px; --plugin-margin:var(--plugin-padding); --button-margin:var(--button-padding); --input-margin:var(--input-padding); --action-margin:200px; --desktop-icon-size:80px;
@ -155,7 +155,7 @@ body>div.input tr.img td:last-child>div>span { font-size:var(--action-height); }
body>div.input tr.icon td:last-child { position:relative; } body>div.input tr.icon td:last-child { position:relative; }
body>div.input tr.icon td:last-child img:first-child { position:absolute; height:28px; width:28px; left:12px; top:12px; } body>div.input tr.icon td:last-child img:first-child { position:absolute; height:28px; width:28px; left:12px; top:12px; }
body>div.input tr.icon td:last-child input { padding-left:var(--action-height); } body>div.input tr.icon td:last-child input { padding-left:var(--action-height); }
body>div.input tr.icons td:last-child img:first-child { position:absolute; height:28px; width:28px; left:12px; top:12px; } body>div.input tr.icons td:last-child img:first-child { position:absolute; height:28px; width:28px; left:2px; top:2px; }
body>div.input tr.icons td:last-child input { padding-left:var(--action-height); } body>div.input tr.icons td:last-child input { padding-left:var(--action-height); }
body>div.input td span.icon { margin-left:-20px; visibility:hidden; } body>div.input td span.icon { margin-left:-20px; visibility:hidden; }
body>div.input td span.icons { margin-left:-20px; visibility:hidden; } body>div.input td span.icons { margin-left:-20px; visibility:hidden; }
@ -327,7 +327,7 @@ div.toggle.project { top:20%; left:0; border-top-right-radius:var(--plugin-radiu
div.content>div.toggle.profile { top:20%; right:0; border-top-left-radius:var(--plugin-radius); border-bottom-left-radius:var(--plugin-radius); } div.content>div.toggle.profile { top:20%; right:0; border-top-left-radius:var(--plugin-radius); border-bottom-left-radius:var(--plugin-radius); }
div.content>div.toggle.display { left:20%; bottom:-52px; rotate:90deg; border-top-left-radius:var(--plugin-radius); border-bottom-left-radius:var(--plugin-radius); } div.content>div.toggle.display { left:20%; bottom:-52px; rotate:90deg; border-top-left-radius:var(--plugin-radius); border-bottom-left-radius:var(--plugin-radius); }
div.project:not(.toggle) { border-right:var(--box-border); width:var(--project-width); flex:0 0 var(--project-width); } div.project:not(.toggle) { border-right:var(--box-border); width:var(--project-width); flex:0 0 var(--project-width); }
div.profile:not(.toggle) { border-left:var(--box-border); width:50%; } div.profile:not(.toggle) { border-left:var(--box-border); width:50%; flex:0 0 50%; }
div.display:not(.toggle) { border-top:var(--box-border); } div.display:not(.toggle) { border-top:var(--box-border); }
/* output style */ /* output style */
div.output.card>div.item { div.output.card>div.item {
@ -471,7 +471,7 @@ body.mobile fieldset.Search>div.action>div.item.filter>span { position:absolute;
body.mobile fieldset.Search>div.action>div.item.filter { width:100%; position:relative; } body.mobile fieldset.Search>div.action>div.item.filter { width:100%; position:relative; }
body.mobile fieldset.River { position:fixed; top:var(--header-height); z-index:11; } body.mobile fieldset.River { position:fixed; top:var(--header-height); z-index:11; }
body.mobile fieldset.River>div.output { font-size:1.4rem; min-width:var(--project-width); } body.mobile fieldset.River>div.output { font-size:1.4rem; min-width:var(--project-width); }
body.mobile fieldset.Action { margin-top:var(--header-height); } html:not(.login) body.mobile fieldset.Action { margin-top:var(--header-height); }
body.mobile fieldset.Action.cmd { margin-top:0; } body.mobile fieldset.Action.cmd { margin-top:0; }
body.mobile fieldset.Action>div.output { overflow-x:hidden; } body.mobile fieldset.Action>div.output { overflow-x:hidden; }
body.mobile fieldset.word>div.output { overflow-x:hidden; } body.mobile fieldset.word>div.output { overflow-x:hidden; }

View File

@ -124,7 +124,7 @@ Volcanos("misc", {
try { var socket = new WebSocket(can.base.MergeURL(url, args)); _msg = _msg || can.request()._caller() } catch {} try { var socket = new WebSocket(can.base.MergeURL(url, args)); _msg = _msg || can.request()._caller() } catch {}
can._socket = socket, socket.onclose = function() { can.misc.Log(html.WSS, cli.CLOSE, args) can._socket = socket, socket.onclose = function() { can.misc.Log(html.WSS, cli.CLOSE, args)
if (socket._close) { return } if (socket._close) { return }
can.base.isFunc(onclose)? onclose(socket): can.core.Timer(can.base.random(3000, 100), function() { can.base.isFunc(onclose)? onclose(socket): can.core.Timer(can.base.random(3000, 300), function() {
args.name = args.name||can._wss_name, can.misc.WSS(can, args, cb, onopen, onerror, onclose, _msg) args.name = args.name||can._wss_name, can.misc.WSS(can, args, cb, onopen, onerror, onclose, _msg)
}) })
}, socket.onerror = function() { can.misc.Log(html.WSS, log.ERROR, args) }, socket.onerror = function() { can.misc.Log(html.WSS, log.ERROR, args)
@ -138,6 +138,7 @@ Volcanos("misc", {
res.append = msg.append, can.core.List(msg.append, function(key) { res[key] = msg[key] }), res.result = (msg.result||[]).concat(can.core.List(arguments)) res.append = msg.append, can.core.List(msg.append, function(key) { res[key] = msg[key] }), res.result = (msg.result||[]).concat(can.core.List(arguments))
res.Option(ice.LOG_DISABLE, msg.Option(ice.LOG_DISABLE)) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_RESULT, msg.result&&msg.result.length>0? msg.result: undefined, msg, _msg) res.Option(ice.LOG_DISABLE, msg.Option(ice.LOG_DISABLE)) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_RESULT, msg.result&&msg.result.length>0? msg.result: undefined, msg, _msg)
res.Option(ice.LOG_TRACEID, msg.Option(ice.LOG_TRACEID)) res.Option(ice.LOG_TRACEID, msg.Option(ice.LOG_TRACEID))
res.Option(ice.MSG_DEBUG, msg.Option(ice.MSG_DEBUG))
socket.send(JSON.stringify(res)) socket.send(JSON.stringify(res))
}, msg.detail = data.detail, msg.Copy(data) }, msg.detail = data.detail, msg.Copy(data)
try { msg.Option(ice.LOG_DISABLE) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_DETAIL, msg.detail, msg, _msg) try { msg.Option(ice.LOG_DISABLE) != ice.TRUE && can.misc.Log(html.WSS, ice.MSG_DETAIL, msg.detail, msg, _msg)

View File

@ -255,8 +255,9 @@ Volcanos("user", {
}), resize: html.IMG, }), resize: html.IMG,
}) }, }) },
login: function(can, cb, msg) { can.misc.CookieSessid(can, ""); var socket = can.misc.WSS(can, {type: aaa.LOGIN}, function(cmd, arg) { login: function(can, cb, msg) { can.misc.CookieSessid(can, ""); var socket = can.misc.WSS(can, {type: aaa.LOGIN}, function(cmd, arg) {
can.page.ClassList.add(can, document.body.parentNode, aaa.LOGIN)
function check() { function check() {
if (can.misc.CookieSessid(can)) { can.page.ClassList.del(can, document.body, aaa.LOGIN) if (can.misc.CookieSessid(can)) { can.page.ClassList.del(can, document.body.parentNode, aaa.LOGIN)
can.onmotion.clearFloat(can), can.onmotion.delay(can, function() { socket._close = true, socket.close() }) can.onmotion.clearFloat(can), can.onmotion.delay(can, function() { socket._close = true, socket.close() })
return can.base.isFunc(cb) && cb(), cb = null, true return can.base.isFunc(cb) && cb(), cb = null, true
} can.core.Timer(1000, function() { check() }), can.onimport.theme(can) } can.core.Timer(1000, function() { check() }), can.onimport.theme(can)

View File

@ -250,7 +250,7 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg, cb) { var paths = can.core.Sp
}) })
} else { } else {
return can.onmotion.toggle(can, target, false), can.onimport.layout(can), can.user.toastFailure(can, "nothing to display") return can.onmotion.toggle(can, target, false), can.onimport.layout(can), can.user.toastFailure(can, "nothing to display")
} return can.onmotion.toggle(can, target, true), can.onmotion.delay(can, function() { can.onimport.layout(can), can.user.toastSuccess(can) }) } return can.onmotion.toggle(can, target, true), can.onmotion.delay(can, function() { can.onimport.layout(can), can.user.toastSuccess(can) }, 0)
}, },
toolkit: function(can, meta, cb) { can.base.isString(meta) && (meta = {index: meta}) toolkit: function(can, meta, cb) { can.base.isString(meta) && (meta = {index: meta})
var key = [meta.index].concat(meta.args).join(","), sub = can.db.toolkit[key]; if (sub) { sub.select(); return } var key = [meta.index].concat(meta.args).join(","), sub = can.db.toolkit[key]; if (sub) { sub.select(); return }
@ -272,7 +272,13 @@ Volcanos(chat.ONIMPORT, {_init: function(can, msg, cb) { var paths = can.core.Sp
var sub = can.ui.content._plugin; if (!sub) { return } if (height == sub.ConfHeight()+sub.onexport.actionHeight(sub)+sub.onexport.statusHeight(sub) && width == sub.ConfWidth()) { return } var sub = can.ui.content._plugin; if (!sub) { return } if (height == sub.ConfHeight()+sub.onexport.actionHeight(sub)+sub.onexport.statusHeight(sub) && width == sub.ConfWidth()) { return }
content._root || sub.onimport.size(sub, height, width, true), can.onlayout.layout(can, height, width) content._root || sub.onimport.size(sub, height, width, true), can.onlayout.layout(can, height, width)
}) })
if (can.isCmdMode()) { can.ui.zone.source._layout(), can.ui.zone[can.Option(nfs.PATH)] && can.ui.zone[can.Option(nfs.PATH)]._layout() } if (can.isCmdMode()) {
can.page.style(can, can.ui.tabs.parentNode, html.WIDTH, can.ui.path.offsetWidth)
can.page.style(can, can.ui.display, html.WIDTH, can.ui.path.offsetWidth)
can.page.style(can, can.ui.display.parentNode, html.WIDTH, can.ui.path.offsetWidth)
can.ui.zone.source._layout(), can.ui.zone[can.Option(nfs.PATH)] && can.ui.zone[can.Option(nfs.PATH)]._layout()
}
try { can.isCmdMode() && can._msg._tab.scrollIntoView() } catch (e) {} try { can.isCmdMode() && can._msg._tab.scrollIntoView() } catch (e) {}
}, },
exts: function(can, url, cb) { var sub = can.db.toolkit[url.split(web.QS)[0]]; if (sub) { return can.base.isFunc(cb)? cb(sub): sub.select() } exts: function(can, url, cb) { var sub = can.db.toolkit[url.split(web.QS)[0]]; if (sub) { return can.base.isFunc(cb)? cb(sub): sub.select() }

View File

@ -14,6 +14,6 @@ App({
this.conf.platform = res.platform this.conf.platform = res.platform
this.conf.brand = res.brand this.conf.brand = res.brand
this.conf.model = res.model this.conf.model = res.model
console.log("app load", this.conf, res) this.misc.Info("app load", this.conf, res)
}, },
}) })

View File

@ -6,6 +6,13 @@
"condition": { "condition": {
"miniprogram": { "miniprogram": {
"list": [ "list": [
{
"name": "",
"pathName": "pages/action/action",
"query": "index=web.chat.wx.ide",
"launchMode": "default",
"scene": null
},
{ {
"name": "web.dream", "name": "web.dream",
"pathName": "pages/action/action", "pathName": "pages/action/action",

View File

@ -43,16 +43,21 @@ var web = {
} }
var aaa = { var aaa = {
} }
var lex = {
NL: "\n",
}
var tcp = { var tcp = {
} }
var nfs = { var nfs = {
DF: ice.DF, PS: ice.PS, PT: ice.PT, DF: ice.DF, PS: ice.PS, PT: ice.PT,
CHAT_RIVER: "/chat/river/", CHAT_RIVER: "/chat/river/",
CHAT_ACTION: "/chat/action/", CHAT_ACTION: "/chat/action/",
PATH: "path",
} }
var cli = { var cli = {
} }
var log = { var log = {
INFO: "info",
} }
var code = { var code = {
COMMENT: "comment", KEYWORD: "keyword", COMMENT: "comment", KEYWORD: "keyword",
@ -92,6 +97,7 @@ var html = {
module.exports = { module.exports = {
kit, ice, kit, ice,
ctx, mdb, web, aaa, ctx, mdb, web, aaa,
lex,
tcp, nfs, cli, log, tcp, nfs, cli, log,
code, wiki, chat, team, mall, code, wiki, chat, team, mall,
http, html, http, html,

View File

@ -28,7 +28,8 @@ Volcanos("base", {
var arg = this.Args.apply(this, [arg].concat(Array.prototype.slice.call(arguments, 1))); return url.split(ice.QS)[0]+(arg? ice.QS+arg: "") var arg = this.Args.apply(this, [arg].concat(Array.prototype.slice.call(arguments, 1))); return url.split(ice.QS)[0]+(arg? ice.QS+arg: "")
}, },
ParseURL: function(url) { var res = this._parse(url); res.link = url, res.origin = res._origin; return res }, ParseURL: function(url) { var res = this._parse(url); res.link = url, res.origin = res._origin; return res },
ParseJSON: function(str) { var res; if (typeof str == code.OBJECT) { return str } ParseJSON: function(str) {
var res; if (typeof str == code.OBJECT) { return str }
if (str.indexOf(ice.HTTP) == 0) { if (str.indexOf(ice.HTTP) == 0) {
var res = this._parse(str, {type: web.LINK, name: "", text: str}) var res = this._parse(str, {type: web.LINK, name: "", text: str})
return res.name = res._origin.split("://").pop().split(nfs.PS)[0], res return res.name = res._origin.split("://").pop().split(nfs.PS)[0], res
@ -65,4 +66,5 @@ Volcanos("base", {
trim: function(arg) { if (this.isString(arg)) { return arg.trim() } trim: function(arg) { if (this.isString(arg)) { return arg.trim() }
if (this.isArray(arg)) { for (var i = arg.length-1; i >= 0; i--) { if (!arg[i]) { arg.pop() } else { break } } } return arg if (this.isArray(arg)) { for (var i = arg.length-1; i >= 0; i--) { if (!arg[i]) { arg.pop() } else { break } } } return arg
}, },
random: function(max, min) { return min = min||0, parseInt(Math.random()*(max-min))+min },
}) })

View File

@ -1,4 +1,4 @@
const {kit, ice, ctx, mdb, web, nfs, code, chat, http, html} = require("../const.js") const {kit, ice, ctx, mdb, web, lex, nfs, log, code, chat, http, html} = require("../const.js")
const {Volcanos} = require("../proto.js") const {Volcanos} = require("../proto.js")
module.exports = module.exports =
Volcanos("misc", { Volcanos("misc", {
@ -57,23 +57,20 @@ Volcanos("misc", {
for (var i = 1; i < ls.length; i += 2) { if (can.base.isIn(ls[i], [ice.POD, ice.CMD])) { args[ls[i]] = ls[i+1] } } for (var i = 1; i < ls.length; i += 2) { if (can.base.isIn(ls[i], [ice.POD, ice.CMD])) { args[ls[i]] = ls[i+1] } }
return args return args
}, },
WSS: function(can) { WSS: function(can) { if (can.conf.platform == "devtools" && can.db.serve != can.conf.serve) { return }
var url = can.base.MergeURL(can.db.serve.replace("http", "ws")+"/space/", mdb.TYPE, "weixin", mdb.NAME, "weixin", mdb.TEXT, can.base.MergeURL(nfs.PS+can.ui.route, can.db), can.conf) var url = can.base.MergeURL(can.db.serve.replace("http", "ws")+"/space/", mdb.TYPE, "weixin", mdb.NAME, "weixin", mdb.TEXT, can.base.MergeURL(nfs.PS+can.ui.route, can.db), can.conf)
var socket = wx.connectSocket({url: url, header:{"content-type": "application/json"}}) var socket = wx.connectSocket({url: url, header:{"content-type": "application/json"}}); can.misc.Info("wss connect", url, socket)
console.log("wss connect", url, socket) socket.onOpen(function(res) { can.misc.Info("wss open", res) })
socket.onOpen(function(res) { console.log("wss open", res) }) socket.onClose(function(res) { can.misc.Info("wss close", res), can._socket && can.core.Timer(can.base.random(30000, 3000), function() { can.misc.WSS(can) }) })
socket.onClose(function(res) { console.log("wss close", res) socket.onMessage(function(res) { var msg = can.request(), data = can.base.Obj(res.data); msg.Copy(data), msg.detail = data.detail, can.misc.Info("wss recv", msg.detail, msg)
if (can._socket) { can._socket = socket = can.misc.WSS(can) }
})
socket.onMessage(function(res) {
var msg = can.request(), data = can.base.Obj(res.data); msg.Copy(data), msg.detail = data.detail, console.log("wss recv", msg)
switch (msg.detail[0]) { switch (msg.detail[0]) {
case "pwd": can._daemon = msg.detail[1]; break case "pwd": can._daemon = msg.detail[1]; break
} case "parse": can.core.Timer(30, function() { can.user.parse(can, data.detail[1]) }); break
msg.Echo("hello world") case "info": break
delete(msg._hand), console.log("wss send", msg), socket.sendSocketMessage({data: JSON.stringify(msg)}) } delete(msg._hand), delete(msg.detail), msg.Option("_handle", ice.TRUE)
}) msg._target = (msg._source||[]).reverse(), msg._source = (msg._target||[]).reverse().slice(1)||[]
return socket can.misc.Info("wss send", msg.result, msg), socket.send({data: JSON.stringify(msg)})
}); return can._socket = socket
}, },
request: function(can, msg, cmd, data, cb) { data.sessid = can.conf.sessid, data.appid = data.appid||can.conf.appid request: function(can, msg, cmd, data, cb) { data.sessid = can.conf.sessid, data.appid = data.appid||can.conf.appid
can.core.List(msg.option, function(key) { data[key] = data[key]||[msg.Option(key)] }), data.option = data.option||msg.option can.core.List(msg.option, function(key) { data[key] = data[key]||[msg.Option(key)] }), data.option = data.option||msg.option
@ -84,7 +81,8 @@ Volcanos("misc", {
can.user.info = {}, can.misc.localStorage(can, ice.MSG_SESSID, can.conf.sessid = "") can.user.info = {}, can.misc.localStorage(can, ice.MSG_SESSID, can.conf.sessid = "")
return can.user.login(can, function() { can.misc.request(can, msg, cmd, data, cb) }) return can.user.login(can, function() { can.misc.request(can, msg, cmd, data, cb) })
} }
msg.Copy(res.data), console.log("request", cmd, data.cmds||data, msg) if (res.statusCode == 403) { msg.result = [res.data] }
msg.Copy(res.data), can.misc.Info("request", cmd, data.cmds||data, msg)
can.base.toLast(msg.append, mdb.TIME), can.base.toLast(msg.append, web.LINK), can.base.toLast(msg.append, ctx.ACTION) can.base.toLast(msg.append, mdb.TIME), can.base.toLast(msg.append, web.LINK), can.base.toLast(msg.append, ctx.ACTION)
if (msg.append && msg.append.indexOf(ctx.ACTION) > 0) { if (msg.append && msg.append.indexOf(ctx.ACTION) > 0) {
msg._style = "content action" msg._style = "content action"
@ -126,4 +124,39 @@ Volcanos("misc", {
value != undefined && wx.setStorageSync(key, value) value != undefined && wx.setStorageSync(key, value)
return wx.getStorageSync(key) return wx.getStorageSync(key)
}, },
Log: function() { var args = this._args("", arguments); console.log.apply(console, args), this._signal(args) },
Info: function() { var args = this._args("", arguments); console.log.apply(console, args), this._signal(args) },
Warn: function() { var args = this._args(log.WARN, arguments); console.warn.apply(console, args), this._signal(args); debugger },
Error: function() { var args = this._args(log.ERROR, arguments); args.push(lex.NL, this._stacks().slice(1).join(lex.NL)), console.error.apply(console, args), this._signal(args); debugger },
FileLine: function(depth, length) { var file = this.fileLine(depth+1, length||9); return file.link },
fileLine: function(depth, length) { var list = this._stacks()
function split(i) { if (!list[i]) { return {} }
var ls = new RegExp("(https?://[^/]+)?([^:]+):([0-9]+):([0-9]+)").exec(list[i]); if (!ls) { return {} }
var name = ""; list[i].lastIndexOf(lex.TB) > 0 && (name = list[i].split(lex.TB).pop())
if (ls[0].indexOf(ice.QS) > -1) { ls[0] = ls[0].split(ice.QS)[0]+nfs.DF+ls[3]+nfs.DF+ls[4] }
return {_path: ls[2]+":"+ls[3], name: name, link: ls[0], path: ls[2], file: ls[2].split(nfs.PS).slice(-length).join(nfs.PS), line: ls[3], cols: ls[4]}
}
if (depth < 0) { var current = split(-depth)
for (var i = -depth+1; i < list.length; i++) { var pos = split(i); if (pos.path != current.path) { return pos } }
} return split(depth)||{}
},
_stacks: function(n, s) { var list = ((s||(new Error())).stack||"").split(lex.NL).slice(typeof n == "undefined"? 2: n)
for (var i = 0; i < list.length; i++) { var ls = list[i].trim().split(lex.SP)
list[i] = ls.pop().trim(); if (list[i][0] == "(") { list[i] = list[i].slice(1, -1) }
list[i] = " "+list[i]; if (ls.length > 1) { list[i] += " "+ls.pop() }
list[i] = list[i].replace(/\?[^:]+/, "")
} return list
}, _stack: function() { return ((new Error()).stack||"").split(lex.NL).slice(2) },
_time: function() { var now = new Date()
var hour = now.getHours(); hour < 10 && (hour = "0"+hour)
var minute = now.getMinutes(); minute < 10 && (minute = "0"+minute)
var second = now.getSeconds(); second < 10 && (second = "0"+second)
var mill = now.getMilliseconds(); mill < 10 && (mill = "00"+mill) || mill < 100 && (mill = "0"+mill)
return [hour, minute, second].join(nfs.DF)+nfs.PT+mill
},
_args: function(level, arg) { var app = getApp()
var args = [this._time(), app && app.conf.platform == "devtools"? this.FileLine(this._skip+1, 3)||"": ""].concat(level? [level]: [])
for (var i in arg) { arg[i] != undefined && args.push(arg[i]) } return args
},
_signal: function(args) { this._list.push(args) }, _list: [], _skip: 2,
}) })

View File

@ -3,6 +3,11 @@ const {shy, Volcanos} = require("../proto.js")
module.exports = module.exports =
Volcanos("user", { Volcanos("user", {
agent: { agent: {
enableDebug: function(can) {
if (can.db.debug == ice.TRUE && can.conf.platform != "devtools") {
wx.setEnableDebug({enableDebug: true})
}
},
getLocation: function(can, cb) { getLocation: function(can, cb) {
wx.chooseLocation({success: function(res) { wx.chooseLocation({success: function(res) {
cb && cb({ cb && cb({
@ -14,14 +19,12 @@ Volcanos("user", {
}, },
connectWifi: function(can, ssid, password, cb, cbs) { wx.showLoading() connectWifi: function(can, ssid, password, cb, cbs) { wx.showLoading()
wx.startWifi({success: function(res) { wx.startWifi({success: function(res) {
wx.connectWifi({SSID: ssid, password: password, success: function(res) { wx.hideLoading() wx.connectWifi({SSID: ssid, password: password, success: function(res) {
console.log("wifi", res), cb && cb(res) can.core.Timer(1000, function() { wx.hideLoading()
}, fail: function(res) { can.misc.Info("wifi", res), cb && cb(res)
console.log("wifi", res), cbs && cbs(res) })
}}) }, fail: function(res) { can.misc.Warn("wifi", res), cbs && cbs(res) }})
}, fail: function(res) { }, fail: function(res) { can.misc.Warn("wifi", res), cbs && cbs(res) }})
console.log("wifi", res), cbs && cbs(res)
}})
}, },
getClipboard: function(can, cb) { getClipboard: function(can, cb) {
wx.getClipboardData({success: function(res) { wx.getClipboardData({success: function(res) {
@ -30,33 +33,37 @@ Volcanos("user", {
}, },
scanQRCode: function(can, cb) { scanQRCode: function(can, cb) {
wx.scanCode({success: function(res) { wx.scanCode({success: function(res) {
if (res.result.indexOf("WIFI:") == 0) { can.misc.Info("scan", res.result)
var ls = can.core.Split(res.result, ":;"), data = {} can.user.parse(can, res.result, cb)
for (var i = 1; i < ls.length; i += 2) { data[ls[i]] = ls[i+1] }
console.log("scan", data)
can.user.agent.connectWifi(can, data.S, data.P, function() {
can.user.toast(can, "success")
})
return
}
var data = can.base.ParseJSON(res.result)
if (data.type == web.LINK && data._origin) { can.base.Copy(data, can.misc.ParseURL(can, res.result)) }
console.log("scan", data)
if (cb && cb(data)) { return }
if (data.type == web.LINK && data._origin) { delete(data.type), delete(data.name), delete(data.text)
var ls = new RegExp("(https?://[^/]+)([^?#]*)([^#]*)(.*)").exec(data._origin); delete(data._origin)
data.serve = ls[1]; if (ls[2].indexOf("/pages/") == 0) { data.pages = ls[2] }
}
if (data.cmd||data.index||data.share) {
can.user.jumps(can.base.MergeURL(data.pages||chat.PAGES_ACTION, data))
} else if (data.pod||data.space||data.serve) {
can.user.jumps(can.base.MergeURL(data.pages||chat.PAGES_RIVER, data))
} else {
can.misc.request(can, can.request(), chat.WX_LOGIN_SCAN, data)
}
}}) }})
}, },
}, info: {}, }, info: {},
scene: function(can, scene) {
can.misc.request(can, can.request(), "/chat/wx/login/action/scene", {scene: scene}, function(msg) {
can.misc.Info("app parse", msg.Result()), can.user.parse(can, msg.Result())
})
},
parse: function(can, text, cb) {
if (text.indexOf("WIFI:") == 0) { var data = kit.Dict(can.core.Split(text, ":;").slice(1))
if (cb && cb(data)) { return }
return can.user.agent.connectWifi(can, data.S, data.P, function() { can.user.toast(can, ice.SUCCESS) })
}
var data = can.base.ParseJSON(text)
if (data.type == web.LINK && data._origin) { can.base.Copy(data, can.misc.ParseURL(can, text)) }
if (cb && cb(data)) { return }
if (data.type == web.LINK && data._origin) { delete(data.type), delete(data.name), delete(data.text)
var ls = new RegExp("(https?://[^/]+)([^?#]*)([^#]*)(.*)").exec(data._origin); delete(data._origin)
data.serve = ls[1]; if (ls[2].indexOf("/pages/") == 0) { data.pages = ls[2] }
}
can.misc.Info("app parse", data)
if (data.cmd||data.index||data.share) {
can.user.jumps(can.base.MergeURL(data.pages||chat.PAGES_ACTION, data))
} else if (data.pod||data.space||data.serve) {
can.user.jumps(can.base.MergeURL(data.pages||chat.PAGES_RIVER, data))
} else {
can.misc.request(can, can.request(), chat.WX_LOGIN_SCAN, data)
}
},
jumps: function(url, cb) { wx.navigateTo({url: url, success: cb}) }, jumps: function(url, cb) { wx.navigateTo({url: url, success: cb}) },
title: function(text, cb) { text && wx.setNavigationBarTitle({title: text, success: cb}) }, title: function(text, cb) { text && wx.setNavigationBarTitle({title: text, success: cb}) },
toast: function(can, title) { wx.showToast({title: title||""}) }, toast: function(can, title) { wx.showToast({title: title||""}) },

View File

@ -4,10 +4,7 @@ function shy(help, meta, list, cb) { var arg = arguments, i = 0; function next(t
} else if (type == code.ARRAY) { if (typeof arg[i] == code.OBJECT && arg[i].length != undefined) { return arg[i++] } } else if (type == code.ARRAY) { if (typeof arg[i] == code.OBJECT && arg[i].length != undefined) { return arg[i++] }
} else if (i < arg.length && (!type || type == typeof arg[i])) { return arg[i++] } } else if (i < arg.length && (!type || type == typeof arg[i])) { return arg[i++] }
} return cb = typeof arg[arg.length-1] == code.FUNCTION? arg[arg.length-1]: function() {}, cb.help = next(code.STRING)||"", cb.meta = next(code.OBJECT)||{}, cb.list = next(code.ARRAY)||[], cb } } return cb = typeof arg[arg.length-1] == code.FUNCTION? arg[arg.length-1]: function() {}, cb.help = next(code.STRING)||"", cb.meta = next(code.OBJECT)||{}, cb.list = next(code.ARRAY)||[], cb }
function Volcanos(name, list) { function Volcanos(name, list) { if (Volcanos._page) { Volcanos._page[name] = list } return list }
if (Volcanos._page) { Volcanos._page[name] = list }
return list
}
Volcanos._init = function() { Volcanos._init = function() {
var can = {__proto__: Volcanos._page, var can = {__proto__: Volcanos._page,
request: function(event) { event = event||{}, event = event._event||event request: function(event) { event = event||{}, event = event._event||event
@ -21,40 +18,36 @@ Volcanos._init = function() {
}): can.core.Item(can.base.isFunc(item)? item(): item, set) }): can.core.Item(can.base.isFunc(item)? item(): item, set)
}); return msg }); return msg
}, },
run: function(event, cmds, cb) { run: function(event, cmds, cb) { wx.showLoading(); const sys = wx.getSystemInfoSync()
wx.showLoading(); const res = wx.getSystemInfoSync()
can.misc.request(can, can.request(event), can.base.MergeURL(can.onaction._apis||nfs.CHAT_ACTION, kit.Dict( can.misc.request(can, can.request(event), can.base.MergeURL(can.onaction._apis||nfs.CHAT_ACTION, kit.Dict(
ice.POD, can.db.pod||can.db.space, ice.MSG_THEME, res.theme, ice.MSG_DEBUG, can.db.debug, ice.POD, can.db.pod||can.db.space, ice.MSG_THEME, sys.theme, ice.MSG_DEBUG, can.db.debug,
)), {cmds: (can.onaction._cmds||[]).concat(cmds)}, function(msg) { )), {cmds: (can.onaction._cmds||[]).concat(cmds)}, function(msg) { wx.hideLoading()
msg.Dump = function() { can.ui.setData({list: msg.Table()}) }, cb(msg), wx.hideLoading() msg.Dump = function() { can.ui.setData({list: msg.Table()}) }, cb(msg)
}) })
}, },
}; Volcanos._page.__proto__ = getApp(), delete(Volcanos._page) }; Volcanos._page.__proto__ = getApp(), delete(Volcanos._page)
var page = {data: {action: can.onaction.list, list: []}, var page = {data: {action: can.onaction.list, list: []},
onLoad: function(options) { can.ui = this, can.db = options, can.db.serve = can.db.serve||can.conf.serve onLoad: function(options) { can.ui = this, can.db = options, can.db.serve = can.db.serve||can.conf.serve
can.core.Item(can.db, function(key, value) { can.db[key] = decodeURIComponent(value) }) can.core.Item(can.db, function(key, value) { can.db[key] = decodeURIComponent(value) })
can.misc.Info("app show", can.ui.route, can.db), can.user.agent.enableDebug(can)
can.user.title(can.db.title||can.db.pod||can.db.space||(can.db.serve||can.conf.serve).split("://")[1]) can.user.title(can.db.title||can.db.pod||can.db.space||(can.db.serve||can.conf.serve).split("://")[1])
console.log("app show", can.ui.route, can.db) function refresh() { can.ui.setData({conf: can.db}), can.user.login(can, function() {
if (can.db.ssid && can.db.password != "******") { can.misc.WSS(can), can.core.Timer(300, function() { can.onaction.refresh({}, can) })
can.user.agent.connectWifi(can, can.db.ssid, can.db.password||"", function() { can.db.password = "******" }) }
can.core.Timer(300, function() { function wifi(cb) { can.db.ssid && can.db.password != "******"? can.user.agent.connectWifi(can, can.db.ssid, can.db.password||"", function() { can.db.password = "******", cb() }): cb() }
can.ui.setData({conf: can.db}), can.user.login(can, function() { can.onaction.refresh({}, can) }) if (can.db.scene) { var ls = can.db.scene.split(nfs.PS); can.db.scene = ls[2]
}) if (ls[0] == "s") { can.db.serve = "https://"+ls[1] } if (ls[0] == "h") { can.db.serve = "http://"+ls[1] }
}) if (ls[0] == "w") { can.db.serve = "http://192.168."+parseInt("0x"+ls[1][0])+"."+parseInt("0x"+ls[1][1])+":9020", can.db.ssid = ls[3], can.db.password = ls[4] }
wifi(function() { can.user.scene(can, can.db.scene) })
} else { } else {
can.ui.setData({conf: can.db}), can.user.login(can, function() { can.onaction.refresh({}, can) }) wifi(refresh)
} }
}, },
onShow: function() { can.misc.WSS(can) }, onShow: function() { }, onReady: function() {},
onReady: function() {},
onHide: function() { can._socket && can._socket.close(), delete(can._socket) }, onHide: function() { can._socket && can._socket.close(), delete(can._socket) },
onUnload: function() { can._socket && can._socket.close(), delete(can._socket) }, onUnload: function() { can._socket && can._socket.close(), delete(can._socket) },
onReachBottom: function() {}, onReachBottom: function() {}, onPullDownRefresh: function() { this.onLoad(can.db) },
onPullDownRefresh: function() { this.onLoad(can.db) },
onShareAppMessage: function() {} onShareAppMessage: function() {}
} }; can.core.ItemCB(can.onaction, function(key, cb) { page[key] = function(event) { can.core.CallFunc(cb, [event, can, key, event.target.dataset]) } }), Page(page)
can.core.ItemCB(can.onaction, function(key, cb) { page[key] = function(event) {
can.core.CallFunc(cb, [event, can, key, event.target.dataset])
} }), Page(page)
} }
module.exports = {shy, Volcanos} module.exports = {shy, Volcanos}