refactor: remove mitt lib

This commit is contained in:
zyronon 2024-04-27 12:43:51 +08:00
parent 1b82072f17
commit 8aedae15a5
6 changed files with 101 additions and 101 deletions

View File

@ -27,7 +27,6 @@
"axios-mock-adapter": "^1.22.0", "axios-mock-adapter": "^1.22.0",
"core-js": "3.21.1", "core-js": "3.21.1",
"libarchive-wasm": "^1.1.0", "libarchive-wasm": "^1.1.0",
"mitt": "3.0.0",
"mockjs": "^1.1.0", "mockjs": "^1.1.0",
"pinia": "^2.1.7", "pinia": "^2.1.7",
"vue": "3.4.21", "vue": "3.4.21",

View File

@ -20,9 +20,6 @@ dependencies:
libarchive-wasm: libarchive-wasm:
specifier: ^1.1.0 specifier: ^1.1.0
version: 1.1.0 version: 1.1.0
mitt:
specifier: 3.0.0
version: 3.0.0
mockjs: mockjs:
specifier: ^1.1.0 specifier: ^1.1.0
version: 1.1.0 version: 1.1.0
@ -3306,10 +3303,6 @@ packages:
resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==} resolution: {integrity: sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==}
dev: true dev: true
/mitt@3.0.0:
resolution: {integrity: sha512-7dX2/10ITVyqh4aOSVI9gdape+t9l2/8QxHrFmUXu4EEUpdlxl6RudZUPZoc+zuY2hk1j7XxVroIVIan/pD/SQ==}
dev: false
/mlly@1.6.1: /mlly@1.6.1:
resolution: {integrity: sha512-vLgaHvaeunuOXHSmEbZ9izxPx3USsk8KCQ8iC+aTlp5sKRSoZvwhHh5L9VbKSaVC6sJDqbyohIS76E2VmHIPAA==} resolution: {integrity: sha512-vLgaHvaeunuOXHSmEbZ9izxPx3USsk8KCQ8iC+aTlp5sKRSoZvwhHh5L9VbKSaVC6sJDqbyohIS76E2VmHIPAA==}
dependencies: dependencies:

View File

