chat-app/src/main.js

58 lines
1.7 KiB
JavaScript

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 { 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'
const { showMessage } = messagePopup()
dayjs.locale('zh-cn')
if (import.meta.env.VITE_SHOW_CONSOLE) {
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.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'))
}
})
},
})
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()