feat(ui): add max. file size check before upload attachment (#2709)
Co-authored-by: TAKAHASHI Shuuji <shuuji3@gmail.com>
This commit is contained in:
parent
8f04ea8eee
commit
3f0b234cc4
5 changed files with 66 additions and 1 deletions
|
@ -77,3 +77,32 @@ export function useTimeAgoOptions(short = false): UseTimeAgoOptions<false> {
|
|||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function useFileSizeFormatter() {
|
||||
const { locale } = useI18n()
|
||||
|
||||
const formatters = computed(() => ([
|
||||
Intl.NumberFormat(locale.value, {
|
||||
style: 'unit',
|
||||
unit: 'megabyte',
|
||||
unitDisplay: 'narrow',
|
||||
maximumFractionDigits: 0,
|
||||
}),
|
||||
Intl.NumberFormat(locale.value, {
|
||||
style: 'unit',
|
||||
unit: 'kilobyte',
|
||||
unitDisplay: 'narrow',
|
||||
maximumFractionDigits: 0,
|
||||
}),
|
||||
]))
|
||||
|
||||
const megaByte = 1024 * 1024
|
||||
|
||||
function formatFileSize(size: number) {
|
||||
return size >= megaByte
|
||||
? formatters.value[0].format(size / megaByte)
|
||||
: formatters.value[1].format(size / 1024)
|
||||
}
|
||||
|
||||
return { formatFileSize }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue