Skip to content

Commit

Permalink
feat:优化代码
Browse files Browse the repository at this point in the history
  • Loading branch information
gzydong committed Nov 24, 2023
1 parent 1c22505 commit 74ac6e5
Show file tree
Hide file tree
Showing 47 changed files with 143 additions and 144 deletions.
1 change: 0 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,3 @@ listener()
</n-layout-content>
</n-config-provider>
</template>
@/utils/event-bus @/constant/event-bus
2 changes: 1 addition & 1 deletion src/components/base/UploadsModal.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import { NProgress } from 'naive-ui'
import { useUploadsStore } from '@/store/uploads'
import { useUploadsStore } from '@/store'
import { fileFormatSize } from '@/utils/strings'
const uploadsStore = useUploadsStore()
Expand Down
2 changes: 1 addition & 1 deletion src/components/editor/MeEditorEmoticon.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script setup>
import { ref, computed } from 'vue'
import { useEditorStore } from '@/store/editor'
import { useEditorStore } from '@/store'
import { UploadOne, Delete } from '@icon-park/vue-next'
import { emojiList as emoji } from '@/utils/emojis'
Expand Down
2 changes: 1 addition & 1 deletion src/components/group/GroupPanel.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="ts">
import { reactive, computed, watch, ref, inject } from 'vue'
import { NEmpty, NPopover, NPopconfirm } from 'naive-ui'
import { useUserStore } from '@/store/user'
import { useUserStore } from '@/store'
import GroupLaunch from './GroupLaunch.vue'
import GroupManage from './manage/index.vue'
import { Comment, Search, Close, Plus } from '@icon-park/vue-next'
Expand Down
2 changes: 1 addition & 1 deletion src/components/group/manage/MemberTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ref, computed, reactive, nextTick, inject } from 'vue'
import { NSpace, NDropdown, NCheckbox } from 'naive-ui'
import { Search, Plus } from '@icon-park/vue-next'
import GroupLaunch from '../GroupLaunch.vue'
import { useUserStore } from '@/store/user'
import { useUserStore } from '@/store'
import {
ServeGetGroupMembers,
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 @@ -2,7 +2,7 @@
import { reactive, computed, onMounted, ref } from 'vue'
import { NCheckbox, NProgress } from 'naive-ui'
import { ServeConfirmVoteHandle } from '@/api/chat'
import { useUserStore } from '@/store/user'
import { useUserStore } from '@/store'
const props = defineProps({
extra: Object,
Expand Down
27 changes: 22 additions & 5 deletions src/components/user/UserCardModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { ref, computed, reactive } from 'vue'
import { NIcon, NModal, NButton, NInput, NDropdown, NPopover } from 'naive-ui'
import { CloseOne, Male, Female, SendOne } from '@icon-park/vue-next'
import { ServeSearchUser } from '@/api/contact'
import { toTalk } from '@/utils/talk'
import { ServeCreateContact } from '@/api/contact'
import { ServeContactGroupList, ServeContactMoveGroup, ServeEditContactRemark } from '@/api/contact'
import { useTalkStore } from '@/store'
const talkStore = useTalkStore()
const emit = defineEmits(['update:show', 'update:uid', 'updateRemark'])
Expand Down Expand Up @@ -72,7 +74,7 @@ const onLoadData = () => {
}
const onToTalk = () => {
toTalk(1, props.uid)
talkStore.toTalk(1, props.uid)
emit('update:show', false)
}
Expand Down Expand Up @@ -316,11 +318,25 @@ const onAfterEnter = () => {
.header {
width: 100%;
height: 230px;
position: relative;
display: flex;
align-items: center;
justify-content: center;
background: linear-gradient(to bottom right, #247ec6, #73c1ff);
background: linear-gradient(to right, rgb(137, 104, 255), rgb(175, 152, 255));
display: flex;
padding: 20px;
position: relative;
overflow: hidden;
&::before {
width: 150px;
height: 150px;
content: '';
background: linear-gradient(to right, rgb(142, 110, 255), rgb(208, 195, 255));
position: absolute;
z-index: 1;
border-radius: 50%;
right: -25%;
top: -25%;
}
.nickname {
position: absolute;
Expand Down Expand Up @@ -349,6 +365,7 @@ const onAfterEnter = () => {
position: absolute;
right: 20px;
top: 20px;
z-index: 1;
&:hover {
cursor: pointer;
transform: scale(1.1);
Expand Down
3 changes: 1 addition & 2 deletions src/event/socket/base.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import router from '@/router'
import { useUserStore } from '@/store/user'
import { useDialogueStore } from '@/store/dialogue'
import { useUserStore, useDialogueStore } from '@/store'

class Base {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/event/socket/keyboard.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Base from './base'

import { useDialogueStore } from '@/store/dialogue'
import { useDialogueStore } from '@/store'

/**
* 键盘输入事件
Expand Down
3 changes: 1 addition & 2 deletions src/event/socket/login.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Base from './base'
import { useTalkStore } from '@/store'
import { useDialogueStore } from '@/store/dialogue'
import { useTalkStore, useDialogueStore } from '@/store'

/**
* 好友状态事件
Expand Down
2 changes: 1 addition & 1 deletion src/event/socket/revoke.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Base from './base'
import { useDialogueStore } from '@/store/dialogue'
import { useDialogueStore } from '@/store'

/**
* 好友状态事件
Expand Down
9 changes: 4 additions & 5 deletions src/event/socket/talk.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,10 @@ import socket from '@/socket'
import { parseTime } from '@/utils/datetime'
import { WebNotify } from '@/utils/notification'
import * as message from '@/constant/message'
import { formatTalkItem, findTalkIndex, palyMusic, formatTalkRecord } from '@/utils/talk'
import { formatTalkItem, palyMusic, formatTalkRecord } from '@/utils/talk'
import { ServeClearTalkUnreadNum, ServeCreateTalkList } from '@/api/chat'
import { useTalkStore } from '@/store/talk'
import { useDialogueStore } from '@/store/dialogue'
import { useSettingsStore } from '@/store/settings'
import { useDialogueStore, useSettingsStore } from '@/store'
import { useTalkStore } from '@/store'

/**
* 好友状态事件
Expand Down Expand Up @@ -105,7 +104,7 @@ class Talk extends Base {
}

// 判断会话列表是否存在,不存在则创建
if (findTalkIndex(this.getIndexName()) == -1) {
if (useTalkStore().findTalkIndex(this.getIndexName()) == -1) {
return this.addTalkItem()
}

Expand Down
2 changes: 1 addition & 1 deletion src/layout/MainLayout.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup>
import Menu from './component/Menu.vue'
import Sponsor from './component/Sponsor.vue'
import { useSettingsStore } from '@/store/settings'
import { useSettingsStore } from '@/store'
import { isElectronMode } from '@/utils/common'
const settingsStore = useSettingsStore()
Expand Down
2 changes: 1 addition & 1 deletion src/layout/component/AccountCard.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { useUserStore } from '@/store/user'
import { useUserStore } from '@/store'
import { Male, Female } from '@icon-park/vue-next'
const store = useUserStore()
</script>
Expand Down
2 changes: 1 addition & 1 deletion src/layout/component/Menu.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup>
import { reactive, computed, markRaw } from 'vue'
import { useRouter } from 'vue-router'
import { useUserStore, useTalkStore, useSettingsStore } from '@/store'
import { useUserStore, useSettingsStore, useTalkStore } from '@/store'
import { NPopover } from 'naive-ui'
import AccountCard from './AccountCard.vue'
import {
Expand Down
4 changes: 1 addition & 3 deletions src/socket.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { h } from 'vue'
import { useTalkStore } from '@/store'
import { useUserStore } from '@/store/user'
import { useDialogueStore } from '@/store/dialogue'
import { useTalkStore, useUserStore, useDialogueStore } from '@/store'
import { getAccessToken, isLoggedIn } from './utils/auth'
import WsSocket from './plugins/ws-socket'
import EventTalk from './event/socket/talk'
Expand Down
20 changes: 11 additions & 9 deletions src/store/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { useUserStore } from '@/store/user'
import { useSettingsStore } from '@/store/settings'
import { useTalkStore } from '@/store/talk'
import { useEditorStore } from '@/store/editor'
import { useDialogueStore } from '@/store/dialogue'
import { useEditorDraftStore } from '@/store/editor-draft'
import { useUploadsStore } from '@/store/uploads'
import { useUserStore } from '@/store/modules/user'
import { useSettingsStore } from '@/store/modules/settings'
import { useTalkStore } from '@/store/modules/talk'
import { useEditorStore } from '@/store/modules/editor'
import { useDialogueStore } from '@/store/modules/dialogue'
import { useEditorDraftStore } from '@/store/modules/editor-draft'
import { useUploadsStore } from '@/store/modules/uploads'
import { useNoteStore } from '@/store/modules/note'

export {
useUserStore,
useSettingsStore,
useTalkStore,
useEditorStore,
useDialogueStore,
useEditorDraftStore,
useUploadsStore
useUploadsStore,
useTalkStore,
useNoteStore
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
48 changes: 43 additions & 5 deletions src/store/talk.js → src/store/modules/talk.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { defineStore } from 'pinia'
import { ServeGetTalkList } from '@/api/chat'
import router from '@/router'
import { ServeGetTalkList, ServeCreateTalkList } from '@/api/chat'
import { formatTalkItem } from '@/utils/talk'
import { useEditorDraftStore } from './index'
import { useEditorDraftStore } from './editor-draft'
const KEY_INDEX_NAME = 'send_message_index_name'

const ttime = (datetime) => {
if (datetime == undefined || datetime == '') {
Expand Down Expand Up @@ -93,14 +95,12 @@ export const useTalkStore = defineStore('talk', {

const response = ServeGetTalkList()

const editorDraftStore = useEditorDraftStore()

response.then(({ code, data }) => {
if (code == 200) {
this.items = data.items.map((item) => {
let value = formatTalkItem(item)

let draft = editorDraftStore.items[value.index_name]
let draft = useEditorDraftStore().items[value.index_name]
if (draft) {
value.draft_text = JSON.parse(draft).text || ''
}
Expand All @@ -121,6 +121,44 @@ export const useTalkStore = defineStore('talk', {
response.catch(() => {
this.loadStatus = 4
})
},

findTalkIndex(index_name) {
return this.items.findIndex((item) => item.index_name === index_name)
},

toTalk(talk_type, receiver_id) {
if (this.findTalkIndex(`${talk_type}_${receiver_id}`) >= 0) {
sessionStorage.setItem(KEY_INDEX_NAME, `${talk_type}_${receiver_id}`)
return router.push({
path: '/message',
query: {
v: new Date().getTime()
}
})
}

ServeCreateTalkList({
talk_type: parseInt(talk_type),
receiver_id: parseInt(receiver_id)
}).then(({ code, data, message }) => {
if (code == 200) {
sessionStorage.setItem(KEY_INDEX_NAME, `${talk_type}_${receiver_id}`)

if (this.findTalkIndex(`${talk_type}_${receiver_id}`) === -1) {
this.addItem(formatTalkItem(data))
}

router.push({
path: '/message',
query: {
v: new Date().getTime()
}
})
} else {
window['$message'].info(message)
}
})
}
}
})
File renamed without changes.
File renamed without changes.
61 changes: 0 additions & 61 deletions src/utils/talk.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import { useTalkStore } from '@/store/talk'
import router from '@/router'
import { parseTime } from '@/utils/datetime'
import { ServeCreateTalkList } from '@/api/chat'

const KEY_INDEX_NAME = 'send_message_index_name'

Expand All @@ -25,24 +22,6 @@ export function palyMusic(muted = false) {
audio.play()
}

/**
* 通过对话索引查找对话列表下标
*
* @param {String} index_name
*/
export function findTalkIndex(index_name) {
return useTalkStore().items.findIndex((item) => item.index_name === index_name)
}

/**
* 通过对话索引查找对话列表
*
* @param {String} index_name
*/
export function findTalk(index_name) {
return useTalkStore().items.find((item) => item.index_name === index_name)
}

/**
* 格式化聊天对话列表数据
*
Expand Down Expand Up @@ -74,46 +53,6 @@ export function formatTalkItem(params) {
return options
}

/**
* 打开指定对话窗口
*
* @param {Integer} talk_type 对话类型[1:私聊;2:群聊;]
* @param {Integer} receiver_id 接收者ID
*/
export function toTalk(talk_type, receiver_id) {
if (findTalkIndex(`${talk_type}_${receiver_id}`) >= 0) {
sessionStorage.setItem(KEY_INDEX_NAME, `${talk_type}_${receiver_id}`)
return router.push({
path: '/message',
query: {
v: new Date().getTime()
}
})
}

ServeCreateTalkList({
talk_type: parseInt(talk_type),
receiver_id: parseInt(receiver_id)
}).then(({ code, data, message }) => {
if (code == 200) {
sessionStorage.setItem(KEY_INDEX_NAME, `${talk_type}_${receiver_id}`)

if (findTalkIndex(`${talk_type}_${receiver_id}`) === -1) {
useTalkStore().addItem(formatTalkItem(data))
}

router.push({
path: '/message',
query: {
v: new Date().getTime()
}
})
} else {
window['$message'].info(message)
}
})
}

/**
* 获取需要打开的对话索引值
*
Expand Down
2 changes: 1 addition & 1 deletion src/views/auth/login.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { ServeLogin } from '@/api/auth'
import { setAccessToken } from '@/utils/auth'
import { palyMusic } from '@/utils/talk'
import socket from '@/socket'
import { useUserStore } from '@/store/user'
import { useUserStore } from '@/store'
const userStore = useUserStore()
const route = useRoute()
Expand Down
Loading

0 comments on commit 74ac6e5

Please sign in to comment.