Skip to content

Commit

Permalink
feat:优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
gzydong committed Jan 3, 2024
1 parent 3360bc3 commit 5e58736
Show file tree
Hide file tree
Showing 16 changed files with 77 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/components/group/GroupLaunch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const onLoad = () => {
.then((res) => {
if (res.code == 200 && res.data) {
let list = res.data || []
items.value = list.map((item) => {
items.value = list.map((item: any) => {
return Object.assign(item, {
nickname: item.friend_remark ? item.friend_remark : item.nickname,
checked: false
Expand Down
8 changes: 4 additions & 4 deletions src/components/talk/ForwardRecord.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { useInject } from '@/hooks'
const emit = defineEmits(['close'])
const props = defineProps({
recordId: {
type: Number,
default: 0
msgId: {
type: String,
required: true
}
})
Expand All @@ -25,7 +25,7 @@ const onMaskClick = () => {
const onLoadData = () => {
ServeGetForwardRecords({
record_id: props.recordId
msg_id: props.msgId
}).then((res) => {
if (res.code == 200) {
items.value = res.data.items || []
Expand Down
3 changes: 2 additions & 1 deletion src/components/talk/message/CodeMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ const onClipboard = () => {
</template>
<style lang="less" scoped>
.im-message-code {
min-width: 150px;
min-width: 300px;
min-height: 100px;
border-radius: 10px;
overflow-x: auto;
border: 1px solid var(--border-color);
Expand Down
2 changes: 1 addition & 1 deletion src/components/talk/message/FileMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ defineProps<{
</div>
</div>
<div class="footer">
<a @click="download(data.id)">下载</a>
<a @click="download(data.msg_id)">下载</a>
<a>在线预览</a>
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion src/components/talk/message/ForwardMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const onClick = () => {
<span>转发:聊天会话记录 ({{ extra.msg_ids.length }}条)</span>
</div>

<ForwardRecord v-if="isShowRecord" :record-id="data.id" @close="isShowRecord = false" />
<ForwardRecord v-if="isShowRecord" :msg-id="data.msg_id" @close="isShowRecord = false" />
</section>
</template>

Expand Down
2 changes: 1 addition & 1 deletion src/components/talk/message/VoteMessage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const onSubmit = () => {
})
ServeConfirmVoteHandle({
record_id: props.data.id,
msg_id: props.data.msg_id,
options: items.join(',')
}).then((res) => {
if (res.code == 200) {
Expand Down
6 changes: 4 additions & 2 deletions src/connect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ class Connect {
return
}

for (const msgid of data.ids) {
dialogueStore.updateDialogueRecord({ id: msgid, is_read: 1 })
const { msg_ids = [] } = data

for (const msgid of msg_ids) {
dialogueStore.updateDialogueRecord({ msg_id: msgid, is_read: 1 })
}
})
}
Expand Down
5 changes: 2 additions & 3 deletions src/event/revoke.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Revoke extends Base {
this.sender_id = resource.sender_id
this.receiver_id = resource.receiver_id
this.talk_type = resource.talk_type
this.record_id = resource.record_id
this.msg_id = resource.msg_id

this.handle()
}
Expand Down Expand Up @@ -67,7 +67,6 @@ class Revoke extends Base {
}

handle() {
console.log(this.resource)
useTalkStore().updateItem({
index_name: this.getIndexName(),
msg_text: this.resource.text,
Expand All @@ -80,7 +79,7 @@ class Revoke extends Base {
}

useDialogueStore().updateDialogueRecord({
id: this.record_id,
msg_id: this.msg_id,
is_revoke: 1
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/event/talk.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ class Talk extends Base {
setTimeout(() => {
ws.emit('im.message.read', {
receiver_id: this.sender_id,
msg_id: [this.resource.id]
msg_ids: [this.resource.msg_id]
})
}, 1000)
}
Expand Down
39 changes: 27 additions & 12 deletions src/store/modules/dialogue.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import { defineStore } from 'pinia'
import { ServeRemoveRecords, ServeRevokeRecords, ServePublishMessage } from '@/api/chat'
import {
ServeRemoveRecords,
ServeRevokeRecords,
ServePublishMessage,
ServeCollectEmoticon
} from '@/api/chat'
import { ServeGetGroupMembers } from '@/api/group'
import { useEditorStore } from './editor'

// 键盘消息事件定时器
let keyboardTimeout = null
Expand Down Expand Up @@ -125,15 +131,17 @@ export const useDialogueStore = defineStore('dialogue', {

// 更新对话记录
updateDialogueRecord(params) {
const item = this.records.find((item) => item.id === params.id)
const { msg_id = '' } = params

const item = this.records.find((item) => item.msg_id === msg_id)

item && Object.assign(item, params)
},

// 批量删除对话记录
batchDelDialogueRecord(ids) {
ids.forEach((id) => {
const index = this.records.findIndex((item) => item.id === id)
batchDelDialogueRecord(msgIds = []) {
msgIds.forEach((msgid) => {
const index = this.records.findIndex((item) => item.msg_id === msgid)

if (index >= 0) this.records.splice(index, 1)
})
Expand Down Expand Up @@ -168,25 +176,25 @@ export const useDialogueStore = defineStore('dialogue', {
},

// 删除聊天记录
ApiDeleteRecord(ids = []) {
ApiDeleteRecord(msgIds = []) {
ServeRemoveRecords({
talk_type: this.talk.talk_type,
receiver_id: this.talk.receiver_id,
record_id: ids.join(',')
msg_ids: msgIds
}).then((res) => {
if (res.code == 200) {
this.batchDelDialogueRecord(ids)
this.batchDelDialogueRecord(msgIds)
} else {
window['$message'].warning(res.message)
}
})
},

// 撤销聊天记录
ApiRevokeRecord(record_id) {
ServeRevokeRecords({ record_id }).then((res) => {
ApiRevokeRecord(msg_id = '') {
ServeRevokeRecords({ msg_id }).then((res) => {
if (res.code == 200) {
this.updateDialogueRecord({ id: record_id, is_revoke: 1 })
this.updateDialogueRecord({ msg_id, is_revoke: 1 })
} else {
window['$message'].warning(res.message)
}
Expand All @@ -211,6 +219,13 @@ export const useDialogueStore = defineStore('dialogue', {
})
},

ApiSendTextMessage(options) {}
ApiCollectImage(options) {
const { msg_id } = options

ServeCollectEmoticon({ msg_id }).then(() => {
useEditorStore().loadUserEmoticon()
window['$message'] && window['$message'].success('收藏成功')
})
}
}
})
2 changes: 1 addition & 1 deletion src/store/modules/uploads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ function fileSlice(file: File, uploadId: string, eachSize: number) {
const form = new FormData()
form.append('file', file.slice(start, end))
form.append('upload_id', uploadId)
form.append('split_index', `${i}`)
form.append('split_index', `${i + 1}`)
form.append('split_num', `${splitNum}`)

items.push(form)
Expand Down
3 changes: 1 addition & 2 deletions src/types/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ export interface ISession {

// 消息记录
export interface ITalkRecord {
id: number
sequence: number
msg_id: string
sequence: number
talk_type: number
msg_type: number
user_id: number
Expand Down
6 changes: 3 additions & 3 deletions src/utils/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ export function getImageInfo(imgsrc) {
/**
* 文件下载方法
*
* @param {Number} cr_id
* @param {Number} msgid
*/
export function download(cr_id) {
export function download(msg_id) {
let token = getAccessToken()
try {
let link = document.createElement('a')
// link.target = '_blank'
link.href = `${
import.meta.env.VITE_BASE_API
}/api/v1/talk/records/file/download?cr_id=${cr_id}&token=${token}`
}/api/v1/talk/records/file/download?msg_id=${msg_id}&token=${token}`
link.click()
} catch (e) {
console.warn(e)
Expand Down
11 changes: 6 additions & 5 deletions src/views/message/inner/panel/MultiSelectFooter.vue
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,16 @@ const onSingleForward = () => {
const onMultiDelete = () => {
// 批量删除
let ids = dialogueStore.selectItems.map((item: any) => item.id)
let msgIds = dialogueStore.selectItems.map((item: any) => item.msg_id)
if (!ids.length) return
if (!msgIds.length) return
dialogueStore.ApiDeleteRecord(ids)
dialogueStore.ApiDeleteRecord(msgIds)
}
const onContactModal = (data: { id: number; type: number }[]) => {
let ids = dialogueStore.selectItems.map((item: any) => item.id)
let msg_ids = dialogueStore.selectItems.map((item: any) => item.msg_id)
let user_ids: number[] = []
let group_ids: number[] = []
Expand All @@ -54,7 +55,7 @@ const onContactModal = (data: { id: number; type: number }[]) => {
dialogueStore.ApiForwardRecord({
mode: forwardMode.value,
message_ids: ids,
message_ids: msg_ids,
uids: user_ids,
gids: group_ids
})
Expand Down
25 changes: 17 additions & 8 deletions src/views/message/inner/panel/PanelContent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ const onPanelScroll = (e: any) => {
// 目前没有用虚拟列表只能这么干
dialogueStore.records.splice(0, len - 100)
let minid = 0
let minSequence = 0
dialogueStore.records.forEach((item: ITalkRecord) => {
if (minid == 0 || item.sequence < minid) {
minid = item.sequence
if (minSequence == 0 || item.sequence < minSequence) {
minSequence = item.sequence
}
})
loadConfig.cursor = minid
loadConfig.cursor = minSequence
loadConfig.status = 1
}
}
Expand All @@ -125,18 +125,18 @@ const onCopyText = (data: ITalkRecord) => {
// 删除对话消息
const onDeleteTalk = (data: ITalkRecord) => {
dialogueStore.ApiDeleteRecord([data.id])
dialogueStore.ApiDeleteRecord([data.msg_id])
}
// 撤销对话消息
const onRevokeTalk = (data: ITalkRecord) => {
dialogueStore.ApiRevokeRecord(data.id)
dialogueStore.ApiRevokeRecord(data.msg_id)
}
// 多选事件
const onMultiSelect = (data: ITalkRecord) => {
dialogueStore.updateDialogueRecord({
id: data.id,
msg_id: data.msg_id,
isCheck: true
})
Expand Down Expand Up @@ -205,6 +205,14 @@ const onQuoteMessage = (data: ITalkRecord) => {
bus.emit('editor:quote', item)
}
const onCollectImage = (data: ITalkRecord) => {
if (data.msg_type == 3) {
dialogueStore.ApiCollectImage({
msg_id: data.msg_id
})
}
}
const onClickNickname = (data: ITalkRecord) => {
bus.emit(EditorConst.Mention, {
id: data.user_id,
Expand All @@ -229,7 +237,8 @@ const evnets = {
delete: onDeleteTalk,
multiSelect: onMultiSelect,
download: onDownloadFile,
quote: onQuoteMessage
quote: onQuoteMessage,
collect: onCollectImage
}
// 会话列表右键菜单回调事件
Expand Down
5 changes: 5 additions & 0 deletions src/views/message/inner/panel/menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,17 @@ export function useMenu() {

dropdown.options.push({ label: '回复', key: 'quote' })
dropdown.options.push({ label: '删除', key: 'delete' })

dropdown.options.push({ label: '多选', key: 'multiSelect' })

if ([3, 4, 5].includes(item.msg_type)) {
dropdown.options.push({ label: '下载', key: 'download' })
}

if ([3].includes(item.msg_type)) {
dropdown.options.push({ label: '收藏', key: 'collect' })
}

dropdown.x = e.clientX
dropdown.y = e.clientY
dropdown.show = true
Expand Down

0 comments on commit 5e58736

Please sign in to comment.