Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
feat: 删除好友
Browse files Browse the repository at this point in the history
  • Loading branch information
mys1024 committed Feb 9, 2023
1 parent a078512 commit 87a95a9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
9 changes: 9 additions & 0 deletions src/renderer/api/friend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,12 @@ export async function putFriendRequestStatus(
body: JSON.stringify({ role, action, associatedUid }),
})
}

export async function deleteFriend(token: string, friendUid: number) {
return fetch(`${API_BASE_URL}/friend?friendUid=${friendUid}`, {
method: 'delete',
headers: {
'x-auth-token': token,
},
})
}
2 changes: 1 addition & 1 deletion src/renderer/pages/main/chat.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import FriendList from '~/components/FriendList.vue'
<div w-48>
<FriendList />
</div>
<div flex-grow>
<div flex-grow overflow-auto>
<RouterView />
</div>
</div>
Expand Down
31 changes: 26 additions & 5 deletions src/renderer/pages/main/friend_detail.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<script lang="ts" setup>
import { computed, nextTick, ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { ElButton, ElForm, ElFormItem, ElInput, ElTag } from 'element-plus'
import { ElButton, ElForm, ElFormItem, ElInput, ElMessage, ElTag } from 'element-plus'
import { DEFAULT_AVATAR_URL } from '~/config'
import { deleteFriend as deleteFriendApi, putFriendInfo } from '~/api/friend'
import { useFriendStore } from '~/stores/friend'
import { useAccountStore } from '~/stores/account'
import { putFriendInfo } from '~/api/friend'
const route = useRoute()
const router = useRouter()
Expand Down Expand Up @@ -71,6 +71,22 @@ async function save() {
throw new Error(`保存好友备注与标签失败,响应状态:${res.status}`)
await friendStore.refreshFriends()
}
async function deleteFriend() {
if (!accountStore.token)
throw new Error('账号的 token 值为空')
if (!friend.value?.uid)
throw new Error('好友的 uid 值为空')
const res = await deleteFriendApi(accountStore.token, friend.value.uid)
if (!res.ok)
throw new Error(`删除好友失败,响应状态:${res.status}`)
await friendStore.refreshFriends()
ElMessage({
type: 'success',
message: '已删除好友',
})
router.replace('/main/chat')
}
</script>

<template>
Expand Down Expand Up @@ -128,9 +144,14 @@ async function save() {
<ElInput v-model="remark" />
</ElFormItem>
</ElForm>
<ElButton :disabled="!edited" @click="save">
保存
</ElButton>
<div flex>
<ElButton type="danger" plain @click="deleteFriend">
删除好友
</ElButton>
<ElButton :disabled="!edited" @click="save">
保存
</ElButton>
</div>
</div>
</div>
</template>

0 comments on commit 87a95a9

Please sign in to comment.