Skip to content

Commit

Permalink
feat: yisibite
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed May 15, 2024
1 parent dfde067 commit 032532a
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 33 deletions.
58 changes: 27 additions & 31 deletions src/appbar/TranslateButton.vue
Original file line number Diff line number Diff line change
@@ -1,41 +1,37 @@
<script lang="ts">
<script setup lang="ts">
import { useI18n } from 'vue-i18n';
import { Locale } from '@intlify/core-base';
export default {
name: 'TranslateButton',
data() {
const t = useI18n();
return {
t,
};
},
methods: {
changeLanguage(locale: Locale) {
localStorage.setItem('locale', locale);
this.$i18n.locale = locale;
},
},
};
const { locale } = useI18n();
if (localStorage && !localStorage.getItem('locale')) {
if (navigator && navigator.language) {
changeLanguage(navigator.language);
console.log('Set locale to', navigator.language);
}
}
function changeLanguage(newLocale: Locale) {
localStorage.setItem('locale', newLocale);
locale.value = newLocale;
}
</script>

<template>
<div class="text-center">
<v-menu :close-on-content-click="true">
<template #activator="{ props }">
<v-btn icon="mdi-translate" v-bind="props" />
</template>

<v-list>
<v-list-item
v-for="locale in $i18n.availableLocales"
:key="`locale-${locale}`"
@click="changeLanguage(locale)"
>
<v-list-item-title>{{ $t(locale) }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
<v-btn icon="mdi-translate">
<v-menu :close-on-content-click="true" activator="parent">
<v-list>
<v-list-item
v-for="locale in $i18n.availableLocales"
:key="`locale-${locale}`"
@click="changeLanguage(locale)"
>
<v-list-item-title>{{ $t(locale) }}</v-list-item-title>
</v-list-item>
</v-list>
</v-menu>
</v-btn>
</div>
</template>

Expand Down
9 changes: 7 additions & 2 deletions src/router/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,19 @@ const routes = [
},
{
path: '/user/:uid(\\d+)',
name: 'UserProfile',
name: 'UserProfileById',
component: () => import('@/views/profile/OtherUser.vue'),
},
{
path: '/@:username',
name: 'UserProfile',
name: 'UserProfileByName',
component: () => import('@/views/profile/OtherUser.vue'),
},
{
path: '/mc-services/download/yisibite',
name: 'YisibiteDownload',
component: () => import('@/views/yisibite/Download.vue'),
},
{
path: '/admin/users',
name: 'AdminUserList',
Expand Down
98 changes: 98 additions & 0 deletions src/views/yisibite/Download.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
<script lang="ts" setup>
import {ref} from "vue";
import {useAppStore} from "@/store/app";
import {SubmitEventPromise} from "vuetify";
import {useRouter} from "vue-router";
const router = useRouter();

Check warning on line 8 in src/views/yisibite/Download.vue

View workflow job for this annotation

GitHub Actions / check

'router' is assigned a value but never used
const xSize = ref(0);
const zSize = ref(0);
const loading = ref(false);
type Machine = {
name: string;
hasX: boolean;
hasZ: boolean;
conditions: (() => any)[];
}
const names: { [key: string]: Machine } = {
'yisibite-world-eater': {
name: '6宽无沟世吞x3.1 - 火弦月',
hasX: true,
hasZ: true,
conditions: [() => xSize.value % 6 == 0 || '宽度必须是6的倍数']
},
'yisibite-once-miner': {
name: '5x3单发盾构 - 火弦月',
hasX: true,
hasZ: false,
conditions: [() => xSize.value % 5 == 0 || '宽度必须是5的倍数']
},
}
const name = ref('yisibite-world-eater')
function submit(e: SubmitEventPromise) {
e.preventDefault()
e.then(e => {
if (e.valid) {
const req = {

Check warning on line 41 in src/views/yisibite/Download.vue

View workflow job for this annotation

GitHub Actions / check

'req' is assigned a value but never used
name: name.value,
xSize: xSize.value,
zSize: zSize.value
}
// open a new window to download
window.open(`/api/mc-services/yisibite/${name.value}?xSize=${xSize.value}&zSize=${zSize.value}`)
}
})
}
</script>

<template>
<v-form class="content-common" @submit="submit">
<h1>投影在线生成</h1>
<v-row>
<v-col>
请选择下载的机器
</v-col>
<v-combobox
v-model="name"
:item-title="(item) => names[item]?.name"
:items="Object.keys(names)"
autofocus
/>
</v-row>
<v-row v-if="names[name]?.hasX">
<v-col>
x宽度
</v-col>
<v-text-field v-model="xSize" :rules="[v => v > 0 || '宽度必须是整数', ...names[name]?.conditions]" />
</v-row>
<v-row v-if="names[name]?.hasZ">
<v-col>
z宽度 (出发和返回站的距离)
</v-col>
<v-text-field v-model="zSize" :rules="[v => v > 0 || '宽度必须是整数']" />
</v-row>
<v-row v-if="!useAppStore().logined">
未登录用户每分钟最多生成5次投影以防范ddos,如果被限制请 <a href="/login">登录</a>
</v-row>
<v-row>
<v-spacer />
<v-btn
:loading="loading"
color="primary"
type="submit"
>
下载
</v-btn>
</v-row>
</v-form>

</template>

<style scoped>
</style>

0 comments on commit 032532a

Please sign in to comment.