接入部分墨册SAAS加好友新需求的相关接口与逻辑处理;完成我的好友和组织架构列表的交互

This commit is contained in:
wangyifeng 2025-06-05 17:04:33 +08:00
parent 7f50f09bbe
commit 98aa8e8fdb
5 changed files with 516 additions and 16 deletions

View File

@ -0,0 +1,28 @@
import request from '@/service/index.js'
// 查询用户是否需要添加好友
export const ServeCheckFriend = (data) => {
return request({
url: '/api/v1/contact/friend/check',
method: 'POST',
data,
})
}
// 主动添加好友(单向好友)
export const ServeAddFriend = (data) => {
return request({
url: '/api/v1/contact/friend/add',
method: 'POST',
data,
})
}
// 查询我的好友列表
export const ServeQueryFriendsList = (data) => {
return request({
url: '/api/v1/contact/friend/list',
method: 'POST',
data,
})
}

View File

@ -48,13 +48,170 @@
class="tabs-panes-each address-book-company"
v-if="state.addressBookActiveTab === 'company'"
>
companycompany
<div class="address-book-company-name">
<span>{{ state.myCompany }}</span>
</div>
<div
class="members-list-each"
v-for="(item, index) in state.myContractList"
:key="index"
@click="toUserDetail(item)"
>
<div class="members-info">
<avatarModule
:mode="1"
:avatar="item.avatar"
:groupType="0"
:userName="item.nickname"
:customStyle="{ width: '72rpx', height: '72rpx' }"
:customTextStyle="{
fontSize: '32rpx',
fontWeight: 'bold',
color: '#fff',
lineHeight: '44rpx',
}"
></avatarModule>
<div class="members-info-area">
<div class="members-info-basic">
<span class="members-name">
{{ item.nickname }}
</span>
<span class="members-jobNum">
{{ item.job_num }}
</span>
</div>
<div class="members-positions-area">
<tm-popover position="bc">
<tm-scrolly :refresher="false" :height="84">
<div class="members-positions">
<div
class="members-positions-each"
v-for="(postionItem,
positionIndex) in item.user_position"
:key="positionIndex"
>
{{ postionItem.position_name }}
</div>
</div>
</tm-scrolly>
<template v-slot:label>
<tm-scrolly
:refresher="false"
:height="
item.user_position.length >= 4
? 180
: item.user_position.length === 3
? 140
: item.user_position.length === 2
? 100
: item.user_position.length === 1
? 60
: 0
"
>
<div class="members-positions-popover-box">
<div
class="members-positions-popover"
v-for="(postionItem,
positionIndex) in item.user_position"
:key="positionIndex"
>
{{ postionItem.position_name }}
</div>
</div>
</tm-scrolly>
</template>
</tm-popover>
</div>
</div>
</div>
</div>
</div>
<div
class="tabs-panes-each address-book-friends"
v-if="state.addressBookActiveTab === 'friends'"
>
friendsfriends
<div
class="members-list-each"
v-for="(item, index) in state.myFriendsList"
:key="index"
@click="toUserDetail(item)"
>
<div class="members-info">
<avatarModule
:mode="1"
:avatar="item.avatar"
:groupType="0"
:userName="item.nickname"
:customStyle="{ width: '72rpx', height: '72rpx' }"
:customTextStyle="{
fontSize: '32rpx',
fontWeight: 'bold',
color: '#fff',
lineHeight: '44rpx',
}"
></avatarModule>
<div class="members-info-area">
<div class="members-info-basic">
<span class="members-name">
{{ item.nickname }}
</span>
<span class="members-jobNum">
{{ item.job_num }}
</span>
<!-- <span class="members-company">{{ item.company_name }}</span> -->
</div>
<div class="members-positions-area">
<tm-popover position="bc">
<tm-scrolly :refresher="false" :height="84">
<div class="members-positions">
<div
class="members-positions-each"
v-for="(postionItem,
positionIndex) in item.user_position"
:key="positionIndex"
>
{{ postionItem.position_name }}
</div>
</div>
</tm-scrolly>
<template v-slot:label>
<tm-scrolly
:refresher="false"
:height="
item.user_position.length >= 4
? 180
: item.user_position.length === 3
? 140
: item.user_position.length === 2
? 100
: item.user_position.length === 1
? 60
: 0
"
>
<div class="members-positions-popover-box">
<div
class="members-positions-popover"
v-for="(postionItem,
positionIndex) in item.user_position"
:key="positionIndex"
>
{{ postionItem.position_name }}
</div>
</div>
</tm-scrolly>
</template>
</tm-popover>
</div>
</div>
</div>
<div class="company-infos" v-if="item.company_name">
<div class="company-each">
<span>{{ item.company_name }}</span>
</div>
</div>
</div>
</div>
<div
class="tabs-panes-each address-book-groups"
@ -112,6 +269,7 @@ import { ServeUserGroupChatList, ServeCreateTalkList } from '@/api/chat/index'
import { ServeGetSessionId } from '@/api/search/index'
import { formatTalkItem } from '@/utils/talk'
import { useDialogueStore, useTalkStore } from '@/store'
import { ServeQueryFriendsList } from '@/api/addressBook/index'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
@ -122,10 +280,19 @@ const searchVal = ref('')
const state = reactive({
addressBookTabs: [], //tab
addressBookActiveTab: 'company', //tab
myContractListPage: 1, //
myContractListPageSize: 10, //
myContractList: [], //
hasMoreContracts: true, //
myFriendsListPage: 1, //
myFriendsListPageSize: 10, //
myFriendsList: [], //
hasMoreFriends: true, //
myGroupsListPage: 1, //
myGroupsListPageSize: 10, //
myGroupsList: [], //
hasMoreGroups: true, //
myCompany: '', //
})
onLoad((options) => {
@ -160,6 +327,7 @@ onMounted(() => {
},
]
handleSetWebviewStyle()
getMyContractList()
})
//
@ -172,6 +340,76 @@ const updateAddressBookTab = (e) => {
state.addressBookActiveTab = e
}
//
const getMyContractList = () => {
let params = {
type: 'addressBook', //addressBook
page: state.myContractListPage,
page_size: state.myContractListPageSize,
name: searchVal.value,
}
console.error(params)
ServeQueryFriendsList(params)
.then((res) => {
console.log(res)
if (res?.code === 200) {
state.myCompany = res.data?.company_name
if (state.myContractListPage === 1) {
state.myContractList = res.data?.user_list || []
} else {
state.myContractList = state.myContractList.concat(
res.data?.user_list || [],
)
}
if (state.myContractList.length < res.data?.count) {
state.hasMoreContracts = true
} else {
state.hasMoreContracts = false
}
}
})
.catch((err) => {})
}
//
const getMyFriendsList = () => {
let params = {
type: 'myFriends', //myFriends
page: state.myFriendsListPage,
page_size: state.myFriendsListPageSize,
name: searchVal.value,
}
console.error(params)
ServeQueryFriendsList(params)
.then((res) => {
console.log(res)
if (res?.code === 200) {
if (state.myFriendsListPage === 1) {
state.myFriendsList = res.data?.user_list || []
} else {
state.myFriendsList = state.myFriendsList.concat(
res.data?.user_list || [],
)
}
if (state.myFriendsList.length < res.data?.count) {
state.hasMoreFriends = true
} else {
state.hasMoreFriends = false
}
}
})
.catch((err) => {})
}
//
const toUserDetail = (userInfo) => {
uni.navigateTo({
url:
'/pages/dialog/dialogDetail/userDetail??erpUserId=' +
userInfo.erp_user_id,
})
}
//
const getMyGroupsList = () => {
let params = {
@ -179,7 +417,6 @@ const getMyGroupsList = () => {
page_size: state.myGroupsListPageSize,
group_name: searchVal.value,
}
console.error(params)
ServeUserGroupChatList(params)
.then((res) => {
console.log(res)
@ -201,7 +438,13 @@ const getMyGroupsList = () => {
//
const doLoadMore = (e) => {
if (state.addressBookActiveTab === 'groups' && state.hasMoreGroups) {
if (state.addressBookActiveTab === 'company' && state.hasMoreContracts) {
state.myContractListPage += 1
getMyContractList()
} else if (state.addressBookActiveTab === 'friends' && state.hasMoreFriends) {
state.myFriendsListPage += 1
getMyFriendsList()
} else if (state.addressBookActiveTab === 'groups' && state.hasMoreGroups) {
state.myGroupsListPage += 1
getMyGroupsList()
}
@ -229,7 +472,6 @@ const getSessionId = (talk_type, receiver_id) => {
//
const toGroupChat = async (groupInfo) => {
console.error(groupInfo)
let talk_type = 2
let receiver_id = groupInfo.id
const sessionId = await getSessionId(talk_type, receiver_id)
@ -275,7 +517,17 @@ const groupTypeMapping = {
watch(
() => state.addressBookActiveTab,
(newVal) => {
if (newVal === 'groups') {
if (newVal === 'company') {
state.myContractListPage = 1
state.myContractList = []
getMyContractList()
} else if (newVal === 'friends') {
state.myFriendsListPage = 1
state.myFriendsList = []
getMyFriendsList()
} else if (newVal === 'groups') {
state.myGroupsListPage = 1
state.myGroupsList = []
getMyGroupsList()
}
},
@ -284,9 +536,17 @@ watch(
watch(
() => searchVal.value,
(newVal) => {
state.myGroupsListPage = 1
state.myGroupsList = []
if (state.addressBookActiveTab === 'groups') {
if (newVal === 'company') {
state.myContractListPage = 1
state.myContractList = []
getMyContractList()
} else if (state.addressBookActiveTab === 'friends') {
state.myFriendsListPage = 1
state.myFriendsList = []
getMyFriendsList()
} else if (state.addressBookActiveTab === 'groups') {
state.myGroupsListPage = 1
state.myGroupsList = []
getMyGroupsList()
}
},
@ -343,9 +603,123 @@ watch(
align-items: flex-start;
justify-content: center;
}
.address-book-company {
}
.address-book-company,
.address-book-friends {
.address-book-company-name {
margin: 0 0 -16rpx;
span {
font-size: 26rpx;
font-weight: 400;
line-height: 1;
color: #999;
}
}
.members-list-each {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
background-color: #fff;
width: 100%;
padding: 24rpx;
border-radius: 8rpx;
.members-info {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
gap: 16rpx;
.members-info-area {
display: flex;
flex-direction: row;
align-items: flex-start;
justify-content: flex-start;
gap: 16rpx;
.members-info-basic {
display: flex;
flex-direction: column;
align-items: flex-start;
justify-content: center;
.members-name {
font-size: 30rpx;
font-weight: 500;
width: 150rpx;
word-break: break-all;
}
.members-jobNum {
font-size: 26rpx;
font-weight: 400;
color: #999;
word-break: break-all;
margin: 10rpx 0 0;
}
.members-company {
font-size: 24rpx;
font-weight: 400;
line-height: 1;
color: #999;
}
}
.members-positions-area {
.members-positions {
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
flex-wrap: wrap;
gap: 10rpx;
padding: 4rpx 0 0;
max-height: 84rpx;
overflow: hidden;
-webkit-box-orient: vertical;
-webkit-line-clamp: 2;
line-clamp: 2;
.members-positions-each {
background-color: #eee9f8;
line-height: 1;
font-size: 24rpx;
padding: 4rpx 16rpx;
color: #46299d;
}
}
.members-positions-popover-box {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10rpx 0;
.members-positions-popover {
background-color: #eee9f8;
line-height: 1;
font-size: 24rpx;
padding: 8rpx 16rpx;
color: #46299d;
width: 100%;
}
}
}
}
}
.company-infos {
margin: 0 0 0 88rpx;
.company-each {
span {
font-size: 24rpx;
font-weight: 400;
line-height: 1;
color: #999;
}
}
}
}
}
.address-book-groups {
.groups-list-each {

View File

@ -116,6 +116,7 @@ const talkStore = useTalkStore()
const userStore = useUserStore()
import { getUserInfoByClickAvatar } from '@/api/user/index'
import { ServeCheckFriend, ServeAddFriend } from '@/api/addressBook/index'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
@ -150,6 +151,7 @@ const getUserInfo = () => {
console.log(data)
if (code == 200) {
state.userInfo = data
checkNeedAddFriend()
let department = ''
let post = ''
if (data?.erp_dept_position?.length > 0) {
@ -245,13 +247,41 @@ const doPhoneCall = () => {
//
const checkSendPermission = () => {
if(state.canSendMsg){
if (state.canSendMsg) {
toTalkUser()
} else {
message.success(t('addressBook.message.addSuccess') + ' !')
state.canSendMsg = true
doAddFriend()
}
}
//
const checkNeedAddFriend = () => {
let params = {
receiver_id: state.userInfo.sys_id, //id
talk_type: 1,
}
ServeCheckFriend(params).then((res) => {
console.log(res)
if (res?.code === 200) {
state.canSendMsg = res.data?.is_friend || false
}
})
}
//
const doAddFriend = () => {
let params = {
receiver_id: state.userInfo.sys_id, //id
talk_type: 1,
}
ServeAddFriend(params).then((res) => {
console.log(res)
if (res?.code === 200) {
message.success(t('addressBook.message.addSuccess') + ' !')
state.canSendMsg = true
}
})
}
</script>
<style scoped lang="scss">
.outer-layer {
@ -294,6 +324,7 @@ const checkSendPermission = () => {
flex-direction: row;
align-items: center;
justify-content: center;
flex-shrink: 0;
img {
width: 100%;
height: 100%;

View File

@ -682,6 +682,21 @@
</tm-sheet>
</div>
</tm-drawer>
<tm-alert
:content="state.notFriendOrSameCompanyHint"
color="#fff"
:shadow="2"
:height="96"
:closable="false"
class="notFriendOrSameCompanyHint"
v-if="talkParams.type === 1 && !state.isFriendOrSameCompany"
>
<template #right>
<div class="addFriendBtn">
<span>{{ $t('addressBook.btns.add') }}</span>
</div>
</template>
</tm-alert>
</div>
</template>
<script setup>
@ -751,6 +766,7 @@ import zu6053 from '@/static/image/chatList/zu6053@2x.png'
import deepBubble from '@/components/deep-bubble/deep-bubble.vue'
import { isRevoke } from './menu'
import useConfirm from '@/components/x-confirm/useConfirm.js'
import { ServeCheckFriend } from '@/api/addressBook/index'
import {
onLoad as uniOnload,
onUnload as uniOnUnload,
@ -758,6 +774,8 @@ import {
onHide,
} from '@dcloudio/uni-app'
import ws from '@/connect'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
Quill.register('formats/emoji', EmojiBlot)
import 'quill-mention'
@ -861,6 +879,12 @@ const state = ref({
readDetailHeight: 400, //
isFirstEnter: true, //
isFromHide: false, //hide
isFriendOrSameCompany: false, ///
notFriendOrSameCompanyHint: [
{
content: t('addressBook.message.notFriendsOrSameCompany'),
},
],
})
// Map
@ -2146,6 +2170,7 @@ const handleAvatarTouchEnd = () => {
}
onMounted(async () => {
checkNeedAddFriend()
if (uni.getSystemInfoSync().osName === 'ios') {
let versions = uni.getSystemInfoSync().osVersion.split('.')
if (Number(versions[0]) < 16) {
@ -2721,6 +2746,20 @@ const chatInputHeight = computed(() => {
console.error(rpxToPx(72) + 'px', 'chatInputHeight')
return rpxToPx(72) + 'px'
})
//
const checkNeedAddFriend = () => {
let params = {
receiver_id: talkParams.receiver_id, //id
talk_type: 1,
}
ServeCheckFriend(params).then((res) => {
console.log(res)
if (res?.code === 200) {
state.value.isFriendOrSameCompany = res.data?.is_friend || false
}
})
}
</script>
<style scoped lang="less">
.dialog-page {
@ -2740,6 +2779,32 @@ const chatInputHeight = computed(() => {
line-height: unset !important;
}
}
.notFriendOrSameCompanyHint {
margin: 120rpx 24rpx;
:deep(.round-2) {
margin: 10rpx !important;
box-shadow: 0 2px 6px 1px rgba(0, 0, 0, 0.2) !important;
}
:deep(.bdcld) {
align-items: center !important;
}
.addFriendBtn {
background-color: #46299d;
display: flex;
flex-direction: row;
align-items: center;
justify-content: center;
padding: 10rpx 16rpx;
border-radius: 8rpx;
span {
color: #fff;
font-size: 30rpx;
font-weight: 500;
line-height: 1;
}
}
}
}
.edit-revoked-message {

View File

@ -202,10 +202,12 @@
},
"btns": {
"enterGroup": "进入群聊",
"addFriend": "添加好友"
"addFriend": "添加好友",
"add": "添加"
},
"message": {
"addSuccess": "添加成功"
"addSuccess": "添加成功",
"notFriendsOrSameCompany": "对方还不是您的好友,请添加到通讯录中吧!"
}
}
}