Skip to content

Commit

Permalink
feat: link
Browse files Browse the repository at this point in the history
  • Loading branch information
zly2006 committed Aug 4, 2024
1 parent ac4c736 commit 82fbc1e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 17 deletions.
24 changes: 24 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,27 @@ export function isStrongPassword(password: string) {
password.match(/[0-9]/)
);
}

export const isInChina = () =>
doFetchGet('/api/ip')
.then((res) => {
if (res.ok) {
return res.json();
}
return Promise.resolve({});
})
.then(
(data: {
ip: string;
mm?: {
country_code?: string;
};
}) => {
if (data.mm?.country_code === 'CN') {
// 判断中国ip只是用来防止有墙的网站,没别的意思
console.log('ip', data.ip, 'is in china.');
return true;
}
return false;
},
);
40 changes: 23 additions & 17 deletions src/views/yisibite/Download.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ type MachineDef = {
hasX?: boolean;
hasY?: boolean;
hasZ?: boolean;
link?: string;
linkChina?: string;
};
type Machine = MachineDef & {
conditions: { [key: string]: ((v: number) => any)[] };
};
const names = ref<{ [key: string]: Machine }>({});
const generators = ref<{ [key: string]: Machine }>({});
const updateDownloads = () =>
doFetchGet('/api/mc-services/yisibite/')
Expand Down Expand Up @@ -63,8 +65,8 @@ const updateDownloads = () =>
},
};
}
names.value = machines;
if (name.value === '') name.value = Object.keys(names.value)[0];
generators.value = machines;
if (name.value === '') name.value = Object.keys(generators.value)[0];
}
})
.catch((e) => console.error(e));
Expand Down Expand Up @@ -105,9 +107,9 @@ function submit(e: SubmitEventPromise) {
</v-col>
<v-select
v-model="name"
:item-title="(item) => names[item]?.name"
:item-title="(item) => generators[item]?.name"
:item-value="(item) => item"
:items="Object.keys(names)"
:items="Object.keys(generators)"
density="comfortable"
autofocus
hide-details
Expand All @@ -120,16 +122,16 @@ function submit(e: SubmitEventPromise) {
<v-chip>
{{
$t('litematica_generator.download_count', {
count: names[name]?.downloads ?? '查询失败',
count: generators[name]?.downloads ?? '查询失败',
})
}}
</v-chip>
</template>
</v-select>
<v-col cols="12">
<a class="router" href="https://www.bilibili.com/video/BV1za4y1P7cw">
<v-col cols="12" v-if="generators[name]?.link">
<a class="router" :href="generators[name]?.link">
<v-icon>mdi-link</v-icon>
https://www.bilibili.com/video/BV1za4y1P7cw
{{ generators[name]?.link }}
</a>
</v-col>
</v-row>
Expand All @@ -138,50 +140,54 @@ function submit(e: SubmitEventPromise) {
<v-col>
<v-card
border
v-if="names[name]?.hasX || names[name]?.hasY || names[name]?.hasZ"
v-if="
generators[name]?.hasX ||
generators[name]?.hasY ||
generators[name]?.hasZ
"
>
<v-card-subtitle class="text-wrap pa-3">
{{ $t('litematica_generator.size_description') }}
</v-card-subtitle>
<v-card-text>
<v-row v-if="names[name]?.hasX">
<v-row v-if="generators[name]?.hasX">
<v-col class="text-md-body-1">
{{ $t('litematica_generator.size_x') }}
</v-col>
<v-text-field
density="compact"
variant="underlined"
v-model="xSize"
:rules="names[name]?.conditions?.x || []"
:rules="generators[name]?.conditions?.x || []"
/>
</v-row>
<v-row v-if="names[name]?.hasY">
<v-row v-if="generators[name]?.hasY">
<v-col class="text-md-body-1">
{{ $t('litematica_generator.size_y') }}
</v-col>
<v-text-field
density="compact"
variant="underlined"
v-model="ySize"
:rules="names[name]?.conditions?.y || []"
:rules="generators[name]?.conditions?.y || []"
/>
</v-row>
<v-row v-if="names[name]?.hasZ">
<v-row v-if="generators[name]?.hasZ">
<v-col class="text-md-body-1">
{{ $t('litematica_generator.size_z') }}
</v-col>
<v-text-field
density="compact"
variant="underlined"
v-model="zSize"
:rules="names[name]?.conditions?.z || []"
:rules="generators[name]?.conditions?.z || []"
/>
</v-row>
<v-row>
<v-spacer />
<LitematicaUpload class="ma-3" />
<v-btn
:disabled="names[name]?.available === false"
:disabled="generators[name]?.available === false"
:loading="loading"
class="ma-3"
color="primary"
Expand Down

0 comments on commit 82fbc1e

Please sign in to comment.