-
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
11 changed files
with
365 additions
and
120 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
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, | ||
}) |
153 changes: 153 additions & 0 deletions
153
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,153 @@ | ||
<template> | ||
<div> | ||
<ElButton | ||
size="small" | ||
type="primary" | ||
icon="el-icon-refresh" | ||
@click="processing || refreshThumbsConfirm()" | ||
>刷新缩略图</ElButton> | ||
<div v-if="show"> | ||
<ElProgress | ||
:percentage="percentage('photo')" | ||
:color="color('photo')" | ||
/> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import { refreshThumb, getAllAvailablePhoto, __AVATAR_THUMB_SIZE__ } from '@/api/image' | ||
import { getList as getMemberList } from '@/api/member' | ||
export default { | ||
data: () => ({ | ||
show: false, | ||
processing: false, | ||
member_progress: [], | ||
photo_progress: [], | ||
}), | ||
watch: { | ||
processing(val) { | ||
if (val === true) { | ||
this.show = true | ||
} | ||
} | ||
}, | ||
mounted() { | ||
}, | ||
methods: { | ||
getProgress(property) { | ||
const [total = 0, ...progress] = this[`${property}_progress`] | ||
const success = progress.filter(p => p).length | ||
const failure = progress.filter(p => !p).length | ||
return [total, progress.length, success, failure] | ||
}, | ||
percentage(property) { | ||
const [total, progress] = this.getProgress(property) | ||
if (total === 0) { | ||
return 0 | ||
} else { | ||
return Math.ceil(100 * (progress / total)) | ||
} | ||
}, | ||
color(property) { | ||
const [, , , failure] = this.getProgress(property) | ||
if (failure > 0) { | ||
return '#e6a23c' | ||
} else { | ||
return '#409eff' | ||
} | ||
}, | ||
Progress(property) { | ||
const [total, progress, success, failure] = this.getProgress(property) | ||
console.log('Progress', total, success, failure) | ||
return { | ||
per: (total === 0) ? 0 : 100 * (progress.length / total), | ||
format: () => { | ||
const [, , success, failure] = this.getProgress(property) | ||
return `成功: ${success}${failure.length ? ` (失败: ${failure.length})` : ''}` | ||
}, | ||
} | ||
}, | ||
async refreshThumbs() { | ||
const [photos, members] = await Promise.all([ | ||
getAllAvailablePhoto(), getMemberList() | ||
]) | ||
const task_list = [ | ||
// eslint-disable-next-line no-extra-parens | ||
...photos.map(p => ( | ||
() => { | ||
return refreshThumb(p.src) | ||
} | ||
)), | ||
// eslint-disable-next-line no-extra-parens | ||
...members.map(m => ( | ||
() => { | ||
return refreshThumb(m.avatar_src, __AVATAR_THUMB_SIZE__) | ||
} | ||
)) | ||
] | ||
{ | ||
this.photo_progress = [task_list.length] | ||
for (const task of task_list) { | ||
try { | ||
await task() | ||
this.photo_progress = [...this.photo_progress, true] | ||
} catch { | ||
this.photo_progress = [...this.photo_progress, false] | ||
} | ||
} | ||
const [, , , failure] = this.getProgress('photo') | ||
if (failure > 0) { | ||
this.$emit('warning', `有${failure}个图片的缩略图刷新失败`) | ||
} | ||
} | ||
}, | ||
async refreshThumbsConfirm() { | ||
const confirm = await this.confirm('', `你确定要刷新吗?`, { | ||
confirmButtonClass: 'el-button--warning', | ||
}) | ||
if (!confirm) { return } | ||
try { | ||
this.processing = true | ||
await this.refreshThumbs() | ||
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.