@ -1,11 +1,11 @@
<template> <template>
<div <div
class="call-float" class="call-float"
v-if="isSmall" v-if="state.isSmall"
:style="callFloatStyle" :style="callFloatStyle"
@touchmove="touchmove" @touchmove="touchmove"
@touchend="touchend" @touchend="touchend"
@click="isSmall = false" @click="state.isSmall = false"
> >
<img src="@/assets/img/icon/message/chat/call-float.png" alt="" /> <img src="@/assets/img/icon/message/chat/call-float.png" alt="" />
<span>呼叫中</span> <span>呼叫中</span>
@ -14,134 +14,145 @@
<transition name="scale"> <transition name="scale">
<div <div
class="audio-call" class="audio-call"
:style="isSmall ? callFloatStyle : { zIndex: 10 }" :style="state.isSmall ? callFloatStyle : { zIndex: 10 }"
:class="isSmall ? 'small' : ''" :class="state.isSmall ? 'small' : ''"
v-if="isShowAudioCall" v-if="state.isShowAudioCall"
> >
<div class="float"> <div class="float">
<div class="header"> <div class="header">
<div class="left"> <div class="left">
<img @click="isSmall = true" src="@/assets/img/icon/message/chat/narrow.png" alt="" /> <img
@click="state.isSmall = true"
src="@/assets/img/icon/message/chat/narrow.png"
alt=""
/>
</div> </div>
<span class="center">等待对方接听...</span> <span class="center">等待对方接听...</span>
<div class="right"> <div class="right">
<div class="option"> <div class="option">
<img <img
v-show="!isOpenCamera" v-show="!state.isOpenCamera"
@click="isOpenCamera = !isOpenCamera" @click="state.isOpenCamera = !state.isOpenCamera"
src="@/assets/img/icon/message/chat/disabled-camera.png" src="@/assets/img/icon/message/chat/disabled-camera.png"
alt="" alt=""
/> />
<img <img
v-show="isOpenCamera" v-show="state.isOpenCamera"
@click="isOpenCamera = !isOpenCamera" @click="state.isOpenCamera = !state.isOpenCamera"
src="@/assets/img/icon/message/chat/able-camera.png" src="@/assets/img/icon/message/chat/able-camera.png"
alt="" alt=""
/> />
<span>摄像头</span> <span>摄像头</span>
</div> </div>
<div class="option" v-if="isExpand"> <div class="option" v-if="state.isExpand">
<img <img
v-show="!isOpenAudio" v-show="!state.isOpenAudio"
@click="isOpenAudio = !isOpenAudio" @click="state.isOpenAudio = !state.isOpenAudio"
src="@/assets/img/icon/message/chat/disabled-volume.png" src="@/assets/img/icon/message/chat/disabled-volume.png"
alt="" alt=""
/> />
<img <img
v-show="isOpenAudio" v-show="state.isOpenAudio"
@click="isOpenAudio = !isOpenAudio" @click="state.isOpenAudio = !state.isOpenAudio"
src="@/assets/img/icon/message/chat/able-volume.png" src="@/assets/img/icon/message/chat/able-volume.png"
alt="" alt=""
/> />
<span>免提</span> <span>免提</span>
</div> </div>
<div class="option"> <div class="option">
<dy-back mode="light" @click="isExpand = !isExpand" img="back" class="shrink" /> <dy-back
mode="light"
@click="state.isExpand = !state.isExpand"
img="back"
class="shrink"
/>
<!-- <img src="@/assets/img/icon/message/chat/narrow.png" alt="">--> <!-- <img src="@/assets/img/icon/message/chat/narrow.png" alt="">-->
</div> </div>
</div> </div>
</div> </div>
<img src="@/assets/img/icon/avatar/2.png" alt="" class="big-avatar" /> <img src="@/assets/img/icon/avatar/2.png" alt="" class="big-avatar" />
<div class="footer"> <div class="footer">
<img @click="isShowAudioCall = false" src="@/assets/img/icon/message/chat/call-end.png" /> <img
@click="state.isShowAudioCall = false"
src="@/assets/img/icon/message/chat/call-end.png"
/>
<span>挂断</span> <span>挂断</span>
</div> </div>
</div> </div>
</div> </div>
</transition> </transition>
</template> </template>
<script> <script setup lang="ts">
import { inject } from 'vue' import { onMounted, reactive, watch } from 'vue'
import bus, { EVENT_KEY } from '@/utils/bus'
export default { defineOptions({
name: 'Call', name: 'Call'
components: {}, })
props: { defineProps({
modelValue: { modelValue: {
type: Boolean, type: Boolean,
default() { default() {
return false return false
}
} }
}, }
data() { })
return {
mitt: inject('mitt'), const state = reactive({
callFloatTransitionTime: 300, callFloatTransitionTime: 300,
callFloatLeft: 15, callFloatLeft: 15,
callFloatTop: 100, callFloatTop: 100,
isOpenCamera: false, isOpenCamera: false,
isOpenAudio: true, isOpenAudio: true,
isExpand: true, isExpand: true,
isSmall: false, isSmall: false,
isShowAudioCall: false, isShowAudioCall: false,
height: 0, height: 0,
width: 0 width: 0
})
const callFloatStyle = $computed(() => {
return {
'transition-duration': state.callFloatTransitionTime + 'ms',
left: state.callFloatLeft + 'px',
top: state.callFloatTop + 'px'
}
})
watch(
() => state.isShowAudioCall,
(newVal) => {
if (!newVal) {
state.isOpenCamera = false
state.isOpenAudio = true
} }
}, }
computed: { )
callFloatStyle() {
return { onMounted(() => {
'transition-duration': this.callFloatTransitionTime + 'ms', bus.on(EVENT_KEY.SHOW_AUDIO_CALL, () => {
left: this.callFloatLeft + 'px', if (state.isShowAudioCall) {
top: this.callFloatTop + 'px' state.isSmall = false
} } else {
state.isShowAudioCall = true
} }
}, })
watch: { state.height = document.body.clientHeight
isShowAudioCall(newVal) { state.width = document.body.clientWidth
if (!newVal) { })
this.isOpenCamera = false
this.isOpenAudio = true function touchmove(e) {
} state.callFloatTransitionTime = 0
} state.callFloatLeft = e.touches[0].pageX - 35
}, state.callFloatTop = e.touches[0].pageY - 40
created() {}, }
methods: {
touchmove(e) { function touchend() {
this.callFloatTransitionTime = 0 state.callFloatTransitionTime = 300
this.callFloatLeft = e.touches[0].pageX - 35 if (state.callFloatLeft < state.width / 2) {
this.callFloatTop = e.touches[0].pageY - 40 state.callFloatLeft = 15
}, } else {
touchend() { state.callFloatLeft = state.width - 15 - 70
this.callFloatTransitionTime = 300
if (this.callFloatLeft < this.width / 2) {
this.callFloatLeft = 15
} else {
this.callFloatLeft = this.width - 15 - 70
}
}
},
mounted() {
this.mitt.on('showAudioCall', () => {
if (this.isShowAudioCall) {
this.isSmall = false
} else {
this.isShowAudioCall = true
}
})
this.height = document.body.clientHeight
this.width = document.body.clientWidth
} }
} }
</script> </script>

