-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
349 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,18 @@ | ||
import request from '@/utils/request' | ||
|
||
export const refreshThumbs = () => | ||
export const __AVATAR_THUMB_SIZE__ = 128 | ||
|
||
export const refreshThumb = (src, thumb_size) => | ||
request({ | ||
url: `admin/image/refresh-thumb`, | ||
method: 'POST', | ||
timeout: 0, | ||
data: { src, thumb_size }, | ||
}) | ||
|
||
export const getAllAvailablePhoto = () => | ||
request({ | ||
url: 'admin/image/refresh-thumb', | ||
url: `admin/image/available-photo`, | ||
method: 'GET', | ||
timeout: 0, | ||
}) |
120 changes: 120 additions & 0 deletions
120
dashboard/src/views/dashboard/components/refresh-thumbs.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
<template> | ||
<div> | ||
<ElButton | ||
size="small" | ||
type="primary" | ||
icon="el-icon-refresh" | ||
@click="processing || refreshThumbsConfirm()" | ||
>刷新缩略图</ElButton> | ||
<ElProgress | ||
v-if="show_progress" | ||
:percentage="percentage" | ||
:color="color" | ||
/> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { refreshThumb, getAllAvailablePhoto, __AVATAR_THUMB_SIZE__ } from '@/api/image' | ||
import { getList as getMemberList } from '@/api/member' | ||
const initProgress = () => ({ total: 0, success: 0, failure: 0 }) | ||
export default { | ||
data: () => ({ | ||
...initProgress(), | ||
processing: false, | ||
show_progress: false, | ||
}), | ||
computed: { | ||
color() { return (this.failure > 0) ? '#e6a23c' : '#409eff' }, | ||
current() { return this.success + this.failure }, | ||
percentage() { | ||
return (this.total === 0) ? 0 : Math.ceil( | ||
100 * (this.current / this.total) | ||
) | ||
}, | ||
}, | ||
watch: { | ||
processing(val) { | ||
if (val === true) { | ||
this.show_progress = true | ||
} | ||
} | ||
}, | ||
methods: { | ||
async refreshThumbs() { | ||
Object.assign(this, initProgress()) | ||
const [photos, members] = await Promise.all([ | ||
getAllAvailablePhoto(), getMemberList() | ||
]) | ||
const task_list = [ | ||
...photos.map(p => ( | ||
[`相片(id=${p.id})`, p.src] | ||
)), | ||
...members.map(m => ( | ||
[`成员头像(id=${m.id})`, m.avatar_src, __AVATAR_THUMB_SIZE__] | ||
)) | ||
] | ||
this.total = task_list.length | ||
for (const [name, ...args] of task_list) { | ||
try { | ||
await refreshThumb(...args) | ||
this.success = this.success + 1 | ||
} catch (err) { | ||
this.failure = this.failure + 1 | ||
this.$emit('warning', `${name}的缩略图生成失败`, err) | ||
} | ||
} | ||
}, | ||
async refreshThumbsConfirm() { | ||
const confirm = await this.confirm('', `你确定要刷新吗?`, { | ||
confirmButtonClass: 'el-button--warning', | ||
}) | ||
if (!confirm) { return } | ||
try { | ||
this.processing = true | ||
await this.refreshThumbs() | ||
if (this.failure === 0) { | ||
this.$emit('success', `所有缩略图已刷新`) | ||
} | ||
} catch (err) { | ||
this.$emit('error', '刷新缓存失败', err) | ||
} finally { | ||
this.processing = false | ||
} | ||
}, | ||
async confirm(title, content, appendOpt = {}) { | ||
const opt = Object.assign({ | ||
confirmButtonText: '确定', | ||
cancelButtonText: '取消', | ||
confirmButtonClass: 'el-button--warning', | ||
showClose: false, | ||
}, appendOpt) | ||
return this.$confirm(content, title, opt) | ||
.then(() => true) | ||
.catch(() => false) | ||
}, | ||
} | ||
} | ||
</script> | ||
|
||
<style lang="scss" scoped> | ||
.dashboard { | ||
&-container { | ||
margin: 30px; | ||
} | ||
&-text { | ||
font-size: 30px; | ||
line-height: 46px; | ||
} | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.