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

add ajax png

This commit is contained in:
shaoying 2020-03-20 02:51:18 +08:00
parent 1e0dbde61b
commit 3e0797251f
3 changed files with 31 additions and 6 deletions

View File

@ -3,10 +3,21 @@ Volcanos("misc", {help: "工具模块",
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}
try { // 解析响应
var res = JSON.parse(xhr.responseText); switch (xhr.getResponseHeader("content-type")) {
} catch (e) { case "image/png":
var res = {"result": [xhr.responseText]} if (xhr.responseType != "blob") {
msg.responseType = "blob"
can.misc.POST(can, msg, url, form, cb)
return
}
break
default:
try { // 解析响应
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));
} }
@ -32,6 +43,7 @@ Volcanos("misc", {help: "工具模块",
// 发送请求 // 发送请求
++arguments.callee.meta.order ++arguments.callee.meta.order
xhr.setRequestHeader("Accept", "application/json") xhr.setRequestHeader("Accept", "application/json")
xhr.responseType = msg.responseType || ""
xhr.send(data) xhr.send(data)
msg._xhr = xhr msg._xhr = xhr
}), }),

View File

@ -62,7 +62,9 @@ Volcanos("onimport", {help: "导入数据", list: [],
Volcanos("onaction", {help: "组件交互", list: [ Volcanos("onaction", {help: "组件交互", list: [
["layout"].concat(Config.layout.list), "清屏", "刷新", "并行","串行", ["layout"].concat(Config.layout.list), "清屏", "刷新", "并行","串行",
["action", "正常", "竖排", "编排", "定位", "定形"], ["action", "正常", "竖排", "编排", "定位", "定形"],
{input: "pod"}, {input: "you"}, {input: "hot"}, {input: "top"}, {input: "pod"}, {input: "you"},
{input: "hot"}, {input: "top"},
{input: "grp"}, {input: "lab"},
], ],
layout: function(event, can, value, cmd, field) {can.Export(event, cmd, value)}, layout: function(event, can, value, cmd, field) {can.Export(event, cmd, value)},

View File

@ -29,7 +29,18 @@ Volcanos("onimport", {help: "导入数据", list: [],
} }
}) })
} else { } else {
msg.result && can.page.Append(can, output, [{view: ["code", "div", can.page.Display(msg.Result())]}]).code; switch (msg._xhr.getResponseHeader("content-type")) {
case "image/png":
if (msg._xhr.responseType != "blob") {
break
}
var str = URL.createObjectURL(new Blob([msg._xhr.response], {type: "image/png"}));
msg.result && can.page.Append(can, output, [{img: [str]}])
break
default:
msg.result && can.page.Append(can, output, [{view: ["code", "div", can.page.Display(msg.Result())]}]).code;
}
} }
return typeof cb == "function" && cb(msg); return typeof cb == "function" && cb(msg);
}, },