2020-10-17 13:12:00 +02:00
|
|
|
<template>
|
2023-04-08 02:01:42 +02:00
|
|
|
<div class="_formRoot">
|
2023-07-26 03:15:20 +02:00
|
|
|
<FormSlot>
|
2023-07-26 03:26:55 +02:00
|
|
|
<VueDraggable v-model="items" animation="150" delay="50">
|
2023-07-26 03:15:20 +02:00
|
|
|
<div
|
|
|
|
v-for="(element, index) in items"
|
|
|
|
:key="index"
|
|
|
|
class="item"
|
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i class="itemHandle ph-list ph-lg"></i>
|
2023-07-26 03:15:20 +02:00
|
|
|
<i
|
|
|
|
:class="
|
2023-10-17 03:57:20 +02:00
|
|
|
icon(
|
|
|
|
`${
|
|
|
|
navbarItemDef[element]?.icon ??
|
|
|
|
'ph-arrows-out-line-vertical'
|
|
|
|
}`,
|
|
|
|
)
|
2023-07-26 03:15:20 +02:00
|
|
|
"
|
|
|
|
></i>
|
|
|
|
<span class="itemText">{{
|
|
|
|
i18n.ts[navbarItemDef[element]?.title] ??
|
|
|
|
i18n.ts.divider
|
|
|
|
}}</span>
|
|
|
|
<button
|
|
|
|
class="_button itemRemove"
|
|
|
|
@click="removeItem(index)"
|
|
|
|
>
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-x')"></i>
|
2023-07-26 03:15:20 +02:00
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</VueDraggable>
|
2023-07-26 03:26:55 +02:00
|
|
|
<FormSection>
|
|
|
|
<div style="display: flex; gap: var(--margin); flex-wrap: wrap">
|
|
|
|
<FormButton primary @click="addItem">
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-plus')"></i>
|
2023-07-26 03:26:55 +02:00
|
|
|
{{ i18n.ts.addItem }}
|
|
|
|
</FormButton>
|
|
|
|
<FormButton @click="reloadAsk">
|
2023-10-17 03:57:20 +02:00
|
|
|
<i :class="icon('ph-floppy-disk-back')"></i>
|
2023-07-26 03:26:55 +02:00
|
|
|
{{ i18n.ts.apply }}
|
|
|
|
</FormButton>
|
|
|
|
</div>
|
|
|
|
</FormSection>
|
2023-07-26 03:15:20 +02:00
|
|
|
</FormSlot>
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
<FormRadios v-model="menuDisplay" class="_formBlock">
|
|
|
|
<template #label>{{ i18n.ts.display }}</template>
|
|
|
|
<option value="sideFull">
|
|
|
|
{{ i18n.ts._menuDisplay.sideFull }}
|
|
|
|
</option>
|
|
|
|
<option value="sideIcon">
|
|
|
|
{{ i18n.ts._menuDisplay.sideIcon }}
|
|
|
|
</option>
|
|
|
|
<!-- <option value="top">{{ i18n.ts._menuDisplay.top }}</option> -->
|
|
|
|
<!-- <MkRadio v-model="menuDisplay" value="hide" disabled>{{ i18n.ts._menuDisplay.hide }}</MkRadio>-->
|
|
|
|
<!-- TODO: サイドバーを完全に隠せるようにすると、別途ハンバーガーボタンのようなものをUIに表示する必要があり面倒 -->
|
|
|
|
</FormRadios>
|
2020-11-25 13:31:34 +01:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
<FormButton danger class="_formBlock" @click="reset()"
|
2023-10-17 03:57:20 +02:00
|
|
|
><i :class="icon('ph-arrow-clockwise')"></i>
|
2023-04-08 02:01:42 +02:00
|
|
|
{{ i18n.ts.default }}</FormButton
|
|
|
|
>
|
|
|
|
</div>
|
2020-10-17 13:12:00 +02:00
|
|
|
</template>
|
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
<script lang="ts" setup>
|
2023-04-08 02:01:42 +02:00
|
|
|
import { computed, ref, watch } from "vue";
|
2023-09-02 01:27:33 +02:00
|
|
|
import { VueDraggable } from "vue-draggable-plus";
|
2023-07-26 03:15:20 +02:00
|
|
|
import FormSlot from "@/components/form/slot.vue";
|
2023-04-08 02:01:42 +02:00
|
|
|
import FormRadios from "@/components/form/radios.vue";
|
|
|
|
import FormButton from "@/components/MkButton.vue";
|
2023-07-26 03:26:55 +02:00
|
|
|
import FormSection from "@/components/form/section.vue";
|
2023-04-08 02:01:42 +02:00
|
|
|
import * as os from "@/os";
|
|
|
|
import { navbarItemDef } from "@/navbar";
|
|
|
|
import { defaultStore } from "@/store";
|
|
|
|
import { unisonReload } from "@/scripts/unison-reload";
|
|
|
|
import { i18n } from "@/i18n";
|
|
|
|
import { definePageMetadata } from "@/scripts/page-metadata";
|
2023-10-17 03:57:20 +02:00
|
|
|
import icon from "@/scripts/icon";
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-07-26 03:15:20 +02:00
|
|
|
const items = ref(defaultStore.state.menu);
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2023-04-08 02:01:42 +02:00
|
|
|
const menuDisplay = computed(defaultStore.makeGetterSetter("menuDisplay"));
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
async function reloadAsk() {
|
|
|
|
const { canceled } = await os.confirm({
|
2023-04-08 02:01:42 +02:00
|
|
|
type: "info",
|
2022-06-20 10:38:49 +02:00
|
|
|
text: i18n.ts.reloadToApplySetting,
|
2022-05-04 03:12:40 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
unisonReload();
|
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
async function addItem() {
|
2023-04-08 02:01:42 +02:00
|
|
|
const menu = Object.keys(navbarItemDef).filter(
|
2023-07-06 03:28:27 +02:00
|
|
|
(k) => !defaultStore.state.menu.includes(k),
|
2023-04-08 02:01:42 +02:00
|
|
|
);
|
2022-05-04 03:12:40 +02:00
|
|
|
const { canceled, result: item } = await os.select({
|
|
|
|
title: i18n.ts.addItem,
|
2023-04-08 02:01:42 +02:00
|
|
|
items: [
|
|
|
|
...menu.map((k) => ({
|
|
|
|
value: k,
|
|
|
|
text: i18n.ts[navbarItemDef[k].title],
|
|
|
|
})),
|
|
|
|
{
|
|
|
|
value: "-",
|
|
|
|
text: i18n.ts.divider,
|
|
|
|
},
|
|
|
|
],
|
2022-05-04 03:12:40 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
2023-07-26 03:15:20 +02:00
|
|
|
items.value = [...items.value, item];
|
|
|
|
}
|
|
|
|
|
|
|
|
async function removeItem(index) {
|
|
|
|
items.value = items.value.filter((_, i) => i !== index);
|
2022-05-04 03:12:40 +02:00
|
|
|
}
|
2021-07-19 04:36:35 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
async function save() {
|
2023-07-26 03:15:20 +02:00
|
|
|
defaultStore.set("menu", items.value);
|
2022-05-04 03:12:40 +02:00
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
function reset() {
|
2023-04-08 02:01:42 +02:00
|
|
|
defaultStore.reset("menu");
|
2023-07-26 03:15:20 +02:00
|
|
|
items.value = defaultStore.state.menu;
|
2022-05-04 03:12:40 +02:00
|
|
|
}
|
2020-10-17 13:12:00 +02:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
watch(items, async () => {
|
|
|
|
await save();
|
|
|
|
});
|
2020-12-29 13:08:16 +01:00
|
|
|
|
2022-05-04 03:12:40 +02:00
|
|
|
watch(menuDisplay, async () => {
|
|
|
|
await reloadAsk();
|
|
|
|
});
|
2020-12-29 13:08:16 +01:00
|
|
|
|
2022-06-20 10:38:49 +02:00
|
|
|
definePageMetadata({
|
2022-07-14 10:42:12 +02:00
|
|
|
title: i18n.ts.navbar,
|
2023-10-17 03:57:20 +02:00
|
|
|
icon: `${icon("ph-list-bullets")}`,
|
2020-10-17 13:12:00 +02:00
|
|
|
});
|
|
|
|
</script>
|
2023-07-26 03:15:20 +02:00
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.item {
|
|
|
|
position: relative;
|
|
|
|
display: block;
|
|
|
|
line-height: 2.85rem;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
white-space: nowrap;
|
|
|
|
border-radius: var(--radius);
|
|
|
|
margin-bottom: 0.5rem;
|
|
|
|
color: var(--navFg);
|
|
|
|
background-color: var(--panel);
|
|
|
|
|
|
|
|
> .itemIcon {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .itemText {
|
|
|
|
position: relative;
|
|
|
|
font-size: 0.9em;
|
|
|
|
margin-left: 1rem;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .itemRemove {
|
|
|
|
position: absolute;
|
|
|
|
z-index: 10000;
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
color: var(--error);
|
|
|
|
top: 4px;
|
|
|
|
right: 8px;
|
|
|
|
opacity: 0.8;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .itemHandle {
|
|
|
|
cursor: move;
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
margin: 0 1rem;
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|