mirror of
https://shylinux.com/x/volcanos
synced 2025-04-25 16:58:06 +08:00
add upload
This commit is contained in:
parent
44ea7eeb88
commit
9f9da31b4f
25
lib/misc.js
25
lib/misc.js
@ -1,9 +1,5 @@
|
||||
Volcanos("misc", {help: "工具模块",
|
||||
POST: shy("请求后端", {order: 0}, function(can, msg, url, form, cb) {
|
||||
var args = can.core.Items(form, function(value, index, key) {
|
||||
return key+"="+encodeURIComponent(value)
|
||||
})
|
||||
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.onreadystatechange = function() {
|
||||
if (xhr.readyState != 4) {return}
|
||||
@ -28,9 +24,24 @@ Volcanos("misc", {help: "工具模块",
|
||||
}
|
||||
|
||||
xhr.open("POST", url)
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
if (msg.upload) {
|
||||
var data = new FormData()
|
||||
can.core.Item(form, function(key, value) {
|
||||
can.core.List(value, function(item) {
|
||||
data.append(key, item)
|
||||
})
|
||||
})
|
||||
data.append("upload", msg.upload)
|
||||
} else {
|
||||
var args = can.core.Items(form, function(value, index, key) {
|
||||
return key+"="+encodeURIComponent(value)
|
||||
})
|
||||
var data = args.join("&")
|
||||
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
}
|
||||
|
||||
xhr.setRequestHeader("Accept", "application/json")
|
||||
xhr.send(args.join("&"))
|
||||
xhr.send(data)
|
||||
++arguments.callee.meta.order
|
||||
}),
|
||||
Run: shy("请求后端", {order: 0}, function(event, can, dataset, cmd, cb) {
|
||||
@ -54,6 +65,8 @@ Volcanos("misc", {help: "工具模块",
|
||||
}
|
||||
// msg.detail = ["run", what].concat(option.group).concat(option.names).concat(option.cmds)
|
||||
// kit.Log(msg.detail.concat([msg]))
|
||||
//
|
||||
//
|
||||
|
||||
// kit.History("run", -1, option)
|
||||
this.POST(can, msg, can.Conf("iceberg")+(dataset.names||msg.names).toLowerCase(), option, function(msg) {
|
||||
|
15
lib/page.js
15
lib/page.js
@ -302,6 +302,21 @@ Volcanos("page", {help: "网页模块",
|
||||
item.click()
|
||||
})
|
||||
},
|
||||
Upload: function(can, url, form, file, cb) {
|
||||
var data = new FormData()
|
||||
can.core.Item(form, function(key, value) {
|
||||
data.append(key, value)
|
||||
})
|
||||
data.append("upload", file)
|
||||
|
||||
var xhr = new XMLHttpRequest()
|
||||
xhr.onreadystatechange = function() {
|
||||
}
|
||||
xhr.open("POST", url)
|
||||
// xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
xhr.setRequestHeader("Accept", "application/json")
|
||||
xhr.send(data)
|
||||
},
|
||||
|
||||
DelText: function(target, start, count) {
|
||||
target.value = target.value.substring(0, start)+target.value.substring(start+(count||target.value.length), target.value.length)
|
||||
|
@ -122,7 +122,8 @@ Volcanos("onfigure", {help: "控件详情", list: [],
|
||||
show(can.now);
|
||||
set(can.now);
|
||||
}},
|
||||
province: {click: function(event, can, value, cmd, target) {if (can.figure) {return}
|
||||
province: {click: function(event, can, value, cmd, target) {
|
||||
if (can.figure) {return}
|
||||
can.figure = can.page.Append(can, document.body, [{view: ["date input", "fieldset"], style: {
|
||||
position: "absolute", left: "20px", top: event.clientY+10+"px",
|
||||
}, onmouseleave: function(event) {
|
||||
@ -143,10 +144,36 @@ Volcanos("onfigure", {help: "控件详情", list: [],
|
||||
}]}]);
|
||||
},
|
||||
},
|
||||
upload: {click: function(event, can, value, cmd, target) {
|
||||
if (!can.onfigure._prepare(event, can, value, cmd, target)) {return}
|
||||
can.figure.stick = true
|
||||
var action = can.page.AppendAction(can, can.figure.action, [{type: "input", data: {name: "upload", type: "file"}}, "上传", "关闭"], function(event, value, cmd) {
|
||||
switch (value) {
|
||||
case "关闭": can.onfigure._release(event, can, value, cmd, target); return
|
||||
}
|
||||
|
||||
var msg = can.Event(event);
|
||||
msg.upload = action.upload.files[0]
|
||||
can.run(event, ["action", "上传"], true, function(msg) {
|
||||
can.user.toast("上传成功")
|
||||
})
|
||||
})
|
||||
}},
|
||||
_prepare: function(event, can, value, cmd, target) {if (can.figure) {return}
|
||||
can.figure = can.page.Append(can, document.body, [{view: ["input "+cmd, "fieldset"], style: {
|
||||
position: "absolute", left: "20px", top: event.clientY+10+"px",
|
||||
}, list: [{view: ["action"]}, {view: ["output"]}], onmouseleave: function(event) {
|
||||
!can.figure.stick && can.onfigure._release(event, can, value, cmd, target)
|
||||
}}])
|
||||
return can.figure
|
||||
},
|
||||
_release: function(event, can, value, cmd, target) {
|
||||
can.page.Remove(can, can.figure.first); delete(can.figure);
|
||||
},
|
||||
})
|
||||
Volcanos("onaction", {help: "控件交互", list: [],
|
||||
onclick: function(event, can) {can.Select(event);
|
||||
var figure = can.onfigure[can.item.figure]
|
||||
var figure = can.onfigure[can.item.cb] || can.onfigure[can.item.figure]
|
||||
figure? figure.click(event, can, can.item, can.item.name, event.target): can.item.type == "button" && can.run(event)
|
||||
},
|
||||
onkeydown: function(event, can) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user