183 lines
6.4 KiB
HTML
183 lines
6.4 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8" />
|
|
<title>上传文件</title>
|
|
<meta charset="UTF-8" />
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, viewport-fit=cover" />
|
|
<script src="${base!}/assets/platform/plugins/vue/vue.js"></script>
|
|
<script src="${base!}/assets/platform/plugins/axios/axios.js"></script>
|
|
<link rel="stylesheet" href="${base!}/assets/platform/plugins/vant/index.css" />
|
|
<script src="${base!}/assets/platform/plugins/vant/index.js"></script>
|
|
|
|
<style>
|
|
:root {
|
|
--color-primary: #1867b0;
|
|
--color-background: #f3f4f6;
|
|
--color-text: #333;
|
|
}
|
|
|
|
body {
|
|
margin: 0;
|
|
font-family: Arial, sans-serif;
|
|
background-color: var(--color-background);
|
|
color: var(--color-text);
|
|
}
|
|
|
|
#app {
|
|
padding: 20px;
|
|
max-width: 600px;
|
|
margin: auto;
|
|
background: white;
|
|
border-radius: 8px;
|
|
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
|
|
}
|
|
|
|
h1 {
|
|
text-align: center;
|
|
color: var(--color-primary);
|
|
}
|
|
|
|
.upload-button {
|
|
margin-top: 20px;
|
|
text-align: center;
|
|
}
|
|
|
|
.van-uploader__tip {
|
|
color: var(--color-primary);
|
|
font-size: 14px;
|
|
}
|
|
|
|
.van-button {
|
|
background-color: var(--color-primary);
|
|
color: white;
|
|
border-radius: 4px;
|
|
}
|
|
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="app" v-cloak>
|
|
<h1>文件上传</h1>
|
|
<van-uploader
|
|
v-model="fileList"
|
|
:before-read="beforeRead"
|
|
:after-read="afterRead"
|
|
multiple
|
|
:accept="accept"
|
|
async
|
|
:max-count="upload_number"
|
|
title="选择文件"
|
|
description=""
|
|
tip=""
|
|
></van-uploader>
|
|
|
|
<div class="upload-button">
|
|
<van-button block type="primary" @click="onSubmit">同步到电脑</van-button>
|
|
</div>
|
|
</div>
|
|
</body>
|
|
<script nonce="${cspNonce!}">
|
|
new Vue({
|
|
el: "#app",
|
|
data() {
|
|
return {
|
|
fileList: [
|
|
// { url: "http://localhost:8080/platform/sys/file/download?id=rn1v1efh2ag0aps59ult3ebudf", isImage: true }
|
|
],
|
|
// accept: "image/*",
|
|
accept: "*",
|
|
upload_number: 9,
|
|
}
|
|
},
|
|
methods: {
|
|
GetQueryString(name) {
|
|
return new URLSearchParams(window.location.search).get(name)
|
|
},
|
|
beforeRead(file) {
|
|
return true
|
|
},
|
|
afterRead(file) {},
|
|
|
|
buildUploadPromises(file) {
|
|
return
|
|
},
|
|
|
|
onSubmit() {
|
|
const loading = this.$toast({
|
|
duration: 0,
|
|
overlay: true,
|
|
forbidClick: true,
|
|
message: "上传中",
|
|
loadingType: "circular"
|
|
})
|
|
|
|
Promise.all(
|
|
this.fileList.map((f) => {
|
|
const formData = new FormData()
|
|
formData.append("file", f.file)
|
|
return axios.post("/platform/sys/h5ScanCodeUploadFile/upload", formData).then((axiosResp) => {
|
|
const resp = axiosResp.data
|
|
if (resp.code === 0) {
|
|
console.log(resp)
|
|
f.name = f.file.name
|
|
f.size = f.file.size
|
|
f.status = null
|
|
f.url = resp.data
|
|
f.response = resp
|
|
f.percentage = 100
|
|
f.isImage = true
|
|
delete f.file
|
|
delete f.content
|
|
console.log(f)
|
|
} else {
|
|
f.status = "fail"
|
|
}
|
|
})
|
|
})
|
|
)
|
|
.then(() => {
|
|
loading.close()
|
|
console.log(this.fileList)
|
|
this.syncPc()
|
|
})
|
|
.catch((error) => {
|
|
loading.close()
|
|
this.$toast.fail(error)
|
|
})
|
|
},
|
|
|
|
syncPc() {
|
|
if(this.fileList.length===0){
|
|
this.$toast('请先选择文件')
|
|
return
|
|
}
|
|
console.log(this.fileList)
|
|
|
|
axios
|
|
.post(
|
|
"/platform/sys/h5ScanCodeUploadFile/syncPc",
|
|
{
|
|
files: JSON.stringify(this.fileList),
|
|
timestamp: this.GetQueryString("timestamp")
|
|
},
|
|
{
|
|
headers: {
|
|
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8"
|
|
}
|
|
}
|
|
)
|
|
.then((resp) => {
|
|
if (resp.data.code === 0) {
|
|
this.$toast.success("上传成功,请关注电脑端信息")
|
|
} else {
|
|
this.$toast.fail(resp.data.msg)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
})
|
|
</script>
|
|
</html>
|