mirror of https://gitee.com/godoos/godoos.git
16 changed files with 924 additions and 526 deletions
@ -1,70 +1,116 @@ |
|||||
<script setup> |
<script setup> |
||||
import {ref} from "vue"; |
|
||||
import { useChatStore } from "@/stores/chat"; |
import { useChatStore } from "@/stores/chat"; |
||||
import {Setting as SettingIcon} from "@element-plus/icons-vue"; |
import { Setting as SettingIcon } from "@element-plus/icons-vue"; |
||||
const store = useChatStore() |
|
||||
const getOnline = () => { |
const store = useChatStore(); |
||||
store.getOnlineUsers() |
|
||||
store.setCurrentNavId(1) |
|
||||
} |
|
||||
</script> |
</script> |
||||
|
|
||||
<template> |
<template> |
||||
<el-row> |
<el-row> |
||||
<el-avatar shape="square" :size="40" class="userAvatar" :src="store.userInfo.avatar"/> |
<el-avatar |
||||
|
shape="square" |
||||
|
:size="40" |
||||
|
class="userAvatar" |
||||
|
:src="store.userInfo.avatar" |
||||
|
/> |
||||
</el-row> |
</el-row> |
||||
<el-row @click="store.setCurrentNavId(0)"> |
<el-row @click="store.setCurrentNavId(0)"> |
||||
<el-icon v-if="store.currentNavId === 0" class="menu-icon-on"> |
<div class="menu-icon-box"> |
||||
<ChatLineRound /> |
<el-icon |
||||
</el-icon> |
v-if="store.currentNavId === 0" |
||||
<el-icon v-else class="menu-icon"> |
class="menu-icon-on" |
||||
<ChatRound /> |
> |
||||
</el-icon> |
<ChatLineRound /> |
||||
|
</el-icon> |
||||
|
<el-icon |
||||
|
v-else |
||||
|
class="menu-icon" |
||||
|
> |
||||
|
<ChatRound /> |
||||
|
</el-icon> |
||||
|
</div> |
||||
</el-row> |
</el-row> |
||||
<el-row @click="getOnline"> |
<el-row @click="store.setCurrentNavId(1)"> |
||||
<el-icon v-if="store.currentNavId === 1" class="menu-icon-on"> |
<div class="menu-icon-box"> |
||||
<UserFilled /> |
<el-icon |
||||
</el-icon> |
v-if="store.currentNavId === 1" |
||||
<el-icon v-else class="menu-icon"> |
class="menu-icon-on" |
||||
<User /> |
> |
||||
</el-icon> |
<UserFilled /> |
||||
|
</el-icon> |
||||
|
<el-icon |
||||
|
v-else |
||||
|
class="menu-icon" |
||||
|
> |
||||
|
<User /> |
||||
|
</el-icon> |
||||
|
</div> |
||||
</el-row> |
</el-row> |
||||
<el-row @click="store.setCurrentNavId(2)"> |
<el-row @click="store.setCurrentNavId(2)"> |
||||
<el-icon v-if="store.currentNavId === 2" class="menu-icon-on"> |
<div class="menu-icon-box"> |
||||
<Platform /> |
<el-icon |
||||
</el-icon> |
v-if="store.currentNavId === 2" |
||||
<el-icon v-else class="menu-icon"> |
class="menu-icon-on" |
||||
<Monitor /> |
> |
||||
</el-icon> |
<Platform /> |
||||
|
</el-icon> |
||||
|
<el-icon |
||||
|
v-else |
||||
|
class="menu-icon" |
||||
|
> |
||||
|
<Monitor /> |
||||
|
</el-icon> |
||||
|
</div> |
||||
</el-row> |
</el-row> |
||||
<el-row @click="store.setCurrentNavId(5)"> |
<el-row @click="store.setCurrentNavId(5)"> |
||||
<el-icon v-if="store.currentNavId === 5" class="menu-icon-on"> |
<div class="menu-icon-box"> |
||||
<SettingIcon /> |
<el-icon |
||||
</el-icon> |
v-if="store.currentNavId === 5" |
||||
<el-icon v-else class="menu-icon"> |
class="menu-icon-on" |
||||
<SettingIcon /> |
> |
||||
</el-icon> |
<SettingIcon /> |
||||
|
</el-icon> |
||||
|
<el-icon |
||||
|
v-else |
||||
|
class="menu-icon" |
||||
|
> |
||||
|
<SettingIcon /> |
||||
|
</el-icon> |
||||
|
</div> |
||||
</el-row> |
</el-row> |
||||
</template> |
</template> |
||||
|
|
||||
<style scoped> |
<style scoped> |
||||
.userAvatar { |
.userAvatar { |
||||
margin: 30px auto 10px; |
margin: 30px auto 10px; |
||||
-webkit-app-region: no-drag |
-webkit-app-region: no-drag; |
||||
|
} |
||||
|
|
||||
|
.menu-icon-box { |
||||
|
display: flex; |
||||
|
align-items: center; |
||||
|
justify-content: center; |
||||
|
width: 40px; |
||||
|
height: 40px; |
||||
|
margin: 10px auto; |
||||
|
border-radius: 15%; |
||||
|
/* background-color: #bae7ff; */ |
||||
|
transition: all 0.5s; |
||||
|
} |
||||
|
.menu-icon-box:hover { |
||||
|
background-color: #d9d9d9; |
||||
} |
} |
||||
|
|
||||
.menu-icon { |
.menu-icon { |
||||
margin: 20px auto; |
margin: 0px auto; |
||||
font-size: 25px; |
font-size: 25px; |
||||
color: #8F8F8F; |
|
||||
cursor: pointer; |
cursor: pointer; |
||||
} |
} |
||||
|
|
||||
.menu-icon-on { |
.menu-icon-on { |
||||
margin: 20px auto; |
margin: 0px auto; |
||||
font-size: 25px; |
font-size: 25px; |
||||
color: #0078d4; |
color: #1890ff; |
||||
cursor: pointer; |
cursor: pointer; |
||||
} |
} |
||||
|
</style> |
||||
</style> |
|
@ -1,158 +1,210 @@ |
|||||
<script setup lang="ts"> |
<script setup lang="ts"> |
||||
import { useChatStore } from '@/stores/chat'; |
import { useChatStore } from "@/stores/chat"; |
||||
const store = useChatStore(); |
|
||||
|
|
||||
|
const chatHistory = computed(() => store.chatHistory as any); |
||||
|
|
||||
|
const store = useChatStore(); |
||||
</script> |
</script> |
||||
|
|
||||
<template> |
<template> |
||||
<div v-for="item in store.chatHistory" :key="item.id"> |
<div |
||||
<div v-if="!item.isme" class="chat-item"> |
v-for="item in chatHistory" |
||||
<el-row> |
:key="item.id" |
||||
<el-col :span="8" /> |
> |
||||
<el-col :span="14"> |
<div |
||||
<el-row> |
v-if="!item.isme" |
||||
<el-col :span="24"> |
class="chat-item" |
||||
<div class="chat-name-me">{{ item.userInfo.username }}</div> |
> |
||||
</el-col> |
<el-row> |
||||
</el-row> |
<el-col :span="8" /> |
||||
<div class="bubble-me" @contextmenu.prevent="store.showContextMenu($event, item.id)"> |
<el-col :span="14"> |
||||
<div class="chat-font"> |
<el-row> |
||||
{{ item.content }} |
<el-col :span="24"> |
||||
</div> |
<div class="chat-name-me"> |
||||
</div> |
{{ item.userInfo.username }} |
||||
</el-col> |
</div> |
||||
<el-col :span="2"> |
</el-col> |
||||
<div class="chat-avatar"> |
</el-row> |
||||
<el-avatar shape="square" style="margin: 0;float: left" :size="32" class="userAvatar" |
<div |
||||
:src="item.userInfo.avatar" /> |
class="bubble-me" |
||||
</div> |
@contextmenu.prevent=" |
||||
</el-col> |
store.showContextMenu($event, item.id) |
||||
</el-row> |
" |
||||
</div> |
> |
||||
<div v-else class="chat-item"> |
<div class="chat-font"> |
||||
<el-row> |
{{ item.content }} |
||||
<el-col :span="2"> |
</div> |
||||
<div class="chat-avatar"> |
</div> |
||||
<el-avatar shape="square" style="margin: 0;float: right" :size="32" class="userAvatar" |
</el-col> |
||||
:src="item.userInfo.avatar" /> |
<el-col :span="2"> |
||||
</div> |
<div class="chat-avatar"> |
||||
</el-col> |
<el-avatar |
||||
<el-col :span="14"> |
shape="square" |
||||
<el-row> |
style="margin: 0; float: left" |
||||
<el-col :span="24"> |
:size="32" |
||||
<div class="chat-name-other">{{ item.userInfo.username }}</div> |
class="userAvatar" |
||||
</el-col> |
:src="item.userInfo.avatar" |
||||
</el-row> |
/> |
||||
<div class="bubble-other"> |
</div> |
||||
<div class="chat-font"> |
</el-col> |
||||
{{ item.content }} |
</el-row> |
||||
</div> |
</div> |
||||
</div> |
<div |
||||
</el-col> |
v-else |
||||
<el-col :span="8" /> |
class="chat-item" |
||||
</el-row> |
> |
||||
</div> |
<el-row> |
||||
<div v-if="item.type === 1" class="withdraw"> |
<el-col :span="2"> |
||||
{{ item.userInfo.id === store.targetUserId ? "你" : item.userInfo.username }}撤回了一条消息 |
<div class="chat-avatar"> |
||||
</div> |
<el-avatar |
||||
</div> |
shape="square" |
||||
<!--悬浮菜单--> |
style="margin: 0; float: right" |
||||
<div class="context-menu" v-if="store.contextMenu.visible" |
:size="32" |
||||
:style="{ top: `${store.contextMenu.y}px`, left: `${store.contextMenu.x}px` }"> |
class="userAvatar" |
||||
<div v-for="contextItem in store.contextMenu.list" :key="contextItem.id" class="context-menu-item"> |
:src="item.userInfo.avatar" |
||||
<div class="context-menu-item-font" @click="store.handleContextMenu(contextItem)"> |
/> |
||||
{{ contextItem.label }} |
</div> |
||||
</div> |
</el-col> |
||||
</div> |
<el-col :span="14"> |
||||
</div> |
<el-row> |
||||
|
<el-col :span="24"> |
||||
|
<div class="chat-name-other"> |
||||
|
{{ item.userInfo.username }} |
||||
|
</div> |
||||
|
</el-col> |
||||
|
</el-row> |
||||
|
<div class="bubble-other"> |
||||
|
<div class="chat-font"> |
||||
|
{{ item.content }} |
||||
|
</div> |
||||
|
</div> |
||||
|
</el-col> |
||||
|
<el-col :span="8" /> |
||||
|
</el-row> |
||||
|
</div> |
||||
|
<div |
||||
|
v-if="item.type === 1" |
||||
|
class="withdraw" |
||||
|
> |
||||
|
{{ |
||||
|
item.userInfo.id === store.targetUserId |
||||
|
? "你" |
||||
|
: item.userInfo.username |
||||
|
}}撤回了一条消息 |
||||
|
</div> |
||||
|
</div> |
||||
|
<!--悬浮菜单--> |
||||
|
<div |
||||
|
class="context-menu" |
||||
|
v-if="store.contextMenu.visible" |
||||
|
:style="{ |
||||
|
top: `${store.contextMenu.y}px`, |
||||
|
left: `${store.contextMenu.x}px`, |
||||
|
}" |
||||
|
> |
||||
|
<div |
||||
|
v-for="contextItem in store.contextMenu.list" |
||||
|
:key="contextItem.id" |
||||
|
class="context-menu-item" |
||||
|
> |
||||
|
<div |
||||
|
class="context-menu-item-font" |
||||
|
@click="store.handleContextMenu()" |
||||
|
> |
||||
|
{{ contextItem.label }} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
</template> |
</template> |
||||
|
|
||||
<style scoped> |
<style scoped> |
||||
.bubble-me { |
.bubble-me { |
||||
background-color: #95EC69; |
background-color: #95ec69; |
||||
float: right; |
float: right; |
||||
border-radius: 4px; |
border-radius: 4px; |
||||
margin-right: 5px; |
margin-right: 5px; |
||||
margin-top: 5px; |
margin-top: 5px; |
||||
} |
} |
||||
|
|
||||
.bubble-me:hover { |
.bubble-me:hover { |
||||
background-color: #89D961; |
background-color: #89d961; |
||||
} |
} |
||||
|
|
||||
.chat-name-me { |
.chat-name-me { |
||||
font-size: 14px; |
font-size: 14px; |
||||
font-family: Arial, sans-serif; |
font-family: Arial, sans-serif; |
||||
line-height: 1.5; |
line-height: 1.5; |
||||
color: #B2B2B2; |
color: #b2b2b2; |
||||
float: right; |
float: right; |
||||
margin-right: 5px; |
margin-right: 5px; |
||||
} |
} |
||||
|
|
||||
.bubble-other { |
.bubble-other { |
||||
background-color: #FFFFFF; |
background-color: #ffffff; |
||||
float: left; |
float: left; |
||||
border-radius: 4px; |
border-radius: 4px; |
||||
margin-left: 5px; |
margin-left: 5px; |
||||
margin-top: 5px; |
margin-top: 5px; |
||||
} |
} |
||||
|
|
||||
.bubble-other:hover { |
.bubble-other:hover { |
||||
background-color: #EBEBEB; |
background-color: #ebebeb; |
||||
} |
} |
||||
|
|
||||
.chat-name-other { |
.chat-name-other { |
||||
font-size: 14px; |
font-size: 14px; |
||||
font-family: Arial, sans-serif; |
font-family: Arial, sans-serif; |
||||
line-height: 1.5; |
line-height: 1.5; |
||||
color: #B2B2B2; |
color: #b2b2b2; |
||||
float: left; |
float: left; |
||||
margin-left: 5px; |
margin-left: 5px; |
||||
} |
} |
||||
|
|
||||
.chat-font { |
.chat-font { |
||||
margin: 8px; |
margin: 8px; |
||||
font-size: 15px; |
font-size: 15px; |
||||
font-family: Arial, sans-serif; |
font-family: Arial, sans-serif; |
||||
line-height: 1.5; |
line-height: 1.5; |
||||
} |
} |
||||
|
|
||||
.chat-avatar { |
.chat-avatar { |
||||
margin: 5px; |
margin: 5px; |
||||
} |
} |
||||
|
|
||||
.chat-item { |
.chat-item { |
||||
margin: 5px; |
margin: 5px; |
||||
} |
} |
||||
|
|
||||
.withdraw { |
.withdraw { |
||||
text-align: center; |
text-align: center; |
||||
font-size: 13px; |
font-size: 13px; |
||||
font-family: Arial, sans-serif; |
font-family: Arial, sans-serif; |
||||
color: #999999; |
color: #999999; |
||||
line-height: 3.2; |
line-height: 3.2; |
||||
} |
} |
||||
|
|
||||
.context-menu { |
.context-menu { |
||||
position: fixed; |
position: fixed; |
||||
background-color: white; |
background-color: white; |
||||
z-index: 9999; |
z-index: 9999; |
||||
border: 1px solid #cccc; |
border: 1px solid #cccc; |
||||
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); |
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1); |
||||
} |
} |
||||
|
|
||||
.context-menu-item { |
.context-menu-item { |
||||
width: 80px; |
width: 80px; |
||||
height: 30px; |
height: 30px; |
||||
} |
} |
||||
|
|
||||
.context-menu-item:hover { |
.context-menu-item:hover { |
||||
background-color: #E2E2E2; |
background-color: #e2e2e2; |
||||
} |
} |
||||
|
|
||||
.context-menu-item-font { |
.context-menu-item-font { |
||||
font-size: 14px; |
font-size: 14px; |
||||
text-align: center; |
text-align: center; |
||||
font-family: Arial, sans-serif; |
font-family: Arial, sans-serif; |
||||
line-height: 2.2; |
line-height: 2.2; |
||||
} |
} |
||||
</style> |
</style> |
||||
|
@ -1,162 +1,185 @@ |
|||||
|
import { t } from '@/i18n'; |
||||
|
import { getSystemConfig, getUrl, parseJson, setSystemKey } from '@/system/config'; |
||||
|
import { RestartApp } from '@/util/goutil'; |
||||
|
import { ElMessage } from 'element-plus'; |
||||
import { defineStore } from "pinia"; |
import { defineStore } from "pinia"; |
||||
import { ref } from "vue"; |
import { ref } from "vue"; |
||||
import { setSystemKey, parseJson, getSystemConfig } from '@/system/config' |
import { useChatStore } from "./chat"; |
||||
import { RestartApp } from '@/util/goutil'; |
|
||||
import { ElMessage } from 'element-plus' |
|
||||
import { t } from '@/i18n'; |
|
||||
import { useLocalChatStore } from "./localchat"; |
import { useLocalChatStore } from "./localchat"; |
||||
export const useUpgradeStore = defineStore('upgradeStore', () => { |
export const useUpgradeStore = defineStore('upgradeStore', () => { |
||||
const hasUpgrade = ref(false); |
const hasUpgrade = ref(false); |
||||
const hasNotice = ref(false); |
const hasNotice = ref(false); |
||||
const hasAd = ref(false); |
const hasAd = ref(false); |
||||
const updateUrl = ref(''); |
const updateUrl = ref(''); |
||||
const versionTag = ref('') |
const versionTag = ref('') |
||||
const upgradeDesc = ref('') |
const upgradeDesc = ref('') |
||||
const currentVersion = ref('') |
const currentVersion = ref('') |
||||
const progress = ref(0) |
const progress = ref(0) |
||||
const noticeList:any = ref([]) |
const noticeList: any = ref([]) |
||||
const adList:any = ref([]) |
const adList: any = ref([]) |
||||
const localChatStore = useLocalChatStore() |
const localChatStore = useLocalChatStore() |
||||
function compareVersions(version1:string, version2:string) { |
const chatChatStore = useChatStore() |
||||
// 将版本号字符串按"."分割成数组
|
function compareVersions(version1: string, version2: string) { |
||||
const parts1 = version1.split('.').map(Number); |
// 将版本号字符串按"."分割成数组
|
||||
const parts2 = version2.split('.').map(Number); |
const parts1 = version1.split('.').map(Number); |
||||
|
const parts2 = version2.split('.').map(Number); |
||||
// 确保两个数组长度相同
|
|
||||
const maxLength = Math.max(parts1.length, parts2.length); |
// 确保两个数组长度相同
|
||||
while (parts1.length < maxLength) parts1.push(0); |
const maxLength = Math.max(parts1.length, parts2.length); |
||||
while (parts2.length < maxLength) parts2.push(0); |
while (parts1.length < maxLength) parts1.push(0); |
||||
|
while (parts2.length < maxLength) parts2.push(0); |
||||
// 比较每个部分
|
|
||||
for (let i = 0; i < maxLength; i++) { |
// 比较每个部分
|
||||
if (parts1[i] > parts2[i]) return 1; |
for (let i = 0; i < maxLength; i++) { |
||||
if (parts1[i] < parts2[i]) return -1; |
if (parts1[i] > parts2[i]) return 1; |
||||
} |
if (parts1[i] < parts2[i]) return -1; |
||||
|
|
||||
// 如果所有部分都相等,则返回0
|
|
||||
return 0; |
|
||||
} |
} |
||||
function systemMessage(){ |
|
||||
const config = getSystemConfig(); |
|
||||
const source = new EventSource(`${config.apiUrl}/system/message`); |
|
||||
|
|
||||
source.onmessage = function(event) { |
// 如果所有部分都相等,则返回0
|
||||
const data = JSON.parse(event.data); |
return 0; |
||||
//console.log(data)
|
} |
||||
handleMessage(data); |
function systemMessage() { |
||||
}; |
const config = getSystemConfig(); |
||||
source.onerror = function(event) { |
const source = new EventSource(`${config.apiUrl}/system/message`); |
||||
console.error('EventSource error:', event); |
|
||||
}; |
source.onmessage = function (event) { |
||||
|
const data = JSON.parse(event.data); |
||||
|
//console.log(data)
|
||||
|
handleMessage(data); |
||||
|
}; |
||||
|
source.onerror = function (event) { |
||||
|
console.error('EventSource error:', event); |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
// 获取在线消息
|
||||
|
function onlineMessage() { |
||||
|
const url = getUrl('/chat/message', false) |
||||
|
const source = new EventSource(url); |
||||
|
|
||||
|
source.onmessage = function (event) { |
||||
|
const data = JSON.parse(event.data); |
||||
|
|
||||
|
handleMessage(data); |
||||
|
}; |
||||
|
source.onerror = function (event) { |
||||
|
console.error('EventSource error:', event); |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
|
||||
|
async function handleMessage(message: any) { |
||||
|
switch (message.type) { |
||||
|
case 'update': |
||||
|
checkUpdate(message.data) |
||||
|
break; |
||||
|
case 'localchat': |
||||
|
localChatStore.handlerMessage(message.data) |
||||
|
break; |
||||
|
case 'online': |
||||
|
chatChatStore.handleUserData(message.data) |
||||
|
break; |
||||
|
default: |
||||
|
console.warn('Unknown message type:', message.type); |
||||
} |
} |
||||
async function handleMessage(message:any) { |
} |
||||
switch (message.type) { |
async function checkUpdate(res: any) { |
||||
case 'update': |
//console.log(res)
|
||||
checkUpdate(message.data) |
if (!res) return |
||||
break; |
const config = getSystemConfig(); |
||||
case 'localchat': |
if (!config.account.ad) return; |
||||
localChatStore.handlerMessage(message.data) |
currentVersion.value = config.version; |
||||
break; |
let bottomList: any = [] |
||||
default: |
let centerList: any = [] |
||||
console.warn('Unknown message type:', message.type); |
if (res.adlist && res.adlist.length > 0) { |
||||
} |
bottomList = res.adlist[0]['bottom'] |
||||
|
centerList = res.adlist[0]['center'] |
||||
} |
} |
||||
async function checkUpdate(res:any) { |
if (bottomList && bottomList.length > 0) { |
||||
//console.log(res)
|
hasNotice.value = true |
||||
if(!res)return |
noticeList.value = [...noticeList.value, ...changeUrl(bottomList)] |
||||
const config = getSystemConfig(); |
} |
||||
if(!config.account.ad)return; |
//console.log(noticeList)
|
||||
currentVersion.value = config.version; |
//console.log(centerList)
|
||||
let bottomList:any = [] |
if (centerList && centerList.length > 0) { |
||||
let centerList:any = [] |
hasAd.value = true |
||||
if (res.adlist && res.adlist.length > 0) { |
adList.value = [...adList.value, ...changeUrl(centerList)] |
||||
bottomList = res.adlist[0]['bottom'] |
} |
||||
centerList = res.adlist[0]['center'] |
//console.log(adList.value)
|
||||
} |
|
||||
if(bottomList && bottomList.length > 0){ |
|
||||
hasNotice.value = true |
|
||||
noticeList.value = [...noticeList.value, ...changeUrl(bottomList)] |
|
||||
} |
|
||||
//console.log(noticeList)
|
|
||||
//console.log(centerList)
|
|
||||
if(centerList && centerList.length > 0){ |
|
||||
hasAd.value = true |
|
||||
adList.value = [...adList.value, ...changeUrl(centerList)] |
|
||||
} |
|
||||
//console.log(adList.value)
|
|
||||
|
|
||||
if(!res.version || res.version == ""){ |
if (!res.version || res.version == "") { |
||||
return |
return |
||||
} |
} |
||||
versionTag.value = res.version |
versionTag.value = res.version |
||||
if (compareVersions(versionTag.value, config.version) > 0) { |
if (compareVersions(versionTag.value, config.version) > 0) { |
||||
upgradeDesc.value = res.desc ?? t('upgrade.msg') |
upgradeDesc.value = res.desc ?? t('upgrade.msg') |
||||
hasUpgrade.value = true |
hasUpgrade.value = true |
||||
updateUrl.value = res.url |
updateUrl.value = res.url |
||||
} |
|
||||
} |
} |
||||
function changeUrl(list : any){ |
} |
||||
list.forEach((item:any) => { |
function changeUrl(list: any) { |
||||
if(item.img && item.img.indexOf('http') == -1){ |
list.forEach((item: any) => { |
||||
item.img = `https://godoos.com${item.img}` |
if (item.img && item.img.indexOf('http') == -1) { |
||||
|
item.img = `https://godoos.com${item.img}` |
||||
} |
|
||||
}); |
} |
||||
return list |
}); |
||||
|
return list |
||||
|
} |
||||
|
async function update() { |
||||
|
const config = getSystemConfig(); |
||||
|
const upUrl = `${config.apiUrl}/system/update?url=${updateUrl.value}` |
||||
|
|
||||
|
const upRes = await fetch(upUrl) |
||||
|
if (!upRes.ok) return; |
||||
|
const reader: any = upRes.body?.getReader(); |
||||
|
if (!reader) { |
||||
|
ElMessage({ |
||||
|
type: 'error', |
||||
|
message: "the system has not stream!" |
||||
|
}) |
||||
} |
} |
||||
async function update() { |
while (true) { |
||||
const config = getSystemConfig(); |
const { done, value } = await reader.read(); |
||||
const upUrl = `${config.apiUrl}/system/update?url=${updateUrl.value}` |
if (done) { |
||||
|
reader.releaseLock(); |
||||
const upRes = await fetch(upUrl) |
break; |
||||
if (!upRes.ok) return; |
} |
||||
const reader: any = upRes.body?.getReader(); |
const rawjson = new TextDecoder().decode(value); |
||||
if (!reader) { |
const json = parseJson(rawjson); |
||||
ElMessage({ |
//console.log(json)
|
||||
type: 'error', |
if (json) { |
||||
message: "the system has not stream!" |
if (json.progress) { |
||||
}) |
progress.value = json.progress |
||||
} |
} |
||||
while (true) { |
if (json.updateCompleted) { |
||||
const { done, value } = await reader.read(); |
hasUpgrade.value = false |
||||
if (done) { |
progress.value = 0 |
||||
reader.releaseLock(); |
ElMessage({ |
||||
break; |
type: 'success', |
||||
} |
message: "update completed!" |
||||
const rawjson = new TextDecoder().decode(value); |
}) |
||||
const json = parseJson(rawjson); |
setSystemKey('version', versionTag.value) |
||||
//console.log(json)
|
currentVersion.value = versionTag.value |
||||
if (json) { |
RestartApp() |
||||
if (json.progress) { |
break; |
||||
progress.value = json.progress |
|
||||
} |
|
||||
if (json.updateCompleted) { |
|
||||
hasUpgrade.value = false |
|
||||
progress.value = 0 |
|
||||
ElMessage({ |
|
||||
type: 'success', |
|
||||
message: "update completed!" |
|
||||
}) |
|
||||
setSystemKey('version', versionTag.value) |
|
||||
currentVersion.value = versionTag.value |
|
||||
RestartApp() |
|
||||
break; |
|
||||
} |
|
||||
} |
|
||||
} |
} |
||||
|
} |
||||
} |
} |
||||
return { |
} |
||||
hasUpgrade, |
return { |
||||
hasNotice, |
hasUpgrade, |
||||
hasAd, |
hasNotice, |
||||
versionTag, |
hasAd, |
||||
upgradeDesc, |
versionTag, |
||||
updateUrl, |
upgradeDesc, |
||||
noticeList, |
updateUrl, |
||||
adList, |
noticeList, |
||||
progress, |
adList, |
||||
checkUpdate, |
progress, |
||||
systemMessage, |
checkUpdate, |
||||
update |
systemMessage, |
||||
} |
onlineMessage, |
||||
|
update |
||||
|
} |
||||
}) |
}) |
Loading…
Reference in new issue