Skip to content

Commit 2b800f4

Browse files
authored
Merge pull request #26 from 0xJacky/frontend-next
Refactored install and 404 pages
2 parents e087c94 + 9be594f commit 2b800f4

33 files changed

+613
-528
lines changed

frontend/.env.development

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
VITE_API_ROOT = /api
2-
VITE_API_WSS_ROOT = wss://nginx.jackyu.cn/api

frontend/.env.production

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
VUE_APP_API_ROOT = /api
2-
VUE_APP_API_WSS_ROOT = /api
1+
VITE_API_ROOT = /api

frontend/frontend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ import (
44
"embed"
55
)
66

7-
//go:embed dist
7+
//go:embed dist/* dist/*/*
88
var DistFS embed.FS

frontend/public/vite.svg

Lines changed: 0 additions & 18 deletions
This file was deleted.

frontend/src/api/index.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import http from '@/lib/http'
2+
3+
const install = {
4+
get_lock() {
5+
return http.get('/install')
6+
},
7+
install_nginx_ui(data: any) {
8+
return http.post('/install', data)
9+
}
10+
}
11+
12+
export default install

frontend/src/components/StdDataDisplay/StdPagination.vue

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,28 @@
1+
<script setup lang="ts">
2+
import {useGettext} from 'vue3-gettext'
3+
4+
const {pagination, size} = defineProps(['pagination', 'size'])
5+
const emit = defineEmits(['changePage'])
6+
const {$gettext} = useGettext()
7+
8+
function changePage(num: number) {
9+
emit('changePage', num)
10+
}
11+
</script>
12+
113
<template>
2-
<div v-if="Object.keys(pagination).length !== 0">
14+
<div v-if="pagination.total>pagination.per_page">
315
<a-pagination
416
:current="pagination.current_page"
5-
:hideOnSinglePage="true"
617
:pageSize="pagination.per_page"
718
:size="size"
819
:total="pagination.total"
9-
:show-total="(total, range) => `当前显示${range[0]}-${range[1]}条数据,共${total}条数据`"
1020
class="pagination"
1121
@change="changePage"
1222
/>
13-
<div class="clear"></div>
1423
</div>
1524
</template>
1625

17-
<script>
18-
export default {
19-
name: 'StdPagination',
20-
props: {
21-
pagination: Object,
22-
size: {
23-
default: ''
24-
}
25-
},
26-
methods: {
27-
changePage(num) {
28-
return this.$emit('changePage', num)
29-
}
30-
}
31-
}
32-
</script>
33-
3426
<style lang="less">
3527
.ant-pagination-total-text {
3628
@media (max-width: 450px) {

frontend/src/components/StdDataDisplay/StdTable.vue

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const {$gettext, interpolate} = gettext
55
66
import StdDataEntry from '@/components/StdDataEntry'
77
import StdPagination from './StdPagination.vue'
8-
import {nextTick, reactive, ref} from 'vue'
8+
import {nextTick, reactive, ref, watch} from 'vue'
99
import {useRoute, useRouter} from 'vue-router'
1010
import {message} from 'ant-design-vue'
1111
@@ -61,9 +61,9 @@ const props = defineProps({
6161
})
6262
6363
64-
const data_source = reactive([])
64+
const data_source = ref([])
6565
const loading = ref(true)
66-
const pagination = ({
66+
const pagination = reactive({
6767
total: 1,
6868
per_page: 10,
6969
current_page: 1,
@@ -80,7 +80,6 @@ const rowSelection = reactive({})
8080
const searchColumns = getSearchColumns()
8181
const pithyColumns = getPithyColumns()
8282
83-
8483
get_list()
8584
8685
defineExpose({
@@ -102,7 +101,7 @@ function get_list(page_num = null) {
102101
params['page'] = page_num
103102
}
104103
props.api!.get_list(params).then((r: any) => {
105-
Object.assign(data_source, r.data)
104+
data_source.value = r.data
106105
107106
if (r.pagination !== undefined) {
108107
Object.assign(pagination, r.pagination)
@@ -161,10 +160,17 @@ function onSelect(record: any) {
161160
const router = useRouter()
162161
163162
const reset_search = async () => {
164-
params = reactive({})
163+
Object.keys(params).forEach(v => {
164+
delete params[v]
165+
})
165166
router.push({query: {}}).catch(() => {
166167
})
167168
}
169+
170+
watch(params, () => {
171+
router.push({query: params})
172+
get_list()
173+
})
168174
</script>
169175

170176
<template>
@@ -212,7 +218,6 @@ const reset_search = async () => {
212218
</template>
213219
</template>
214220
</template>
215-
216221
</a-table>
217222
<std-pagination :pagination="pagination" @changePage="get_list"/>
218223
</div>

frontend/src/dark.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
@import "ant-design-vue/dist/antd.dark";
2+
3+
.directive-editor-extra {
4+
background-color: rgba(0, 0, 0, 0.84) !important;
5+
}

frontend/src/lib/http/index.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,12 @@ import axios, {AxiosRequestConfig} from 'axios'
22
import {useUserStore} from '@/pinia'
33
import {storeToRefs} from 'pinia'
44

5+
import router from '@/routes'
6+
57
const user = useUserStore()
68

79
const {token} = storeToRefs(user)
810

9-
declare module 'axios' {
10-
export interface AxiosResponse<T = any> extends Promise<T> {
11-
}
12-
}
13-
1411
let instance = axios.create({
1512
baseURL: import.meta.env.VITE_API_ROOT,
1613
timeout: 50000,
@@ -38,7 +35,6 @@ instance.interceptors.request.use(
3835
}
3936
)
4037

41-
4238
instance.interceptors.response.use(
4339
response => {
4440
return Promise.resolve(response.data)
@@ -47,6 +43,8 @@ instance.interceptors.response.use(
4743
switch (error.response.status) {
4844
case 401:
4945
case 403:
46+
user.logout()
47+
await router.push('/login')
5048
break
5149
}
5250
return Promise.reject(error.response.data)

frontend/src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import {createPinia} from 'pinia'
33
import gettext from './gettext'
44
import App from './App.vue'
55
import router from './routes'
6-
import 'ant-design-vue/dist/antd.less'
6+
//import 'ant-design-vue/dist/antd.less'
77
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
88
import {useSettingsStore} from '@/pinia'
99

0 commit comments

Comments
 (0)