feat(P4): precompute移植+app.js sources双向回填+回归1003/1003+验收体积/文件/data.json
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<title>Aurora Admin · DragUpload</title>
|
||||
<link rel="stylesheet" href="../.design_library/aurora-admin/colors_and_type.css" />
|
||||
<link rel="stylesheet" href="./DragUpload.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="aa-page">
|
||||
<h2 class="aa-h2">DragUpload 拖拽上传</h2>
|
||||
<p class="aa-desc">支持点击或拖拽文件上传,显示进度与缩略图,可删除。</p>
|
||||
|
||||
<div class="aa-demo">
|
||||
<div class="aa-upload" role="button" tabindex="0" id="upload">
|
||||
<div class="aa-upload-drop" role="button" tabindex="0" id="drop">
|
||||
<span class="aa-upload-icon">⬆️</span>
|
||||
<div class="aa-upload-hint">将文件拖到此处,或 <b>点击选择</b></div>
|
||||
</div>
|
||||
<input type="file" id="file" multiple style="display:none" />
|
||||
<div class="aa-upload-list" role="button" tabindex="0" id="list"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var drop = document.getElementById('drop');
|
||||
var input = document.getElementById('file');
|
||||
var list = document.getElementById('list');
|
||||
var files = [];
|
||||
|
||||
drop.addEventListener('click', function () { input.click(); });
|
||||
input.addEventListener('change', function () { addFiles(input.files); input.value = ''; });
|
||||
['dragenter', 'dragover'].forEach(function (ev) {
|
||||
drop.addEventListener(ev, function (e) { e.preventDefault(); drop.classList.add('is-over'); });
|
||||
});
|
||||
['dragleave', 'drop'].forEach(function (ev) {
|
||||
drop.addEventListener(ev, function (e) { e.preventDefault(); drop.classList.remove('is-over'); });
|
||||
});
|
||||
drop.addEventListener('drop', function (e) { addFiles(e.dataTransfer.files); });
|
||||
|
||||
function addFiles(flist) {
|
||||
Array.prototype.forEach.call(flist, function (f) {
|
||||
var id = 'f' + Date.now() + Math.random().toString(36).slice(2, 6);
|
||||
var item = { id: id, name: f.name, progress: 0, done: false, thumb: '' };
|
||||
if (/^image\//.test(f.type) && f.size < 2 * 1024 * 1024) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (e) { item.thumb = e.target.result; render(); };
|
||||
reader.readAsDataURL(f);
|
||||
}
|
||||
files.push(item);
|
||||
render();
|
||||
simulate(item);
|
||||
});
|
||||
}
|
||||
function simulate(item) {
|
||||
var timer = setInterval(function () {
|
||||
item.progress = Math.min(100, item.progress + Math.random() * 22);
|
||||
if (item.progress >= 100) { item.progress = 100; item.done = true; clearInterval(timer); }
|
||||
render();
|
||||
}, 220);
|
||||
}
|
||||
function render() {
|
||||
list.innerHTML = files.map(function (it) {
|
||||
var thumb = it.thumb ? '<img src="' + it.thumb + '">' : '文件';
|
||||
return '<div class="aa-upload-item" role="button" tabindex="0">' +
|
||||
'<div class="aa-upload-thumb">' + thumb + '</div>' +
|
||||
'<div class="aa-upload-meta">' +
|
||||
'<div class="aa-upload-name" role="button" tabindex="0">' + it.name + '</div>' +
|
||||
'<div class="aa-upload-bar"><i style="width:' + it.progress + '%"></i></div>' +
|
||||
'</div>' +
|
||||
'<div class="aa-upload-status" role="button" tabindex="0">' + (it.done ? '已完成' : Math.round(it.progress) + '%') + '</div>' +
|
||||
'<button class="aa-upload-del" role="button" tabindex="0" data-id="' + it.id + '">×</button>' +
|
||||
'</div>';
|
||||
}).join('');
|
||||
}
|
||||
list.addEventListener('click', function (e) {
|
||||
var del = e.target.closest('[data-id]');
|
||||
if (del) { files = files.filter(function (x) { return x.id !== del.dataset.id; }); render(); }
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,65 @@
|
||||
import React, { useRef, useState } from 'react';
|
||||
import './DragUpload.css';
|
||||
|
||||
export default function DragUpload() {
|
||||
const [files, setFiles] = useState([]);
|
||||
const [over, setOver] = useState(false);
|
||||
const fileRef = useRef(null);
|
||||
|
||||
const addFiles = (flist) => {
|
||||
Array.prototype.forEach.call(flist, (f) => {
|
||||
const id = 'f' + Date.now() + Math.random().toString(36).slice(2, 6);
|
||||
const item = { id, name: f.name, progress: 0, done: false, thumb: '' };
|
||||
if (/^image\//.test(f.type) && f.size < 2 * 1024 * 1024) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => setFiles((fs) => fs.map((x) => (x.id === id ? { ...x, thumb: e.target.result } : x)));
|
||||
reader.readAsDataURL(f);
|
||||
}
|
||||
setFiles((fs) => [...fs, item]);
|
||||
const t = setInterval(() => {
|
||||
setFiles((fs) =>
|
||||
fs.map((x) => {
|
||||
if (x.id !== id) return x;
|
||||
const p = Math.min(100, x.progress + Math.random() * 22);
|
||||
return { ...x, progress: p, done: p >= 100 };
|
||||
})
|
||||
);
|
||||
setFiles((fs) => {
|
||||
if (fs.find((x) => x.id === id && x.progress >= 100)) clearInterval(t);
|
||||
return fs;
|
||||
});
|
||||
}, 220);
|
||||
});
|
||||
};
|
||||
|
||||
const remove = (id) => setFiles((fs) => fs.filter((x) => x.id !== id));
|
||||
|
||||
return (
|
||||
<div className="aa-upload">
|
||||
<div
|
||||
className={'aa-upload-drop' + (over ? ' is-over' : '')}
|
||||
onClick={() => fileRef.current.click()}
|
||||
onDragOver={(e) => { e.preventDefault(); setOver(true); }}
|
||||
onDragLeave={() => setOver(false)}
|
||||
onDrop={(e) => { e.preventDefault(); setOver(false); addFiles(e.dataTransfer.files); }}
|
||||
>
|
||||
<span className="aa-upload-icon">⬆️</span>
|
||||
<div className="aa-upload-hint">将文件拖到此处,或 <b>点击选择</b></div>
|
||||
</div>
|
||||
<input ref={fileRef} type="file" multiple style={{ display: 'none' }} onChange={(e) => { addFiles(e.target.files); e.target.value = ''; }} />
|
||||
<div className="aa-upload-list">
|
||||
{files.map((it) => (
|
||||
<div key={it.id} className="aa-upload-item">
|
||||
<div className="aa-upload-thumb">{it.thumb ? <img src={it.thumb} alt="" /> : '文件'}</div>
|
||||
<div className="aa-upload-meta">
|
||||
<div className="aa-upload-name">{it.name}</div>
|
||||
<div className="aa-upload-bar"><i style={{ width: it.progress + '%' }} /></div>
|
||||
</div>
|
||||
<div className="aa-upload-status">{it.done ? '已完成' : Math.round(it.progress) + '%'}</div>
|
||||
<button className="aa-upload-del" onClick={() => remove(it.id)}>×</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<template>
|
||||
<div class="aa-upload">
|
||||
<div class="aa-upload-drop" :class="{ 'is-over': over }" @click="$refs.file.click()" @dragover.prevent="over = true" @dragleave="over = false" @drop.prevent="onDrop">
|
||||
<span class="aa-upload-icon">⬆️</span>
|
||||
<div class="aa-upload-hint">将文件拖到此处,或 <b>点击选择</b></div>
|
||||
</div>
|
||||
<input ref="file" type="file" multiple style="display:none" @change="onChange" />
|
||||
<div class="aa-upload-list">
|
||||
<div v-for="it in files" :key="it.id" class="aa-upload-item">
|
||||
<div class="aa-upload-thumb"><img v-if="it.thumb" :src="it.thumb" /><span v-else>文件</span></div>
|
||||
<div class="aa-upload-meta">
|
||||
<div class="aa-upload-name">{{ it.name }}</div>
|
||||
<div class="aa-upload-bar"><i :style="{ width: it.progress + '%' }"></i></div>
|
||||
</div>
|
||||
<div class="aa-upload-status">{{ it.done ? '已完成' : Math.round(it.progress) + '%' }}</div>
|
||||
<button class="aa-upload-del" @click="remove(it.id)">×</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: 'AaDragUpload',
|
||||
data() {
|
||||
return { files: [], over: false };
|
||||
},
|
||||
methods: {
|
||||
addFiles(flist) {
|
||||
var self = this;
|
||||
Array.prototype.forEach.call(flist, function (f) {
|
||||
var id = 'f' + Date.now() + Math.random().toString(36).slice(2, 6);
|
||||
var item = { id: id, name: f.name, progress: 0, done: false, thumb: '' };
|
||||
if (/^image\//.test(f.type) && f.size < 2 * 1024 * 1024) {
|
||||
var reader = new FileReader();
|
||||
reader.onload = function (e) { item.thumb = e.target.result; };
|
||||
reader.readAsDataURL(f);
|
||||
}
|
||||
self.files.push(item);
|
||||
self.simulate(item);
|
||||
});
|
||||
},
|
||||
onChange(e) { this.addFiles(e.target.files); e.target.value = ''; },
|
||||
onDrop(e) { this.over = false; this.addFiles(e.dataTransfer.files); },
|
||||
simulate(item) {
|
||||
var t = setInterval(function () {
|
||||
item.progress = Math.min(100, item.progress + Math.random() * 22);
|
||||
if (item.progress >= 100) { item.progress = 100; item.done = true; clearInterval(t); }
|
||||
}, 220);
|
||||
},
|
||||
remove(id) { this.files = this.files.filter(function (x) { return x.id !== id; }); }
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<style src="./DragUpload.css"></style>
|
||||
@@ -0,0 +1,53 @@
|
||||
<template>
|
||||
<div class="aa-upload">
|
||||
<div class="aa-upload-drop" :class="{ 'is-over': over }" @click="file.click()" @dragover.prevent="over = true" @dragleave="over = false" @drop.prevent="onDrop">
|
||||
<span class="aa-upload-icon">⬆️</span>
|
||||
<div class="aa-upload-hint">将文件拖到此处,或 <b>点击选择</b></div>
|
||||
</div>
|
||||
<input ref="file" type="file" multiple style="display:none" @change="onChange" />
|
||||
<div class="aa-upload-list">
|
||||
<div v-for="it in files" :key="it.id" class="aa-upload-item">
|
||||
<div class="aa-upload-thumb"><img v-if="it.thumb" :src="it.thumb" /><span v-else>文件</span></div>
|
||||
<div class="aa-upload-meta">
|
||||
<div class="aa-upload-name">{{ it.name }}</div>
|
||||
<div class="aa-upload-bar"><i :style="{ width: it.progress + '%' }"></i></div>
|
||||
</div>
|
||||
<div class="aa-upload-status">{{ it.done ? '已完成' : Math.round(it.progress) + '%' }}</div>
|
||||
<button class="aa-upload-del" @click="remove(it.id)">×</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
|
||||
const files = ref([]);
|
||||
const over = ref(false);
|
||||
const file = ref(null);
|
||||
|
||||
function addFiles(flist) {
|
||||
Array.prototype.forEach.call(flist, (f) => {
|
||||
const id = 'f' + Date.now() + Math.random().toString(36).slice(2, 6);
|
||||
const item = { id, name: f.name, progress: 0, done: false, thumb: '' };
|
||||
if (/^image\//.test(f.type) && f.size < 2 * 1024 * 1024) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e) => (item.thumb = e.target.result);
|
||||
reader.readAsDataURL(f);
|
||||
}
|
||||
files.value.push(item);
|
||||
simulate(item);
|
||||
});
|
||||
}
|
||||
function onChange(e) { addFiles(e.target.files); e.target.value = ''; }
|
||||
function onDrop(e) { over.value = false; addFiles(e.dataTransfer.files); }
|
||||
function simulate(item) {
|
||||
const t = setInterval(() => {
|
||||
item.progress = Math.min(100, item.progress + Math.random() * 22);
|
||||
if (item.progress >= 100) { item.progress = 100; item.done = true; clearInterval(t); }
|
||||
}, 220);
|
||||
}
|
||||
function remove(id) { files.value = files.value.filter((x) => x.id !== id); }
|
||||
</script>
|
||||
|
||||
<style src="./DragUpload.css"></style>
|
||||
Reference in New Issue
Block a user