Skip to content

Commit f6f8a8f

Browse files
committed
add window target mode switch
1 parent 848c423 commit f6f8a8f

File tree

10 files changed

+129
-28
lines changed

10 files changed

+129
-28
lines changed

src/App.vue

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,21 @@ import TitleBar from "./components/native/TitleBar.vue"
33
import Dialog from "./components/Dialog.vue"
44
import TopLinks from "./components/TopLinks.vue"
55
6-
import { ref } from "vue"
6+
import { ref, onMounted } from "vue"
77
import { useStorage } from "@vueuse/core"
8+
import { nextTickToShow } from "./composables/useLocal"
89
910
const isOpenModelDialog = ref(false)
1011
const slideDirection = useStorage(
1112
"roco-navigation-transition-direction",
1213
"slideleft"
1314
)
15+
16+
onMounted(() => {
17+
setTimeout(() => {
18+
nextTickToShow()
19+
}, 0)
20+
})
1421
</script>
1522

1623
<template>
@@ -50,9 +57,13 @@ html.dark {
5057
}
5158
</style>
5259

53-
<style lang="postcss" scoped>
60+
<style lang="postcss">
5461
.slideleft-enter-active,
5562
.slideleft-leave-active,
63+
.slideup-enter-active,
64+
.slideup-leave-active,
65+
.slidedown-enter-active,
66+
.slidedown-leave-active,
5667
.slideright-enter-active,
5768
.slideright-leave-active {
5869
@apply transition-all;
@@ -66,6 +77,18 @@ html.dark {
6677
.slideright-leave-to {
6778
@apply -translate-x-4 opacity-0;
6879
}
80+
.slideup-enter-from {
81+
@apply translate-y-0 opacity-0;
82+
}
83+
.slideup-leave-to {
84+
@apply translate-y-2 opacity-0;
85+
}
86+
.slidedown-enter-from {
87+
@apply translate-y-0 opacity-0;
88+
}
89+
.slidedown-leave-to {
90+
@apply -translate-y-2 opacity-0;
91+
}
6992
</style>
7093

7194
<style scoped lang="postcss">

src/components/FeatureFilter.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ watch(checkedOption, (value) => {
5252

5353
<template>
5454
<Popover as="div" v-slot="{ open, close }">
55-
<PopoverButton class="transition-all shadow-lg outline-none">
55+
<PopoverButton
56+
class="transition-all rounded shadow-lg outline-none focus:ring-2 ring-green-300 dark:ring-green-500"
57+
>
5658
<div class="btn-context">
5759
<img
5860
v-if="checkedOption !== ''"

src/components/SpiritList.vue

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<script lang="ts" setup>
22
import { Ref, ref, toRefs, watch } from "vue"
3+
import { useRouter } from "vue-router"
34
import { useApi } from "../composables/useApi"
45
import { computedAsync, useStorage } from "@vueuse/core"
56
@@ -63,6 +64,8 @@ function getAngelIconSrc(iconSrc: string) {
6364
return `${iconStaticURL}${iconSrc}`
6465
}
6566
67+
const $router = useRouter()
68+
const alwaysTargetNewWindow = useStorage("roco-new-window-target", false)
6669
const angelPageTitle = useStorage("roco-angel-page-title", "一只迪莫小可爱")
6770
const AngelWindow: Ref<WindowCreator | null> = ref(null)
6871
@@ -72,7 +75,16 @@ function setupWindowParams(id: string, name: string, hash: string) {
7275
url: `/#/angel/${hash}`,
7376
title: angelPageTitle.value,
7477
})
75-
AngelWindow.value.setup()
78+
79+
goAngelView(hash)
80+
}
81+
function goAngelView(hash: string) {
82+
if (alwaysTargetNewWindow.value) AngelWindow.value!.setup()
83+
else
84+
$router.push({
85+
name: "Angel",
86+
params: { hash },
87+
})
7688
}
7789
</script>
7890

src/components/TopLinks.vue

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script lang="ts" setup>
22
import { BookOpenIcon, QuestionMarkCircleIcon } from "@heroicons/vue/20/solid"
33
import Menu from "./native/Menu.vue"
4+
import GoBack from "./native/GoBack.vue"
45
import { computed } from "vue"
56
import { RouterLink, useRoute } from "vue-router"
67
import { useStorage } from "@vueuse/core"
@@ -19,25 +20,26 @@ const categoryNameMap = new Map([
1920
["skills", "技能"],
2021
["items", "物品"],
2122
])
22-
2323
function getMatchCategroyName() {
2424
return categoryNameMap.get(category.value)
2525
}
2626
</script>
2727

2828
<template>
29-
<div id="top-links" v-show="hasActivedLink">
30-
<Menu class="links-menu" />
31-
32-
<RouterLink draggable="false" class="link" to="/">
33-
<BookOpenIcon class="icon" />
34-
<span class="text">{{ getMatchCategroyName() }}</span>
35-
</RouterLink>
36-
<RouterLink draggable="false" class="link" to="/about">
37-
<QuestionMarkCircleIcon class="icon" />
38-
<span class="text">关于</span>
39-
</RouterLink>
40-
</div>
29+
<Transition name="slideup" mode="in-out" appear>
30+
<div id="top-links" v-show="hasActivedLink">
31+
<Menu class="links-menu" />
32+
<GoBack />
33+
<RouterLink draggable="false" class="link" to="/">
34+
<BookOpenIcon class="icon" />
35+
<span class="text">{{ getMatchCategroyName() }}</span>
36+
</RouterLink>
37+
<RouterLink draggable="false" class="link" to="/about">
38+
<QuestionMarkCircleIcon class="icon" />
39+
<span class="text">关于</span>
40+
</RouterLink>
41+
</div>
42+
</Transition>
4143
</template>
4244

4345
<style lang="postcss" scoped>

src/components/native/GoBack.vue

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script lang="ts" setup>
2+
import { ArrowLeftIcon } from "@heroicons/vue/20/solid"
3+
import { useStorage, useThrottleFn } from "@vueuse/core"
4+
import { useRouter } from "vue-router"
5+
6+
const alwaysTargetNewWindow = useStorage("roco-new-window-target", false)
7+
8+
const $router = useRouter()
9+
const goPrevHistory = useThrottleFn(() => {
10+
$router.back()
11+
}, 100)
12+
</script>
13+
14+
<template>
15+
<Transition name="slideright" mode="out-in" appear :duration="800">
16+
<button
17+
v-if="!alwaysTargetNewWindow"
18+
class="navigation-return"
19+
@click="goPrevHistory"
20+
>
21+
<ArrowLeftIcon class="icon" />
22+
</button>
23+
</Transition>
24+
</template>
25+
26+
<style lang="postcss" scoped>
27+
.navigation-return {
28+
@apply fixed left-16 inline-flex justify-center items-center py-1.5 px-2
29+
bg-slate-200 dark:bg-slate-600 text-slate-500 dark:text-slate-300
30+
focus:ring-2 ring-green-400 dark:ring-green-500
31+
rounded transition-all outline-none shadow-md
32+
z-10;
33+
}
34+
.navigation-return .icon {
35+
@apply w-4 h-4;
36+
}
37+
</style>

src/components/native/Menu.vue

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { Menu, MenuButton, MenuItems, MenuItem } from "@headlessui/vue"
33
import {
44
EllipsisHorizontalIcon,
55
ArrowsRightLeftIcon,
6+
ArrowTopRightOnSquareIcon,
7+
HomeModernIcon,
68
} from "@heroicons/vue/20/solid"
79
import { useStorage } from "@vueuse/core"
810
@@ -13,6 +15,11 @@ function isMatchCategoryOption(key: string): boolean {
1315
function turnToCategory(key: "angels" | "skills" | "items") {
1416
category.value = key
1517
}
18+
19+
const alwaysTargetNewWindow = useStorage("roco-new-window-target", false)
20+
function toggleTargetMode() {
21+
alwaysTargetNewWindow.value = !alwaysTargetNewWindow.value
22+
}
1623
</script>
1724

1825
<template>
@@ -86,16 +93,27 @@ function turnToCategory(key: "angels" | "skills" | "items") {
8693
>
8794
</MenuItem>
8895
</div>
89-
<MenuItem as="div" class="menu-item" v-slot="{ disabled, active }">
90-
<ArrowsRightLeftIcon class="icon" />
96+
<MenuItem
97+
as="div"
98+
class="menu-item"
99+
v-slot="{ disabled, active }"
100+
@click="toggleTargetMode()"
101+
>
102+
<ArrowTopRightOnSquareIcon
103+
v-show="!alwaysTargetNewWindow"
104+
class="icon"
105+
/>
106+
<HomeModernIcon v-show="alwaysTargetNewWindow" class="icon" />
91107
<span
92108
:class="[
93109
'text',
94110
disabled ? 'disabled' : null,
95111
active ? 'active' : null,
96112
]"
97113
title="切换浏览模式"
98-
>总是打开新页面</span
114+
>{{
115+
alwaysTargetNewWindow ? "总在当前页面" : "总是打开新页面"
116+
}}</span
99117
>
100118
</MenuItem>
101119
</MenuItems>
@@ -111,7 +129,7 @@ function turnToCategory(key: "angels" | "skills" | "items") {
111129
112130
.menu-button {
113131
@apply py-1 px-1.5
114-
bg-slate-200 dark:bg-slate-600
132+
bg-slate-200 dark:bg-slate-600 text-slate-500 dark:text-slate-300
115133
focus:ring-2 ring-green-400 dark:ring-green-500
116134
rounded transition-all outline-none shadow-md;
117135
}

src/composables/useLocal.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { nextTick } from "vue"
22
import { appWindow } from "@tauri-apps/api/window"
33

44
export function nextTickToShow() {
5-
nextTick(() => {
6-
appWindow.show()
5+
nextTick(async () => {
6+
await appWindow.show()
7+
await appWindow.setFocus()
78
})
89
}

src/composables/useWindow.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { WebviewWindow, WindowOptions, getAll } from "@tauri-apps/api/window"
1+
import { WebviewWindow, WindowOptions } from "@tauri-apps/api/window"
22

33
export class WindowCreator {
44
private label: string = "DefaultLabel"
@@ -10,12 +10,15 @@ export class WindowCreator {
1010
fullscreen: false,
1111
title: this.label,
1212
resizable: false,
13+
visible: false,
1314
center: true,
1415
}
1516
private window: WebviewWindow | null = null
17+
public uri: string = ""
1618

1719
constructor(label: string, options: WindowOptions) {
1820
this.label = label
21+
this.uri = options.url ?? ""
1922
this.options = Object.assign(this.options, options)
2023
}
2124

@@ -25,7 +28,7 @@ export class WindowCreator {
2528
this.window = new WebviewWindow(label, options)
2629
this.window.once("tauri://created", function () {
2730
// webview window successfully created
28-
console.log("Window Creator Setup Success", label, options)
31+
console.log("Window Creator Setup Success", label)
2932
})
3033
this.window.once("tauri://error", async function (e) {
3134
// an error happened creating the webview window

src/main.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { createApp } from "vue"
22
import "./styles.css"
33
import router from "./router"
44
import App from "./App.vue"
5-
import { nextTickToShow } from "./composables/useLocal"
65

76
import NProgress from "nprogress"
87
import "nprogress/nprogress.css" // nprogress样式文件
@@ -26,4 +25,3 @@ router.afterEach(() => {
2625
})
2726

2827
createApp(App).use(router).mount("#app")
29-
nextTickToShow()

src/views/Angel.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<script lang="ts" setup>
2+
import GoBack from "../components/native/GoBack.vue"
23
import { CubeTransparentIcon } from "@heroicons/vue/20/solid"
34
import { TabGroup, TabList, Tab, TabPanels, TabPanel } from "@headlessui/vue"
45
@@ -46,6 +47,7 @@ function log() {
4647
<template>
4748
<div @click="log" v-if="!isLoadingData">
4849
<span class="names">
50+
<GoBack class="go-back" />
4951
<span class="features">
5052
<img
5153
class="icon"
@@ -252,6 +254,9 @@ function log() {
252254
.features .icon {
253255
@apply w-6 h-6 inline-block mx-1;
254256
}
257+
.go-back {
258+
@apply left-8;
259+
}
255260
256261
.details {
257262
@apply w-full inline-flex justify-center items-center px-4
@@ -285,7 +290,7 @@ function log() {
285290
286291
.info-main,
287292
.skill-main {
288-
@apply max-h-40 flex flex-wrap justify-start
293+
@apply max-h-48 flex flex-wrap justify-center
289294
overflow-auto;
290295
}
291296
.info-item,

0 commit comments

Comments
 (0)