chore(ui): 圖片加載失敗使用 snackbar 提示
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import { $ } from 'mdui/jq'
|
import { $ } from 'mdui/jq'
|
||||||
import { dialog } from 'mdui'
|
|
||||||
|
|
||||||
import 'pinch-zoom-element'
|
import 'pinch-zoom-element'
|
||||||
|
import { snackbar } from "../snackbar.ts";
|
||||||
|
|
||||||
function openImageViewer(src: string) {
|
function openImageViewer(src: string) {
|
||||||
$('#image-viewer-dialog-inner').empty()
|
$('#image-viewer-dialog-inner').empty()
|
||||||
@@ -25,32 +25,18 @@ customElements.define('chat-image', class extends HTMLElement {
|
|||||||
const e = new Image()
|
const e = new Image()
|
||||||
e.style.maxWidth = "100%"
|
e.style.maxWidth = "100%"
|
||||||
e.style.maxHeight = "90%"
|
e.style.maxHeight = "90%"
|
||||||
e.style.marginTop = "13px"
|
e.style.marginTop = '5px'
|
||||||
|
e.style.marginBottom = '5px'
|
||||||
e.style.borderRadius = "var(--mdui-shape-corner-medium)"
|
e.style.borderRadius = "var(--mdui-shape-corner-medium)"
|
||||||
e.alt = $(this).attr('alt') || ""
|
e.alt = $(this).attr('alt') || ""
|
||||||
e.onerror = () => {
|
e.onerror = () => {
|
||||||
const bak = $(this).html()
|
const src = $(this).attr('src')
|
||||||
$(this).html(`<br/><mdui-icon name="broken_image" style="font-size: 2rem;"></mdui-icon>`)
|
$(this).html(`<mdui-icon name="broken_image" style="font-size: 2rem;"></mdui-icon>`)
|
||||||
$(this).attr('alt', '無法加載圖像')
|
$(this).attr('alt', '無法加載圖像')
|
||||||
$(this).on('click', () => {
|
$(this).on('click', () => {
|
||||||
dialog({
|
snackbar({
|
||||||
headline: "圖片無法載入",
|
message: `圖片 (${src}) 無法加載!`,
|
||||||
description: "您是否需要重新加載?",
|
placement: 'top'
|
||||||
actions: [
|
|
||||||
{
|
|
||||||
text: "重載",
|
|
||||||
onClick: () => {
|
|
||||||
$(this).html(bak)
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
text: "取消",
|
|
||||||
onClick: () => {
|
|
||||||
return false
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user