change: 切换标签页不会滚动到底部

This commit is contained in:
MoonLeeeaf
2024-06-15 12:44:57 +08:00
parent 1cb0dd3885
commit 585ea41831
2 changed files with 38 additions and 36 deletions

View File

@@ -53,9 +53,9 @@ ChatMsgAdapter.initMsgElementEvents()
ChatMsgAdapter.initInputResizer() ChatMsgAdapter.initInputResizer()
const showLinkDialog = (link) => mdui.alert(decodeURI(link) + "<br/>如果你确认此链接是安全的, 那么请<a class=\"mdui-text-color-theme-accent\" href=\"" + link + "\">点我</a>", '链接', () => { }, { confirmText: "关闭" }) const showLinkDialog = (link) => mdui.alert(decodeURI(link) + "<br/>如果你确认此链接是安全的, 那么请<a class=\"mdui-text-color-theme\" href=\"" + link + "\">点我</a>", '链接', () => { }, { confirmText: "关闭" })
const showImageDialog = (link, id, alt) => mdui.alert(`此图片链接来源未知: ${decodeURI(link)}<br/>如果你希望加载, 请<a class="mdui-text-color-theme-accent" mdui-dialog-close onclick="$('#${id}').html('<img src=\\'${link}\\' alt=\\'${decodeURI(alt)}\\' class=\\'message-image\\'></img>')">点我</a>`, '外部图片', () => { }, { confirmText: "关闭" }) const showImageDialog = (link, id, alt) => mdui.alert(`此图片链接来源未知: ${decodeURI(link)}<br/>如果你希望加载, 请<a class="mdui-text-color-theme" mdui-dialog-close onclick="$('#${id}').html('<img src=\\'${link}\\' alt=\\'${decodeURI(alt)}\\' class=\\'message-image\\'></img>')">点我</a>`, '外部图片', () => { }, { confirmText: "关闭" })
const showCodeDialog = (code) => mdui.alert(`<pre><code>${decodeURI(code)}</code></pre>`, '代码块', () => { }, { confirmText: "关闭" }) const showCodeDialog = (code) => mdui.alert(`<pre><code>${decodeURI(code)}</code></pre>`, '代码块', () => { }, { confirmText: "关闭" })
@@ -70,7 +70,7 @@ const renderer = {
return text return text
}, },
link(href, title, text) { link(href, title, text) {
return `<a class="mdui-text-color-theme-accent" onclick="showLinkDialog('${encodeURI(href)}')">[链接] ${text}</a>` return `<a class="mdui-text-color-theme" onclick="showLinkDialog('${encodeURI(href)}')">[链接] ${text}</a>`
}, },
image(href, title, text) { image(href, title, text) {
let h = Hash.sha256(href) let h = Hash.sha256(href)
@@ -81,10 +81,10 @@ const renderer = {
if (out) if (out)
return `<img src="${encodeURI(href)}" alt="${text}" class="message-image"></img>` return `<img src="${encodeURI(href)}" alt="${text}" class="message-image"></img>`
else else
return `<div id="${h}"><a class="mdui-text-color-theme-accent" onclick="showImageDialog('${encodeURI(href)}', '${h}', '${encodeURI(text)}')">[外部图片] ${text}</a></div>` return `<div id="${h}"><a class="mdui-text-color-theme" onclick="showImageDialog('${encodeURI(href)}', '${h}', '${encodeURI(text)}')">[外部图片] ${text}</a></div>`
}, },
code(src) { code(src) {
return `<a class="mdui-text-color-theme-accent" onclick="showCodeDialog(\`${encodeURI(src)}\`)">[代码块]</a>` return `<a class="mdui-text-color-theme" onclick="showCodeDialog(\`${encodeURI(src)}\`)">[代码块]</a>`
}, },
} }

View File

