ui: 提及 使用 a 而不是 span
This commit is contained in:
@@ -3,7 +3,7 @@ import DataCaches from "../../api/DataCaches.ts"
|
|||||||
import { snackbar } from "../snackbar.ts"
|
import { snackbar } from "../snackbar.ts"
|
||||||
|
|
||||||
customElements.define('chat-mention', class extends HTMLElement {
|
customElements.define('chat-mention', class extends HTMLElement {
|
||||||
declare span: HTMLSpanElement
|
declare link: HTMLAnchorElement
|
||||||
static observedAttributes = ['user-id']
|
static observedAttributes = ['user-id']
|
||||||
constructor() {
|
constructor() {
|
||||||
super()
|
super()
|
||||||
@@ -13,10 +13,11 @@ customElements.define('chat-mention', class extends HTMLElement {
|
|||||||
connectedCallback() {
|
connectedCallback() {
|
||||||
const shadow = this.shadowRoot as ShadowRoot
|
const shadow = this.shadowRoot as ShadowRoot
|
||||||
|
|
||||||
this.span = document.createElement('span')
|
this.link = document.createElement('a')
|
||||||
this.span.style.fontSynthesis = 'style weight'
|
this.link.style.fontSynthesis = 'style weight'
|
||||||
this.span.style.color = 'rgb(var(--mdui-color-primary))'
|
this.link.style.color = 'rgb(var(--mdui-color-primary))'
|
||||||
shadow.appendChild(this.span)
|
this.link.href = 'javascript:void(0)'
|
||||||
|
shadow.appendChild(this.link)
|
||||||
|
|
||||||
this.update()
|
this.update()
|
||||||
}
|
}
|
||||||
@@ -24,33 +25,33 @@ customElements.define('chat-mention', class extends HTMLElement {
|
|||||||
this.update()
|
this.update()
|
||||||
}
|
}
|
||||||
async update() {
|
async update() {
|
||||||
if (this.span == null) return
|
if (this.link == null) return
|
||||||
|
|
||||||
const userId = $(this).attr('user-id')
|
const userId = $(this).attr('user-id')
|
||||||
const chatId = $(this).attr('chat-id')
|
const chatId = $(this).attr('chat-id')
|
||||||
const text = $(this).attr('text')
|
const text = $(this).attr('text')
|
||||||
this.span.style.fontStyle = ''
|
this.link.style.fontStyle = ''
|
||||||
if (chatId) {
|
if (chatId) {
|
||||||
const chat = await DataCaches.getChatInfo(chatId)
|
const chat = await DataCaches.getChatInfo(chatId)
|
||||||
this.span.textContent = chat?.title
|
this.link.textContent = chat?.title
|
||||||
this.span.onclick = () => {
|
this.link.onclick = () => {
|
||||||
// deno-lint-ignore no-window
|
// deno-lint-ignore no-window
|
||||||
window.openChatInfoDialog(chat)
|
window.openChatInfoDialog(chat)
|
||||||
}
|
}
|
||||||
} else if (userId) {
|
} else if (userId) {
|
||||||
const user = await DataCaches.getUserProfile(userId)
|
const user = await DataCaches.getUserProfile(userId)
|
||||||
this.span.textContent = user?.nickname
|
this.link.textContent = user?.nickname
|
||||||
this.span.onclick = () => {
|
this.link.onclick = () => {
|
||||||
// deno-lint-ignore no-window
|
// deno-lint-ignore no-window
|
||||||
window.openUserInfoDialog(user)
|
window.openUserInfoDialog(user)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
text && (this.span.textContent = text)
|
text && (this.link.textContent = text)
|
||||||
if (!(userId || chatId)) {
|
if (!(userId || chatId)) {
|
||||||
this.span.textContent = "无效的提及"
|
this.link.textContent = "无效的提及"
|
||||||
this.span.style.fontStyle = 'italic'
|
this.link.style.fontStyle = 'italic'
|
||||||
this.span.onclick = () => {
|
this.link.onclick = () => {
|
||||||
snackbar({
|
snackbar({
|
||||||
message: "该提及没有指定用户或者对话!",
|
message: "该提及没有指定用户或者对话!",
|
||||||
placement: 'top',
|
placement: 'top',
|
||||||
|
|||||||
Reference in New Issue
Block a user