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