From 5b8b51a89487d247e2ec22f6f32877ea4fc35ecb Mon Sep 17 00:00:00 2001
From: dylanmay <670374839@qq.com>
Date: Wed, 20 Sep 2023 17:51:50 +0800
Subject: [PATCH 1/3] feat: friends
---
src/views/chat/ChatPage/Index.vue | 18 ++++----
.../chat/components/FriendItem/Index.vue | 32 ++++++++++++++
src/views/chat/components/Friends/Index.vue | 28 +++++++++++++
.../chat/components/ToolSection/Index.vue | 36 ++++++++++++++++
src/views/chat/model/Friend.ts | 15 +++++++
src/views/chat/store/friendstore.ts | 42 +++++++++++++++++++
src/views/chat/types/index.d.ts | 5 +++
7 files changed, 169 insertions(+), 7 deletions(-)
create mode 100644 src/views/chat/components/FriendItem/Index.vue
create mode 100644 src/views/chat/components/Friends/Index.vue
create mode 100644 src/views/chat/model/Friend.ts
create mode 100644 src/views/chat/store/friendstore.ts
diff --git a/src/views/chat/ChatPage/Index.vue b/src/views/chat/ChatPage/Index.vue
index b17e70645..e81604a5b 100644
--- a/src/views/chat/ChatPage/Index.vue
+++ b/src/views/chat/ChatPage/Index.vue
@@ -1,7 +1,8 @@
-
-
+
+
+
@@ -17,14 +18,17 @@
import ToolSection from '../components/ToolSection/Index.vue'
import Session from '../components/Session/Index.vue'
+import Friends from '../components/Friends/Index.vue'
import ChatHeader from '../components/ChatHeader/Index.vue'
import ChatMessage from '../components/ChatMessage/Index.vue'
import InputSection from '../components/InputSection/index.vue'
-
-/**
- * Define Data Structure of this page, then initialize it with reactive object
- */
-interface State {}
+import { MENU_LIST_ENUM } from '../types/index.d.ts'
defineOptions({ name: 'ChatPage' })
+
+const bussinessType = ref(1)
+
+const toolMenuSelectChange = (value) => {
+ bussinessType.value = value
+}
diff --git a/src/views/chat/components/FriendItem/Index.vue b/src/views/chat/components/FriendItem/Index.vue
new file mode 100644
index 000000000..0cd5d841a
--- /dev/null
+++ b/src/views/chat/components/FriendItem/Index.vue
@@ -0,0 +1,32 @@
+
+
+
+
+
+
+
+
diff --git a/src/views/chat/components/Friends/Index.vue b/src/views/chat/components/Friends/Index.vue
new file mode 100644
index 000000000..80cf8113c
--- /dev/null
+++ b/src/views/chat/components/Friends/Index.vue
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
diff --git a/src/views/chat/components/ToolSection/Index.vue b/src/views/chat/components/ToolSection/Index.vue
index 98fb157b1..405fdbfe2 100644
--- a/src/views/chat/components/ToolSection/Index.vue
+++ b/src/views/chat/components/ToolSection/Index.vue
@@ -1,9 +1,45 @@
+
+
diff --git a/src/views/chat/model/Friend.ts b/src/views/chat/model/Friend.ts
new file mode 100644
index 000000000..3a62b79b7
--- /dev/null
+++ b/src/views/chat/model/Friend.ts
@@ -0,0 +1,15 @@
+export default class Friend {
+ public id: string
+ public avatar: string
+ public name: string
+ public description: string
+ public createTime: number
+
+ constructor(id, avatar, name, description, createTime) {
+ this.id = id
+ this.avatar = avatar
+ this.name = name
+ this.description = description
+ this.createTime = createTime
+ }
+}
diff --git a/src/views/chat/store/friendstore.ts b/src/views/chat/store/friendstore.ts
new file mode 100644
index 000000000..7b121701b
--- /dev/null
+++ b/src/views/chat/store/friendstore.ts
@@ -0,0 +1,42 @@
+import { defineStore } from 'pinia'
+import BaseConversation from '../model/BaseConversation'
+import Friend from '../model/Friend'
+
+interface FriendStoreModel {
+ friendList: Array
+}
+
+export const useFriendStore = defineStore('friendStore', {
+ state: (): FriendStoreModel => ({
+ friendList: [
+ {
+ id: '1111',
+ name: 'Elon Musk',
+ avatar:
+ 'https://img0.baidu.com/it/u=4211304696,1059959254&fm=253&fmt=auto&app=120&f=JPEG?w=800&h=1174',
+ description: 'cool boy',
+ createTime: 1695201147622
+ },
+ {
+ id: '2222',
+ name: 'Spider Man',
+ avatar:
+ 'https://www.hottoys.com.cn/wp-content/uploads/2019/06/bloggerreview_spiderman_advanced_ben-9.jpg',
+ description: 'hero',
+ createTime: 1695201147622
+ }
+ ]
+ }),
+
+ getters: {
+ getFriendList(state: FriendStoreModel): Array {
+ return state.friendList
+ }
+ },
+
+ actions: {
+ addSession(session: BaseConversation) {
+ this.friendList.push(session)
+ }
+ }
+})
diff --git a/src/views/chat/types/index.d.ts b/src/views/chat/types/index.d.ts
index 697decec0..ab8b15076 100644
--- a/src/views/chat/types/index.d.ts
+++ b/src/views/chat/types/index.d.ts
@@ -23,5 +23,10 @@ export enum MessageType {
SYSTEM = 4
}
+export const enum MENU_LIST_ENUM {
+ CONVERSATION = 1,
+ FRIENDS = 2
+}
+
export type MessageModelType = BaseMessage | TextMessage | ImageMessage
export type ConversationModelType = BaseConversation | ChatConversation
From aaba03d0010b6b72f8fb8ce2f93128e42c6684ab Mon Sep 17 00:00:00 2001
From: dylanmay <670374839@qq.com>
Date: Fri, 22 Sep 2023 16:30:43 +0800
Subject: [PATCH 2/3] update friend
---
src/views/chat/ChatPage/Index.vue | 4 ++-
.../chat/components/FriendDetail/Index.vue | 29 +++++++++++++++++++
.../chat/components/FriendItem/Index.vue | 16 ++++------
src/views/chat/components/Friends/Index.vue | 11 +++++--
.../chat/components/ToolSection/Index.vue | 2 +-
src/views/chat/store/friendstore.ts | 9 ++++--
6 files changed, 55 insertions(+), 16 deletions(-)
create mode 100644 src/views/chat/components/FriendDetail/Index.vue
diff --git a/src/views/chat/ChatPage/Index.vue b/src/views/chat/ChatPage/Index.vue
index e81604a5b..47a4bc0c7 100644
--- a/src/views/chat/ChatPage/Index.vue
+++ b/src/views/chat/ChatPage/Index.vue
@@ -3,11 +3,12 @@
-
+
+
@@ -22,6 +23,7 @@ import Friends from '../components/Friends/Index.vue'
import ChatHeader from '../components/ChatHeader/Index.vue'
import ChatMessage from '../components/ChatMessage/Index.vue'
import InputSection from '../components/InputSection/index.vue'
+import FriendDetail from '../components/FriendDetail/Index.vue'
import { MENU_LIST_ENUM } from '../types/index.d.ts'
defineOptions({ name: 'ChatPage' })
diff --git a/src/views/chat/components/FriendDetail/Index.vue b/src/views/chat/components/FriendDetail/Index.vue
new file mode 100644
index 000000000..474ebfcdf
--- /dev/null
+++ b/src/views/chat/components/FriendDetail/Index.vue
@@ -0,0 +1,29 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/views/chat/components/FriendItem/Index.vue b/src/views/chat/components/FriendItem/Index.vue
index 0cd5d841a..9f3eaea72 100644
--- a/src/views/chat/components/FriendItem/Index.vue
+++ b/src/views/chat/components/FriendItem/Index.vue
@@ -7,26 +7,22 @@
diff --git a/src/views/chat/components/Friends/Index.vue b/src/views/chat/components/Friends/Index.vue
index 80cf8113c..55df4e295 100644
--- a/src/views/chat/components/Friends/Index.vue
+++ b/src/views/chat/components/Friends/Index.vue
@@ -5,10 +5,11 @@
>
onFriendClick(item)"
/>
@@ -18,11 +19,17 @@
import FriendItem from '../FriendItem/Index.vue'
import { useFriendStore } from '../../store/friendstore'
import { onMounted } from 'vue'
+import Friend from '../../model/Friend'
defineOptions({ name: 'Friends' })
-const { friendList } = useFriendStore()
+const friendStore = useFriendStore()
onMounted(() => {
// set default conversation
})
+
+const onFriendClick = (friend: Friend) => {
+ console.log('====>', friend)
+ friendStore.setCurrentFriend(friend)
+}
diff --git a/src/views/chat/components/ToolSection/Index.vue b/src/views/chat/components/ToolSection/Index.vue
index 405fdbfe2..769e66399 100644
--- a/src/views/chat/components/ToolSection/Index.vue
+++ b/src/views/chat/components/ToolSection/Index.vue
@@ -1,5 +1,5 @@
-
+
+ currentFriend: Friend | null
}
export const useFriendStore = defineStore('friendStore', {
@@ -25,7 +26,8 @@ export const useFriendStore = defineStore('friendStore', {
description: 'hero',
createTime: 1695201147622
}
- ]
+ ],
+ currentFriend: null
}),
getters: {
@@ -35,8 +37,11 @@ export const useFriendStore = defineStore('friendStore', {
},
actions: {
- addSession(session: BaseConversation) {
+ addFriend(session: BaseConversation) {
this.friendList.push(session)
+ },
+ setCurrentFriend(friend: Friend) {
+ this.currentFriend = friend
}
}
})
From 90619542c823d536a4a884b5c070fe4578aaf418 Mon Sep 17 00:00:00 2001
From: dylanmay <670374839@qq.com>
Date: Sat, 19 Oct 2024 16:06:29 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E5=8D=95=E8=81=8A=E5=AF=B9=E6=8E=A5?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/utils/formatTime.ts | 2 +-
src/views/chat/api/messageApi.ts | 58 +++++++
src/views/chat/api/sessionApi.ts | 22 +++
.../chat/components/ChatHeader/Index.vue | 2 +-
.../chat/components/ChatMessage/Index.vue | 20 ++-
.../chat/components/InputSection/Index.vue | 23 +--
.../Message/{BaseMessage.vue => BaseMsg.vue} | 10 +-
.../{ImageMessage.vue => ImageMsg.vue} | 2 +-
.../Message/{TextMessage.vue => TextMsg.vue} | 9 +-
src/views/chat/components/Session/Index.vue | 12 +-
.../chat/components/SessionItem/Index.vue | 39 +++--
src/views/chat/model/BaseConversation.ts | 11 +-
src/views/chat/model/BaseMessage.ts | 36 +++-
src/views/chat/model/BaseResponse.ts | 5 +
src/views/chat/model/ChatConversation.ts | 17 +-
src/views/chat/model/ImageMessage.ts | 21 ++-
src/views/chat/model/TextMessage.ts | 21 ++-
src/views/chat/store/chatstore.ts | 164 +++++++++++-------
src/views/chat/types/index.d.ts | 17 +-
19 files changed, 354 insertions(+), 137 deletions(-)
create mode 100644 src/views/chat/api/messageApi.ts
create mode 100644 src/views/chat/api/sessionApi.ts
rename src/views/chat/components/Message/{BaseMessage.vue => BaseMsg.vue} (62%)
rename src/views/chat/components/Message/{ImageMessage.vue => ImageMsg.vue} (91%)
rename src/views/chat/components/Message/{TextMessage.vue => TextMsg.vue} (58%)
create mode 100644 src/views/chat/model/BaseResponse.ts
diff --git a/src/utils/formatTime.ts b/src/utils/formatTime.ts
index 874092609..64ce8adfe 100644
--- a/src/utils/formatTime.ts
+++ b/src/utils/formatTime.ts
@@ -61,7 +61,7 @@ export function getWeek(dateTime: Date): number {
* @description param 3天: 60 * 60* 24 * 1000 * 3
* @returns 返回拼接后的时间字符串
*/
-export function formatPast(param: string | Date, format = 'YYYY-mm-dd HH:MM:SS'): string {
+export function formatPast(param: string | Date, format = 'YYYY-MM-DD HH:mm:ss'): string {
// 传入格式处理、存储转换值
let t: any, s: number
// 获取js 时间戳
diff --git a/src/views/chat/api/messageApi.ts b/src/views/chat/api/messageApi.ts
new file mode 100644
index 000000000..cbab90cdf
--- /dev/null
+++ b/src/views/chat/api/messageApi.ts
@@ -0,0 +1,58 @@
+/*
+ * @Author: dylan.may@qq.com
+ * @Date: 2024-10-16 11:30:31
+ * @Last Modified by: dylan.may@qq.com
+ * @Last Modified time: 2024-10-16 16:01:25
+ */
+
+import request from '@/config/axios'
+import { MessageModelType } from '../types'
+
+export interface SendMsg {
+ clientMessageId: string
+ receiverId: number
+ conversationType: number
+ contentType: number
+ content: string
+}
+
+export interface SessionMsgReq {
+ receiverId: number
+ conversationType: number
+ sendTime: Date
+}
+
+/**
+ * 消息接口
+ */
+export default class MessageApi {
+ /**
+ * 发送消息
+ * @param data SendMsg
+ * @returns Promise<{ id: number; sendTime: number }>
+ */
+ static send(data: SendMsg): Promise<{ id: number; sendTime: number }> {
+ return request.post({ url: '/im/message/send', data })
+ }
+
+ /**
+ * 获取会话消息
+ * @param data SessionMsgReq
+ * @returns Promise>
+ */
+ static getSessionMsg(params: SessionMsgReq): Promise> {
+ return request.get({ url: '/im/message/list', params })
+ }
+
+ /**
+ * 获取所有消息
+ * @param data { sequence: number; size: number }
+ * @returns Promise>
+ */
+ static getMessageForAllSession(params: {
+ sequence: number
+ size: number
+ }): Promise> {
+ return request.get({ url: '/im/message/pull', params })
+ }
+}
diff --git a/src/views/chat/api/sessionApi.ts b/src/views/chat/api/sessionApi.ts
new file mode 100644
index 000000000..a11f9ca44
--- /dev/null
+++ b/src/views/chat/api/sessionApi.ts
@@ -0,0 +1,22 @@
+/*
+ * @Author: dylan.may@qq.com
+ * @Date: 2024-10-16 11:30:31
+ * @Last Modified by: dylan.may@qq.com
+ * @Last Modified time: 2024-10-16 16:01:25
+ */
+
+import request from '@/config/axios'
+import { ChatConversation } from '../model/ChatConversation'
+
+/**
+ * 会话接口
+ */
+export default class SessionApi {
+ /**
+ * 获取会话列表
+ * @returns Promise>
+ */
+ static getSessionList(): Promise> {
+ return request.get({ url: '/im/conversation/list' })
+ }
+}
diff --git a/src/views/chat/components/ChatHeader/Index.vue b/src/views/chat/components/ChatHeader/Index.vue
index ab697ca8b..6b33c3efc 100644
--- a/src/views/chat/components/ChatHeader/Index.vue
+++ b/src/views/chat/components/ChatHeader/Index.vue
@@ -1,7 +1,7 @@