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",
"private": true,
"version": "1.0.0",
"version": "1.0.2",
"type": "module",
"scripts": {
"dev": "vite",

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

@ -2,7 +2,7 @@
<div class="upgrade-dialog">
<el-dialog
v-model="state.isUpgrade"
width="300px"
width="350px"
destroy-on-close
:show-close="false"
:close-on-click-modal="false"
@ -15,12 +15,7 @@
</div>
</div>
<div class="upgrade-content">
GodoOS {{ upgradeStore.upgradeDesc }}
<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-txt" v-html="upgradeStore.upgradeDesc"></div>
<div class="upgrade-content-desc mt5">{{ $t('upgrade.desc') }}</div>
<div class="upgrade-content-desc" v-if="upgradeStore.progress > 0">
<el-progress :text-inside="true" :stroke-width="20" :percentage="upgradeStore.progress" />
@ -124,6 +119,10 @@ onMounted(() => {
.upgrade-content {
padding: 20px;
line-height: 22px;
.upgrade-content-txt{
max-height: 300px;
overflow-y: auto;
}
.upgrade-content-desc {
color: rgba(255, 255, 255, 0.7);
font-size: 12px;

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

@ -16,56 +16,14 @@
import { onMounted } from "vue";
import { useLocalChatStore } from "@/stores/localchat";
//import { ElMessage } from "element-plus";
//import { getSystemConfig } from "@/system/config";
const store = useLocalChatStore();
//const config = getSystemConfig();
//let source:any;
onMounted(async () => {
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>

56
frontend/src/stores/localchat.ts

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

26
frontend/src/stores/upgrade.ts

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

30
frontend/src/system/config.ts

@ -14,7 +14,7 @@ export const getSystemConfig = (ifset = false) => {
// 初始化配置对象的各项属性,若本地存储中已存在则不进行覆盖
if (!config.version) {
config.version = '1.0.1';
config.version = '1.0.2';
}
if (!config.isFirstRun) {
config.isFirstRun = false;
@ -155,7 +155,12 @@ export const getSystemConfig = (ifset = false) => {
};
export function getApiUrl() {
return getSystemKey('apiUrl')
const config = getSystemConfig();
if (config.userType == 'person') {
return config.apiUrl
}else{
return config.userInfo.url
}
}
export function getFileUrl() {
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) {
const config = getSystemConfig();
if (config.userType == 'person') {

Loading…
Cancel
Save