View File

@ -1,6 +1,5 @@
import { createApp } from 'vue' import { createApp } from 'vue'
import App from './App.vue' import App from './App.vue'
import mitt from 'mitt'
import './assets/less/index.less' import './assets/less/index.less'
import { startMock } from '@/mock' import { startMock } from '@/mock'
import router from './router' import router from './router'
@ -37,10 +36,7 @@ HTMLElement.prototype.addEventListener = new Proxy(HTMLElement.prototype.addEven
const vClick = useClick() const vClick = useClick()
const pinia = createPinia() const pinia = createPinia()
const emitter = mitt()
const app = createApp(App) const app = createApp(App)
app.config.globalProperties.emitter = emitter
app.provide('mitt', emitter)
app.mixin(mixin) app.mixin(mixin)
const loadImage = new URL('./assets/img/icon/img-loading.png', import.meta.url).href const loadImage = new URL('./assets/img/icon/img-loading.png', import.meta.url).href
app.use(VueLazyload, { app.use(VueLazyload, {

View File

@ -9,7 +9,7 @@
</div> </div>
<div class="right"> <div class="right">
<img <img
@click="mitt.emit('showAudioCall')" @click="bus.emit(EVENT_KEY.SHOW_AUDIO_CALL)"
src="../../../assets/img/icon/message/chat/call.png" src="../../../assets/img/icon/message/chat/call.png"
alt="" alt=""
/> />
@ -187,12 +187,13 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import ChatMessage from '../components/ChatMessage.vue' import ChatMessage from '../components/ChatMessage.vue'
import { computed, inject, nextTick, onMounted, onUnmounted, reactive, ref } from 'vue' import { computed, nextTick, onMounted, onUnmounted, reactive, ref } from 'vue'
import Loading from '@/components/Loading.vue' import Loading from '@/components/Loading.vue'
import { useBaseStore } from '@/store/pinia' import { useBaseStore } from '@/store/pinia'
import { _checkImgUrl, _no, _sleep } from '@/utils' import { _checkImgUrl, _no, _sleep } from '@/utils'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { useNav } from '@/utils/hooks/useNav' import { useNav } from '@/utils/hooks/useNav'
import bus, { EVENT_KEY } from '@/utils/bus'
let CALL_STATE = { let CALL_STATE = {
REJECT: 0, REJECT: 0,
@ -233,7 +234,6 @@ defineOptions({
name: 'Chat' name: 'Chat'
}) })
const mitt = inject('mitt')
const router = useRouter() const router = useRouter()
const nav = useNav() const nav = useNav()
const store = useBaseStore() const store = useBaseStore()

View File

@ -65,5 +65,6 @@ export const EVENT_KEY = {
CURRENT_ITEM: 'CURRENT_ITEM', CURRENT_ITEM: 'CURRENT_ITEM',
REMOVE_MUTED: 'REMOVE_MUTED', REMOVE_MUTED: 'REMOVE_MUTED',
HIDE_MUTED_NOTICE: 'HIDE_MUTED_NOTICE', HIDE_MUTED_NOTICE: 'HIDE_MUTED_NOTICE',
TOGGLE_VIDEO: 'TOGGLE_VIDEO' TOGGLE_VIDEO: 'TOGGLE_VIDEO',
SHOW_AUDIO_CALL: 'SHOW_AUDIO_CALL'
} }