@peng_kai/kit 0.3.0-beta.37 → 0.3.0-beta.39

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,16 +1,38 @@
1
1
  <script lang="ts">
2
- import { useEventListener, useIntervalFn } from '@vueuse/core';
2
+ import { useEventListener, useIntervalFn, useLocalStorage } from '@vueuse/core';
3
3
  import { Empty, Dropdown, Badge, Menu, MenuItem } from 'ant-design-vue';
4
4
  import { type UseQueryReturnType } from '@tanstack/vue-query'
5
- import { watch, ref, computed } from 'vue'
5
+ import { ref, computed, customRef, triggerRef } from 'vue'
6
6
  import dayjs from '../../../libs/dayjs';
7
7
  import { useRouter } from 'vue-router';
8
8
  import audioURL from './y682.mp3?url';
9
9
 
10
+ function useAudioMuted(audio: HTMLAudioElement, cacheKey: string) {
11
+ const audioMutedCache = useLocalStorage(cacheKey, false);
12
+ const audioMuted = customRef<boolean>((track, tracker) => ({
13
+ get: () => {
14
+ track();
15
+ return audio.muted;
16
+ },
17
+ set: (val) => {
18
+ audio.muted = audioMutedCache.value = val;
19
+ tracker();
20
+ }
21
+ }));
22
+
23
+ useEventListener(document, 'click', () => {
24
+ audio.muted = audioMutedCache.value;
25
+ triggerRef(audioMuted);
26
+ }, {once: true});
27
+
28
+ return audioMuted;
29
+ }
30
+
10
31
  const noticeAudio = new Audio(audioURL);
11
32
  noticeAudio.muted = true;
12
33
  noticeAudio.src = audioURL;
13
34
  document.body.append(noticeAudio);
35
+ export const audioMuted = useAudioMuted(noticeAudio, 'notice_audio_muted');
14
36
 
15
37
  const faviconEle = document.querySelector('link[rel="icon"]');
16
38
  const logoFaviconHref = document.querySelector('link[rel="icon"]')?.getAttribute('href')!;
@@ -51,9 +73,7 @@ function operate(notice: TNotice) {
51
73
  // watch(noticeNum, (num = 0, oldNum = 0) => {
52
74
  // num > oldNum && noticeAudio.play();
53
75
  // }, { immediate: true });
54
- useEventListener(document, 'click', () => {
55
- noticeAudio.muted = false;
56
- });
76
+
57
77
 
58
78
  useIntervalFn(() => {
59
79
  const num = noticeNum.value;
@@ -100,7 +120,8 @@ useIntervalFn(() => {
100
120
  <i class="i-ri:notification-4-line block text-5" :class="{ shake: !!noticeNum }" />
101
121
  </div>
102
122
  <template #overlay>
103
- <Menu v-if="noticeNum" @click="visible = false" class="max-h-100 overflow-y-auto">
123
+ <div v-if="noticeNum">
124
+ <Menu @click="visible = false" class="max-h-100 overflow-y-auto">
104
125
  <MenuItem v-for="(item, i) of noticeList" :key="i" @click="operate(item)">
105
126
  <div class="min-w-50">
106
127
  <div>{{ item.title }}</div>
@@ -110,6 +131,9 @@ useIntervalFn(() => {
110
131
  </div>
111
132
  </MenuItem>
112
133
  </Menu>
134
+ 123
135
+ </div>
136
+
113
137
  <div v-else class="h-40 min-w-50 flex items-center justify-center rounded-2 bg-$antd-colorBgElevated shadow"
114
138
  @click="visible = false">
115
139
  <Empty description="暂无通知" :image="Empty.PRESENTED_IMAGE_SIMPLE" />
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
3
  "type": "module",
4
- "version": "0.3.0-beta.37",
4
+ "version": "0.3.0-beta.39",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",