diff --git a/src/pinia/store.js b/src/pinia/store.js index 9c4c15d..0c5cd55 100644 --- a/src/pinia/store.js +++ b/src/pinia/store.js @@ -1,72 +1,80 @@ -import { defineStore } from "pinia"; -import config from "../../miaoShareConfig.json" +import { defineStore } from 'pinia' +import config from '../../miaoShareConfig.json' -const userID = localStorage.getItem('userID'); -const userGroup = localStorage.getItem('userGroup'); +console.log(location) + +const userID = localStorage.getItem('userID') +const userGroup = localStorage.getItem('userGroup') const tokenExpiresIn = config.tokenExpiresIn -if(localStorage.getItem('tokenExpiredTime') == null || - parseInt(localStorage.getItem('tokenExpiredTime')) < parseInt(Date.now())){ - localStorage.removeItem('token') - } +if ( + localStorage.getItem('tokenExpiredTime') == null || + parseInt(localStorage.getItem('tokenExpiredTime')) < parseInt(Date.now()) +) { + localStorage.removeItem('token') +} -const token = localStorage.getItem('token'); - -// console.log(token) +const token = localStorage.getItem('token') var activeFuctionLocal = localStorage.getItem('activeFuction') -if (activeFuctionLocal == null){ +if (activeFuctionLocal == null) { activeFuctionLocal = 'AES128' - localStorage.setItem('activeFuction',activeFuctionLocal) + localStorage.setItem('activeFuction', activeFuctionLocal) } // localStorage.removeItem('activeKeyMap') var activeKeyMap = localStorage.getItem('activeKeyMap') -if (activeKeyMap == null ){ - activeKeyMap = JSON.stringify(['A-Z','0-9']) - localStorage.setItem('activeKeyMap',activeKeyMap) +if (activeKeyMap == null) { + activeKeyMap = JSON.stringify(['A-Z', '0-9']) + localStorage.setItem('activeKeyMap', activeKeyMap) } // 开发环境下服务器端口使用设置的端口,否则使用与页面相同的端口 -const serverPort = process.env.NODE_ENV === 'development' ? config.PORT : location.port +const serverPort = + process.env.NODE_ENV === 'development' ? config.PORT : location.port + +const baseUrl = + location.protocol + '//' + location.hostname + ':' + serverPort + '/' // console.log(process.env.NODE_ENV,config.DEVPORT,location.port,serverPort) -export const useSettingStore = defineStore("setting", { - state: () => ({ +export const useSettingStore = defineStore('setting', { + state: () => ({ activeFuction: activeFuctionLocal, - activeKeyMap:JSON.parse(activeKeyMap), - enableGuest:config.enableGuest, - serverPort, - token, - userID, - userGroup + activeKeyMap: JSON.parse(activeKeyMap), + enableGuest: config.enableGuest, + serverPort, + token, + userID, + userGroup, + baseUrl }), - getters: { - // double: state => state.count * 2 - }, - actions: { - setJWT( token,keepTokenLocal ){ - this.token = token - if(keepTokenLocal){ - localStorage.setItem('token',token) - localStorage.setItem('tokenExpiredTime',parseInt(Date.now())+parseInt(tokenExpiresIn)*3600000) - } - }, - setUserID( id,keepTokenLocal ){ - this.userID = id - if(keepTokenLocal) - localStorage.setItem('userID',id) - }, - setUserGroup( g,keepTokenLocal ){ - this.userGroup = g - if(keepTokenLocal) - localStorage.setItem('userGroup',g) - }, - getToken(){ - return localStorage.getItem('token') - } - // increment() { - // this.count++; - // } - } -}); + getters: { + // double: state => state.count * 2 + }, + actions: { + setJWT(token, keepTokenLocal) { + this.token = token + if (keepTokenLocal) { + localStorage.setItem('token', token) + localStorage.setItem( + 'tokenExpiredTime', + parseInt(Date.now()) + parseInt(tokenExpiresIn) * 3600000 + ) + } + }, + setUserID(id, keepTokenLocal) { + this.userID = id + if (keepTokenLocal) localStorage.setItem('userID', id) + }, + setUserGroup(g, keepTokenLocal) { + this.userGroup = g + if (keepTokenLocal) localStorage.setItem('userGroup', g) + }, + getToken() { + return localStorage.getItem('token') + } + // increment() { + // this.count++; + // } + } +}) diff --git a/src/views/chat.vue b/src/views/chat.vue index eb065fc..0bf6b6c 100644 --- a/src/views/chat.vue +++ b/src/views/chat.vue @@ -37,7 +37,7 @@
- + - + - + - @@ -106,7 +106,8 @@ const _toClipboard = async (text) => { const setting = useSettingStore(); const serverPort = setting.serverPort; const wsBaseUrl = 'ws' + "://" + location.hostname + ":" + serverPort; -const baseUrl = location.protocol + "//" + location.hostname + ":" + serverPort + "/"; +// const baseUrl = location.protocol + "//" + location.hostname + ":" + serverPort + "/"; +const baseUrl = setting.baseUrl const QRIconUrl = ref(location.protocol + "//" + location.hostname + ":" + serverPort + "/favicon.ico") const columns = [ @@ -290,7 +291,7 @@ function joinGroup_Verify(gID) { } function sendMsg(gID, msg) { - if(msg === '' || msg === null || activeGID.value === null)return + if(msg === '' || msg === null || activeGID.value === null)return let key = gID2key[gID].key msg = encryptString(key, msg, setting) socket.send(JSON.stringify({ type: 'message',type1:'text', msg, gID })) @@ -306,7 +307,7 @@ function sendMsg(gID, msg) { // } async function uploadFile(file){ - if(activeGID.value === null)return + if(activeGID.value === null)return var fileName = file.name; let key = gID2key[activeGID.value].key const encryptedFileName = encryptString(key, fileName, setting); diff --git a/src/views/downloadFileMiao.vue b/src/views/downloadFileMiao.vue index baf3888..4cd9f7b 100644 --- a/src/views/downloadFileMiao.vue +++ b/src/views/downloadFileMiao.vue @@ -40,8 +40,8 @@ const setting = useSettingStore(); // 服务端端口 const serverPort = setting.serverPort; -var baseUrl = - location.protocol + "//" + location.hostname + ":" + serverPort + "/"; +// const baseUrl = location.protocol + "//" + location.hostname + ":" + serverPort + "/"; +const baseUrl = setting.baseUrl // console.log(baseUrl); // const blob2Uint8Array = function(blob) { diff --git a/src/views/login.vue b/src/views/login.vue index 69c1a9d..41b051c 100644 --- a/src/views/login.vue +++ b/src/views/login.vue @@ -43,8 +43,8 @@ const serverPort = settingData.serverPort; const userIDInput = ref('') const userPasswordInput = ref('') const isLogining = ref(false) -const baseUrl = - location.protocol + "//" + location.hostname + ":" + serverPort + "/"; +// const baseUrl = location.protocol + "//" + location.hostname + ":" + serverPort + "/"; +const baseUrl = settingData.baseUrl const Token = computed(() => settingData.token) const keepTokenLocal = ref(true) diff --git a/src/views/uploadFileMiao.vue b/src/views/uploadFileMiao.vue index 78fe4f5..4308642 100644 --- a/src/views/uploadFileMiao.vue +++ b/src/views/uploadFileMiao.vue @@ -19,7 +19,7 @@ - + 开始上传 @@ -94,8 +94,9 @@ var file_Code_Map = ref([]); var uploadProcess = ref(0); -const baseUrl = - location.protocol + "//" + location.hostname + ":" + serverPort + "/"; +// const baseUrl = location.protocol + "//" + location.hostname + ":" + serverPort + "/"; +const baseUrl = setting.baseUrl +console.log(baseUrl) // const blob2Uint8Array = function(blob) {