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

add can.dir

This commit is contained in:
IT 老营长 @云轩领航-创始人 2023-12-24 19:37:04 +08:00
parent ff638822af
commit 25cdf367d7
3 changed files with 31 additions and 29 deletions

View File

@ -174,6 +174,7 @@ Volcanos(chat.ONAPPEND, {_init: function(can, meta, list, cb, target, field) {
_target: can.onappend.input(can, item, args[index]||opts[item.name], option||can._option), _option: option||can._option, _action: can._action, _output: can._output, _status: can._status, _target: can.onappend.input(can, item, args[index]||opts[item.name], option||can._option), _option: option||can._option, _action: can._action, _output: can._output, _status: can._status,
CloneField: can.Clone, CloneInput: function() { can.onmotion.focus(can, add(item)._target) }, Input: can.Input, Option: can.Option, Action: can.Action, Status: can.Status, CloneField: can.Clone, CloneInput: function() { can.onmotion.focus(can, add(item)._target) }, Input: can.Input, Option: can.Option, Action: can.Action, Status: can.Status,
}, [item.display, chat.PLUGIN_INPUT_JS], function(sub) { sub.Conf(item) }, [item.display, chat.PLUGIN_INPUT_JS], function(sub) { sub.Conf(item)
sub._fields = can
if (item.type == html.TEXT) { can.page.Append(can, sub._target.parentNode, [{text: [sub._target.value, html.SPAN, mdb.VALUE]}]) } if (item.type == html.TEXT) { can.page.Append(can, sub._target.parentNode, [{text: [sub._target.value, html.SPAN, mdb.VALUE]}]) }
if (item.type == html.BUTTON && can.base.isIn(item.name, mdb.CREATE, mdb.INSERT, mdb.PRUNES, mdb.PRUNE)) { if (item.type == html.BUTTON && can.base.isIn(item.name, mdb.CREATE, mdb.INSERT, mdb.PRUNES, mdb.PRUNE)) {
can.onappend.icons(can, sub._target, item.name, function(event) { can.onappend.icons(can, sub._target, item.name, function(event) {

View File

@ -197,18 +197,22 @@ Volcanos("page", {
} }); return table }, } }); return table },
RangeTable: function(can, table, index, asc) { index = can.base.isArray(index)? can.core.List(index, function(item) { if (item > -1) { return item } }): [index]; if (index.length == 0) { return } RangeTable: function(can, table, index, asc) { index = can.base.isArray(index)? can.core.List(index, function(item) { if (item > -1) { return item } }): [index]; if (index.length == 0) { return }
var list = can.page.Select(can, table, html.TR, function(tr) { if (can.page.isDisplay(tr)) { return tr } }).slice(1) var list = can.page.Select(can, table, html.TR, function(tr) { if (can.page.isDisplay(tr)) { return tr } }).slice(1)
var is_time = true, is_number = true; can.core.List(list, function(tr) { var is_time = true, is_number = true; can.core.List(list, function(tr) { var text = tr.childNodes[index[0]].innerHTML;
var text = tr.childNodes[index[0]].innerHTML;
is_time = is_time && Date.parse(text) > 0, is_number = is_number && !isNaN(parseFloat(text||"0")) is_time = is_time && Date.parse(text) > 0, is_number = is_number && !isNaN(parseFloat(text||"0"))
}) })
var num_list = can.core.List(list, function(tr) { var text = tr.childNodes[index[0]].innerHTML; return is_time? Date.parse(text): is_number? can.base.ParseSize(text)||0: text }) var num_list = can.core.List(list, function(tr) { var text = tr.childNodes[index[0]].innerHTML; return is_time? Date.parse(text): is_number? can.base.ParseSize(text)||0: text })
function less(a, b) {
if (can.base.endWith(a, nfs.PS) && !can.base.endWith(b, nfs.PS)) { return true }
if (!can.base.endWith(a, nfs.PS) && can.base.endWith(b, nfs.PS)) { return false }
return a < b
}
function isless(a, b, index) { if (a.childNodes[index[0]] && b.childNodes[index[0]]) { function isless(a, b, index) { if (a.childNodes[index[0]] && b.childNodes[index[0]]) {
if (a.childNodes[index[0]].innerHTML < b.childNodes[index[0]].innerHTML) { return true } if (a.childNodes[index[0]].innerHTML < b.childNodes[index[0]].innerHTML) { return true }
if (a.childNodes[index[0]].innerHTML > b.childNodes[index[0]].innerHTML) { return false } if (a.childNodes[index[0]].innerHTML > b.childNodes[index[0]].innerHTML) { return false }
} return index.length > 1 && isless(a, b, index.slice(1)) } } return index.length > 1 && isless(a, b, index.slice(1)) }
for (var i = 0; i < num_list.length; i++) { var min = i for (var i = 0; i < num_list.length; i++) { var min = i
for (var j = i+1; j < num_list.length; j++) { for (var j = i+1; j < num_list.length; j++) {
if (asc? num_list[min] < num_list[j]: num_list[j] < num_list[min]) { min = j; continue } if (asc? less(num_list[min], num_list[j]): less(num_list[j], num_list[min])) { min = j; continue }
if (num_list[min] == num_list[j] && index.length > 1) { if (asc? isless(list[min], list[j], index.slice(1)): isless(list[j], list[min], index.slice(1))) { min = j } } if (num_list[min] == num_list[j] && index.length > 1) { if (asc? isless(list[min], list[j], index.slice(1)): isless(list[j], list[min], index.slice(1))) { min = j } }
} }
if (min != i) { if (min != i) {

View File

@ -164,36 +164,33 @@ Volcanos(chat.ONPLUGIN, {
boot: can.db._boot, boot: can.db._boot,
})).Display("/plugin/story/json.js") })).Display("/plugin/story/json.js")
}), }),
dir: shy("网页目录", [nfs.PATH, ice.LIST, ice.BACK], async function(can, msg, arg, cb) { dir: shy("网页目录", [nfs.PATH, ice.LIST, ice.BACK], async function(can, msg, arg, cb) { var can = msg._can._fields? msg._can.sup: msg._can
async function list(key, root) { async function list(key, root) { can._handle[key] = root
msg._can._handle[key] = root for await (const [name, handle] of root) { if (can.base.beginWith(name, nfs.PT)) { continue }
for await (const [name, handle] of root) { if (handle.kind == nfs.FILE) { var _file = await handle.getFile()
if (can.base.beginWith(name, nfs.PT)) { continue } msg.Push(mdb.TIME, can.base.Time(new Date(_file.lastModified))), msg.Push(nfs.PATH, key+name), msg.Push(nfs.SIZE, can.base.Size(_file.size))
if (handle.kind === 'file') {
msg.Push(nfs.PATH, key+name)
} else { } else {
msg.Push(nfs.PATH, key+name+nfs.PS) msg.Push(mdb.TIME, can.base.Time()), msg.Push(nfs.PATH, key+name+nfs.PS), msg.Push(nfs.SIZE, 0)
} }
} } can.onmotion.delay(can, function() { can.page.Select(can, can._output, "tr>th")[1].click(), can.page.Select(can, msg._can._output, "tr>th")[1].click() }, 50)
} } can._handle = can._handle||{}; if (arg[0] == ctx.ACTION && arg[1] == ice.LIST) { arg = [] }
msg._can._handle = msg._can._handle||{} if (arg.length == 0) { if (!msg._event.isTrusted) { return msg.Echo(can.page.Format(html.INPUT, "", mdb.TYPE, html.BUTTON, mdb.NAME, ice.LIST, mdb.VALUE, "list")), cb(msg) }
var raw = arg[0]||"" await list("", can._handle[""] || await window.showDirectoryPicker()), cb(msg)
arg[0] = can.base.trimSuffix(raw, nfs.PS)
var key = arg[0].indexOf(nfs.PS) > -1? arg[0].slice(0, arg[0].lastIndexOf(nfs.PS)): ""
var handle = msg._can._handle[key]
if (raw == "") { if (!msg._event.isTrusted) { return }
await list("", handle || await window.showDirectoryPicker())
cb(msg)
} else { } else {
if (can.base.endWith(raw, nfs.PS)) { if (can.base.endWith(arg[0], nfs.PS)) { var path = can.base.trimSuffix(arg[0], nfs.PS)
await list(key, await handle.getDirectoryHandle(arg[0])) if (path.indexOf(nfs.PS) == -1) {
cb(msg) var file = path, path = ""
} else { } else {
const file = await handle.getFileHandle(arg[0]) var file = path.slice(path.lastIndexOf(nfs.PS)+1), path = path.slice(0, path.lastIndexOf(nfs.PS)+1)
const reader = new FileReader() } var handle = can._handle[path]
reader.onload = () => { msg.Echo(reader.result), cb(msg) } await list(arg[0], await handle.getDirectoryHandle(file)), cb(msg)
reader.readAsText(await file.getFile()) } else {
if (arg[0].indexOf(nfs.PS) == -1) {
var file = arg[0], path = ""
} else { var path = can.base.trimSuffix(arg[0], nfs.PS)
var file = path.slice(path.lastIndexOf(nfs.PS)+1), path = path.slice(0, path.lastIndexOf(nfs.PS)+1)
} var handle = can._handle[path], _file = await handle.getFileHandle(file)
var reader = new FileReader(); reader.onload = () => { msg.Echo(reader.result), cb(msg) }, reader.readAsText(await _file.getFile())
} }
} }
}), }),