forked from x/volcanos
opt mp
This commit is contained in:
parent
0fd8b5a59f
commit
9f936179e2
40
lib/misc.js
40
lib/misc.js
@ -1,4 +1,5 @@
|
|||||||
Volcanos("misc", {
|
Volcanos("misc", {
|
||||||
|
Event: function(event, can, cb) { for (var i = 3; i < arguments.length; i++) { can.request(event, arguments[i]) } cb(can.request(event)) },
|
||||||
Message: function(event, can) { var msg = kit.proto({}, {_event: event, _can: can, _target: can._target,
|
Message: function(event, can) { var msg = kit.proto({}, {_event: event, _can: can, _target: can._target,
|
||||||
RunAction: function(event, sub, cmds, meta) { var msg = can.request(event); meta = meta || sub&&sub.onaction || {}
|
RunAction: function(event, sub, cmds, meta) { var msg = can.request(event); meta = meta || sub&&sub.onaction || {}
|
||||||
if (!msg._method) {
|
if (!msg._method) {
|
||||||
@ -83,16 +84,43 @@ Volcanos("misc", {
|
|||||||
_caller: function(skip) { msg.Option("log.caller") || msg.Option("log.caller", can.misc.fileLine((skip||2)+3).link); return msg },
|
_caller: function(skip) { msg.Option("log.caller") || msg.Option("log.caller", can.misc.fileLine((skip||2)+3).link); return msg },
|
||||||
isDebug: function() { return msg.Option(log.DEBUG) == ice.TRUE },
|
isDebug: function() { return msg.Option(log.DEBUG) == ice.TRUE },
|
||||||
}); return msg },
|
}); return msg },
|
||||||
Event: function(event, can, cb) { for (var i = 3; i < arguments.length; i++) { can.request(event, arguments[i]) } cb(can.request(event)) },
|
ParseCmd: function(can, msg, cb, cbs) { var list = []
|
||||||
|
return msg.Table(function(field, order) {
|
||||||
|
field.feature = can.base.Obj(field.meta, {})
|
||||||
|
field.inputs = can.base.Obj(field.list, [])
|
||||||
|
field.name = can.core.Split(field.name)[0]
|
||||||
|
if (!field.inputs || field.inputs.length === 0) {
|
||||||
|
return can.onmotion.delay(can, function() { cb(field, order) })
|
||||||
|
}
|
||||||
|
can.core.List(field.inputs, function(input, index) {
|
||||||
|
input.action = input.action || input.value
|
||||||
|
input.value == ice.AUTO && (input.value = "")
|
||||||
|
if (input.value && input.value.indexOf("@") == 0) {
|
||||||
|
input.action = input.value.slice(1), input.value = ""
|
||||||
|
}
|
||||||
|
if (input.type == html.SELECT) {
|
||||||
|
input.values = input.values || can.core.Split(input.value)
|
||||||
|
}
|
||||||
|
if (can.base.isIn(input.type, html.TEXT, html.TEXTAREA)) {
|
||||||
|
input.placeholder = can.user.trans(can, input.placeholder||input.name, field, html.INPUT)
|
||||||
|
}
|
||||||
|
if (input.type == html.BUTTON) {
|
||||||
|
input.value = can.user.trans(can, input.value||input.name, field)
|
||||||
|
} else {
|
||||||
|
cbs(input, index, field, order)
|
||||||
|
}
|
||||||
|
input.type == html.BUTTON && input.action == ice.AUTO && can.onmotion.delay(can, function() { cb(field, order) })
|
||||||
|
})
|
||||||
|
return field
|
||||||
|
})
|
||||||
|
},
|
||||||
Run: function(event, can, dataset, cmds, cb) { var msg = can.request(event), _can = msg._can; _can._fields && _can.sup && (_can = _can.sup)
|
Run: function(event, can, dataset, cmds, cb) { var msg = can.request(event), _can = msg._can; _can._fields && _can.sup && (_can = _can.sup)
|
||||||
var form = {cmds: cmds}; can.core.List(msg.option, function(key) { !can.base.isIn(key, "log.caller", "_handle", "_toast") && msg[key] && (form[key] = msg[key]) })
|
var form = {cmds: cmds}; can.core.List(msg.option, function(key) { !can.base.isIn(key, "log.caller", "_handle", "_toast") && msg[key] && (form[key] = msg[key]) })
|
||||||
can.misc.POST(can, msg, dataset.names.toLowerCase(), form, cb)
|
can.misc.POST(can, msg, dataset.names.toLowerCase(), form, cb)
|
||||||
},
|
},
|
||||||
GET: function(can, path, cb) {
|
GET: function(can, path, cb) { can.misc.POST(can, can.request({}, {_method: http.GET}), path, {}, function(msg) {
|
||||||
can.misc.POST(can, can.request({}, {_method: http.GET}), path, {}, function(msg) {
|
cb(msg._xhr.responseText)
|
||||||
cb(msg._xhr.responseText)
|
}) },
|
||||||
})
|
|
||||||
},
|
|
||||||
POST: function(can, msg, url, form, cb, cbs) { var xhr = new XMLHttpRequest(), begin = new Date(); msg._xhr = xhr
|
POST: function(can, msg, url, form, cb, cbs) { var xhr = new XMLHttpRequest(), begin = new Date(); msg._xhr = xhr
|
||||||
xhr._begin = begin
|
xhr._begin = begin
|
||||||
var data = can.core.ItemForm(form, function(v, i, k) { return k+mdb.EQ+encodeURIComponent(v) }).join("&")
|
var data = can.core.ItemForm(form, function(v, i, k) { return k+mdb.EQ+encodeURIComponent(v) }).join("&")
|
||||||
|
@ -365,8 +365,7 @@ Volcanos("page", {
|
|||||||
return canvas.toDataURL(html.IMAGE_PNG, 1)
|
return canvas.toDataURL(html.IMAGE_PNG, 1)
|
||||||
},
|
},
|
||||||
position: function(event, target) { var p = target.getBoundingClientRect(); return {x: event.clientX - p.x, y: event.clientY - p.y} },
|
position: function(event, target) { var p = target.getBoundingClientRect(); return {x: event.clientX - p.x, y: event.clientY - p.y} },
|
||||||
theme: function(cb) {
|
theme: function(cb) { var themeMedia = window.matchMedia("(prefers-color-scheme: dark)")
|
||||||
var themeMedia = window.matchMedia("(prefers-color-scheme: dark)")
|
|
||||||
cb && themeMedia.addListener(function(event) { cb(event.matches? html.DARK: html.LIGHT) })
|
cb && themeMedia.addListener(function(event) { cb(event.matches? html.DARK: html.LIGHT) })
|
||||||
cb && cb(themeMedia.matches? html.DARK: html.LIGHT)
|
cb && cb(themeMedia.matches? html.DARK: html.LIGHT)
|
||||||
return themeMedia.matches? html.DARK: html.LIGHT
|
return themeMedia.matches? html.DARK: html.LIGHT
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
Volcanos("user", {
|
Volcanos("user", {
|
||||||
agent: {
|
agent: {
|
||||||
|
enableDebug: function(can) {
|
||||||
|
},
|
||||||
getLocation: function(can, cb) { var call = arguments.callee; if (call._res) { return cb(call._res) }
|
getLocation: function(can, cb) { var call = arguments.callee; if (call._res) { return cb(call._res) }
|
||||||
navigator.geolocation.getCurrentPosition(function(res) {
|
navigator.geolocation.getCurrentPosition(function(res) {
|
||||||
cb(call._res = {type: "ip", name: "当前位置", text: "某某大街", latitude: res.coords.latitude.toFixed(6), longitude: res.coords.longitude.toFixed(6)})
|
cb(call._res = {type: "ip", name: "当前位置", text: "某某大街", latitude: res.coords.latitude.toFixed(6), longitude: res.coords.longitude.toFixed(6)})
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
const conf = require("conf.js")
|
||||||
const base = require("utils/lib/base.js")
|
const base = require("utils/lib/base.js")
|
||||||
const core = require("utils/lib/core.js")
|
const core = require("utils/lib/core.js")
|
||||||
const misc = require("utils/lib/misc.js")
|
const misc = require("utils/lib/misc.js")
|
||||||
@ -6,18 +7,21 @@ const user = require("utils/lib/user.js")
|
|||||||
const misc_wx = require("utils/lib/misc-wx.js")
|
const misc_wx = require("utils/lib/misc-wx.js")
|
||||||
const page_wx = require("utils/lib/page-wx.js")
|
const page_wx = require("utils/lib/page-wx.js")
|
||||||
const user_wx = require("utils/lib/user-wx.js")
|
const user_wx = require("utils/lib/user-wx.js")
|
||||||
const zh_cn = require("utils/lib/zh-cn.js")
|
|
||||||
const conf = require("conf.js")
|
|
||||||
|
|
||||||
App({conf: conf,
|
App({conf: conf,
|
||||||
base: base, core: core,
|
base: base, core: core,
|
||||||
misc: base.Copy(misc, misc_wx),
|
misc: base.Copy(misc, misc_wx),
|
||||||
page: base.Copy(page, page_wx),
|
page: base.Copy(page, page_wx),
|
||||||
user: base.Copy(user, base.Copy(user_wx, zh_cn)),
|
user: base.Copy(user, user_wx),
|
||||||
onLaunch: function() { const res = wx.getSystemInfoSync()
|
onLaunch: function() { const info = wx.getSystemInfoSync()
|
||||||
this.conf.platform = res.platform
|
switch (info.language.toLowerCase().replaceAll("_", "-")) {
|
||||||
this.conf.brand = res.brand
|
case "zh-cn": base.Copy(user, require("utils/lib/zh-cn.js")); break
|
||||||
this.conf.model = res.model
|
default: base.Copy(user, require("utils/lib/en-us.js"))
|
||||||
this.misc.Info("app load", this.conf, res)
|
user.trans = function(can, text, list, zone) { return text }
|
||||||
|
}
|
||||||
|
this.conf.platform = info.platform
|
||||||
|
this.conf.brand = info.brand
|
||||||
|
this.conf.model = info.model
|
||||||
|
this.misc.Info("app load", this.conf, info)
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
const {ice, ctx, mdb, web, code, chat, http, html} = require("../../utils/const.js")
|
const {kit, ice, ctx, mdb, web, nfs, code, chat, http, html} = require("../../utils/const.js")
|
||||||
const {shy, Volcanos} = require("../../utils/proto.js")
|
const {shy, Volcanos} = require("../../utils/proto.js")
|
||||||
Volcanos._page = {}
|
Volcanos._page = {}
|
||||||
Volcanos(chat.ONACTION, {list: ["刷新", "扫码", "清屏"]})
|
Volcanos(chat.ONACTION, {list: ["刷新", "扫码", "清屏"]})
|
||||||
|
@ -1,12 +1,7 @@
|
|||||||
const {ice, mdb, chat, html} = require("../../utils/const.js")
|
const {kit, ice, ctx, mdb, web, nfs, code, chat, http, html} = require("../../utils/const.js")
|
||||||
const {shy, Volcanos} = require("../../utils/proto.js")
|
const {shy, Volcanos} = require("../../utils/proto.js")
|
||||||
Volcanos._page = {}
|
Volcanos._page = {}
|
||||||
Volcanos(chat.ONIMPORT, {
|
|
||||||
_init: function(can, msg) {},
|
|
||||||
})
|
|
||||||
Volcanos(chat.ONACTION, {list: ["刷新", "扫码"],
|
Volcanos(chat.ONACTION, {list: ["刷新", "扫码"],
|
||||||
"刷新": function(event, can) { can.onaction.refresh(event, can) },
|
|
||||||
"扫码": function(event, can) { can.user.agent.scanQRCode(can) },
|
|
||||||
refresh: function(event, can) {
|
refresh: function(event, can) {
|
||||||
can.core.List(can.data.insert.list, function(input) {
|
can.core.List(can.data.insert.list, function(input) {
|
||||||
input.action = input.action || input.value
|
input.action = input.action || input.value
|
||||||
@ -17,10 +12,7 @@ Volcanos(chat.ONACTION, {list: ["刷新", "扫码"],
|
|||||||
if (input.type == html.SELECT) {
|
if (input.type == html.SELECT) {
|
||||||
input.values = input.values || can.core.Split(input.value)
|
input.values = input.values || can.core.Split(input.value)
|
||||||
}
|
}
|
||||||
}), can.misc.setData(can, can.data.insert.list)
|
}), can.page.setData(can, can.data.insert.list)
|
||||||
},
|
|
||||||
onaction: function(event, can, button, data) { var name = data.name;
|
|
||||||
(can.onaction[name]||function(event) { can.run(event, [ctx.ACTION, name]) })(event, can)
|
|
||||||
},
|
},
|
||||||
onInputs: function(event, can, button, data) { var index = data.index
|
onInputs: function(event, can, button, data) { var index = data.index
|
||||||
var input = can.data.insert.list[index]
|
var input = can.data.insert.list[index]
|
||||||
|
@ -1,33 +1,16 @@
|
|||||||
const {ice, nfs, chat, html} = require("../../utils/const.js")
|
const {kit, ice, ctx, mdb, web, nfs, code, chat, http, html} = require("../../utils/const.js")
|
||||||
const {shy, Volcanos} = require("../../utils/proto.js")
|
const {shy, Volcanos} = require("../../utils/proto.js")
|
||||||
Volcanos._page = {}
|
Volcanos._page = {}
|
||||||
Volcanos(chat.ONIMPORT, {
|
Volcanos(chat.ONACTION, {list: ["刷新", "扫码", "登录"], _apis: nfs.CHAT_RIVER,
|
||||||
_init: function(can, msg) {
|
refresh: function(event, can) { can.run(event, [], function(msg) { msg.Dump(can), can.user.toast(can, "加载成功") }) },
|
||||||
msg.Dump(can), can.user.toast(can, "加载成功")
|
|
||||||
},
|
|
||||||
})
|
|
||||||
Volcanos("onaction", {list: ["刷新", "扫码", "登录"],
|
|
||||||
// "刷新": function(event, can) { can.onaction.refresh(event, can) },
|
|
||||||
// "扫码": function(event, can) { can.user.agent.scanQRCode(can) },
|
|
||||||
// "登录": function(event, can) {
|
|
||||||
// can.user.info = {}, can.misc.localStorage(can, ice.MSG_SESSID, can.conf.sessid = "")
|
|
||||||
// can.user.userinfo(can, function() { can.onaction.refresh(event, can) })
|
|
||||||
// },
|
|
||||||
refresh: function(event, can) { can.run(event, [], function(msg) { can.onimport._init(can, msg) }) },
|
|
||||||
onaction: function(event, can, button, data) { var name = data.name;
|
|
||||||
(can.onaction[name]||function(event) { can.run(event, [ctx.ACTION, name]) })(event, can)
|
|
||||||
},
|
|
||||||
ondetail: function(event, can, button, data) { var index = data.index
|
ondetail: function(event, can, button, data) { var index = data.index
|
||||||
var item = can.ui.data.list[index]; item._show = !item._show
|
var item = can.ui.data.list[index]; item._show = !item._show
|
||||||
if (item.list) { return can.misc.setData(can) }
|
if (item.list) { return can.page.setData(can) }
|
||||||
can.run(event, [item.hash, chat.STORM], function(msg) {
|
can.run(event, [item.hash, chat.STORM], function(msg) { item.list = msg.Table(), can.page.setData(can) })
|
||||||
item.list = msg.Table(), can.misc.setData(can)
|
|
||||||
})
|
|
||||||
},
|
},
|
||||||
onchange: function(event, can, button, data) { var index = data.index, i = data.i
|
onchange: function(event, can, button, data) { var index = data.index, i = data.i
|
||||||
var river = can.ui.data.list[index], storm = river.list[i]
|
var river = can.ui.data.list[index], storm = river.list[i]
|
||||||
can.user.jumps(can.base.MergeURL(chat.PAGES_ACTION, {river: river.hash, storm: storm.hash, serve: can.db.serve, space: can.db.space}))
|
can.user.jumps(can.base.MergeURL(chat.PAGES_ACTION, {river: river.hash, storm: storm.hash, serve: can.db.serve, space: can.db.space}))
|
||||||
},
|
},
|
||||||
_apis: nfs.CHAT_RIVER,
|
|
||||||
})
|
})
|
||||||
Volcanos._init()
|
Volcanos._init()
|
||||||
|
@ -11,19 +11,18 @@ Volcanos(chat.ONIMPORT, {})
|
|||||||
Volcanos(chat.ONACTION, {
|
Volcanos(chat.ONACTION, {
|
||||||
"刷新": function(event, can) { can.onaction.refresh(event, can) },
|
"刷新": function(event, can) { can.onaction.refresh(event, can) },
|
||||||
"扫码": function(event, can) { can.user.agent.scanQRCode(can) },
|
"扫码": function(event, can) { can.user.agent.scanQRCode(can) },
|
||||||
"清屏": function(event, can) { can.core.List(can.ui.data.list, function(item) { delete(item.msg) }), can.misc.setData(can) },
|
"清屏": function(event, can) { can.core.List(can.ui.data.list, function(item) { delete(item.msg) }), can.page.setData(can) },
|
||||||
"登录": function(event, can) {
|
_refresh: function(event, can, order) { can.page.setData(can)
|
||||||
can.user.info = {}, can.misc.localStorage(can, ice.MSG_SESSID, can.conf.sessid = "")
|
|
||||||
can.user.userinfo(can, function() { can.onaction.refresh(event, can) })
|
|
||||||
},
|
|
||||||
_refresh: function(event, can, order) { can.misc.setData(can)
|
|
||||||
can.onaction.onAction({}, can, ice.LIST, {order: order, name: ice.LIST})
|
can.onaction.onAction({}, can, ice.LIST, {order: order, name: ice.LIST})
|
||||||
},
|
},
|
||||||
_reload: function(can, msg) {
|
_reload: function(can, msg) {
|
||||||
can.misc.ParseCmd(can, msg)
|
can.ui.data.list = can.misc.ParseCmd(can, msg, function(field, order) {
|
||||||
|
can.onaction._refresh({}, can, order)
|
||||||
|
}, function(input, index, field, order) {
|
||||||
|
if (can.db.cmd||can.db.index) { input.value = input.value||can.db[input.name] }
|
||||||
|
}), can.page.setData(can), can.user.toast(can, "加载成功")
|
||||||
},
|
},
|
||||||
refresh: function(event, can) {
|
refresh: function(event, can) { can.onaction._apis = "", can.onaction._cmds = []
|
||||||
can.onaction._apis = "", can.onaction._cmds = []
|
|
||||||
if (can.db.share) { can.onaction._apis = "/share/"+can.db.share
|
if (can.db.share) { can.onaction._apis = "/share/"+can.db.share
|
||||||
can.run(event, [ctx.ACTION, ctx.COMMAND], function(msg) {
|
can.run(event, [ctx.ACTION, ctx.COMMAND], function(msg) {
|
||||||
can.onaction._cmds = [ctx.ACTION, ctx.RUN], can.onaction._reload(can, msg)
|
can.onaction._cmds = [ctx.ACTION, ctx.RUN], can.onaction._reload(can, msg)
|
||||||
@ -82,7 +81,7 @@ Volcanos(chat.ONACTION, {
|
|||||||
msg._action = can.core.List(can.base.Obj(msg.Option(ice.MSG_ACTION)), function(item) {
|
msg._action = can.core.List(can.base.Obj(msg.Option(ice.MSG_ACTION)), function(item) {
|
||||||
if (typeof item == code.STRING) { return {type: html.BUTTON, name: item, value: can.user.trans(can, item)} }
|
if (typeof item == code.STRING) { return {type: html.BUTTON, name: item, value: can.user.trans(can, item)} }
|
||||||
return item.value = can.user.trans(can, item.value||item.name), item
|
return item.value = can.user.trans(can, item.value||item.name), item
|
||||||
}), field.msg = msg, can.misc.setData(can)
|
}), field.msg = msg, can.page.setData(can)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
onDetail: function(event, can, button, data) { var order = data.order, name = data.name, value = data.value, input = data.input
|
onDetail: function(event, can, button, data) { var order = data.order, name = data.name, value = data.value, input = data.input
|
@ -8,62 +8,14 @@ const {kit, ice,
|
|||||||
const {shy, Volcanos} = require("../proto.js")
|
const {shy, Volcanos} = require("../proto.js")
|
||||||
module.exports =
|
module.exports =
|
||||||
Volcanos("misc", {
|
Volcanos("misc", {
|
||||||
ParseCmd: function(can, msg) { can.ui.data.list = []
|
POST: function(can, msg, cmd, data, cb) { data.sessid = can.conf.sessid, data.appid = data.appid||can.conf.appid
|
||||||
msg.Table(function(field, order) { can.ui.data.list.push(field)
|
|
||||||
field.feature = can.base.Obj(field.meta, {})
|
|
||||||
field.inputs = can.base.Obj(field.list, [])
|
|
||||||
field.name = can.core.Split(field.name)[0]
|
|
||||||
if (!field.inputs || field.inputs.length === 0) {
|
|
||||||
return can.core.Timer(30, function() {
|
|
||||||
can.onaction._refresh({}, can, order)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
can.core.List(field.inputs, function(input) {
|
|
||||||
input.action = input.action || input.value
|
|
||||||
input.value == ice.AUTO && (input.value = "")
|
|
||||||
if (input.value && input.value.indexOf("@") == 0) {
|
|
||||||
input.action = input.value.slice(1), input.value = ""
|
|
||||||
}
|
|
||||||
if (input.type == html.SELECT) {
|
|
||||||
input.values = input.values || can.core.Split(input.value)
|
|
||||||
}
|
|
||||||
if (can.base.isIn(input.type, html.TEXT, html.TEXTAREA)) {
|
|
||||||
input.placeholder = can.user.trans(can, input.placeholder||input.name, field, html.INPUT)
|
|
||||||
}
|
|
||||||
if (input.type == html.BUTTON) {
|
|
||||||
input.value = can.user.trans(can, input.value||input.name, field)
|
|
||||||
} else {
|
|
||||||
if (can.db.cmd||can.db.index) { input.value = input.value||can.db[input.name] }
|
|
||||||
}
|
|
||||||
input.type == html.BUTTON && input.action == ice.AUTO && can.core.Timer(30, function() {
|
|
||||||
can.onaction._refresh({}, can, order)
|
|
||||||
})
|
|
||||||
})
|
|
||||||
}), can.misc.setData(can), can.user.toast(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 socket = wx.connectSocket({url: url, header:{"content-type": "application/json"}}); can.misc.Info("wss connect", url, socket)
|
|
||||||
socket.onOpen(function(res) { can.misc.Info("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.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)
|
|
||||||
switch (msg.detail[0]) {
|
|
||||||
case "pwd": can._daemon = msg.detail[1]; break
|
|
||||||
case "parse": can.core.Timer(30, function() { can.user.parse(can, data.detail[1]) }); break
|
|
||||||
case "info": break
|
|
||||||
} delete(msg._hand), delete(msg.detail), msg.Option("_handle", ice.TRUE)
|
|
||||||
msg._target = (msg._source||[]).reverse(), msg._source = (msg._target||[]).reverse().slice(1)||[]
|
|
||||||
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
|
|
||||||
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
|
||||||
var url = (msg._serve||can.db.serve||can.conf.serve)+cmd
|
var url = (msg._serve||can.db.serve||can.conf.serve)+cmd
|
||||||
if (data && can.base.isIn(msg._method, http.GET, http.DELETE)) { url = can.base.MergeURL(url, data), data = {} }
|
if (data && can.base.isIn(msg._method, http.GET, http.DELETE)) { url = can.base.MergeURL(url, data), data = {} }
|
||||||
wx.request({method: msg._method||http.POST, url: url, data: data, success: function(res) {
|
wx.request({method: msg._method||http.POST, url: url, data: data, success: function(res) {
|
||||||
if (res.statusCode == 401) {
|
if (res.statusCode == 401) {
|
||||||
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.POST(can, msg, cmd, data, cb) })
|
||||||
}
|
}
|
||||||
if (res.statusCode == 403) { msg.result = [res.data] }
|
if (res.statusCode == 403) { msg.result = [res.data] }
|
||||||
msg.Copy(res.data), can.misc.Info("request", cmd, data.cmds||data, msg)
|
msg.Copy(res.data), can.misc.Info("request", cmd, data.cmds||data, msg)
|
||||||
@ -101,14 +53,20 @@ Volcanos("misc", {
|
|||||||
}), cb && cb(msg)
|
}), cb && cb(msg)
|
||||||
}})
|
}})
|
||||||
},
|
},
|
||||||
download: function(can, msg, cmd, data, cb) { data.sessid = can.conf.sessid
|
WSS: function(can) { if (can.conf.platform == "devtools" && can.db.serve != can.conf.serve) { return }
|
||||||
wx.downloadFile({url: can.conf.serve+nfs.PS+cmd, data: data, success: cb})
|
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"}}); can.misc.Info("wss connect", url, socket)
|
||||||
localStorage: function(can, key, value) {
|
socket.onOpen(function(res) { can.misc.Info("wss open", res) })
|
||||||
value != undefined && wx.setStorageSync(key, value)
|
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) }) })
|
||||||
return wx.getStorageSync(key)
|
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)
|
||||||
},
|
switch (msg.detail[0]) {
|
||||||
setData: function(can, list) {
|
case "pwd": can._daemon = msg.detail[1]; break
|
||||||
can.ui.setData({list: list||can.ui.data.list})
|
case "parse": can.core.Timer(30, function() { can.user.parse(can, data.detail[1]) }); break
|
||||||
|
case "info": break
|
||||||
|
} delete(msg._hand), delete(msg.detail), msg.Option("_handle", ice.TRUE)
|
||||||
|
msg._target = (msg._source||[]).reverse(), msg._source = (msg._target||[]).reverse().slice(1)||[]
|
||||||
|
can.misc.Info("wss send", msg.result, msg), socket.send({data: JSON.stringify(msg)})
|
||||||
|
}); return can._socket = socket
|
||||||
},
|
},
|
||||||
|
localStorage: function(can, key, value) { value != undefined && wx.setStorageSync(key, value); return wx.getStorageSync(key) },
|
||||||
})
|
})
|
||||||
|
@ -8,4 +8,5 @@ const {kit, ice,
|
|||||||
const {shy, Volcanos} = require("../proto.js")
|
const {shy, Volcanos} = require("../proto.js")
|
||||||
module.exports =
|
module.exports =
|
||||||
Volcanos("page", {
|
Volcanos("page", {
|
||||||
|
setData: function(can, list) { can.ui.setData({list: list||can.ui.data.list}) },
|
||||||
})
|
})
|
||||||
|
@ -45,7 +45,7 @@ Volcanos("user", {
|
|||||||
},
|
},
|
||||||
}, info: {},
|
}, info: {},
|
||||||
scene: function(can, scene) {
|
scene: function(can, scene) {
|
||||||
can.misc.request(can, can.request(), "/chat/wx/login/action/scene", {scene: scene, serve: can.db.serve}, function(msg) {
|
can.misc.POST(can, can.request(), "/chat/wx/login/action/scene", {scene: scene, serve: can.db.serve}, function(msg) {
|
||||||
can.misc.Info("app parse", msg.Result()), can.user.parse(can, msg.Result())
|
can.misc.Info("app parse", msg.Result()), can.user.parse(can, msg.Result())
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
@ -67,36 +67,19 @@ Volcanos("user", {
|
|||||||
} else if (data.pod||data.space||data.serve) {
|
} else if (data.pod||data.space||data.serve) {
|
||||||
can.user.jumps(can.base.MergeURL(data.pages||chat.PAGES_RIVER, data))
|
can.user.jumps(can.base.MergeURL(data.pages||chat.PAGES_RIVER, data))
|
||||||
} else {
|
} else {
|
||||||
can.misc.request(can, can.request(), chat.WX_LOGIN_SCAN, data)
|
can.misc.POST(can, can.request(), chat.WX_LOGIN_SCAN, data)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
jumps: function(url, cb) {
|
jumps: function(url, cb) { wx.navigateTo({url: url, success: cb, fail: function(res) { console.warn(res) }}) },
|
||||||
wx.navigateTo({url: url, success: cb, fail: function(res) {
|
|
||||||
console.log(res)
|
|
||||||
}})
|
|
||||||
},
|
|
||||||
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||""}) },
|
|
||||||
modal: function(can, content, title, cb) { wx.showModal({title: title||"", content: content||"", success: cb}) },
|
|
||||||
login: function(can, cb) {
|
|
||||||
can.conf.sessid = can.conf.sessid||can.misc.localStorage(can, ice.MSG_SESSID)
|
|
||||||
if (can.conf.sessid) { return cb && cb() }
|
|
||||||
wx.login({success: function(res) { can.misc.request(can, can.request(), chat.WX_LOGIN_SESS, {code: res.code}, function(msg) {
|
|
||||||
wx.setStorage({key: ice.MSG_SESSID, data: can.conf.sessid = msg.Result()}), cb && cb()
|
|
||||||
}) }})
|
|
||||||
},
|
|
||||||
userinfo: function(can, cb) {
|
|
||||||
can.user.info.userNick? can.misc.request(can, can.request(), chat.WX_LOGIN_USER, {}, function(msg) {
|
|
||||||
cb && cb(can.user.info)
|
|
||||||
}): can.user.login(can, function() { wx.getSetting({success: function(res) {
|
|
||||||
res.authSetting['scope.userInfo'] && wx.getUserInfo({success: function(res) {
|
|
||||||
can.misc.request(can, can.request(), chat.WX_LOGIN_USER, can.user.info = res.userInfo, function(msg) {
|
|
||||||
cb && cb(can.user.info)
|
|
||||||
})
|
|
||||||
}})
|
|
||||||
}}) })
|
|
||||||
},
|
|
||||||
trans: function(can, text, list, zone) { if (!text) { return text }
|
trans: function(can, text, list, zone) { if (!text) { return text }
|
||||||
return can.core.Value(can.core.Value(list, ctx.FEATURE_TRANS), can.core.Keys(zone, text))||can.core.Value(can.user._trans, can.core.Keys(zone, text))||text
|
return can.core.Value(can.core.Value(list, ctx.FEATURE_TRANS), can.core.Keys(zone, text))||can.core.Value(can.user._trans, can.core.Keys(zone, text))||text
|
||||||
}, _trans: {},
|
}, _trans: {},
|
||||||
|
toast: function(can, title) { wx.showToast({title: title||""}) },
|
||||||
|
modal: function(can, content, title, cb) { wx.showModal({title: title||"", content: content||"", success: cb}) },
|
||||||
|
login: function(can, cb) { can.conf.sessid = can.conf.sessid||can.misc.localStorage(can, ice.MSG_SESSID); if (can.conf.sessid) { return cb && cb() }
|
||||||
|
wx.login({success: function(res) { can.misc.POST(can, can.request(), chat.WX_LOGIN_SESS, {code: res.code}, function(msg) {
|
||||||
|
wx.setStorage({key: ice.MSG_SESSID, data: can.conf.sessid = msg.Result()}), cb && cb()
|
||||||
|
}) }})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
@ -5,6 +5,7 @@ const {kit, ice,
|
|||||||
code, wiki, chat, team, mall,
|
code, wiki, chat, team, mall,
|
||||||
http, html, icon, svg
|
http, html, icon, svg
|
||||||
} = require("const.js")
|
} = require("const.js")
|
||||||
|
|
||||||
function shy(help, meta, list, cb) { var arg = arguments, i = 0; function next(type) {
|
function shy(help, meta, list, cb) { var arg = arguments, i = 0; function next(type) {
|
||||||
if (type == code.OBJECT) { if (typeof arg[i] == code.OBJECT && arg[i].length == undefined) { return arg[i++] }
|
if (type == code.OBJECT) { 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 (type == code.ARRAY) { if (typeof arg[i] == code.OBJECT && arg[i].length != undefined) { return arg[i++] }
|
||||||
@ -12,8 +13,8 @@ function shy(help, meta, list, cb) { var arg = arguments, i = 0; function next(t
|
|||||||
} 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) { if (Volcanos._page) { Volcanos._page[name] = list } return list }
|
function Volcanos(name, list) { if (Volcanos._page) { Volcanos._page[name] = list } return list }
|
||||||
|
|
||||||
Volcanos._init = function() {
|
Volcanos._init = function() { var page = Volcanos._page; page.__proto__ = getApp(), delete(Volcanos._page)
|
||||||
var can = {__proto__: Volcanos._page,
|
var can = {__proto__: page,
|
||||||
request: function(event) { event = event||{}, event = event._event||event
|
request: function(event) { event = event||{}, event = event._event||event
|
||||||
var msg = event._msg||can.misc.Message(event, can); event._msg = msg
|
var msg = event._msg||can.misc.Message(event, can); event._msg = msg
|
||||||
function set(key, value) { if (key == "_method") { return msg._method = value }
|
function set(key, value) { if (key == "_method") { return msg._method = value }
|
||||||
@ -25,47 +26,34 @@ 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) { wx.showLoading(); const sys = wx.getSystemInfoSync()
|
run: function(event, cmds, cb) { wx.showLoading(); const info = wx.getSystemInfoSync()
|
||||||
can.misc.request(can, can.request(event, {share: can.db.share}), can.base.MergeURL(can.onaction._apis||nfs.CHAT_ACTION, kit.Dict(
|
can.misc.POST(can, can.request(event, {share: can.db.share}), can.base.MergeURL(can.onaction._apis||nfs.CHAT_ACTION, kit.Dict(
|
||||||
ice.POD, can.db.pod||can.db.space, ice.MSG_THEME, sys.theme, ice.MSG_DEBUG, can.db.debug,
|
ice.POD, can.db.pod||can.db.space, ice.MSG_THEME, info.theme, ice.MSG_DEBUG, can.db.debug,
|
||||||
)), {cmds: (can.onaction._cmds||[]).concat(cmds)}, function(msg) { wx.hideLoading()
|
)), {cmds: (can.onaction._cmds||[]).concat(cmds)}, function(msg) { wx.hideLoading()
|
||||||
msg.Dump = function() { can.ui.setData({list: msg.Table()}) }, cb(msg)
|
msg.Dump = function() { can.ui.setData({list: msg.Table()}) }, cb(msg)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}; Volcanos._page.__proto__ = getApp()
|
}
|
||||||
can.core.Item(require("frame.js"), function(key, mod) { Volcanos._page[key] = can.base.Copy(Volcanos._page[key]||{}, mod, true) })
|
can.core.Item(require("frame-wx.js"), function(key, mod) { page[key] = can.base.Copy(page[key]||{}, mod, true) })
|
||||||
delete(Volcanos._page)
|
can.core.Item(require("frame.js"), function(key, mod) { page[key] = can.base.Copy(page[key]||{}, mod, true) })
|
||||||
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.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.info), can.user.agent.enableDebug(can)
|
can.misc.Info("app show", can.ui.route, can.db, can.user.info), 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])
|
||||||
function refresh() { can.ui.setData({conf: can.db}), can.user.login(can, function() {
|
function refresh() { can.ui.setData({conf: can.db}), can.user.login(can, function() { can.misc.WSS(can), can.onmotion.delay(can, function() { can.onaction.refresh({}, can) }, 300) }) }
|
||||||
can.misc.WSS(can), can.core.Timer(300, function() {
|
|
||||||
if (can.onaction.refresh) {
|
|
||||||
can.onaction.refresh({}, can)
|
|
||||||
} else {
|
|
||||||
can.run({}, [ctx.ACTION, ctx.COMMAND, can.db.index], function(msg) {
|
|
||||||
can.misc.ParseCmd(can, msg)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}) }
|
|
||||||
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() }
|
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() }
|
||||||
if (can.db.scene) { var ls = can.db.scene.split(nfs.PS); can.db.scene = ls[2]
|
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] == "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] }
|
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) })
|
wifi(function() { can.user.scene(can, can.db.scene) })
|
||||||
} else {
|
} else { wifi(refresh) }
|
||||||
wifi(refresh)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
onShow: function() { }, onReady: function() {},
|
onShow: function() {}, onReady: function() {}, onHide: function() {},
|
||||||
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() {}, onPullDownRefresh: function() { this.onLoad(can.db) },
|
onReachBottom: function() {}, onPullDownRefresh: function() { this.onUnload(), 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}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user