diff --git a/frontend/components.d.ts b/frontend/components.d.ts index 1fe9ff8..33e7e69 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -40,6 +40,7 @@ declare module 'vue' { DialogTemp: typeof import('./src/components/window/DialogTemp.vue')['default'] EditFileName: typeof import('./src/components/builtin/EditFileName.vue')['default'] EditType: typeof import('./src/components/builtin/EditType.vue')['default'] + ElAlert: typeof import('element-plus/es')['ElAlert'] ElAvatar: typeof import('element-plus/es')['ElAvatar'] ElBadge: typeof import('element-plus/es')['ElBadge'] ElButton: typeof import('element-plus/es')['ElButton'] diff --git a/frontend/src/components/localchat/ChatContent.vue b/frontend/src/components/localchat/ChatContent.vue index dc59388..ca8754f 100644 --- a/frontend/src/components/localchat/ChatContent.vue +++ b/frontend/src/components/localchat/ChatContent.vue @@ -88,12 +88,49 @@ async function scroll({ scrollTop }: { scrollTop: number }) { +
+ + +
+
{{ el }}
+
+ +
+
-
-
+ + +
{{ el }}
-
+ +
diff --git a/frontend/src/stores/localchat.ts b/frontend/src/stores/localchat.ts index 2f6a902..202a7ff 100644 --- a/frontend/src/stores/localchat.ts +++ b/frontend/src/stores/localchat.ts @@ -1,8 +1,7 @@ import { defineStore } from 'pinia' import emojiList from "@/assets/emoji.json" -import { ref, toRaw, inject } from "vue"; +import { ref, toRaw } from "vue"; import { db } from './db' -import { System } from "@/system"; import { getSystemConfig } from "@/system/config"; import { isValidIP } from "@/util/common"; import { notifyError, notifySuccess } from "@/util/msg"; @@ -58,6 +57,9 @@ export const useLocalChatStore = defineStore('localChatStore', () => { else if (msg.type === "fileSending"){ addText(msg) } + else if( msg.type === "fileCannel") { + changeMsg(msg) + } }) } } @@ -371,19 +373,25 @@ export const useLocalChatStore = defineStore('localChatStore', () => { msgList.value.push(saveMsg) const targetUser = userList.value.find((d: any) => d.ip === chatTargetIp.value) //console.log(targetUser) + const messages = { + type: type, + message: content, + ip: saveMsg.targetIp + } if (targetUser.isOnline) { let postUrl = `${config.apiUrl}/localchat/message` if(type === 'applyfile'){ + messages.message = { + fileList: messages.message, + msgId: msgId, + status: 'apply' + } postUrl = `${config.apiUrl}/localchat/applyfile` } if(type === 'image'){ postUrl = `${config.apiUrl}/localchat/sendimage` } - const messages = { - type: type, - message: content, - ip: saveMsg.targetIp - } + const completion = await fetch(postUrl, { method: "POST", body: JSON.stringify(messages), @@ -402,11 +410,44 @@ export const useLocalChatStore = defineStore('localChatStore', () => { // } } + await updateContentList(saveMsg) + }else{ + notifyError("对方不在线!") } sendInfo.value = "" - await updateContentList(saveMsg) + } + async function cannelFile(item:any){ + const messages = { + type: 'cannelFile', + message: item.content.msgId, + ip: item.targetIp + } + const postUrl = `${config.apiUrl}/localchat/cannelfile` + const coms = await fetch(postUrl, { + method: "POST", + body: JSON.stringify(messages), + }) + if (!coms.ok) { + console.log(coms) + notifyError("确认失败!") + } else { + item.content.status = 'cannel' + await db.update('chatmsg', item.id, item) + await updateContentList(item) + notifySuccess("确认成功!") + } + } + async function changeMsg(msg:any){ + const msgId = msg.content.msgId + const item = await db.getOne('chatmsg', msgId) + item.content.status = 'cannel' + await db.update('chatmsg', item.id, item) + await updateContentList(item) + } + async function accessFile(item:any){ + } return { userList, @@ -436,6 +477,8 @@ export const useLocalChatStore = defineStore('localChatStore', () => { refreshUserList, clearMsg, //addUser, - handlerMessage + handlerMessage, + cannelFile, + accessFile } }) diff --git a/godo/cmd/main.go b/godo/cmd/main.go index 3110258..2ac8556 100644 --- a/godo/cmd/main.go +++ b/godo/cmd/main.go @@ -104,6 +104,7 @@ func OsStart() { localchatRouter := router.PathPrefix("/localchat").Subrouter() localchatRouter.HandleFunc("/message", localchat.HandleMessage).Methods(http.MethodPost) localchatRouter.HandleFunc("/applyfile", localchat.HandlerApplySendFile).Methods(http.MethodPost) + localchatRouter.HandleFunc("/cannelfile", localchat.HandlerCannelFile).Methods(http.MethodPost) localchatRouter.HandleFunc("/accessfile", localchat.HandlerAccessFile).Methods(http.MethodPost) localchatRouter.HandleFunc("/sendimage", localchat.HandlerSendImg).Methods(http.MethodPost) localchatRouter.HandleFunc("/viewimage", localchat.HandleViewImg).Methods(http.MethodGet) diff --git a/godo/localchat/file.go b/godo/localchat/file.go index 6b8a41f..fcabf96 100644 --- a/godo/localchat/file.go +++ b/godo/localchat/file.go @@ -69,7 +69,25 @@ func HandlerApplySendFile(w http.ResponseWriter, r *http.Request) { msg.Hostname = hostname msg.Time = time.Now() msg.Type = "fileSending" - msg.Message = "" + SendToIP(msg) + libs.SuccessMsg(w, nil, "请求文件发送成功") +} +func HandlerCannelFile(w http.ResponseWriter, r *http.Request) { + var msg UdpMessage + decoder := json.NewDecoder(r.Body) + if err := decoder.Decode(&msg); err != nil { + http.Error(w, "Invalid request body", http.StatusBadRequest) + return + } + defer r.Body.Close() + hostname, err := os.Hostname() + if err != nil { + libs.ErrorMsg(w, "HandleMessage error") + return + } + msg.Hostname = hostname + msg.Time = time.Now() + msg.Type = "fileCannel" SendToIP(msg) libs.SuccessMsg(w, nil, "请求文件发送成功") } @@ -89,7 +107,6 @@ func HandlerAccessFile(w http.ResponseWriter, r *http.Request) { msg.Hostname = hostname msg.Time = time.Now() msg.Type = "fileAccessed" - msg.Message = "" SendToIP(msg) libs.SuccessMsg(w, nil, "请求文件发送成功") }