提交 107a96c3 编写于 作者: jlj05024111@163.com's avatar jlj05024111@163.com

feat: 更新数据导入样式

上级 f036b92a
...@@ -30,12 +30,15 @@ export const DataImport = defineComponent({ ...@@ -30,12 +30,15 @@ export const DataImport = defineComponent({
message: '', message: '',
rowError: [], rowError: [],
}); });
// 是否正在导入
const isImporting = ref(false);
// 上传数据 // 上传数据
const uploadFile = async (file: Blob) => { const uploadFile = async (file: Blob) => {
const data = new FormData(); const data = new FormData();
data.append('file', file); data.append('file', file);
try { try {
isImporting.value = true;
const res = await ibiz.net.request(props.importUrl, { const res = await ibiz.net.request(props.importUrl, {
method: 'post', method: 'post',
data, data,
...@@ -60,6 +63,8 @@ export const DataImport = defineComponent({ ...@@ -60,6 +63,8 @@ export const DataImport = defineComponent({
} catch (error) { } catch (error) {
message.value.state = 'fail'; message.value.state = 'fail';
message.value.message = `导入失败!${(error as HttpError).message}`; message.value.message = `导入失败!${(error as HttpError).message}`;
} finally {
isImporting.value = false;
} }
}; };
...@@ -100,6 +105,9 @@ export const DataImport = defineComponent({ ...@@ -100,6 +105,9 @@ export const DataImport = defineComponent({
}; };
const selectFile = () => { const selectFile = () => {
if (isImporting.value) {
return;
}
inputUpLoad.value.click(); inputUpLoad.value.click();
}; };
...@@ -116,11 +124,12 @@ export const DataImport = defineComponent({ ...@@ -116,11 +124,12 @@ export const DataImport = defineComponent({
onFileChange, onFileChange,
inputUpLoad, inputUpLoad,
message, message,
isImporting,
}; };
}, },
render() { render() {
return ( return (
<div class={this.ns.b()}> <div class={[this.ns.b()]}>
<input <input
ref='inputUpLoad' ref='inputUpLoad'
type='file' type='file'
...@@ -130,12 +139,22 @@ export const DataImport = defineComponent({ ...@@ -130,12 +139,22 @@ export const DataImport = defineComponent({
/> />
<div class={this.ns.e('caption')}>导入数据</div> <div class={this.ns.e('caption')}>导入数据</div>
{this.message.state === 'ready' ? ( {this.message.state === 'ready' ? (
<div class={this.ns.b('upload')} onClick={this.selectFile}> <div
class={[
this.ns.b('upload'),
this.ns.is('loading', this.isImporting),
]}
onClick={this.selectFile}
>
<img <img
class={this.ns.be('upload', 'img')} class={this.ns.be('upload', 'img')}
src='./assets/img/icon-import.svg' src='./assets/img/icon-import.svg'
></img> ></img>
<span class={this.ns.be('upload', 'text')}>单击此区域进行上传</span> <span class={this.ns.be('upload', 'text')}>单击此区域进行上传</span>
<div class={this.ns.be('upload', 'loading')}>
<i-icon type='ios-loading' />
<span>导入中...</span>
</div>
</div> </div>
) : ( ) : (
<div class={this.ns.b('message')}> <div class={this.ns.b('message')}>
......
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册