@@ -9,12 +9,13 @@
// ================================ // ================================
class CurrentUser { class CurrentUser {
/** @type { String } */
static myAccessToken static myAccessToken
/** /**
* 登录账号 * 登录账号
* @param {String} name * @param { String } name
* @param {String} passwd * @param { String } passwd
* @param {Function} callback * @param { Function } callback
*/ */
static signIn(name, passwd, cb) { static signIn(name, passwd, cb) {
client.emit("user.signIn", { client.emit("user.signIn", {
@@ -29,9 +30,9 @@ class CurrentUser {
} }
/** /**
* 注册账号 * 注册账号
* @param {String} name * @param { String } name
* @param {String} passwd * @param { String } passwd
* @param {Function} callback * @param { Function } callback
*/ */
static signUp(name, passwd, cb) { static signUp(name, passwd, cb) {
client.emit("user.signUp", { client.emit("user.signUp", {
@@ -46,8 +47,8 @@ class CurrentUser {
} }
/** /**
* 登录对话框中的登录逻辑 * 登录对话框中的登录逻辑
* @param {String} name * @param { String } name
* @param {String} passwd * @param { String } passwd
*/ */
static signInWithDialog(name, passwd) { static signInWithDialog(name, passwd) {
this.signIn(name, passwd, (re) => { this.signIn(name, passwd, (re) => {
@@ -59,8 +60,8 @@ class CurrentUser {
} }
/** /**
* 设置昵称 * 设置昵称
* @param {String} nick * @param { String } nick
* @param {Function} callback * @param { Function } callback
*/ */
static async setNick(nick, cb) { static async setNick(nick, cb) {
client.emit("user.setNick", { client.emit("user.setNick", {
@@ -75,16 +76,16 @@ class CurrentUser {
} }
/** /**
* 获取用户头像的链接 * 获取用户头像的链接
* @param {String} name * @param { String } name
* @returns {String} headImageUrl * @returns { String } headImageUrl
*/ */
static getUserHeadUrl(name) { static getUserHeadUrl(name) {
return client.io.uri + "/users_head/" + name + ".png" return client.io.uri + "/users_head/" + name + ".png"
} }
/** /**
* 获取访问密钥 * 获取访问密钥
* @param {String} name * @param { String } name
* @returns {Promise<String>} accessToken * @returns { Promise<String> } accessToken
*/ */
static async getAccessToken(er) { static async getAccessToken(er) {
if (this.myAccessToken == null) if (this.myAccessToken == null)
@@ -104,7 +105,7 @@ class CurrentUser {
} }
/** /**
* 上传头像回调事件 * 上传头像回调事件
* @param {Element} element * @param { Element } element
*/ */
static async uploadHeadImageCallback(self) { static async uploadHeadImageCallback(self) {
let img = self.files[0] let img = self.files[0]
@@ -169,7 +170,7 @@ class CurrentUser {
} }
/** /**
* 打开资料卡 * 打开资料卡
* @param {String} name * @param { String } name
*/ */
static async openProfileDialog(name) { static async openProfileDialog(name) {
viewBinding.dialogProfileHead.attr("src", CurrentUser.getUserHeadUrl(name)) viewBinding.dialogProfileHead.attr("src", CurrentUser.getUserHeadUrl(name))
@@ -186,8 +187,8 @@ class NickCache {
static data = {} static data = {}
/** /**
* 获取昵称 * 获取昵称
* @param {String} name * @param { String } name
* @returns {String} nick * @returns { String } nick
*/ */
static async getNick(name) { static async getNick(name) {
return await new Promise((res, _rej) => { return await new Promise((res, _rej) => {
@@ -227,7 +228,7 @@ class ContactsList {
for (let index in ls) { for (let index in ls) {
let name = ls[index] let name = ls[index]
let dick = await NickCache.getNick(name) let dick = await NickCache.getNick(name)
$($.parseHTML(`<li class="mdui-list-item mdui-ripple" mdui-drawer-close><div class="mdui-list-item-avatar"><img src="${ CurrentUser.getUserHeadUrl(name) }" onerror="this.src='res/default_head.png'" /></div><div class="mdui-list-item-content">` + dick + `</div></li>`)).appendTo(viewBinding.contactsList).click(() => { $($.parseHTML(`<li class="mdui-list-item mdui-ripple" mdui-drawer-close><div class="mdui-list-item-avatar"><img src="${CurrentUser.getUserHeadUrl(name)}" onerror="this.src='res/default_head.png'" /></div><div class="mdui-list-item-content">` + dick + `</div></li>`)).appendTo(viewBinding.contactsList).click(() => {
ChatMsgAdapter.switchTo(name, "single") ChatMsgAdapter.switchTo(name, "single")
}) })
} }
@@ -236,7 +237,7 @@ class ContactsList {
} }
/** /**
* 添加联系人/群峦 * 添加联系人/群峦
* @param {String} nameOrId * @param { String } nameOrId
*/ */
static async add(name, type) { static async add(name, type) {
if (type == "single") { if (type == "single") {
@@ -303,7 +304,9 @@ class ChatPage {
this.chatType = type this.chatType = type
ChatTabManager.add(title, this.chatTarget) ChatTabManager.add(title, this.chatTarget)
this.chatPageElement = $($.parseHTML(`<div class="chat-seesion" id="chatPageTargetIs${this.chatTarget}" target="${this.chatTarget}"></div>`)) this.chatPageElement = $($.parseHTML(`<div class="chat-seesion" id="chatPageTargetIs${this.chatTarget}" target="${this.chatTarget}"></div>`))
this.chatPageElement.hide()
this.chatPageElement.appendTo(viewBinding.pageChatSeesion) this.chatPageElement.appendTo(viewBinding.pageChatSeesion)
;(async () => await this.loadMore())()
} }
/** /**
* 获取当前的聊天栏 * 获取当前的聊天栏
@@ -335,13 +338,12 @@ class ChatPage {
tbe.removeClass("mdui-tab-active") tbe.removeClass("mdui-tab-active")
} }
$(this.chatPageElement).empty()
$(this.chatPageElement).attr("actived", "true") $(this.chatPageElement).attr("actived", "true")
$(this.chatPageElement).show()
ChatTabManager.find(this.chatTarget).addClass("mdui-tab-active") ChatTabManager.find(this.chatTarget).addClass("mdui-tab-active")
await this.loadMore()
ChatMsgAdapter.scrollToBottom() $(this.chatPageElement).show()
} }
/** /**
* 连带Tab一起销毁 * 连带Tab一起销毁
@@ -353,7 +355,7 @@ class ChatPage {
} }
/** /**
* 加载更多聊天记录 * 加载更多聊天记录
* @param {int} 加载数量 * @param { int } 加载数量
*/ */
async loadMore(limit) { async loadMore(limit) {
let histroy = await this.getHistroy(this.minMsgId, limit == null ? 13 : limit) let histroy = await this.getHistroy(this.minMsgId, limit == null ? 13 : limit)
@@ -379,8 +381,8 @@ class ChatPage {
} }
/** /**
* 获取聊天消息记录 * 获取聊天消息记录
* @param {int} 起始点 * @param { int } 起始点
* @param {int} 获取数量 * @param { int } 获取数量
*/ */
async getHistroy(start, limit) { async getHistroy(start, limit) {
if (this.chatType == "single") if (this.chatType == "single")
@@ -517,8 +519,8 @@ class ChatMsgAdapter {
static resizeDick static resizeDick
/** /**
* 切换到某一个聊天对象 * 切换到某一个聊天对象
* @param {String} name * @param { String } name
* @param {String} type * @param { String } type
*/ */
static async switchTo(name, type) { static async switchTo(name, type) {
if (!ChatPage.cached[name]) if (!ChatPage.cached[name])
@@ -528,7 +530,7 @@ class ChatMsgAdapter {
} }
/** /**
* 是否在底部 * 是否在底部
* @returns {Boolean} 是否在底部 * @returns { Boolean } 是否在底部
*/ */
static isAtBottom() { static isAtBottom() {
let elementRect = viewBinding.pageChatSeesion.get(0).getBoundingClientRect() let elementRect = viewBinding.pageChatSeesion.get(0).getBoundingClientRect()