Fix bug
在首次进入时将默认设置保存进localStorage,以免在收到礼物时出现 `Cannot read properties of null (reading 'value')`
This commit is contained in:
parent
a01c2e1997
commit
39941bfdfd
@ -20,7 +20,6 @@
|
||||
"vue-tsc": "0.29.8",
|
||||
"ws": "8.17.0",
|
||||
"qrcode": "1.5.3",
|
||||
"notyf": "3.0.0",
|
||||
"node-localstorage": "3.0.5"
|
||||
"notyf": "3.0.0"
|
||||
}
|
||||
}
|
||||
|
@ -34,11 +34,12 @@ if (window.localStorage.getItem("settings")) {
|
||||
settings.value = JSON.parse(window.localStorage.getItem("settings") || '{}');
|
||||
// console.log(settings.value)
|
||||
} else {
|
||||
// 如果没有,使用默认值
|
||||
// 如果没有,使用默认值并且保存
|
||||
settings.value = {
|
||||
waveData: waveData,
|
||||
strengthData: strengthData
|
||||
};
|
||||
window.localStorage.setItem('settings', JSON.stringify(settings.value));
|
||||
}
|
||||
|
||||
|
||||
|
@ -54,10 +54,8 @@ function createSocket(authBody: string, wssLinks: string[]) {
|
||||
|
||||
settings = window.localStorage.getItem("settings") ? ref(JSON.parse(window.localStorage.getItem("settings") || '{}')) : null
|
||||
|
||||
console.log(settings.value)
|
||||
|
||||
if (res.cmd == "LIVE_OPEN_PLATFORM_SEND_GIFT") {
|
||||
if (res.data.gift_id.toString() === settings.value.strengthData[0]) {
|
||||
if (settings && res.data.gift_id.toString() === settings.value.strengthData[0]) {
|
||||
// 牛哇牛哇:加强度1
|
||||
try {
|
||||
console.log("开始操作")
|
||||
@ -70,7 +68,7 @@ function createSocket(authBody: string, wssLinks: string[]) {
|
||||
console.log(e)
|
||||
notyf.error("强度操作失败!")
|
||||
}
|
||||
} else if (res.data.gift_id.toString() === settings.value.strengthData[1]) {
|
||||
} else if (settings && res.data.gift_id.toString() === settings.value.strengthData[1]) {
|
||||
// 小花花:减强度1
|
||||
try {
|
||||
addOrIncrease(1, 1, 1)
|
||||
@ -81,7 +79,7 @@ function createSocket(authBody: string, wssLinks: string[]) {
|
||||
console.log(e)
|
||||
notyf.error("强度操作失败!")
|
||||
}
|
||||
} else if(settings.value.waveData[res.data.gift_id]) {
|
||||
} else if(settings && settings.value.waveData[res.data.gift_id]) {
|
||||
// 其他礼物,发送波形数据
|
||||
try {
|
||||
sendWaveData(5, 5, settings.value.waveData[res.data.gift_id], settings.value.waveData[res.data.gift_id])
|
||||
|
Loading…
x
Reference in New Issue
Block a user