Skip to content

Commit 1290e03

Browse files
committed
feat(website): add website config checkout (#9752)
1 parent 806de63 commit 1290e03

3 files changed

Lines changed: 92 additions & 37 deletions

File tree

‎frontend/src/api/interface/website.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ export namespace Website {
3232
}
3333

3434
export interface WebsiteDTO extends Website {
35+
status: string;
36+
expireDate: string;
3537
errorLogPath: string;
3638
accessLogPath: string;
3739
sitePath: string;

‎frontend/src/views/website/website/config/index.vue‎

Lines changed: 22 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,42 +11,44 @@
1111
<LayoutContent :title="$t('website.websiteConfig')" :back-name="'Website'" v-loading="loading">
1212
<template #app>
1313
<WebsiteStatus
14-
v-if="website.id > 0"
14+
v-if="website"
15+
:id="id"
16+
@select="selectWebsite"
1517
:primary-domain="website.primaryDomain"
1618
:status="website.status"
1719
:expire-date="website.expireDate"
1820
/>
1921
</template>
2022
<template #leftToolBar>
21-
<el-button type="primary" :plain="index !== 'basic'" @click="changeTab('basic')">
23+
<el-button type="primary" :plain="props.tab !== 'basic'" @click="changeTab('basic')">
2224
{{ $t('website.basic') }}
2325
</el-button>
24-
<el-button type="primary" :plain="index !== 'log'" @click="changeTab('log')">
26+
<el-button type="primary" :plain="props.tab !== 'log'" @click="changeTab('log')">
2527
{{ $t('commons.button.log') }}
2628
</el-button>
27-
<el-button type="primary" :plain="index !== 'resource'" @click="changeTab('resource')">
29+
<el-button type="primary" :plain="props.tab !== 'resource'" @click="changeTab('resource')">
2830
{{ $t('website.source', 2) }}
2931
</el-button>
3032
</template>
3133
<template #main>
32-
<MainDiv :heightDiff="260">
33-
<Basic :website="website" v-if="index === 'basic' && website.id" :heightDiff="320"></Basic>
34-
<Log :id="id" v-if="index === 'log'"></Log>
35-
<Resource :id="id" v-if="index === 'resource'"></Resource>
34+
<MainDiv v-if="website" :heightDiff="260">
35+
<Basic :website="website" v-if="props.tab === 'basic'" :heightDiff="320"></Basic>
36+
<Log :id="id" v-if="props.tab === 'log'"></Log>
37+
<Resource :id="id" v-if="props.tab === 'resource'"></Resource>
3638
</MainDiv>
3739
</template>
3840
</LayoutContent>
3941
</div>
4042
</template>
4143

4244
<script setup lang="ts">
43-
import { onMounted, ref, watch } from 'vue';
45+
import { onMounted, ref } from 'vue';
4446
import Basic from './basic/index.vue';
4547
import Resource from './resource/index.vue';
4648
import Log from './log/index.vue';
4749
import WebsiteStatus from '@/views/website/website/status/index.vue';
4850
import { getWebsite } from '@/api/modules/website';
49-
import { GetRuntime } from '@/api/modules/runtime';
51+
import type { Website } from '@/api/interface/website';
5052
import { routerToNameWithParams } from '@/utils/router';
5153
import MainDiv from '@/components/main-div/index.vue';
5254
import { useGlobalStore } from '@/composables/useGlobalStore';
@@ -66,34 +68,19 @@ const props = defineProps({
6668
},
6769
});
6870
69-
const id = ref(0);
70-
const index = ref('basic');
71-
const website = ref<any>({});
72-
const loading = ref(false);
73-
const configPHP = ref(false);
71+
const id = Number(props.id);
72+
const website = ref<Website.WebsiteDTO>();
73+
const loading = ref(true);
7474
75-
watch(index, (curr, old) => {
76-
if (curr != old) {
77-
changeTab(curr);
78-
}
79-
});
80-
81-
const changeTab = (index: string) => {
82-
routerToNameWithParams('WebsiteConfig', { id: id.value, tab: index });
83-
};
75+
const changeTab = (tab: string) => routerToNameWithParams('WebsiteConfig', { id, tab });
76+
const selectWebsite = (id: number) => routerToNameWithParams('WebsiteConfig', { id, tab: props.tab });
8477
8578
onMounted(async () => {
86-
index.value = props.tab;
87-
id.value = Number(props.id);
88-
loading.value = true;
89-
const res = await getWebsite(id.value);
90-
website.value = res.data;
91-
if (res.data.type === 'runtime') {
92-
const runRes = await GetRuntime(res.data.runtimeID);
93-
if (runRes.data.type == 'php' && runRes.data.resource === 'appstore') {
94-
configPHP.value = true;
95-
}
79+
try {
80+
const { data } = await getWebsite(id);
81+
website.value = data;
82+
} finally {
83+
loading.value = false;
9684
}
97-
loading.value = false;
9885
});
9986
</script>

‎frontend/src/views/website/website/status/index.vue‎

Lines changed: 68 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@
22
<div class="app-status">
33
<el-card>
44
<div>
5-
<el-tag effect="dark" type="success">{{ props.primaryDomain }}</el-tag>
5+
<el-select
6+
class="website-select"
7+
:model-value="props.id"
8+
:aria-label="$t('menu.website')"
9+
filterable
10+
remote
11+
remote-show-suffix
12+
:remote-method="search"
13+
:loading="loading && page === 0"
14+
@end-reached="loadMore"
15+
@change="(id) => emit('select', id)"
16+
>
17+
<template #label>{{ props.primaryDomain }}</template>
18+
<el-option v-for="site in options" :key="site.id" :value="site.id" :label="site.primaryDomain" />
19+
</el-select>
620
<span class="status-content">
721
<Status class="span-font" :key="props.status" :status="props.status"></Status>
822
</span>
@@ -20,9 +34,13 @@
2034
</div>
2135
</template>
2236
<script lang="ts" setup>
37+
import { ref } from 'vue';
38+
import { searchWebsites } from '@/api/modules/website';
39+
import type { Website } from '@/api/interface/website';
2340
import Status from '@/components/status/index.vue';
2441
import { dateFormatSimple } from '@/utils/date';
2542
const props = defineProps({
43+
id: { type: Number, required: true },
2644
primaryDomain: {
2745
type: String,
2846
default: '',
@@ -37,10 +55,58 @@ const props = defineProps({
3755
},
3856
});
3957
58+
const emit = defineEmits<{ select: [id: number] }>();
59+
const options = ref<Website.WebsiteRes[]>([]);
60+
const loading = ref(false);
61+
const page = ref(0);
62+
let total = 0;
63+
let query = '';
64+
let revision = 0;
65+
66+
const fetchPage = async () => {
67+
const request = revision;
68+
const nextPage = page.value + 1;
69+
loading.value = true;
70+
try {
71+
const { data } = await searchWebsites({
72+
page: nextPage,
73+
pageSize: 20,
74+
name: query,
75+
orderBy: 'favorite',
76+
order: 'descending',
77+
websiteGroupId: 0,
78+
});
79+
if (request !== revision) return;
80+
options.value = options.value.concat(data.items ?? []);
81+
total = data.total;
82+
page.value = nextPage;
83+
} finally {
84+
if (request === revision) loading.value = false;
85+
}
86+
};
87+
88+
const search = (name: string) => {
89+
if (query === name && (loading.value || page.value > 0)) return;
90+
revision++;
91+
query = name;
92+
page.value = 0;
93+
total = 0;
94+
options.value = [];
95+
return fetchPage();
96+
};
97+
98+
const loadMore = (direction: string) => {
99+
if (direction === 'bottom' && !loading.value && options.value.length < total) return fetchPage();
100+
};
101+
40102
const isEver = (time: string) => {
41103
const expireDate = new Date(time);
42104
return expireDate > new Date('9999-12-30');
43105
};
44106
</script>
45107

46-
<style lang="scss" scoped></style>
108+
<style scoped>
109+
.website-select {
110+
width: min(18rem, 100%);
111+
}
112+
</style>

0 commit comments

Comments
 (0)