-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
126 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
const style = { | ||
info: { | ||
levelColor: 'color: #00cc00;' | ||
}, | ||
warn: { | ||
levelColor: 'color: #ff9933;' | ||
}, | ||
error: { | ||
levelColor: 'color: red;' | ||
}, | ||
reset: 'color: none; background: none;' | ||
} | ||
|
||
const logger = { | ||
info: (m: any) => { | ||
console.log( | ||
`[%cINFO%c] ${m}`, | ||
style.info.levelColor, | ||
style.reset | ||
) | ||
}, | ||
warn: (m: any, clevel = true) => { | ||
const fn = (clevel) ? console.warn : console.log | ||
fn( | ||
`[%cWARN%c] ${m}`, | ||
style.warn.levelColor, | ||
style.reset | ||
) | ||
}, | ||
error: (m: any, clevel = true) => { | ||
const fn = (clevel) ? console.error : console.log | ||
fn( | ||
`[%cERROR%c] ${m}`, | ||
style.error.levelColor, | ||
style.reset | ||
) | ||
}, | ||
} | ||
|
||
export default logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,29 @@ | ||
import logger from '@/utils/logger' | ||
|
||
// 在当前js全局化 | ||
let ws | ||
|
||
export function init_ws() { | ||
if ('WebSocket' in window) { | ||
console.log('您的浏览器支持 WebSocket!') | ||
logger.info('您的浏览器支持 WebSocket!') | ||
ws = new WebSocket(`wss://ws.api.locyanfrp.cn/api`) | ||
ws.onopen = function () { | ||
console.log('webSocket connect successful') | ||
logger.info('webSocket connect successful') | ||
} | ||
ws.onclose = function () { | ||
// 关闭 websocket | ||
console.log('webSocket connect closed') | ||
logger.warn('webSocket connect closed') | ||
setTimeout(() => { | ||
init_ws() | ||
}, 2000) | ||
} | ||
} else { | ||
// 浏览器不支持 WebSocket | ||
console.log('您的浏览器不支持 WebSocket!') | ||
logger.error('您的浏览器不支持 WebSocket!') | ||
} | ||
} | ||
|
||
export function SetOnMessageFunction(handle_function) { | ||
ws.onmessage = handle_function | ||
console.log('成功设置回调函数') | ||
logger.info('成功设置回调函数') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.