Skip to content

Commit

Permalink
fix: 🐛 pwa 立即切换 bug、优化loading、设置等
Browse files Browse the repository at this point in the history
  • Loading branch information
adams549659584 committed May 30, 2023
1 parent d39376c commit da33467
Show file tree
Hide file tree
Showing 14 changed files with 162 additions and 132 deletions.
2 changes: 1 addition & 1 deletion cloudflare/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ const home = async (pathname) => {
let url;
// if (pathname.startsWith('/github/')) {
if (pathname.indexOf('/github/') === 0) {
url = pathname.replace('/github/', 'https://raw.githubusercontent.com/adams549659584/go-proxy-bingai/master/');
url = pathname.replace('/github/', baseUrl);
} else {
url = baseUrl + 'cloudflare/index.html';
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "go-proxy-bingai",
"version": "1.8.3",
"version": "1.8.4",
"private": true,
"scripts": {
"dev": "vite",
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/ChatNav/ChatNav.vue
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,10 @@ const saveUserToken = () => {

<template>
<NDropdown v-if="isMobile()" class="select-none" :show="isShowMore" :options="navConfigs" :render-label="renderDropdownLabel" @select="handleSelect">
<NImage class="fixed top-6 right-4 cursor-pointer" :src="settingSvgUrl" alt="设置菜单" :preview-disabled="true" @click="isShowMore = !isShowMore"></NImage>
<NImage class="fixed top-6 right-4 cursor-pointer z-50" :src="settingSvgUrl" alt="设置菜单" :preview-disabled="true" @click="isShowMore = !isShowMore"></NImage>
</NDropdown>
<NDropdown v-else class="select-none" trigger="hover" :options="navConfigs" :render-label="renderDropdownLabel" @select="handleSelect">
<NImage class="fixed top-6 right-6 cursor-pointer" :src="settingSvgUrl" alt="设置菜单" :preview-disabled="true"></NImage>
<NImage class="fixed top-6 right-6 cursor-pointer z-50" :src="settingSvgUrl" alt="设置菜单" :preview-disabled="true"></NImage>
</NDropdown>
<NModal v-model:show="isShowSetTokenModal" preset="dialog" :show-icon="false">
<template #header>
Expand Down
43 changes: 17 additions & 26 deletions frontend/src/components/LoadingSpinner/LoadingSpinner.vue
Original file line number Diff line number Diff line change
@@ -1,44 +1,35 @@
<script setup lang="ts">
import { onMounted } from 'vue';
import { ref } from 'vue';
defineProps<{
isShow: boolean;
}>();
const isRemoveLoading = ref(false);
const loadingRef = ref<HTMLDivElement>();
onMounted(() => {
if (loadingRef.value) {
loadingRef.value.addEventListener('transitionend', () => {
isRemoveLoading.value = true;
});
}
});
</script>

<template>
<div v-if="!isRemoveLoading" ref="loadingRef" class="loading-spinner" :class="{ hidden: !isShow }">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
<Transition name="fade">
<div v-if="isShow" class="loading-spinner">
<div class="bounce1"></div>
<div class="bounce2"></div>
<div class="bounce3"></div>
</div>
</Transition>
</template>

<style scoped>
.fade-enter-active,
.fade-leave-active {
transition: opacity 2.5s ease;
}
.fade-enter-from,
.fade-leave-to {
opacity: 0;
}
.loading-spinner {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
opacity: 1;
transition: opacity 2s ease-out;
}
.loading-spinner.hidden {
opacity: 0;
}
.loading-spinner > div {
Expand Down
15 changes: 13 additions & 2 deletions frontend/src/components/ReloadPWA/ReloadPWA.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<script setup lang="ts">
import { ref } from 'vue';
import { NModal, NButton } from 'naive-ui';
import { NModal, NButton, useMessage } from 'naive-ui';
import { useRegisterSW } from 'virtual:pwa-register/vue';
const message = useMessage();
const isShowModal = ref(false);
const isUpdateLoading = ref(false);
const { offlineReady, needRefresh, updateServiceWorker } = useRegisterSW({
immediate: true,
Expand All @@ -17,6 +19,7 @@ const { offlineReady, needRefresh, updateServiceWorker } = useRegisterSW({
},
onNeedRefresh() {
isShowModal.value = true;
// updateServiceWorker();
},
});
Expand All @@ -25,13 +28,21 @@ const close = async () => {
needRefresh.value = false;
isShowModal.value = false;
};
const update = async () => {
isUpdateLoading.value = true;
await updateServiceWorker();
message.success('已切换新版');
isUpdateLoading.value = false;
isShowModal.value = false;
};
</script>

<template>
<NModal v-model:show="isShowModal" preset="dialog" title="更新提示" content="新版本已经更新完毕,是否切换?">
<template #action>
<NButton size="large" @click="close">下次再说</NButton>
<NButton ghost size="large" type="info" @click="updateServiceWorker()">立即切换</NButton>
<NButton ghost size="large" type="info" @click="update" :loading="isUpdateLoading">立即切换</NButton>
</template>
</NModal>
</template>
28 changes: 28 additions & 0 deletions frontend/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,31 @@ export const isMobile = () => {
};

export const sleep = (timeout: number) => new Promise((resolve, reject) => setTimeout(resolve, timeout));

export const copy = async (text: string) => {
if (navigator.clipboard && navigator.clipboard.writeText) {
// 使用Clipboard API复制文本到剪贴板
try {
await navigator.clipboard.writeText(text);
return true;
} catch (error) {
console.error('error : ', error);
}
}
// 使用备用方案
try {
const ele = document.createElement('textarea');
ele.value = text;
ele.setAttribute('readonly', '');
ele.style.position = 'absolute';
ele.style.left = '-9999px';
document.body.appendChild(ele);
ele.select();
document.execCommand('copy');
document.body.removeChild(ele);
return true;
} catch (error) {
console.error(error);
}
return false;
};
1 change: 0 additions & 1 deletion web/assets/index-0e8bf8a6.css

This file was deleted.

1 change: 1 addition & 0 deletions web/assets/index-1dc749ba.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion web/assets/index-2c05b5de.css

This file was deleted.

1 change: 1 addition & 0 deletions web/assets/index-4b631cfd.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

72 changes: 36 additions & 36 deletions web/assets/index-8a670f2e.js → web/assets/index-4cac3f94.js

Large diffs are not rendered by default.

118 changes: 59 additions & 59 deletions web/assets/index-c254a98d.js → web/assets/index-58dc3d18.js

Large diffs are not rendered by default.

Loading

1 comment on commit da33467

@vercel
Copy link

@vercel vercel bot commented on da33467 May 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.