1
0
mirror of https://shylinux.com/x/volcanos synced 2025-04-25 16:58: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: "工具模块",
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() {
if (xhr.readyState != 4) {return}
@ -14,21 +14,21 @@ var misc = Volcanos("misc", {help: "工具模块",
break
default:
try { // 解析响应
var res = JSON.parse(xhr.responseText);
var res = JSON.parse(xhr.responseText)
} catch (e) {
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) {
// 文件参数
var data = new FormData();
var data = new FormData()
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) {
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) {
return key+"="+encodeURIComponent(value)
}).join("&");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}).join("&")
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
}
// 发送请求
@ -48,12 +48,12 @@ var misc = Volcanos("misc", {help: "工具模块",
xhr.send(data)
} catch(e) {
console.error(e)
cb == "function" && cb(msg);
cb == "function" && cb(msg)
}
msg._xhr = xhr
}),
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}

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_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) {
var view = can.onappend.item(can, can._output, "item", value, function(event, item) { var msg = can.request(event, {_msg: sup})
// 左键点击
can.onimport.storm(event, can, value.hash)
}, function(event) {
// 右键点击
can.onappend.menu(can, sup, value)
})
can.run({}, [], function(sup) {
can._output.innerHTML = ""; var select;
sup.Table(function(value, index, array) {
var view = can.onappend.item(can, can._output, "item", value, function(event, item) { var msg = can.request(event, {_msg: sup})
// 左键点击
can.onimport.storm(event, can, value.hash)
}, function(event) {
// 右键点击
can.onappend.menu(can, sup, value)
})
if (index == 0 || [value.hash, value.name].indexOf(can._main_river) > -1) { select = view }
}); select && select.click(), typeof cb == "function" && cb(sup) })
if (index == 0 || [value.hash, value.name].indexOf(can._main_river) > -1) { select = view }
});
select && select.click(), typeof cb == "function" && cb(sup)
})
},
storm: function(event, can, river) {
var list = can.sublist[river]; if (list) { var hide = list.style.display == "none"