This commit is contained in:
yumoqing 2025-09-29 23:48:41 +08:00
parent 567101ea19
commit 709ea3afe0
2 changed files with 39 additions and 26 deletions

View File

@ -484,6 +484,22 @@ bricks.UiFile = class extends bricks.VBox {
this.add_widget(new bricks.Text({text:'drop in or click to choose file'})); this.add_widget(new bricks.Text({text:'drop in or click to choose file'}));
this.dom_element.appendChild(this.input); this.dom_element.appendChild(this.input);
} }
handleFileSelect(event){
if (this.opts.multiple){
files = [];
event.target.files.forEach(f => {
if (! this.accept || f.type.startsWith(this.accept)){
files.push(f);
}
});
this.value = files;
} else {
const file = event.target.files[0];
this.value = file;
}
console.log('"changed" fired', this.value);
this.dispatch('changed', this.value);
}
set_input_file(files){ set_input_file(files){
const dt = new DataTransfer(); const dt = new DataTransfer();
if (this.opts.multiple){ if (this.opts.multiple){
@ -500,22 +516,6 @@ bricks.UiFile = class extends bricks.VBox {
this.input.files = dt.files; this.input.files = dt.files;
} }
} }
handleFileSelect(event){
if (this.opts.multiple){
files = [];
event.target.files.forEach(f => {
if (! this.accept || f.type.startsWith(this.accept)){
files.push(f);
}
});
this.value = files;
} else {
const file = event.target.files[0];
this.value = file;
}
this.dispatch('changed', this.value);
console.log('"changed" fired', this.value);
}
dropHandle(event){ dropHandle(event){
event.preventDefault(); event.preventDefault();
var files = []; var files = [];
@ -524,6 +524,8 @@ bricks.UiFile = class extends bricks.VBox {
files.push(f); files.push(f);
} }
}; };
if (files.length == 0) return;
consoles.log('dragin files=', files)
if (this.opts.multiple){ if (this.opts.multiple){
this.value = files; this.value = files;
this.set_input_file(files); this.set_input_file(files);
@ -531,7 +533,6 @@ bricks.UiFile = class extends bricks.VBox {
this.value = files[0]; this.value = files[0];
this.set_input_file([this.value]); this.set_input_file([this.value]);
} }
this.dispatch('changed', this.value);
console.log('"changed" fired', this.value); console.log('"changed" fired', this.value);
} }
set_formdata(fd){ set_formdata(fd){
@ -584,7 +585,9 @@ bricks.UiAudio =class extends bricks.UiFile {
recorder.dismiss(); recorder.dismiss();
this.value = event.params.file this.value = event.params.file
console.log('record finished, value=', this.value); console.log('record finished, value=', this.value);
this.dispatch('changed', event.params.url); var data = {};
data[this.name] = this.value;
this.dispatch('changed', data);
} }
show_audio(event){ show_audio(event){
var params = event.params; var params = event.params;
@ -656,10 +659,12 @@ bricks.UiVideo =class extends bricks.UiFile {
recorder.dismiss(); recorder.dismiss();
this.value = event.params.file this.value = event.params.file
console.log('record finished, value=', this.value); console.log('record finished, value=', this.value);
this.dispatch('changed', event.params.url); var data = {};
data[this.name] = this.value;
this.dispatch('changed', data);
} }
show_video(event){ show_video(event){
var params = event.params; var params = event.params[this.name];
if (params instanceof File){ if (params instanceof File){
params = [ params ]; params = [ params ];
} }
@ -726,12 +731,14 @@ bricks.UiImage =class extends bricks.UiFile {
} }
accept_photo(camera, event){ accept_photo(camera, event){
camera.dismiss(); camera.dismiss();
this.value = event.params this.value = event.params.file;
this.dispatch('changed', this.value); this.set_input_file([this.value]);
// this.add_widget(this.imgw); var data = {};
data['name'] = this.value;
this.dispatch('changed', data);
} }
show_image(event){ show_image(event){
var params = event.params; var params = event.params[this.value];
if (params instanceof File){ if (params instanceof File){
params = [ params ]; params = [ params ];
} }

View File

@ -248,8 +248,11 @@ bricks.SysVideoRecorder = class extends bricks.MediaRecorder {
if (this.task_period == 0){ if (this.task_period == 0){
return; return;
} }
const blob = await this.imageCapture.takePhoto(); blob = await this.imageCapture.takePhoto();
this.dataurl = URL.createObjectURL(blob); this.dataurl = URL.createObjectURL(blob);
this.imgfile = new File([blob],
'image.jpg',
{ type: 'image/jpeg' });
this.imgw.set_url(this.dataurl); this.imgw.set_url(this.dataurl);
this.pic_task = schedule_once(this.show_picture.bind(this), this.pic_task = schedule_once(this.show_picture.bind(this),
this.task_period); this.task_period);
@ -272,7 +275,10 @@ bricks.SysCamera= class extends bricks.SysVideoRecorder {
} }
this.task_period = 0; this.task_period = 0;
this.task = null; this.task = null;
this.dispatch('shot', this.dataurl); const file = new File([blob],
filename,
{ type: this.mimetype });
this.dispatch('shot', {url: this.dataurl, file:this.imgfile});
this.close_recorder(); this.close_recorder();
} }
} }