统一在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 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++;
// }
}
})
+9 -8
View File
@@ -37,7 +37,7 @@
<div style="flex:1; position: relative;min-height: none;">
<chatui style="margin-bottom: 10px; height: 65vh"
: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="{
minRows: 1,
maxRows: 2
@@ -48,7 +48,7 @@
<n-icon :component="SendOutline" style="cursor: pointer;" @click='sendMsg(activeGID, msgInput)'/>
</template>
</n-input>
<!-- <n-button @click="sendMsg(activeGID, msg)" :disabled="msg === '' || activeGID === null"
:type="msg === '' || activeGID === null ? 'default' : 'primary'">
发送消息
@@ -58,7 +58,7 @@
<!-- {{ dataTest }} -->
<!-- {{ Messages }} -->
<n-modal v-model:show="showModal">
<n-card
style="width: fit-content;"
@@ -68,8 +68,8 @@
role="dialog"
aria-modal="true"
>
<n-qr-code :value="QRCodeData" style="padding: 0;" :size="256" error-correction-level="Q" :v-if="showModal"
:icon-src='0?QRIconUrl:null'
<n-qr-code :value="QRCodeData" style="padding: 0;" :size="256" error-correction-level="Q" :v-if="showModal"
:icon-src='0?QRIconUrl:null'
:icon-size="128"/>
</n-card>
</n-modal>
@@ -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);
+2 -2
View File
@@ -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) {
+2 -2
View File
@@ -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)
+4 -3
View File
@@ -19,7 +19,7 @@
</n-p>
</n-upload-dragger>
</n-upload>
<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-button type="primary" @click="clickUpload">开始上传</n-button>
@@ -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) {