-
Notifications
You must be signed in to change notification settings - Fork 3k
Expand file tree
/
Copy pathindex.vue
More file actions
159 lines (148 loc) · 4.8 KB
/
index.vue
File metadata and controls
159 lines (148 loc) · 4.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<template>
<div>
<LayoutContent v-loading="loading" :title="$t('logs.websiteLog')">
<template #search>
<el-button
class="tag-button"
:class="logConfig.name === 'access.log' ? '' : 'no-active'"
:type="logConfig.name === 'access.log' ? 'primary' : ''"
@click="changeType('access.log')"
>
{{ $t('logs.runLog') }}
</el-button>
<el-button
class="tag-button"
:class="logConfig.name === 'error.log' ? '' : 'no-active'"
:type="logConfig.name === 'error.log' ? 'primary' : ''"
@click="changeType('error.log')"
>
{{ $t('logs.errLog') }}
</el-button>
</template>
<template #leftToolBar>
<el-select v-model="logConfig.id" @change="changeWebsite()" class="p-w-200 mr-2.5">
<template #prefix>{{ $t('website.website') }}</template>
<el-option
v-for="(website, index) in websites"
:key="index"
:label="website.primaryDomain"
:value="website.id"
></el-option>
</el-select>
<el-button>
<el-checkbox v-model="tailLog" @change="changeTail" :disabled="logConfig.id == undefined">
{{ $t('commons.button.watch') }}
</el-checkbox>
</el-button>
<el-button @click="onDownload" icon="Download" :disabled="!hasContent">
{{ $t('file.download') }}
</el-button>
<el-button type="primary" plain @click="onClean()" :disabled="!hasContent">
{{ $t('logs.deleteLogs') }}
</el-button>
</template>
<template #main>
<MainDiv :heightDiff="370">
<LogFile
ref="logRef"
:config="logConfig"
:default-button="false"
v-if="showLog"
v-model:loading="loading"
v-model:hasContent="hasContent"
/>
</MainDiv>
</template>
</LayoutContent>
<ConfirmDialog ref="confirmDialogRef" @confirm="onSubmitClean"></ConfirmDialog>
</div>
</template>
<script setup lang="ts">
import { ListWebsites, OpWebsiteLog } from '@/api/modules/website';
import { reactive } from 'vue';
import { onMounted } from 'vue';
import { ref, nextTick } from 'vue';
import i18n from '@/lang';
import { MsgSuccess } from '@/utils/message';
import LogFile from '@/components/log-file/index.vue';
const logConfig = reactive({
type: 'website',
id: undefined,
name: 'access.log',
colorMode: 'nginx',
});
const showLog = ref(false);
const loading = ref(false);
const websites = ref();
const confirmDialogRef = ref();
const tailLog = ref(false);
const logRef = ref();
const hasContent = ref(false);
const searchLog = () => {
showLog.value = false;
nextTick(() => {
showLog.value = true;
});
};
const getWebsites = async () => {
loading.value = true;
await ListWebsites()
.then((res) => {
websites.value = res.data || [];
if (websites.value.length > 0) {
logConfig.id = websites.value[0].id;
showLog.value = true;
}
})
.finally(() => {
loading.value = false;
});
};
const changeType = (type: string) => {
logConfig.name = type;
if (logConfig.id != undefined) {
searchLog();
}
};
const changeWebsite = () => {
searchLog();
};
const onClean = async () => {
const params = {
header: i18n.global.t('logs.deleteLogs'),
operationInfo: i18n.global.t('commons.msg.delete'),
submitInputInfo: i18n.global.t('logs.deleteLogs'),
};
confirmDialogRef.value!.acceptParams(params);
};
const onDownload = async () => {
logRef.value.onDownload();
};
const changeTail = () => {
logRef.value.changeTail(true);
};
// const onCloseLog = async () => {
// tailLog.value = false;
// clearInterval(Number(timer));
// timer = null;
// };
const onSubmitClean = async () => {
const req = {
id: logConfig.id,
operate: 'delete',
logType: logConfig.name,
};
loading.value = true;
OpWebsiteLog(req)
.then(() => {
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
searchLog();
})
.finally(() => {
loading.value = false;
});
};
onMounted(() => {
getWebsites();
});
</script>