Commit 3f345fb5 by pangchong

feat: 优化

parent aaa4ad49
import { defineStore } from 'pinia' import { defineStore } from 'pinia'
import { ContactsState, UserItemDto } from './types' import { ContactsState, ContactsItemDto } from './types'
import { userStates } from 'AnyR/states/wsStates' import { userStates } from 'AnyR/states/wsStates'
const useContactsStore = defineStore('contacts', { const useContactsStore = defineStore('contacts', {
state: (): ContactsState => { state: (): ContactsState => {
return { return {
showWait: false, //是否等待接通 showContactsWait: false, //是否等待接通
chooseUser: undefined, //当前选中的联系人 chooseContactsItem: undefined, //当前选中的联系人
userList: [] //所有联系人 allContactsList: [] //所有联系人
} }
}, },
getters: { getters: {
//获取合并ws后的所有用户列表 //获取合并ws后的所有用户列表
getAllOnlineContacts(state) { getAllOnlineContacts(state) {
const userList = [] as UserItemDto[] const allContactsList = [] as ContactsItemDto[]
state.userList.forEach((item1) => { state.allContactsList.forEach((item1) => {
userStates.value.onlineContacts.forEach((item2: any) => { userStates.value.onlineContacts.forEach((item2: any) => {
if (item1.id == item2.fromID) { if (item1.id == item2.fromID) {
Object.assign(item1, item2) Object.assign(item1, item2)
} }
}) })
userList.push(item1) allContactsList.push(item1)
}) })
return userList return allContactsList
}, },
//获取ws的用户列表 //获取ws的用户列表
getOnlineContacts(state) { getOnlineContacts(state) {
const userList = [] as UserItemDto[] const allContactsList = [] as ContactsItemDto[]
userStates.value.onlineContacts.forEach((item1: any) => { userStates.value.onlineContacts.forEach((item1: any) => {
state.userList.forEach((item2) => { state.allContactsList.forEach((item2) => {
if (item1.fromID == item2.id) { if (item1.fromID == item2.id) {
Object.assign(item1, item2) Object.assign(item1, item2)
} }
}) })
userList.push(item1) allContactsList.push(item1)
}) })
return userList return allContactsList
} }
}, },
actions: { actions: {
//设置当前选中联系人 //设置当前选中联系人
setChooseUser(info: UserItemDto | undefined) { setChooseUser(info: ContactsItemDto | undefined) {
this.chooseUser = info this.chooseContactsItem = info
}, },
//修改通话状态 //修改通话状态
changeWait(val: boolean) { changeWait(val: boolean) {
this.showWait = val this.showContactsWait = val
}, },
//获取全部联系人 //获取全部联系人
setUserList(info: UserItemDto[]) { setUserList(info: ContactsItemDto[]) {
this.userList = info this.allContactsList = info
} }
}, },
......
export interface UserItemDto { export interface ContactsItemDto {
id: string id: string
nickname: string nickname: string
remark: string remark: string
...@@ -7,7 +7,7 @@ export interface UserItemDto { ...@@ -7,7 +7,7 @@ export interface UserItemDto {
[propName: string]: any [propName: string]: any
} }
export interface ContactsState { export interface ContactsState {
showWait: boolean showContactsWait: boolean
chooseUser?: UserItemDto chooseContactsItem?: ContactsItemDto
userList: UserItemDto[] allContactsList: ContactsItemDto[]
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
<!-- 内容区域 --> <!-- 内容区域 -->
<a-layout class="h-[calc(100%-60px)]"> <a-layout class="h-[calc(100%-60px)]">
<!-- 视频等待遮罩 --> <!-- 视频等待遮罩 -->
<contacts-wait v-if="showWait"></contacts-wait> <contacts-wait v-if="showContactsWait"></contacts-wait>
<!-- 侧边栏 --> <!-- 侧边栏 -->
<g-aside v-if="getShowMenu"></g-aside> <g-aside v-if="getShowMenu"></g-aside>
<!-- 路由内容 --> <!-- 路由内容 -->
...@@ -29,7 +29,7 @@ import { activedTheme } from '../../../project.ui.config' ...@@ -29,7 +29,7 @@ import { activedTheme } from '../../../project.ui.config'
//显示通话等待 //显示通话等待
const contactsStore = useContactsStore() const contactsStore = useContactsStore()
const { showWait } = storeToRefs(contactsStore) const { showContactsWait } = storeToRefs(contactsStore)
//是否展示菜单 //是否展示菜单
const route = useRoute() const route = useRoute()
const getShowMenu = computed(() => { const getShowMenu = computed(() => {
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
import contactsList from './contactsList.vue' import contactsList from './contactsList.vue'
import multiCallModel from './multiCallModel.vue' import multiCallModel from './multiCallModel.vue'
import { alova } from '@/api/alova-instance' import { alova } from '@/api/alova-instance'
import type { UserItemDto } from '@/store/contacts/types' import type { ContactsItemDto } from '@/store/contacts/types'
import useContactsStore from '@/store/contacts/index' import useContactsStore from '@/store/contacts/index'
import { useRequest } from 'alova' import { useRequest } from 'alova'
import { videoGroup } from '@/constants/common/user' import { videoGroup } from '@/constants/common/user'
...@@ -58,7 +58,7 @@ const { loading, data, onSuccess } = useRequest( ...@@ -58,7 +58,7 @@ const { loading, data, onSuccess } = useRequest(
pageSize: 99999 pageSize: 99999
}, },
{ {
transformData: (res: any) => res.data as UserItemDto[] transformData: (res: any) => res.data as ContactsItemDto[]
} }
), ),
{ {
......
<template> <template>
<template v-for="(item, index) in data" :key="item.id"> <template v-for="(item, index) in data" :key="item.id">
<div class="item flex items-center px-4 py-3 rounded cursor-pointer" :class="{ active: chooseUser?.id == item.id }" @click="handleClick(item)"> <div class="item flex items-center px-4 py-3 rounded cursor-pointer" :class="{ active: chooseContactsItem?.id == item.id }" @click="handleClick(item)">
<global-avatar></global-avatar> <global-avatar></global-avatar>
<div class="ml-[9px] inline-block">{{ item.nickname }}</div> <div class="ml-[9px] inline-block">{{ item.nickname }}</div>
<div class="flex items-center ml-6"> <div class="flex items-center ml-6">
<global-icon icon="camera" :size="14" class="mr-2"></global-icon> <global-icon icon="camera" :size="14" class="mr-2" v-if="item.hasCamera == 1"></global-icon>
<global-icon icon="mic" :size="14"></global-icon> <global-icon icon="mic" :size="14" v-if="item.hasMike == 1"></global-icon>
</div> </div>
<div class="flex-auto text-right"> <div class="flex-auto text-right">
<a-button type="primary" shape="circle" @click.stop="changeWait(true)" :disabled="!(item.callState == 'callState' && item.hasCamera == 1 && item.hasMike == 1)"> <a-button type="primary" shape="circle" @click.stop="changeWait(true)" :disabled="!(item.callState == 'callState' && item.hasCamera == 1 && item.hasMike == 1)">
...@@ -18,11 +18,11 @@ ...@@ -18,11 +18,11 @@
<script setup lang="ts"> <script setup lang="ts">
import useContactsStore from '@/store/contacts/index' import useContactsStore from '@/store/contacts/index'
import { UserItemDto } from '@/store/contacts/types' import { ContactsItemDto } from '@/store/contacts/types'
import { storeToRefs } from 'pinia' import { storeToRefs } from 'pinia'
interface Props { interface Props {
data?: Array<UserItemDto> data?: Array<ContactsItemDto>
} }
const ps = withDefaults(defineProps<Props>(), { const ps = withDefaults(defineProps<Props>(), {
data: () => [] data: () => []
...@@ -30,9 +30,9 @@ const ps = withDefaults(defineProps<Props>(), { ...@@ -30,9 +30,9 @@ const ps = withDefaults(defineProps<Props>(), {
//拨打视频 //拨打视频
const { changeWait, setChooseUser } = useContactsStore() const { changeWait, setChooseUser } = useContactsStore()
//当前联系人 //当前联系人
const { chooseUser } = storeToRefs(useContactsStore()) const { chooseContactsItem } = storeToRefs(useContactsStore())
//点击联系人 //点击联系人
const handleClick = (item: UserItemDto) => { const handleClick = (item: ContactsItemDto) => {
setChooseUser(item) setChooseUser(item)
} }
onBeforeUnmount(() => { onBeforeUnmount(() => {
......
...@@ -13,10 +13,10 @@ ...@@ -13,10 +13,10 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { UserItemDto } from '@/store/contacts/types' import { ContactsItemDto } from '@/store/contacts/types'
interface Props { interface Props {
data?: Array<UserItemDto> data?: Array<ContactsItemDto>
} }
const ps = withDefaults(defineProps<Props>(), { const ps = withDefaults(defineProps<Props>(), {
data: () => [] data: () => []
......
...@@ -36,11 +36,11 @@ const beginTime = ref('') ...@@ -36,11 +36,11 @@ const beginTime = ref('')
const endTime = ref('') const endTime = ref('')
const keyword = ref('') const keyword = ref('')
//当前联系人 //当前联系人
const { chooseUser } = storeToRefs(useContactsStore()) const { chooseContactsItem } = storeToRefs(useContactsStore())
//表格搜索 //表格搜索
const getEventList = (pageIndex: number, pageSize: number) => { const getEventList = (pageIndex: number, pageSize: number) => {
const params = { const params = {
userId: chooseUser?.value?.id, userId: chooseContactsItem?.value?.id,
pageIndex, pageIndex,
pageSize, pageSize,
uid: 2, uid: 2,
...@@ -77,7 +77,7 @@ const { ...@@ -77,7 +77,7 @@ const {
// Method实例获取函数,它将接收page和pageSize,并返回一个Method实例 // Method实例获取函数,它将接收page和pageSize,并返回一个Method实例
(pageIndex: number, pageSize: number) => getEventList(pageIndex, pageSize), (pageIndex: number, pageSize: number) => getEventList(pageIndex, pageSize),
{ {
watchingStates: [beginTime, endTime, () => chooseUser?.value?.id, keyword], watchingStates: [beginTime, endTime, () => chooseContactsItem?.value?.id, keyword],
// 请求前的初始数据(接口返回的数据格式) // 请求前的初始数据(接口返回的数据格式)
initialData: { initialData: {
total: 0, total: 0,
...@@ -90,7 +90,7 @@ const { ...@@ -90,7 +90,7 @@ const {
total: (res) => parseInt(res.data.total), total: (res) => parseInt(res.data.total),
data: (res) => res.data.list, data: (res) => res.data.list,
sendable: () => { sendable: () => {
return chooseUser?.value?.id ? true : false return chooseContactsItem?.value?.id ? true : false
} }
} }
) )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment