test/custom-admin-ui #3
@@ -41,8 +41,8 @@ index_html = open('templates/index.html', 'r', encoding='utf-8').read() \
|
||||
.replace('{{title}}', settings.TITLE) \
|
||||
.replace('{{description}}', settings.DESCRIPTION) \
|
||||
.replace('{{keywords}}', settings.KEYWORDS) \
|
||||
.replace("'{{fileSizeLimit}}'", str(settings.FILE_SIZE_LIMIT))
|
||||
# 管理页面
|
||||
.replace("'{{fileSizeLimit}}'", str(settings.FILE_SIZE_LIMIT)) \
|
||||
# 管理页面
|
||||
admin_html = open('templates/admin.html', 'r', encoding='utf-8').read() \
|
||||
.replace('{{title}}', settings.TITLE) \
|
||||
.replace('{{description}}', settings.DESCRIPTION) \
|
||||
@@ -107,7 +107,7 @@ async def index():
|
||||
|
||||
|
||||
@app.get('/banner')
|
||||
async def banner(s: AsyncSession = Depends(get_session)):
|
||||
async def banner(request: Request, s: AsyncSession = Depends(get_session)):
|
||||
# 数据库查询config
|
||||
config = (await s.execute(select(Values).filter(Values.key == 'config'))).scalar_one_or_none()
|
||||
# 如果存在config,就返回config的value
|
||||
@@ -119,6 +119,7 @@ async def banner(s: AsyncSession = Depends(get_session)):
|
||||
# 如果不存在config,就返回默认的banner
|
||||
return {
|
||||
'detail': 'banner',
|
||||
'enable': request.headers.get('pwd', '') == settings.ADMIN_PASSWORD,
|
||||
'data': [{
|
||||
'text': 'FileCodeBox',
|
||||
'url': 'https://github.com/vastsa/FileCodeBox',
|
||||
|
||||
+37
-19
@@ -271,6 +271,7 @@
|
||||
fileSizeLimit: '{{fileSizeLimit}}',
|
||||
pwd: localStorage.getItem('pwd') || '',
|
||||
banners: [],
|
||||
enableUpload: false,
|
||||
uploadData: {
|
||||
style: '2',
|
||||
type: '1',
|
||||
@@ -313,7 +314,12 @@
|
||||
}
|
||||
});
|
||||
// 获取Banner
|
||||
axios.get('/banner').then(res => {
|
||||
axios.get('/banner', {
|
||||
headers: {
|
||||
pwd: localStorage.getItem('pwd')
|
||||
}
|
||||
}).then(res => {
|
||||
this.enableUpload = res.data.enable
|
||||
this.banners = res.data.data
|
||||
})
|
||||
},
|
||||
@@ -385,6 +391,22 @@
|
||||
changeInput: function (value) {
|
||||
this.code = value;
|
||||
},
|
||||
checkFile: function (file) {
|
||||
if (!this.enable) {
|
||||
this.$message({
|
||||
message: '上传功能已关闭',
|
||||
type: 'error'
|
||||
});
|
||||
return false
|
||||
}
|
||||
if (file.size > this.fileSizeLimit) {
|
||||
this.$message({
|
||||
message: `文件大小不能超过${this.fileSizeLimit/1024/1024}MB`,
|
||||
type: 'error'
|
||||
});
|
||||
return false
|
||||
}
|
||||
},
|
||||
toUploadData: function () {
|
||||
if (this.uploadData.text === '' && this.uploadData.file === null) {
|
||||
this.$message({
|
||||
@@ -392,17 +414,19 @@
|
||||
type: 'error'
|
||||
});
|
||||
} else {
|
||||
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;
|
||||
});
|
||||
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;
|
||||
});
|
||||
}
|
||||
}
|
||||
},
|
||||
successUpload(response, file, fileList) {
|
||||
@@ -420,13 +444,7 @@
|
||||
});
|
||||
},
|
||||
beforeUpload: function (file) {
|
||||
if (file.size > this.fileSizeLimit) {
|
||||
this.$message({
|
||||
message: `文件大小不能超过${this.fileSizeLimit/1024/1024}MB`,
|
||||
type: 'error'
|
||||
});
|
||||
return false
|
||||
}
|
||||
return this.checkFile(file);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user