1
0
mirror of https://shylinux.com/x/volcanos synced 2025-04-26 01:04:06 +08:00
This commit is contained in:
shaoying 2020-11-02 22:13:18 +08:00
parent 79390e79be
commit 69c092bde6
2 changed files with 24 additions and 20 deletions

View File

@ -1,6 +1,6 @@
var misc = Volcanos("misc", {help: "工具模块", var misc = Volcanos("misc", {help: "工具模块",
POST: shy("请求后端", {order: 0}, function(can, msg, url, form, cb) { POST: shy("请求后端", {order: 0}, function(can, msg, url, form, cb) {
var xhr = new XMLHttpRequest(); var xhr = new XMLHttpRequest()
xhr.open("POST", url), xhr.onreadystatechange = function() { xhr.open("POST", url), xhr.onreadystatechange = function() {
if (xhr.readyState != 4) {return} if (xhr.readyState != 4) {return}
@ -14,21 +14,21 @@ var misc = Volcanos("misc", {help: "工具模块",
break break
default: default:
try { // 解析响应 try { // 解析响应
var res = JSON.parse(xhr.responseText); var res = JSON.parse(xhr.responseText)
} catch (e) { } catch (e) {
var res = {"result": []} var res = {"result": []}
} }
} }
xhr.status == 200 && typeof cb == "function" && cb(msg.Copy(res)); xhr.status == 200 && typeof cb == "function" && cb(msg.Copy(res))
} }
if (msg.upload) { if (msg.upload) {
// 文件参数 // 文件参数
var data = new FormData(); var data = new FormData()
can.core.Item(form, function(key, value) { can.core.Item(form, function(key, value) {
can.core.List(value, function(item) {data.append(key, item)}); can.core.List(value, function(item) {data.append(key, item)})
}) })
data.append("upload", msg.upload); data.append("upload", msg.upload)
xhr.upload.onprogress = function(event) { xhr.upload.onprogress = function(event) {
typeof msg._progress == "function" && msg._progress(event, parseInt(event.loaded/event.total*100), event.total, event.loaded) typeof msg._progress == "function" && msg._progress(event, parseInt(event.loaded/event.total*100), event.total, event.loaded)
} }
@ -36,8 +36,8 @@ var misc = Volcanos("misc", {help: "工具模块",
// 表单参数 // 表单参数
var data = can.core.Items(form, function(value, index, key) { var data = can.core.Items(form, function(value, index, key) {
return key+"="+encodeURIComponent(value) return key+"="+encodeURIComponent(value)
}).join("&"); }).join("&")
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
} }
// 发送请求 // 发送请求
@ -48,12 +48,12 @@ var misc = Volcanos("misc", {help: "工具模块",
xhr.send(data) xhr.send(data)
} catch(e) { } catch(e) {
console.error(e) console.error(e)
cb == "function" && cb(msg); cb == "function" && cb(msg)
} }
msg._xhr = xhr msg._xhr = xhr
}), }),
Run: shy("请求后端", {order: 0}, function(event, can, dataset, cmd, cb) { event = event || {} Run: shy("请求后端", {order: 0}, function(event, can, dataset, cmd, cb) { event = event || {}
var msg = (can.request||can.Event)(event); var msg = (can.request||can.Event)(event)
// 解析参数 // 解析参数
var option = {"cmds": cmd||msg.cmd} var option = {"cmds": cmd||msg.cmd}

View File

@ -9,17 +9,21 @@ Volcanos("onimport", {help: "导入数据", list: [], _init: function(can, meta,
can._main_river = can.user.Search(can, RIVER) || (can.user.isExtension? "product": "project") can._main_river = can.user.Search(can, RIVER) || (can.user.isExtension? "product": "project")
can._main_storm = can.user.Search(can, STORM) || (can.user.isExtension? "chrome": "studio") can._main_storm = can.user.Search(can, STORM) || (can.user.isExtension? "chrome": "studio")
can.run({}, [], function(sup) { can._output.innerHTML = ""; var select; sup.Table(function(value, index, array) { can.run({}, [], function(sup) {
var view = can.onappend.item(can, can._output, "item", value, function(event, item) { var msg = can.request(event, {_msg: sup}) can._output.innerHTML = ""; var select;
// 左键点击 sup.Table(function(value, index, array) {
can.onimport.storm(event, can, value.hash) var view = can.onappend.item(can, can._output, "item", value, function(event, item) { var msg = can.request(event, {_msg: sup})
}, function(event) { // 左键点击
// 右键点击 can.onimport.storm(event, can, value.hash)
can.onappend.menu(can, sup, value) }, function(event) {
}) // 右键点击
can.onappend.menu(can, sup, value)
})
if (index == 0 || [value.hash, value.name].indexOf(can._main_river) > -1) { select = view } if (index == 0 || [value.hash, value.name].indexOf(can._main_river) > -1) { select = view }
}); select && select.click(), typeof cb == "function" && cb(sup) }) });
select && select.click(), typeof cb == "function" && cb(sup)
})
}, },
storm: function(event, can, river) { storm: function(event, can, river) {
var list = can.sublist[river]; if (list) { var hide = list.style.display == "none" var list = can.sublist[river]; if (list) { var hide = list.style.display == "none"