feat(im): 添加平台事件通知功能支持应用审核状态实时更新
- 新增 ImPlatformEventController 提供令牌获取接口 - 新增 InternalImPlatformEventController 处理内部通知请求 - 实现 ImPlatformEventService 核心服务逻辑包括令牌签发和消息推送 - 添加 StoreReviewImNotifier 在更新服务中触发审核状态变更通知 - 在前端平台中集成实时审核状态更新功能 - 配置各项目环境版本管理文件 (.java-version, .nvmrc) - 更新 Docker 忽略文件和 Maven 配置以优化构建流程
这个提交包含在:
父节点
168bf4662c
当前提交
c11e8f6d71
10
.dockerignore
普通文件
10
.dockerignore
普通文件
@ -0,0 +1,10 @@
|
||||
.git
|
||||
.idea
|
||||
node_modules
|
||||
**/node_modules
|
||||
dist
|
||||
**/dist
|
||||
docs-site/docs/.vitepress/dist
|
||||
**/.DS_Store
|
||||
**/*.log
|
||||
*.iml
|
||||
@ -0,0 +1,91 @@
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { init, login, ImClient, type ImMessage } from '@xuqm/vue3-sdk'
|
||||
import client from '@/api/client'
|
||||
|
||||
export interface StoreReviewRefreshEvent {
|
||||
event: string
|
||||
appKey: string
|
||||
versionId?: string
|
||||
storeType?: string
|
||||
reviewState?: string
|
||||
reviewReason?: string
|
||||
stage?: string
|
||||
batchId?: string
|
||||
publishStatus?: string
|
||||
source?: string
|
||||
timestamp?: number
|
||||
}
|
||||
|
||||
interface PlatformEventTokenResponse {
|
||||
userId: string
|
||||
token: string
|
||||
}
|
||||
|
||||
let imClient: ImClient | null = null
|
||||
let activeAppKey = ''
|
||||
|
||||
function sdkBaseUrl() {
|
||||
return import.meta.env.VITE_IM_API_BASE_URL ?? ''
|
||||
}
|
||||
|
||||
function sdkWsUrl() {
|
||||
return import.meta.env.VITE_IM_WS_URL ?? ''
|
||||
}
|
||||
|
||||
function parseEvent(message: ImMessage): StoreReviewRefreshEvent | null {
|
||||
if (!['NOTIFY', 'CUSTOM'].includes(message.msgType)) return null
|
||||
try {
|
||||
const payload = JSON.parse(message.content) as Partial<StoreReviewRefreshEvent>
|
||||
if (!payload || payload.event !== 'store_review_update') return null
|
||||
if (!payload.appKey) return null
|
||||
return payload as StoreReviewRefreshEvent
|
||||
} catch {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export async function connectStoreReviewRealtime(appKey: string, onEvent: (event: StoreReviewRefreshEvent) => void) {
|
||||
if (!appKey) return
|
||||
disconnectStoreReviewRealtime()
|
||||
activeAppKey = appKey
|
||||
|
||||
const res = await client.get<{ data: PlatformEventTokenResponse }>('/im/platform-events/token', {
|
||||
params: { appKey },
|
||||
})
|
||||
const token = res.data.data
|
||||
init({
|
||||
appKey,
|
||||
baseUrl: sdkBaseUrl(),
|
||||
wsUrl: sdkWsUrl(),
|
||||
debug: import.meta.env.DEV,
|
||||
})
|
||||
login(token.userId, token.token)
|
||||
|
||||
const clientInstance = new ImClient()
|
||||
clientInstance.on('message', (message) => {
|
||||
const event = parseEvent(message)
|
||||
if (!event || event.appKey !== activeAppKey) return
|
||||
onEvent(event)
|
||||
})
|
||||
clientInstance.on('error', (error) => {
|
||||
if (import.meta.env.DEV) {
|
||||
console.warn('[tenant-platform][IM] store review realtime error', error)
|
||||
}
|
||||
})
|
||||
clientInstance.connect()
|
||||
imClient = clientInstance
|
||||
}
|
||||
|
||||
export function disconnectStoreReviewRealtime() {
|
||||
if (imClient) {
|
||||
imClient.disconnect()
|
||||
imClient = null
|
||||
}
|
||||
activeAppKey = ''
|
||||
}
|
||||
|
||||
export function notifyStoreReviewRefresh(appKey: string) {
|
||||
if (appKey && appKey === activeAppKey) {
|
||||
ElMessage.info('检测到审核状态更新,正在刷新...')
|
||||
}
|
||||
}
|
||||
正在加载...
在新工单中引用
屏蔽一个用户