Files

458 lines
18 KiB
Python
Raw Permalink Normal View History

2022-12-13 11:29:33 +08:00
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
2022-12-16 11:51:13 +08:00
<link rel="stylesheet" href="/static/asserts/index.css">
<link rel="shortcut icon" href="/static/asserts/favicon.ico" type="image/x-icon"/>
2022-12-13 11:29:33 +08:00
<title>{{title}}</title>
<meta name="description" content="{{description}}"/>
<meta name="keywords" content="{{keywords}}"/>
<meta name="generator" content="FileCodeBox"/>
2023-01-18 10:41:02 +08:00
<meta name="template" content="V1.6 Beta"/>
2022-12-13 11:29:33 +08:00
<style>
2022-12-19 22:00:04 +08:00
body {
background: #f5f5f5;
}
2022-12-13 11:29:33 +08:00
.qu .el-button {
width: 100px;
height: 100px;
margin: 0.2rem;
font-size: 30px;
font-weight: bold;
}
2022-12-27 10:01:10 +08:00
.el-icon-circle-close::before {
font-size: 26px !important;
line-height: 128px;
}
2022-12-13 11:29:33 +08:00
.qu .el-input__inner {
height: 100px;
margin: 1rem 0;
font-size: 30px;
font-weight: bold;
2022-12-17 14:02:27 +08:00
border-radius: 20px;
2022-12-13 11:29:33 +08:00
}
2022-12-17 14:02:27 +08:00
2022-12-23 12:07:46 +08:00
.el-card {
border-radius: 20px;
}
2022-12-21 18:55:30 +08:00
@media (prefers-color-scheme: dark) {
body {
background-color: #18181c;
}
2022-12-21 19:19:42 +08:00
.el-card, .el-textarea__inner, .el-upload-dragger {
2022-12-21 18:55:30 +08:00
border-radius: 20px;
border: 1px solid transparent;
background-color: rgba(255, 255, 255, 0.1);
box-shadow: 5px 5px 0 0 rgba(0, 0, 0, 0.2);
}
2023-01-10 13:40:07 +08:00
#app * {
2022-12-21 18:55:30 +08:00
color: #ccc !important;
}
2022-12-21 19:19:42 +08:00
.el-input-group__prepend, .el-input__inner, .el-input-group__append, .el-empty__description, .el-select-dropdown, .el-button {
2022-12-21 18:55:30 +08:00
border: 1px solid transparent;
2022-12-21 19:10:51 +08:00
background-color: rgba(0, 0, 0, 0.2);
}
.el-drawer, #el-drawer__title, .el-drawer__body, .el-drawer__wrapper {
background-color: rgba(0, 0, 0, 0.5);
2022-12-21 19:19:42 +08:00
border: 1px solid transparent;
2022-12-21 18:55:30 +08:00
}
2022-12-19 13:59:44 +08:00
}
2022-12-21 18:55:30 +08:00
2022-12-13 11:29:33 +08:00
</style>
2022-12-16 11:51:13 +08:00
<script src="/static/asserts/vue.min.js"></script>
<script src="/static/asserts/index.js"></script>
2022-12-13 11:29:33 +08:00
</head>
<body>
<div id="app" style="text-align: center">
2022-12-20 11:46:48 +08:00
<el-row v-if="pageNum === 0" class="qu" style="max-width:400px;margin: 4rem auto 0 auto">
2022-12-21 18:55:30 +08:00
<el-card class="glass" style="padding-bottom: 1rem">
2022-12-13 11:29:33 +08:00
<el-col :span="24">
2022-12-17 14:02:27 +08:00
<el-input round autofocus @change="changeInput" clearable v-model:value="code" maxlength="5"
2022-12-13 11:29:33 +08:00
:disabled="inputDisable" placeholder="请输入五位取件码">
</el-input>
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="listenInput('1')">1</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="listenInput('2')">2</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="listenInput('3')">3</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="listenInput('4')">4</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="listenInput('5')">5</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="listenInput('6')">6</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="listenInput('7')">7</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="listenInput('8')">8</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="listenInput('9')">9</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="pageNum=1">
<div style="height: 10px" class="el-icon-upload2"></div>
</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="listenInput('0')">0</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
<el-col :span=8>
2022-12-17 14:02:27 +08:00
<el-button round @click="quDrawer=true">
<div class="el-icon-takeaway-box"></div>
</el-button>
2022-12-13 11:29:33 +08:00
</el-col>
</el-card>
</el-row>
2022-12-20 11:46:48 +08:00
<el-row v-else style="max-width:400px;margin: 4rem auto 0 auto">
2022-12-19 13:59:44 +08:00
<el-col :span="24">
2022-12-19 15:21:24 +08:00
<el-card :body-style="{ padding: '0px 0px 20px 0px' }">
<div class="block" style="margin-bottom: 1rem">
<el-carousel height="150px">
<el-carousel-item v-for="item in banners" :key="item">
2022-12-19 18:01:50 +08:00
<a :href="item.url" target="_blank">
<img class="image" style="width: 400px" :src="item.src" :alt="item.text">
2022-12-19 15:21:24 +08:00
</a>
</el-carousel-item>
</el-carousel>
</div>
<el-row>
2022-12-17 14:02:27 +08:00
<el-input style="width: 190px" placeholder="数量" v-model="uploadData.value"
class="input-with-select">
<el-select style="width: 75px" v-model="uploadData.style" slot="prepend" placeholder="请选择">
<el-option label="天数" value="2"></el-option>
<el-option label="次数" value="1"></el-option>
</el-select>
<el-button v-if="uploadData.style === '1'" slot="append" disabled>次</el-button>
<el-button v-else slot="append" disabled>天</el-button>
</el-input>
2022-12-17 14:02:27 +08:00
<el-radio-group style="margin-left: 18px" v-model="uploadData.type">
<el-radio label="1">
文件
</el-radio>
<el-radio label="2">
文本
</el-radio>
</el-radio-group>
</el-row>
2022-12-13 11:29:33 +08:00
<el-upload
v-if="uploadData.type === '1'"
drag
action="/share"
multiple
style="margin: 1rem 0;"
:data="uploadData"
2022-12-15 16:34:18 +08:00
:before-upload="beforeUpload"
:headers="{'pwd':pwd}"
2022-12-13 11:29:33 +08:00
:on-success="successUpload"
:on-error="errorUpload"
>
<i class="el-icon-upload"></i>
<div class="el-upload__text">将文字、文件拖、粘贴到此处,或<em>点击上传</em></div>
<div class="el-upload__text" style="font-size: 10px">天数<7或限制次数(24h后删除)</div>
</el-upload>
<el-input
v-else
type="textarea"
:autosize="{ minRows: 8}"
style="margin: 1rem 0"
placeholder="请输入内容,使用按钮存入"
2022-12-13 11:29:33 +08:00
v-model="uploadData.text">
</el-input>
2022-12-19 15:21:24 +08:00
2022-12-13 11:29:33 +08:00
<div class="el-upload__tip">
2022-12-17 14:02:27 +08:00
<el-button round @click="pageNum=0">
<div class="el-icon-back"></div>
取件
</el-button>
<el-button round @click="jiDrawer=true">
<div class="el-icon-takeaway-box"></div>
我的文件
</el-button>
<el-button round v-if="uploadData.type === '2'" @click="toUploadData">
<div class="el-icon-upload2"></div>
存入
</el-button>
2022-12-13 11:29:33 +08:00
</div>
</el-card>
</el-col>
</el-row>
<el-drawer
title="文件箱"
:visible.sync="quDrawer"
:direction="direction"
size="50%"
>
2022-12-22 12:11:32 +08:00
<el-card v-for="(file,index) in quFiles" :key="index" class="box-card">
2022-12-19 14:32:48 +08:00
<div style="cursor: pointer;text-align: left;margin-left: 2rem">
2022-12-13 11:29:33 +08:00
<div>取件码:${ file.code }</div>
<div>文件名:${ file.name }</div>
<div v-if="file.name==='文本分享'">
2023-01-16 18:53:45 +08:00
<span style="white-space: pre-line"
@click="copyText(file.text,1)">内&nbsp;&nbsp; 容:${ file.text }</span>
2022-12-13 11:29:33 +08:00
</div>
<div v-else>
<span>链&nbsp;&nbsp; 接:</span>
<a :href="file.text" target="_blank"
style="color: #1E9FFF;text-underline: none"
type="primary">点击下载</a>
</div>
</div>
</el-card>
2022-12-22 12:11:32 +08:00
<el-empty v-if="quFiles.length===0" description="请输入取件码,收取文件"></el-empty>
2022-12-13 11:29:33 +08:00
</el-drawer>
<el-drawer
title="文件箱"
:visible.sync="jiDrawer"
:direction="direction"
size="50%">
2022-12-22 12:11:32 +08:00
<el-empty v-if="jiFiles.length===0" description="请上传文件"></el-empty>
<el-card style="margin-top: 0.2rem" v-for="(file,index) in jiFiles" :key="index">
2022-12-21 18:55:30 +08:00
<el-row>
<el-col :span="15">
<el-row>
<el-col :span="24" style="line-height: 45px">
${ file.name }
</el-col>
<el-col :span="24">
取件码:
<h1 @click="copyText(file.code,0)" style="margin: 0;display: inline;cursor: pointer">
${ file.code }
</h1>
</el-col>
</el-row>
</el-col>
<el-col :span="4">
<img style="width: 80px;height: 80px;"
:src="qrcodeUrl(file)" alt="二维码" :alt="file.code">
</el-col>
</el-row>
2022-12-13 11:29:33 +08:00
</el-card>
</el-drawer>
<div style="text-align: center; margin-top: 1rem;color: #606266">
2023-01-09 23:10:38 +08:00
<a style="text-decoration: none;color: #606266" target="_blank" href="https://github.com/vastsa/FileCodeBox">FileCodeBox
2023-01-18 10:41:02 +08:00
V1.6 Beta</a>
2022-12-13 11:29:33 +08:00
</div>
</div>
</body>
2022-12-16 11:51:13 +08:00
<script src="/static/asserts/axios.min.js"></script>
2022-12-13 11:29:33 +08:00
<script>
new Vue({
el: '#app',
delimiters: ['${', '}'],
data: function () {
return {
code: '',
quDrawer: false,
jiDrawer: false,
direction: 'btt',
2022-12-22 12:11:32 +08:00
quFiles: [],
jiFiles: [],
2022-12-13 11:29:33 +08:00
pageNum: 0,
inputDisable: false,
2022-12-15 16:34:18 +08:00
fileSizeLimit: '{{fileSizeLimit}}',
pwd: localStorage.getItem('pwd') || '',
2022-12-19 15:21:24 +08:00
banners: [],
2022-12-23 12:32:18 +08:00
enableUpload: false,
2022-12-13 11:29:33 +08:00
uploadData: {
style: '2',
type: '1',
value: 1,
file: null,
text: ''
},
};
},
mounted: function () {
// 进入网站时,判断Get是否有code参数,有则直接进行取件操作
let code = window.location.search.substring('code=='.length)
if (code) {
this.code = code
this.getFile()
}
// 剪切板监听
const that = this
document.addEventListener('paste', function (event) {
if (that.pageNum === 1) {
const items = event.clipboardData && event.clipboardData.items;
if (items && items.length) {
for (let i = 0; i < items.length; i++) {
if (items[i].kind === 'string') {
if (items[i].type.match(/^text\/plain/) && that.uploadData.type !== '2') {
that.$message('剪切板文字正在上传,请稍等');
items[i].getAsString(function (str) {
that.uploadData.text = str;
that.toUploadData();
});
}
} else {
const file = items[i].getAsFile();
that.$message('剪切板文件正在上传,请稍等');
that.uploadData.file = file
that.toUploadData();
}
}
}
}
});
2022-12-19 15:21:24 +08:00
// 获取Banner
2022-12-23 12:32:18 +08:00
axios.get('/banner', {
headers: {
pwd: localStorage.getItem('pwd')
}
}).then(res => {
this.enableUpload = res.data.enable
2022-12-19 15:21:24 +08:00
this.banners = res.data.data
})
2022-12-13 11:29:33 +08:00
},
2022-12-13 18:51:14 +08:00
watch: {
code: function (code) {
if (code.length === 5) {
this.inout_disable = true;
this.getFile();
}
}
},
2022-12-13 11:29:33 +08:00
methods: {
http: function (method, url, data = {}, config = {}) {
return new Promise((resolve, reject) => {
axios({
method: method,
url: url,
data: data,
...config
}).then(res => {
this.$message({
message: res.data.detail,
type: 'success'
});
resolve(res.data)
}).catch(err => {
this.$message({
message: err.response.data.detail,
type: 'error'
});
})
})
},
2022-12-19 14:32:48 +08:00
copyText: function (value, style = 1) {
if (style === 0) {
2022-12-21 14:33:26 +08:00
value = `我给你分享了文件,取件码:${value},${window.location.href}?code=${value}`;
2022-12-19 14:32:48 +08:00
}
2022-12-19 13:59:44 +08:00
const input = document.createElement('input');
input.setAttribute('readonly', 'readonly');
2022-12-19 14:32:48 +08:00
input.setAttribute('value', value);
2022-12-19 13:59:44 +08:00
document.body.appendChild(input);
input.select();
if (document.execCommand('copy')) {
document.execCommand('copy');
this.$message({
message: '复制成功,快去分享给你的朋友吧',
type: 'success'
});
}
document.body.removeChild(input);
},
2022-12-13 11:29:33 +08:00
getFile: function () {
const that = this;
this.http('post', `?code=${that.code}`).then(res => {
that.quDrawer = true;
2022-12-22 12:11:32 +08:00
that.quFiles.unshift(res.data);
2022-12-13 11:29:33 +08:00
})
that.code = '';
that.input_disable = false
},
qrcodeUrl(file) {
2022-12-30 16:59:03 +08:00
return 'https://api.qrserver.com/v1/create-qr-code/?data=' + window.location.href + '?code=' + file.code
2022-12-13 11:29:33 +08:00
},
listenInput: function (value) {
if (this.code.length < 5) {
this.code += value;
}
2022-12-13 18:51:14 +08:00
},
changeInput: function (value) {
this.code = value;
2022-12-13 11:29:33 +08:00
},
2022-12-23 12:32:18 +08:00
checkFile: function (file) {
2022-12-27 13:27:23 +08:00
if (!this.enableUpload) {
2022-12-23 12:32:18 +08:00
this.$message({
message: '上传功能已关闭',
type: 'error'
});
return false
}
2022-12-27 13:27:23 +08:00
if (file != null) {
if (file.size > this.fileSizeLimit) {
this.$message({
message: `文件大小不能超过${this.fileSizeLimit/1024/1024}MB`,
type: 'error'
});
return false;
}
2022-12-23 12:32:18 +08:00
}
2022-12-27 13:27:23 +08:00
return true;
2022-12-23 12:32:18 +08:00
},
2022-12-13 11:29:33 +08:00
toUploadData: function () {
if (this.uploadData.text === '' && this.uploadData.file === null) {
this.$message({
message: '请先粘贴文字或者上传文件',
type: 'error'
});
} else {
2022-12-23 12:32:18 +08:00
if (this.checkFile(this.uploadData.file)) {
this.http('post', '/share', this.uploadData, {
headers: {
'Content-Type': 'multipart/form-data',
'pwd': this.pwd
}
}).then(res => {
this.jiFiles.unshift(res.data);
this.jiDrawer = true;
this.uploadData.text = '';
this.uploadData.file = null;
});
}
2022-12-13 11:29:33 +08:00
}
},
successUpload(response, file, fileList) {
this.$message({
message: response.detail,
2022-12-13 11:29:33 +08:00
type: 'success'
});
2022-12-22 12:11:32 +08:00
this.jiFiles.unshift(response.data);
2022-12-13 11:29:33 +08:00
},
errorUpload(error, file, fileList) {
error = JSON.parse(error.message)
this.$message({
message: error.detail,
type: 'error'
});
},
2022-12-15 16:34:18 +08:00
beforeUpload: function (file) {
2022-12-23 12:32:18 +08:00
return this.checkFile(file);
2022-12-15 16:34:18 +08:00
}
2022-12-13 11:29:33 +08:00
}
})
</script>
2022-12-19 22:28:59 +08:00
</html>