| ¶Ô±ÈÐÂÎļþ |
| | |
| | | import { formatDateTime } from '#/packages/utils/src'; |
| | | |
| | | /** å±ç¤ºç¨æ·åç§° */ |
| | | export function formatUserLabel( |
| | | nickname: string | undefined, |
| | | userId: number | undefined, |
| | | ) { |
| | | if (!userId) { |
| | | return '-'; |
| | | } |
| | | return `${nickname || '-'} (${userId})`; |
| | | } |
| | | |
| | | /** å±ç¤ºç¾¤åç§° */ |
| | | export function formatGroupLabel( |
| | | name: string | undefined, |
| | | groupId: number | undefined, |
| | | ) { |
| | | if (!groupId) { |
| | | return '-'; |
| | | } |
| | | return `${name || '-'} (${groupId})`; |
| | | } |
| | | |
| | | /** å±ç¤ºæ¥ææ¶é´ */ |
| | | export function formatDateTimeText(value?: Date | number | string) { |
| | | return value ? (formatDateTime(value) as string) : '-'; |
| | | } |
| | | |
| | | /** æ ¼å¼å JSON */ |
| | | export function formatJsonText(content?: string) { |
| | | if (!content) { |
| | | return ''; |
| | | } |
| | | try { |
| | | return JSON.stringify(JSON.parse(content), null, 2); |
| | | } catch { |
| | | return content; |
| | | } |
| | | } |
| | | |
| | | /** æ¢æµå¾ç尺寸 */ |
| | | export function probeImageSize(url: string) { |
| | | return new Promise<{ height: number; width: number }>((resolve, reject) => { |
| | | const img = new Image(); |
| | | img.addEventListener('load', () => { |
| | | resolve({ |
| | | width: img.naturalWidth || img.width, |
| | | height: img.naturalHeight || img.height, |
| | | }); |
| | | }); |
| | | img.addEventListener('error', reject); |
| | | img.src = url; |
| | | }); |
| | | } |