Browse Source

change file status

master
godo 9 months ago
parent
commit
27e4c64f25
  1. 1
      frontend/components.d.ts
  2. 43
      frontend/src/components/localchat/ChatContent.vue
  3. 61
      frontend/src/stores/localchat.ts
  4. 1
      godo/cmd/main.go
  5. 21
      godo/localchat/file.go

1
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']

43
frontend/src/components/localchat/ChatContent.vue

@ -88,12 +88,49 @@ async function scroll({ scrollTop }: { scrollTop: number }) {
</div>
</div>
</div>
<div v-if="item.type === 'fileSending'">
<el-card style="max-width: 480px">
<template #header>
<div class="card-header">
<span>对方发送文件</span>
</div>
</template>
<div class="file-content" v-for="el in item.content.fileList">
<div class="file-name">{{ el }}</div>
</div>
<template #footer>
<span v-if="item.content.status === 'apply'">
<el-button @click="store.cannelFile(item)">取消</el-button>
<el-button type="primary" @click="store.accessFile(item)">
接收
</el-button>
</span>
<span v-if="item.content.status === 'cannel'">
已拒绝
</span>
</template>
</el-card>
</div>
<div v-if="item.type === 'applyfile'">
<div class="file-bubble">
<div class="file-content" v-for="el in item.content" @click="sys.openFile(el)">
<el-card style="max-width: 480px">
<template #header>
<div class="card-header">
<span>发送文件</span>
</div>
</template>
<div class="file-content" v-for="el in item.content.fileList" @click="sys.openFile(el)">
<div class="file-name">{{ el }}</div>
</div>
</div>
<template #footer>
<span v-if="item.content.status === 'apply'">对方确认中</span>
<span v-if="item.content.status === 'confirm'">
对方已接收
</span>
<span v-if="item.content.status === 'cannel'">
对方已拒绝
</span>
</template>
</el-card>
</div>
<div v-if="item.type === 'image'">
<div class="file-bubble">

61
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
}
})

1
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)

21
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, "请求文件发送成功")
}

Loading…
Cancel
Save