统一在store.js中管理baseUrl

This commit is contained in:
539943419 committed 2024-07-29 14:41:50 +08:00
1 parent dfc26aedea
commit 44f3d57884
5 files changed
+79 -69

No files matched your search

+62 -54
View File
@@ -1,72 +1,80 @@
import { defineStore } from "pinia"; import { defineStore } from 'pinia'
import config from "../../miaoShareConfig.json" import config from '../../miaoShareConfig.json'
const userID = localStorage.getItem('userID'); console.log(location)
const userGroup = localStorage.getItem('userGroup');
const userID = localStorage.getItem('userID')
const userGroup = localStorage.getItem('userGroup')
const tokenExpiresIn = config.tokenExpiresIn const tokenExpiresIn = config.tokenExpiresIn
if(localStorage.getItem('tokenExpiredTime') == null || if (
parseInt(localStorage.getItem('tokenExpiredTime')) < parseInt(Date.now())){ localStorage.getItem('tokenExpiredTime') == null ||
localStorage.removeItem('token') parseInt(localStorage.getItem('tokenExpiredTime')) < parseInt(Date.now())
} ) {
localStorage.removeItem('token')
}
const token = localStorage.getItem('token'); const token = localStorage.getItem('token')
// console.log(token)
var activeFuctionLocal = localStorage.getItem('activeFuction') var activeFuctionLocal = localStorage.getItem('activeFuction')
if (activeFuctionLocal == null){ if (activeFuctionLocal == null) {
activeFuctionLocal = 'AES128' activeFuctionLocal = 'AES128'
localStorage.setItem('activeFuction',activeFuctionLocal) localStorage.setItem('activeFuction', activeFuctionLocal)
} }
// localStorage.removeItem('activeKeyMap') // localStorage.removeItem('activeKeyMap')
var activeKeyMap = localStorage.getItem('activeKeyMap') var activeKeyMap = localStorage.getItem('activeKeyMap')
if (activeKeyMap == null ){ if (activeKeyMap == null) {
activeKeyMap = JSON.stringify(['A-Z','0-9']) activeKeyMap = JSON.stringify(['A-Z', '0-9'])
localStorage.setItem('activeKeyMap',activeKeyMap) 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) // console.log(process.env.NODE_ENV,config.DEVPORT,location.port,serverPort)
export const useSettingStore = defineStore("setting", { export const useSettingStore = defineStore('setting', {
state: () => ({ state: () => ({
activeFuction: activeFuctionLocal, activeFuction: activeFuctionLocal,
activeKeyMap:JSON.parse(activeKeyMap), activeKeyMap: JSON.parse(activeKeyMap),
enableGuest:config.enableGuest, enableGuest: config.enableGuest,
serverPort, serverPort,
token, token,
userID, userID,
userGroup userGroup,
baseUrl
}), }),
getters: { getters: {
// double: state => state.count * 2 // double: state => state.count * 2
}, },
actions: { actions: {
setJWT( token,keepTokenLocal ){ setJWT(token, keepTokenLocal) {
this.token = token this.token = token
if(keepTokenLocal){ if (keepTokenLocal) {
localStorage.setItem('token',token) localStorage.setItem('token', token)
localStorage.setItem('tokenExpiredTime',parseInt(Date.now())+parseInt(tokenExpiresIn)*3600000) localStorage.setItem(
} 'tokenExpiredTime',
}, parseInt(Date.now()) + parseInt(tokenExpiresIn) * 3600000
setUserID( id,keepTokenLocal ){ )
this.userID = id }
if(keepTokenLocal) },
localStorage.setItem('userID',id) setUserID(id, keepTokenLocal) {
}, this.userID = id
setUserGroup( g,keepTokenLocal ){ if (keepTokenLocal) localStorage.setItem('userID', id)
this.userGroup = g },
if(keepTokenLocal) setUserGroup(g, keepTokenLocal) {
localStorage.setItem('userGroup',g) this.userGroup = g
}, if (keepTokenLocal) localStorage.setItem('userGroup', g)
getToken(){ },
return localStorage.getItem('token') getToken() {
} return localStorage.getItem('token')
// increment() { }
// this.count++; // increment() {
// } // this.count++;
} // }
}); }
})
+9 -8
View File
@@ -37,7 +37,7 @@
<div style="flex:1; position: relative;min-height: none;"> <div style="flex:1; position: relative;min-height: none;">
<chatui style="margin-bottom: 10px; height: 65vh" <chatui style="margin-bottom: 10px; height: 65vh"
:messages="activeGID ? Messages[activeGID].map(v => { v.timestampString = new Date(v.timestamp).toLocaleString(); return v }).reverse() : []"/> :messages="activeGID ? Messages[activeGID].map(v => { v.timestampString = new Date(v.timestamp).toLocaleString(); return v }).reverse() : []"/>
<n-input v-model:value="msgInput" type="textarea" placeholder="发送信息" :autosize="{ <n-input v-model:value="msgInput" type="textarea" placeholder="发送信息" :autosize="{
minRows: 1, minRows: 1,
maxRows: 2 maxRows: 2
@@ -48,7 +48,7 @@
<n-icon :component="SendOutline" style="cursor: pointer;" @click='sendMsg(activeGID, msgInput)'/> <n-icon :component="SendOutline" style="cursor: pointer;" @click='sendMsg(activeGID, msgInput)'/>
</template> </template>
</n-input> </n-input>
<!-- <n-button @click="sendMsg(activeGID, msg)" :disabled="msg === '' || activeGID === null" <!-- <n-button @click="sendMsg(activeGID, msg)" :disabled="msg === '' || activeGID === null"
:type="msg === '' || activeGID === null ? 'default' : 'primary'"> :type="msg === '' || activeGID === null ? 'default' : 'primary'">
发送消息 发送消息
@@ -58,7 +58,7 @@
<!-- {{ dataTest }} --> <!-- {{ dataTest }} -->
<!-- {{ Messages }} --> <!-- {{ Messages }} -->
<n-modal v-model:show="showModal"> <n-modal v-model:show="showModal">
<n-card <n-card
style="width: fit-content;" style="width: fit-content;"
@@ -68,8 +68,8 @@
role="dialog" role="dialog"
aria-modal="true" aria-modal="true"
> >
<n-qr-code :value="QRCodeData" style="padding: 0;" :size="256" error-correction-level="Q" :v-if="showModal" <n-qr-code :value="QRCodeData" style="padding: 0;" :size="256" error-correction-level="Q" :v-if="showModal"
:icon-src='0?QRIconUrl:null' :icon-src='0?QRIconUrl:null'
:icon-size="128"/> :icon-size="128"/>
</n-card> </n-card>
</n-modal> </n-modal>
@@ -106,7 +106,8 @@ const _toClipboard = async (text) => {
const setting = useSettingStore(); const setting = useSettingStore();
const serverPort = setting.serverPort; const serverPort = setting.serverPort;
const wsBaseUrl = 'ws' + "://" + location.hostname + ":" + 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 QRIconUrl = ref(location.protocol + "//" + location.hostname + ":" + serverPort + "/favicon.ico")
const columns = [ const columns = [
@@ -290,7 +291,7 @@ function joinGroup_Verify(gID) {
} }
function sendMsg(gID, msg) { 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 let key = gID2key[gID].key
msg = encryptString(key, msg, setting) msg = encryptString(key, msg, setting)
socket.send(JSON.stringify({ type: 'message',type1:'text', msg, gID })) socket.send(JSON.stringify({ type: 'message',type1:'text', msg, gID }))
@@ -306,7 +307,7 @@ function sendMsg(gID, msg) {
// } // }
async function uploadFile(file){ async function uploadFile(file){
if(activeGID.value === null)return if(activeGID.value === null)return
var fileName = file.name; var fileName = file.name;
let key = gID2key[activeGID.value].key let key = gID2key[activeGID.value].key
const encryptedFileName = encryptString(key, fileName, setting); const encryptedFileName = encryptString(key, fileName, setting);
+2 -2
View File
@@ -40,8 +40,8 @@ const setting = useSettingStore();
// 服务端端口 // 服务端端口
const serverPort = setting.serverPort; const serverPort = setting.serverPort;
var baseUrl = // const baseUrl = location.protocol + "//" + location.hostname + ":" + serverPort + "/";
location.protocol + "//" + location.hostname + ":" + serverPort + "/"; const baseUrl = setting.baseUrl
// console.log(baseUrl); // console.log(baseUrl);
// const blob2Uint8Array = function(blob) { // const blob2Uint8Array = function(blob) {
+2 -2
View File
@@ -43,8 +43,8 @@ const serverPort = settingData.serverPort;
const userIDInput = ref('') const userIDInput = ref('')
const userPasswordInput = ref('') const userPasswordInput = ref('')
const isLogining = ref(false) const isLogining = ref(false)
const baseUrl = // const baseUrl = location.protocol + "//" + location.hostname + ":" + serverPort + "/";
location.protocol + "//" + location.hostname + ":" + serverPort + "/"; const baseUrl = settingData.baseUrl
const Token = computed(() => settingData.token) const Token = computed(() => settingData.token)
const keepTokenLocal = ref(true) const keepTokenLocal = ref(true)
+4 -3
View File
@@ -19,7 +19,7 @@
</n-p> </n-p>
</n-upload-dragger> </n-upload-dragger>
</n-upload> </n-upload>
<n-flex justify="end" style="margin: 10px 0;position:relative"> <n-flex justify="end" style="margin: 10px 0;position:relative">
<n-input-number v-model:value="downloadCredit" placeholder="可下载次数,默认无限" clearable :min="1" :max="2147483647" style="width:max-content"/> <n-input-number v-model:value="downloadCredit" placeholder="可下载次数,默认无限" clearable :min="1" :max="2147483647" style="width:max-content"/>
<n-button type="primary" @click="clickUpload">开始上传</n-button> <n-button type="primary" @click="clickUpload">开始上传</n-button>
@@ -94,8 +94,9 @@ var file_Code_Map = ref([]);
var uploadProcess = ref(0); var uploadProcess = ref(0);
const baseUrl = // const baseUrl = location.protocol + "//" + location.hostname + ":" + serverPort + "/";
location.protocol + "//" + location.hostname + ":" + serverPort + "/"; const baseUrl = setting.baseUrl
console.log(baseUrl)
// const blob2Uint8Array = function(blob) { // const blob2Uint8Array = function(blob) {