chat-app/src/main.js
wangyifeng e7ec387735
Some checks are pending
Check / lint (push) Waiting to run
Check / typecheck (push) Waiting to run
Check / build (build, 18.x, ubuntu-latest) (push) Waiting to run
Check / build (build, 18.x, windows-latest) (push) Waiting to run
Check / build (build:app, 18.x, ubuntu-latest) (push) Waiting to run
Check / build (build:app, 18.x, windows-latest) (push) Waiting to run
Check / build (build:mp-weixin, 18.x, ubuntu-latest) (push) Waiting to run
Check / build (build:mp-weixin, 18.x, windows-latest) (push) Waiting to run
处理文件上传中友好提示;处理文件上传失败场景图标展示;解决图片上传loading问题;替换所有进度条颜色更醒目;
2025-03-30 16:22:29 +08:00

102 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import customNavbar from '@/components/custom-navbar/index'
import { createSSRApp } from 'vue'
import App from './App.vue'
import dayjs from 'dayjs'
import 'virtual:uno.css'
import VConsole from 'vconsole'
import '@/utils/uni.webview.js'
import tmui from '@/uni_modules/tmui'
import { config } from '@/config/tmui/index.js'
import 'dayjs/locale/zh-cn'
import xLoaderror from '@/components/x-loaderror/index.vue'
import asyncLoading from '@/components/async-loading/index.vue'
import asyncError from '@/components/async-error/index.vue'
import { vLoading } from '@/components/x-loading/index.js'
import messagePopup from '@/components/x-message/useMessagePopup'
import pageAnimation from '@/components/page-animation/index.vue'
import * as plugins from './plugins'
import { useDialogueStore, useTalkStore } from '@/store'
const { showMessage } = messagePopup()
dayjs.locale('zh-cn')
if (import.meta.env.VITE_SHOW_CONSOLE === 'true') {
new VConsole()
}
export function createApp() {
const app = createSSRApp(App)
plugins.setPinia(app)
plugins.setComponents(app)
app.use(tmui, { ...config })
app.directive('loading', vLoading)
app.mixin(pageAnimation)
app.component('customNavbar', customNavbar)
app.component('x-loaderror', xLoaderror)
app.component('AsyncLoading', asyncLoading)
app.component('AsyncError', asyncError)
app.directive('no-space', {
mounted(el) {
el.addEventListener('input', (e) => {
const originalValue = e.target.value
const newValue = originalValue.replace(/\s/g, '')
if (originalValue !== newValue) {
e.target.value = newValue
e.target.dispatchEvent(new Event('input'))
}
})
},
})
//获取当前聊天页面所在页面并通过当前的receiver_id判断是否要创建本地通知栏消息
window.getCurrentChatRoute = (msg) => {
let pushMsg = JSON.parse(decodeURIComponent(msg))
//当前所在聊天会话的receiver_id
const receiver_id = pushMsg?.payload?.receiver_id
// 获取当前页面路径
const pages = getCurrentPages()
const page = pages[pages.length - 1]
console.log(page.route)
const dialogueStore = useDialogueStore()
console.log(dialogueStore?.talk?.receiver_id)
if (
page?.route === 'pages/dialog/index' &&
receiver_id === dialogueStore?.talk?.receiver_id
) {
return
}
console.log('===准备创建本地通知栏消息')
let OAWebView = plus.webview.all()
OAWebView.forEach((webview, index) => {
if (webview.id === 'webviewId1') {
webview.evalJS(`doCreatePushMessage('${msg}')`)
}
})
}
//处理聊天推送弹窗点开
window.openUniPushMsg = (msg) => {
console.log('=====点击通知栏消息')
let pushMsg = JSON.parse(decodeURIComponent(msg))
console.log('=====pushMsg', pushMsg)
//由于弹窗前处理了不该弹窗的场景,因此这里弹窗可以一并处理
//也就是都跳转到聊天页面
const talkStore = useTalkStore()
talkStore.toTalk(pushMsg?.payload?.talk_type, pushMsg?.payload?.receiver_id)
}
window.message = ['success', 'error', 'warning'].reduce((acc, type) => {
acc[type] = (message) => {
if (typeof message === 'string') {
showMessage({ type, message })
} else if (typeof message === 'object') {
showMessage({ type, ...message })
}
}
return acc
}, {})
return {
app,
}
}
createApp()