Browse Source

change update

master
godo 9 months ago
parent
commit
0c9c671050
  1. 2
      frontend/package.json
  2. 13
      frontend/src/components/desktop/Upgrade.vue
  3. 46
      frontend/src/components/localchat/Chat.vue
  4. 56
      frontend/src/stores/localchat.ts
  5. 26
      frontend/src/stores/upgrade.ts
  6. 30
      frontend/src/system/config.ts

2
frontend/package.json

@ -1,7 +1,7 @@
{ {
"name": "godoos", "name": "godoos",
"private": true, "private": true,
"version": "1.0.0", "version": "1.0.2",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

13
frontend/src/components/desktop/Upgrade.vue

@ -2,7 +2,7 @@
<div class="upgrade-dialog"> <div class="upgrade-dialog">
<el-dialog <el-dialog
v-model="state.isUpgrade" v-model="state.isUpgrade"
width="300px" width="350px"
destroy-on-close destroy-on-close
:show-close="false" :show-close="false"
:close-on-click-modal="false" :close-on-click-modal="false"
@ -15,12 +15,7 @@
</div> </div>
</div> </div>
<div class="upgrade-content"> <div class="upgrade-content">
GodoOS {{ upgradeStore.upgradeDesc }} <div class="upgrade-content-txt" v-html="upgradeStore.upgradeDesc"></div>
<div class="mt5">
<el-link type="primary" class="font12" href="https://godoos.com/home/blog/godoos/" target="_black">
查看详情
</el-link>
</div>
<div class="upgrade-content-desc mt5">{{ $t('upgrade.desc') }}</div> <div class="upgrade-content-desc mt5">{{ $t('upgrade.desc') }}</div>
<div class="upgrade-content-desc" v-if="upgradeStore.progress > 0"> <div class="upgrade-content-desc" v-if="upgradeStore.progress > 0">
<el-progress :text-inside="true" :stroke-width="20" :percentage="upgradeStore.progress" /> <el-progress :text-inside="true" :stroke-width="20" :percentage="upgradeStore.progress" />
@ -124,6 +119,10 @@ onMounted(() => {
.upgrade-content { .upgrade-content {
padding: 20px; padding: 20px;
line-height: 22px; line-height: 22px;
.upgrade-content-txt{
max-height: 300px;
overflow-y: auto;
}
.upgrade-content-desc { .upgrade-content-desc {
color: rgba(255, 255, 255, 0.7); color: rgba(255, 255, 255, 0.7);
font-size: 12px; font-size: 12px;

46
frontend/src/components/localchat/Chat.vue

@ -16,56 +16,14 @@
import { onMounted } from "vue"; import { onMounted } from "vue";
import { useLocalChatStore } from "@/stores/localchat"; import { useLocalChatStore } from "@/stores/localchat";
//import { ElMessage } from "element-plus";
//import { getSystemConfig } from "@/system/config";
const store = useLocalChatStore(); const store = useLocalChatStore();
//const config = getSystemConfig();
//let source:any; //let source:any;
onMounted(async () => { onMounted(async () => {
await store.init() await store.init()
//init()
}); });
// onUnmounted(() => {
// if (source) {
// source.close();
// }
// });
// function init() {
// if (typeof EventSource === "undefined") {
// ElMessage.error("SSE");
// return;
// }
// const sseUrl = config.apiUrl + "/localchat/sse";
// source = new EventSource(sseUrl);
// //
// source.onmessage = async function (event:any) {
// //console.log("has message!");
// const eventData = event.data; //
// const jsonData = JSON.parse(eventData); //
// //console.log(jsonData);
// if (jsonData.type == "user_list") {
// //store.userList = jsonData;
// store.setUserList(jsonData.content);
// //await nextTick();
// }
// if(jsonData.type == 'text'){
// store.addText(jsonData);
// }
// if(jsonData.type == 'file'){
// store.addFile(jsonData);
// }
// };
// //
// source.onopen = function () {
// console.log("Connection opened.");
// };
// //
// source.onerror = function () {
// console.log("Connection closed.");
// };
// }
</script> </script>

56
frontend/src/stores/localchat.ts

@ -2,11 +2,12 @@ import { defineStore } from 'pinia'
import emojiList from "@/assets/emoji.json" import emojiList from "@/assets/emoji.json"
import { ref, toRaw } from "vue"; import { ref, toRaw } from "vue";
import { db } from './db' import { db } from './db'
import { getSystemConfig, setSystemKey } from "@/system/config"; import { fetchPost, getChatUrl, getUrl, setSystemKey } from "@/system/config";
import { isValidIP } from "@/util/common"; import { isValidIP } from "@/util/common";
import { notifyError, notifySuccess } from "@/util/msg"; import { notifyError, notifySuccess } from "@/util/msg";
export const useLocalChatStore = defineStore('localChatStore', () => { export const useLocalChatStore = defineStore('localChatStore', () => {
const config = getSystemConfig(); //const config = getSystemConfig();
const chatUrl = getChatUrl();
//const sys = inject<System>("system"); //const sys = inject<System>("system");
const userList: any = ref([]) const userList: any = ref([])
const msgList: any = ref([]) const msgList: any = ref([])
@ -38,7 +39,6 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
setUserList(ips); setUserList(ips);
} }
if(data.messages){ if(data.messages){
const apiUrl = `${config.apiUrl}/localchat/viewimage?img=`
for(let ip in data.messages){ for(let ip in data.messages){
const msgList:any = data.messages[ip] const msgList:any = data.messages[ip]
if(!msgList || msgList.length < 1)return; if(!msgList || msgList.length < 1)return;
@ -50,7 +50,10 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
addText(msg) addText(msg)
} }
else if (msg.type === "image"){ else if (msg.type === "image"){
msg.message = msg.message.map((d: any) => `${apiUrl}${encodeURIComponent(d)}`) msg.message = msg.message.map((d: any) => {
const url = `/localchat/viewimage?img=${encodeURIComponent(d)}`
return getUrl(url)
})
//console.log(msg) //console.log(msg)
addText(msg) addText(msg)
} }
@ -318,18 +321,21 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
return return
} }
const content = toRaw(sendInfo.value) const content = toRaw(sendInfo.value)
let saves:any let saveContent:any
if (type === 'image') { if (type === 'image') {
const apiUrl = `${config.apiUrl}/localchat/viewimage?img=` saveContent = content.map((d: any) => {
saves = content.map((d: any) => `${apiUrl}${encodeURIComponent(d)}`) const url = `/localchat/viewimage?img=${encodeURIComponent(d)}`
return getUrl(url)
})
}else{ }else{
saves = content saveContent = content
} }
console.log(saveContent)
const saveMsg: any = { const saveMsg: any = {
type: type, type: type,
targetId: chatTargetId.value, targetId: chatTargetId.value,
targetIp: chatTargetIp.value, targetIp: chatTargetIp.value,
content: saves, content: saveContent,
createdAt: Date.now(), createdAt: Date.now(),
isMe: true, isMe: true,
isRead: false, isRead: false,
@ -347,23 +353,20 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
ip: saveMsg.targetIp ip: saveMsg.targetIp
} }
if (targetUser.isOnline) { if (targetUser.isOnline) {
let postUrl = `${config.apiUrl}/localchat/message` let postUrl = `${chatUrl}/message`
if(type === 'applyfile'){ if(type === 'applyfile'){
messages.message = { messages.message = {
fileList: messages.message, fileList: messages.message,
msgId: msgId, msgId: msgId,
status: 'apply' status: 'apply'
} }
postUrl = `${config.apiUrl}/localchat/applyfile` postUrl = `${chatUrl}/applyfile`
} }
if(type === 'image'){ if(type === 'image'){
postUrl = `${config.apiUrl}/localchat/sendimage` postUrl = `${chatUrl}/sendimage`
} }
const completion = await fetch(postUrl, { const completion = await fetchPost(postUrl, JSON.stringify(messages))
method: "POST",
body: JSON.stringify(messages),
})
//console.log(completion) //console.log(completion)
if (!completion.ok) { if (!completion.ok) {
console.log(completion) console.log(completion)
@ -390,11 +393,8 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
message: item.content.msgId, message: item.content.msgId,
ip: item.targetIp ip: item.targetIp
} }
const postUrl = `${config.apiUrl}/localchat/cannelfile` const postUrl = `${chatUrl}/cannelfile`
const coms = await fetch(postUrl, { const coms = await fetchPost(postUrl, JSON.stringify(messages))
method: "POST",
body: JSON.stringify(messages),
})
if (!coms.ok) { if (!coms.ok) {
console.log(coms) console.log(coms)
notifyError("确认失败!") notifyError("确认失败!")
@ -421,11 +421,8 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
message: item.content, message: item.content,
ip: item.targetIp ip: item.targetIp
} }
const postUrl = `${config.apiUrl}/localchat/accessfile` const postUrl = `${chatUrl}/accessfile`
const coms = await fetch(postUrl, { const coms = await fetchPost(postUrl, JSON.stringify(messages))
method: "POST",
body: JSON.stringify(messages),
})
if (!coms.ok) { if (!coms.ok) {
//console.log(coms) //console.log(coms)
notifyError("确认失败!") notifyError("确认失败!")
@ -452,11 +449,8 @@ export const useLocalChatStore = defineStore('localChatStore', () => {
async function saveConfig(conf:any){ async function saveConfig(conf:any){
conf = toRaw(conf) conf = toRaw(conf)
//console.log(conf) //console.log(conf)
const postUrl = `${config.apiUrl}/localchat/setting` const postUrl = `${chatUrl}/setting`
const coms = await fetch(postUrl, { const coms = await fetchPost(postUrl, JSON.stringify(conf))
method: "POST",
body: JSON.stringify(conf),
})
if (!coms.ok) { if (!coms.ok) {
//console.log(coms) //console.log(coms)
notifyError("保存失败!") notifyError("保存失败!")

26
frontend/src/stores/upgrade.ts

@ -1,6 +1,6 @@
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { ref } from "vue"; import { ref } from "vue";
import { getSystemKey, setSystemKey, parseJson, getSystemConfig } from '@/system/config' import { setSystemKey, parseJson, getSystemConfig, getUrl } from '@/system/config'
import { RestartApp } from '@/util/goutil'; import { RestartApp } from '@/util/goutil';
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { t } from '@/i18n'; import { t } from '@/i18n';
@ -37,9 +37,9 @@ export const useUpgradeStore = defineStore('upgradeStore', () => {
return 0; return 0;
} }
function systemMessage(){ function systemMessage(){
const config = getSystemConfig(); //const config = getSystemConfig();
const apiUrl = getUrl('/system/message',false)
const source = new EventSource(`${config.apiUrl}/system/message`); const source = new EventSource(apiUrl);
source.onmessage = function(event) { source.onmessage = function(event) {
const data = JSON.parse(event.data); const data = JSON.parse(event.data);
@ -53,7 +53,7 @@ export const useUpgradeStore = defineStore('upgradeStore', () => {
async function handleMessage(message:any) { async function handleMessage(message:any) {
switch (message.type) { switch (message.type) {
case 'update': case 'update':
checkUpdate(message.data.data) checkUpdate(message.data)
break; break;
case 'localchat': case 'localchat':
localChatStore.handlerMessage(message.data) localChatStore.handlerMessage(message.data)
@ -64,6 +64,7 @@ export const useUpgradeStore = defineStore('upgradeStore', () => {
} }
async function checkUpdate(res:any) { async function checkUpdate(res:any) {
//console.log(res) //console.log(res)
if(!res)return
const config = getSystemConfig(); const config = getSystemConfig();
if(!config.account.ad)return; if(!config.account.ad)return;
currentVersion.value = config.version; currentVersion.value = config.version;
@ -96,17 +97,24 @@ export const useUpgradeStore = defineStore('upgradeStore', () => {
} }
} }
function changeUrl(list : any){ function changeUrl(list : any){
const config = getSystemConfig();
list.forEach((item:any) => { list.forEach((item:any) => {
if(item.img && item.img.indexOf('http') == -1){ if(item.img && item.img.indexOf('http') == -1){
item.img = `https://godoos.com${item.img}` if(config.userType === 'person'){
item.img = `https://godoos.com${item.img}`
}else{
item.img = `${config.userInfo.url}${item.img}`
}
} }
}); });
return list return list
} }
async function update() { async function update() {
const apiUrl = getSystemKey('apiUrl') //const apiUrl = getApiUrl()
const upUrl = `${apiUrl}/system/update?url=${updateUrl.value}` const upUrl = `/system/update?url=${updateUrl.value}`
const upRes = await fetch(upUrl) const apiUrl = getUrl(upUrl,true)
const upRes = await fetch(apiUrl)
if (!upRes.ok) return; if (!upRes.ok) return;
const reader: any = upRes.body?.getReader(); const reader: any = upRes.body?.getReader();
if (!reader) { if (!reader) {

30
frontend/src/system/config.ts

@ -14,7 +14,7 @@ export const getSystemConfig = (ifset = false) => {
// 初始化配置对象的各项属性,若本地存储中已存在则不进行覆盖 // 初始化配置对象的各项属性,若本地存储中已存在则不进行覆盖
if (!config.version) { if (!config.version) {
config.version = '1.0.1'; config.version = '1.0.2';
} }
if (!config.isFirstRun) { if (!config.isFirstRun) {
config.isFirstRun = false; config.isFirstRun = false;
@ -155,7 +155,12 @@ export const getSystemConfig = (ifset = false) => {
}; };
export function getApiUrl() { export function getApiUrl() {
return getSystemKey('apiUrl') const config = getSystemConfig();
if (config.userType == 'person') {
return config.apiUrl
}else{
return config.userInfo.url
}
} }
export function getFileUrl() { export function getFileUrl() {
const config = getSystemConfig(); const config = getSystemConfig();
@ -173,6 +178,27 @@ export function getFileUrl() {
} }
} }
export function getChatUrl() {
const config = getSystemConfig();
if (config.userType == 'person') {
return config.apiUrl + '/localchat'
} else {
return config.userInfo.url + '/localchat'
}
}
export function getUrl(url: string, islast = true) {
const config = getSystemConfig();
if (config.userType == 'person') {
return config.apiUrl + url
} else {
if(islast){
return config.userInfo.url + url + '&uuid=' + getClientId() + '&token=' + config.userInfo.token
}else{
return config.userInfo.url + url + '?uuid=' + getClientId() + '&token=' + config.userInfo.token
}
}
}
export function fetchGet(url: string) { export function fetchGet(url: string) {
const config = getSystemConfig(); const config = getSystemConfig();
if (config.userType == 'person') { if (config.userType == 'person') {

Loading…
Cancel
Save