提交 d30d31f0 作者: 方治民

合并分支 '3.x' 到 'main'

3.x

查看合并请求 !66
# API 接口地址
VITE_GLOB_API_URL=http://192.168.0.156:8081
VITE_GLOB_API_URL=http://127.0.0.1:8081
# API 接口地址前缀
VITE_GLOB_API_URL_PREFIX=/api
{
"name": "basic-app",
"version": "3.0.3.0",
"version": "1.0.0",
"description": "APP 基础工程",
"keywords": [
"app",
......@@ -66,20 +66,20 @@
}
},
"dependencies": {
"@dcloudio/uni-app": "3.0.0-4000620240325001",
"@dcloudio/uni-app-plus": "3.0.0-4000620240325001",
"@dcloudio/uni-components": "3.0.0-4000620240325001",
"@dcloudio/uni-h5": "3.0.0-4000620240325001",
"@dcloudio/uni-mp-alipay": "3.0.0-4000620240325001",
"@dcloudio/uni-mp-baidu": "3.0.0-4000620240325001",
"@dcloudio/uni-mp-jd": "3.0.0-4000620240325001",
"@dcloudio/uni-mp-kuaishou": "3.0.0-4000620240325001",
"@dcloudio/uni-mp-lark": "3.0.0-4000620240325001",
"@dcloudio/uni-mp-qq": "3.0.0-4000620240325001",
"@dcloudio/uni-mp-toutiao": "3.0.0-4000620240325001",
"@dcloudio/uni-mp-weixin": "3.0.0-4000620240325001",
"@dcloudio/uni-quickapp-webview": "3.0.0-4000620240325001",
"@dcloudio/uni-ui": "^1.5.3",
"@dcloudio/uni-app": "3.0.0-4000820240401001",
"@dcloudio/uni-app-plus": "3.0.0-4000820240401001",
"@dcloudio/uni-components": "3.0.0-4000820240401001",
"@dcloudio/uni-h5": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-alipay": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-baidu": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-jd": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-kuaishou": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-lark": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-qq": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-toutiao": "3.0.0-4000820240401001",
"@dcloudio/uni-mp-weixin": "3.0.0-4000820240401001",
"@dcloudio/uni-quickapp-webview": "3.0.0-4000820240401001",
"@dcloudio/uni-ui": "^1.5.5",
"@faker-js/faker": "^8.4.1",
"@vue/runtime-core": "3.3.11",
"@vueuse/core": "^10.9.0",
......@@ -87,46 +87,46 @@
"crypto-js": "^4.2.0",
"dayjs": "^1.11.10",
"lodash-es": "^4.17.21",
"nanoid": "^5.0.6",
"pinia": "~2.1.7",
"qs": "~6.12.0",
"nanoid": "^5.0.7",
"pinia": "~2.0.36",
"qs": "~6.12.1",
"stompjs": "^2.3.3",
"urijs": "^1.19.11",
"vue": "3.3.11",
"vue-i18n": "^9.10.2",
"vue-i18n": "^9.13.0",
"vue-request": "^2.0.4",
"vue-types": "^5.1.1"
},
"devDependencies": {
"@antfu/eslint-config": "^0.43.1",
"@commitlint/cli": "^19.2.1",
"@commitlint/config-conventional": "^19.1.0",
"@commitlint/cli": "^19.2.2",
"@commitlint/config-conventional": "^19.2.2",
"@dcloudio/types": "^3.4.8",
"@dcloudio/uni-automator": "3.0.0-4000620240325001",
"@dcloudio/uni-cli-shared": "3.0.0-4000620240325001",
"@dcloudio/uni-automator": "3.0.0-4000820240401001",
"@dcloudio/uni-cli-shared": "3.0.0-4000820240401001",
"@dcloudio/uni-helper-json": "^1.0.13",
"@dcloudio/uni-stacktracey": "3.0.0-4000620240325001",
"@dcloudio/vite-plugin-uni": "3.0.0-4000620240325001",
"@iconify/json": "^2.2.196",
"@dcloudio/uni-stacktracey": "3.0.0-4000820240401001",
"@dcloudio/vite-plugin-uni": "3.0.0-4000820240401001",
"@iconify/json": "^2.2.202",
"@types/crypto-js": "^4.2.2",
"@types/lodash-es": "^4.17.12",
"@types/node": "^20.11.30",
"@types/qs": "^6.9.14",
"@types/node": "^20.12.7",
"@types/qs": "^6.9.15",
"@types/stompjs": "^2.3.9",
"@types/urijs": "^1.19.25",
"@typescript-eslint/eslint-plugin": "^7.4.0",
"@typescript-eslint/parser": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^7.7.0",
"@typescript-eslint/parser": "^7.7.0",
"commitizen": "^4.3.0",
"conventional-changelog-cli": "^4.1.0",
"cz-conventional-changelog": "^3.3.0",
"cz-customizable": "^7.0.0",
"cz-git": "^1.9.0",
"czg": "^1.9.0",
"cz-git": "^1.9.1",
"czg": "^1.9.1",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-vue": "^9.24.0",
"eslint-plugin-vue": "^9.25.0",
"husky": "^8.0.3",
"jest": "27.0.4",
"jest-environment-node": "27.5.1",
......@@ -134,22 +134,22 @@
"lint-staged": "^15.2.2",
"npm-run-all": "^4.1.5",
"picocolors": "^1.0.0",
"pont-engine": "^1.6.2",
"pont-engine": "^1.6.3",
"postcss": "^8.4.38",
"postcss-html": "^1.6.0",
"postcss-less": "^6.0.0",
"prettier": "^3.2.5",
"rimraf": "^5.0.5",
"sass": "^1.72.0",
"sort-package-json": "^2.8.0",
"stylelint": "^16.3.0",
"sass": "^1.75.0",
"sort-package-json": "^2.10.0",
"stylelint": "^16.3.1",
"stylelint-config-html": "^1.1.0",
"stylelint-config-recommended": "^14.0.0",
"stylelint-config-standard": "^36.0.0",
"stylelint-order": "^6.0.4",
"typescript": "~5.4.3",
"unocss": "^0.58.6",
"unocss-preset-weapp": "^0.58.7",
"typescript": "~5.4.5",
"unocss": "^0.58.9",
"unocss-preset-weapp": "^0.58.8",
"unplugin-auto-import": "^0.17.5",
"unplugin-vue-components": "^0.26.0",
"vite": "^4.5.3",
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -13,7 +13,7 @@
// FIXED: 开发模式,关闭启动页,防止调试内部页面时无法进入的问题
// #ifdef APP-PLUS
if (isDevMode) {
if (isDevMode()) {
setTimeout(() => {
plus.navigator.closeSplashscreen()
}, 3000)
......@@ -35,7 +35,8 @@
})
onUnhandledRejection((err) => {
Message.toast(`App UnhandledRejection: ${err}`)
// Message.toast(`App UnhandledRejection: ${err}`)
console.error('App UnhandledRejection:', err)
})
</script>
......
......@@ -26,6 +26,11 @@
.catch((err) => {
console.error('[API]', err)
})
// test WebSocket(STOMP)
Stomp.connect(() => {
Stomp.send('/app/ping', 'ping')
})
})
function surprise() {
......
......@@ -6,6 +6,7 @@ import type { RequestOptions, Result } from '/#/axios'
export interface CreateAxiosOptions extends AxiosRequestConfig {
authenticationScheme?: string
authenticationHeader?: string
transform?: AxiosTransform
requestOptions?: RequestOptions
}
......
......@@ -157,7 +157,7 @@ const transform: AxiosTransform = {
const token = userStore.getToken
if (token && (config as Recordable)?.requestOptions?.withToken !== false) {
// jwt token
;(config as Recordable).headers.Authorization = options.authenticationScheme
;(config as Recordable).headers[options.authenticationHeader] = options.authenticationScheme
? `${options.authenticationScheme} ${token}`
: token
}
......@@ -223,6 +223,8 @@ function createAxios(opt?: Partial<CreateAxiosOptions>) {
// authentication schemes,e.g: Bearer
// authenticationScheme: 'Bearer',
authenticationScheme: '',
// authenticationHeader: 'Authorization',
authenticationHeader: 'App-Token',
timeout: 10 * 1000,
// 基础接口地址
// baseURL: globSetting.apiUrl,
......
......@@ -76,18 +76,18 @@ class StompInstance {
/**
* 创建连接
*/
connect() {
async connect(cb?: () => void) {
// 如已存在连接则不创建
if (this.client && this.client.connected) {
return
}
// 检查登录是否有效
const available = await API.auth.valid.request()
// 从缓存中获取token
const useStore = useUserStoreWithOut()
const token = useStore.getToken
const options = token ? { token } : {}
// TODO: 检查 Token 是否有效
const options = token && available ? { token } : {}
// 创建 Stomp 实例
this.client = Stomp.client(this.url) as Client
......@@ -121,7 +121,7 @@ class StompInstance {
const body = JSON.parse(frame.body)
if (body.status === 400) {
createMessage.warn(body.message)
} else if (body.status === 401) {
} else if ([401, 403].includes(body.status)) {
// TODO: 退出登录
}
......@@ -129,12 +129,17 @@ class StompInstance {
})
// 发送登录消息
this.send('/app/login', { token })
if (token && available) {
this.send('/app/login', token)
}
// 连接成功后触发回调
cb?.()
},
(_) => {
// 重连
this.reconnectId = setTimeout(() => {
this.reconnect()
this.reconnectId = setTimeout(async () => {
await this.reconnect()
}, this.reconnectInterval)
},
)
......@@ -143,7 +148,7 @@ class StompInstance {
/**
* 重新连接
*/
reconnect() {
async reconnect() {
// 停止重连事件
if (this.reconnectId) {
clearTimeout(this.reconnectId)
......@@ -161,7 +166,7 @@ class StompInstance {
})
// 连接
this.connect()
await this.connect()
}
/**
......@@ -220,7 +225,7 @@ class StompInstance {
/**
* 轮询检查订阅状态
*/
loopCheckSubscribe() {
private loopCheckSubscribe() {
this.checkSubscribeId = setInterval(() => {
Object.keys(this.subscribes).forEach((key) => {
this.subscribe(key, this.subscribes[key].callback)
......@@ -244,7 +249,7 @@ class StompInstance {
const baseUrl = API_URL + API_URL_PREFIX
const instance = new StompInstance({
url: `${baseUrl}/stomp/ws`,
debug: false,
debug: true,
})
export default instance
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论