提交 a7d9d836 作者: 方治民

feat: 新增 WebSocket(STOMP) 的示例默认启用

上级 a77a1060
# API 接口地址 # API 接口地址
VITE_GLOB_API_URL=http://192.168.0.156:8081 VITE_GLOB_API_URL=http://127.0.0.1:8081
# API 接口地址前缀 # API 接口地址前缀
VITE_GLOB_API_URL_PREFIX=/api VITE_GLOB_API_URL_PREFIX=/api
{ {
"name": "basic-app", "name": "basic-app",
"version": "3.0.3.0", "version": "1.0.0",
"description": "APP 基础工程", "description": "APP 基础工程",
"keywords": [ "keywords": [
"app", "app",
...@@ -66,20 +66,20 @@ ...@@ -66,20 +66,20 @@
} }
}, },
"dependencies": { "dependencies": {
"@dcloudio/uni-app": "3.0.0-4000620240325001", "@dcloudio/uni-app": "3.0.0-4000820240401001",
"@dcloudio/uni-app-plus": "3.0.0-4000620240325001", "@dcloudio/uni-app-plus": "3.0.0-4000820240401001",
"@dcloudio/uni-components": "3.0.0-4000620240325001", "@dcloudio/uni-components": "3.0.0-4000820240401001",
"@dcloudio/uni-h5": "3.0.0-4000620240325001", "@dcloudio/uni-h5": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-alipay": "3.0.0-4000620240325001", "@dcloudio/uni-mp-alipay": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-baidu": "3.0.0-4000620240325001", "@dcloudio/uni-mp-baidu": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-jd": "3.0.0-4000620240325001", "@dcloudio/uni-mp-jd": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-kuaishou": "3.0.0-4000620240325001", "@dcloudio/uni-mp-kuaishou": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-lark": "3.0.0-4000620240325001", "@dcloudio/uni-mp-lark": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-qq": "3.0.0-4000620240325001", "@dcloudio/uni-mp-qq": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-toutiao": "3.0.0-4000620240325001", "@dcloudio/uni-mp-toutiao": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-weixin": "3.0.0-4000620240325001", "@dcloudio/uni-mp-weixin": "3.0.0-4000820240401001",
"@dcloudio/uni-quickapp-webview": "3.0.0-4000620240325001", "@dcloudio/uni-quickapp-webview": "3.0.0-4000820240401001",
"@dcloudio/uni-ui": "^1.5.3", "@dcloudio/uni-ui": "^1.5.5",
"@faker-js/faker": "^8.4.1", "@faker-js/faker": "^8.4.1",
"@vue/runtime-core": "3.3.11", "@vue/runtime-core": "3.3.11",
"@vueuse/core": "^10.9.0", "@vueuse/core": "^10.9.0",
...@@ -87,46 +87,46 @@ ...@@ -87,46 +87,46 @@
"crypto-js": "^4.2.0", "crypto-js": "^4.2.0",
"dayjs": "^1.11.10", "dayjs": "^1.11.10",
"lodash-es": "^4.17.21", "lodash-es": "^4.17.21",
"nanoid": "^5.0.6", "nanoid": "^5.0.7",
"pinia": "~2.1.7", "pinia": "~2.0.36",
"qs": "~6.12.0", "qs": "~6.12.1",
"stompjs": "^2.3.3", "stompjs": "^2.3.3",
"urijs": "^1.19.11", "urijs": "^1.19.11",
"vue": "3.3.11", "vue": "3.3.11",
"vue-i18n": "^9.10.2", "vue-i18n": "^9.13.0",
"vue-request": "^2.0.4", "vue-request": "^2.0.4",
"vue-types": "^5.1.1" "vue-types": "^5.1.1"
}, },
"devDependencies": { "devDependencies": {
"@antfu/eslint-config": "^0.43.1", "@antfu/eslint-config": "^0.43.1",
"@commitlint/cli": "^19.2.1", "@commitlint/cli": "^19.2.2",
"@commitlint/config-conventional": "^19.1.0", "@commitlint/config-conventional": "^19.2.2",
"@dcloudio/types": "^3.4.8", "@dcloudio/types": "^3.4.8",
"@dcloudio/uni-automator": "3.0.0-4000620240325001", "@dcloudio/uni-automator": "3.0.0-4000820240401001",
"@dcloudio/uni-cli-shared": "3.0.0-4000620240325001", "@dcloudio/uni-cli-shared": "3.0.0-4000820240401001",
"@dcloudio/uni-helper-json": "^1.0.13", "@dcloudio/uni-helper-json": "^1.0.13",
"@dcloudio/uni-stacktracey": "3.0.0-4000620240325001", "@dcloudio/uni-stacktracey": "3.0.0-4000820240401001",
"@dcloudio/vite-plugin-uni": "3.0.0-4000620240325001", "@dcloudio/vite-plugin-uni": "3.0.0-4000820240401001",
"@iconify/json": "^2.2.196", "@iconify/json": "^2.2.202",
"@types/crypto-js": "^4.2.2", "@types/crypto-js": "^4.2.2",
"@types/lodash-es": "^4.17.12", "@types/lodash-es": "^4.17.12",
"@types/node": "^20.11.30", "@types/node": "^20.12.7",
"@types/qs": "^6.9.14", "@types/qs": "^6.9.15",
"@types/stompjs": "^2.3.9", "@types/stompjs": "^2.3.9",
"@types/urijs": "^1.19.25", "@types/urijs": "^1.19.25",
"@typescript-eslint/eslint-plugin": "^7.4.0", "@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.4.0", "@typescript-eslint/parser": "^7.7.0",
"commitizen": "^4.3.0", "commitizen": "^4.3.0",
"conventional-changelog-cli": "^4.1.0", "conventional-changelog-cli": "^4.1.0",
"cz-conventional-changelog": "^3.3.0", "cz-conventional-changelog": "^3.3.0",
"cz-customizable": "^7.0.0", "cz-customizable": "^7.0.0",
"cz-git": "^1.9.0", "cz-git": "^1.9.1",
"czg": "^1.9.0", "czg": "^1.9.1",
"dotenv": "^16.4.5", "dotenv": "^16.4.5",
"eslint": "^8.57.0", "eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3", "eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-vue": "^9.24.0", "eslint-plugin-vue": "^9.25.0",
"husky": "^8.0.3", "husky": "^8.0.3",
"jest": "27.0.4", "jest": "27.0.4",
"jest-environment-node": "27.5.1", "jest-environment-node": "27.5.1",
...@@ -134,22 +134,22 @@ ...@@ -134,22 +134,22 @@
"lint-staged": "^15.2.2", "lint-staged": "^15.2.2",
"npm-run-all": "^4.1.5", "npm-run-all": "^4.1.5",
"picocolors": "^1.0.0", "picocolors": "^1.0.0",
"pont-engine": "^1.6.2", "pont-engine": "^1.6.3",
"postcss": "^8.4.38", "postcss": "^8.4.38",
"postcss-html": "^1.6.0", "postcss-html": "^1.6.0",
"postcss-less": "^6.0.0", "postcss-less": "^6.0.0",
"prettier": "^3.2.5", "prettier": "^3.2.5",
"rimraf": "^5.0.5", "rimraf": "^5.0.5",
"sass": "^1.72.0", "sass": "^1.75.0",
"sort-package-json": "^2.8.0", "sort-package-json": "^2.10.0",
"stylelint": "^16.3.0", "stylelint": "^16.3.1",
"stylelint-config-html": "^1.1.0", "stylelint-config-html": "^1.1.0",
"stylelint-config-recommended": "^14.0.0", "stylelint-config-recommended": "^14.0.0",
"stylelint-config-standard": "^36.0.0", "stylelint-config-standard": "^36.0.0",
"stylelint-order": "^6.0.4", "stylelint-order": "^6.0.4",
"typescript": "~5.4.3", "typescript": "~5.4.5",
"unocss": "^0.58.6", "unocss": "^0.58.9",
"unocss-preset-weapp": "^0.58.7", "unocss-preset-weapp": "^0.58.8",
"unplugin-auto-import": "^0.17.5", "unplugin-auto-import": "^0.17.5",
"unplugin-vue-components": "^0.26.0", "unplugin-vue-components": "^0.26.0",
"vite": "^4.5.3", "vite": "^4.5.3",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -26,6 +26,9 @@ ...@@ -26,6 +26,9 @@
.catch((err) => { .catch((err) => {
console.error('[API]', err) console.error('[API]', err)
}) })
// test WebSocket(STOMP)
Stomp.connect()
}) })
function surprise() { function surprise() {
......
...@@ -121,7 +121,7 @@ class StompInstance { ...@@ -121,7 +121,7 @@ class StompInstance {
const body = JSON.parse(frame.body) const body = JSON.parse(frame.body)
if (body.status === 400) { if (body.status === 400) {
createMessage.warn(body.message) createMessage.warn(body.message)
} else if (body.status === 401) { } else if ([401, 403].includes(body.status)) {
// TODO: 退出登录 // TODO: 退出登录
} }
...@@ -129,7 +129,9 @@ class StompInstance { ...@@ -129,7 +129,9 @@ class StompInstance {
}) })
// 发送登录消息 // 发送登录消息
this.send('/app/login', { token }) if (token) {
this.send('/app/login', { token })
}
}, },
(_) => { (_) => {
// 重连 // 重连
...@@ -220,7 +222,7 @@ class StompInstance { ...@@ -220,7 +222,7 @@ class StompInstance {
/** /**
* 轮询检查订阅状态 * 轮询检查订阅状态
*/ */
loopCheckSubscribe() { private loopCheckSubscribe() {
this.checkSubscribeId = setInterval(() => { this.checkSubscribeId = setInterval(() => {
Object.keys(this.subscribes).forEach((key) => { Object.keys(this.subscribes).forEach((key) => {
this.subscribe(key, this.subscribes[key].callback) this.subscribe(key, this.subscribes[key].callback)
...@@ -244,7 +246,7 @@ class StompInstance { ...@@ -244,7 +246,7 @@ class StompInstance {
const baseUrl = API_URL + API_URL_PREFIX const baseUrl = API_URL + API_URL_PREFIX
const instance = new StompInstance({ const instance = new StompInstance({
url: `${baseUrl}/stomp/ws`, url: `${baseUrl}/stomp/ws`,
debug: false, debug: true,
}) })
export default instance export default instance
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论