Skip to content

Commit

Permalink
feat: 大部分视图支持消息总线
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Oct 23, 2024
1 parent f760dba commit fb88060
Show file tree
Hide file tree
Showing 13 changed files with 113 additions and 82 deletions.
8 changes: 1 addition & 7 deletions web/src/views/backup/IndexView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,12 @@ const createModel = ref({
target: '',
path: ''
})
const oldTab = ref('')
const handleCreate = () => {
backup.create(currentTab.value, createModel.value.target, createModel.value.path).then(() => {
createModal.value = false
window.$message.success('创建成功')
// 有点low,但是没找到更好的办法
oldTab.value = currentTab.value
currentTab.value = ''
setTimeout(() => {
currentTab.value = oldTab.value
}, 0)
window.$bus.emit('backup:refresh')
})
}
</script>
Expand Down
7 changes: 7 additions & 0 deletions web/src/views/backup/ListView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,13 @@ const handleDelete = async (file: string) => {
onMounted(() => {
onPageChange(pagination.page)
window.$bus.on('backup:refresh', () => {
onPageChange(pagination.page)
})
})
onUnmounted(() => {
window.$bus.off('backup:refresh')
})
</script>

Expand Down
47 changes: 27 additions & 20 deletions web/src/views/cert/AccountView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const updateAccountModel = ref<any>({
const updateAccountModal = ref(false)
const updateAccount = ref<any>()
const accountColumns: any = [
const columns: any = [
{
title: '邮箱',
key: 'email',
Expand Down Expand Up @@ -100,7 +100,7 @@ const accountColumns: any = [
onPositiveClick: async () => {
await cert.accountDelete(row.id)
window.$message.success('删除成功')
onAccountPageChange(1)
onPageChange(1)
}
},
{
Expand All @@ -126,9 +126,9 @@ const accountColumns: any = [
}
}
]
const accountData = ref<Account[]>([] as Account[])
const data = ref<Account[]>([] as Account[])
const accountPagination = reactive({
const pagination = reactive({
page: 1,
pageCount: 1,
pageSize: 20,
Expand All @@ -138,18 +138,18 @@ const accountPagination = reactive({
pageSizes: [20, 50, 100, 200]
})
const onAccountPageChange = (page: number) => {
accountPagination.page = page
getAccountList(page, accountPagination.pageSize).then((res) => {
accountData.value = res.items
accountPagination.itemCount = res.total
accountPagination.pageCount = res.total / accountPagination.pageSize + 1
const onPageChange = (page: number) => {
pagination.page = page
getAccountList(page, pagination.pageSize).then((res) => {
data.value = res.items
pagination.itemCount = res.total
pagination.pageCount = res.total / pagination.pageSize + 1
})
}
const onAccountPageSizeChange = (pageSize: number) => {
accountPagination.pageSize = pageSize
onAccountPageChange(1)
const onPageSizeChange = (pageSize: number) => {
pagination.pageSize = pageSize
onPageChange(1)
}
const getAccountList = async (page: number, limit: number) => {
Expand All @@ -165,14 +165,21 @@ const handleUpdateAccount = async () => {
messageReactive.destroy()
window.$message.success('更新成功')
updateAccountModal.value = false
onAccountPageChange(1)
onPageChange(1)
updateAccountModel.value.email = ''
updateAccountModel.value.hmac_encoded = ''
updateAccountModel.value.kid = ''
}
onMounted(() => {
onAccountPageChange(1)
onPageChange(pagination.page)
window.$bus.on('cert:refresh-account', () => {
onPageChange(pagination.page)
})
})
onUnmounted(() => {
window.$bus.off('cert:refresh-account')
})
</script>

Expand All @@ -183,12 +190,12 @@ onMounted(() => {
remote
:scroll-x="1000"
:loading="false"
:columns="accountColumns"
:data="accountData"
:columns="columns"
:data="data"
:row-key="(row: any) => row.id"
:pagination="accountPagination"
@update:page="onAccountPageChange"
@update:page-size="onAccountPageSizeChange"
:pagination="pagination"
@update:page="onPageChange"
@update:page-size="onPageSizeChange"
/>
</n-space>
<n-modal
Expand Down
55 changes: 31 additions & 24 deletions web/src/views/cert/CertView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const deployCertModel = ref<any>({
website_id: 0
})
const certColumns: any = [
const columns: any = [
{
title: '域名',
key: 'domains',
Expand Down Expand Up @@ -221,7 +221,7 @@ const certColumns: any = [
.obtain(row.id)
.then(() => {
window.$message.success('签发成功')
onCertPageChange(1)
onPageChange(1)
})
.finally(() => {
d.loading = false
Expand All @@ -234,7 +234,7 @@ const certColumns: any = [
.obtain(row.id)
.then(() => {
window.$message.success('签发成功')
onCertPageChange(1)
onPageChange(1)
})
.finally(() => {
messageReactive.destroy()
Expand Down Expand Up @@ -282,7 +282,7 @@ const certColumns: any = [
await cert.renew(row.id)
messageReactive.destroy()
window.$message.success('续签成功')
onCertPageChange(1)
onPageChange(1)
}
},
{
Expand Down Expand Up @@ -335,7 +335,7 @@ const certColumns: any = [
onPositiveClick: async () => {
await cert.certDelete(row.id)
window.$message.success('删除成功')
onCertPageChange(1)
onPageChange(1)
}
},
{
Expand All @@ -361,9 +361,9 @@ const certColumns: any = [
}
}
]
const certData = ref<Cert[]>([] as Cert[])
const data = ref<Cert[]>([] as Cert[])
const certPagination = reactive({
const pagination = reactive({
page: 1,
pageCount: 1,
pageSize: 20,
Expand All @@ -373,18 +373,18 @@ const certPagination = reactive({
pageSizes: [20, 50, 100, 200]
})
const onCertPageChange = (page: number) => {
certPagination.page = page
getCertList(page, certPagination.pageSize).then((res) => {
certData.value = res.items
certPagination.itemCount = res.total
certPagination.pageCount = res.total / certPagination.pageSize + 1
const onPageChange = (page: number) => {
pagination.page = page
getCertList(page, pagination.pageSize).then((res) => {
data.value = res.items
pagination.itemCount = res.total
pagination.pageCount = res.total / pagination.pageSize + 1
})
}
const onCertPageSizeChange = (pageSize: number) => {
certPagination.pageSize = pageSize
onCertPageChange(1)
const onPageSizeChange = (pageSize: number) => {
pagination.pageSize = pageSize
onPageChange(1)
}
const getCertList = async (page: number, limit: number) => {
Expand All @@ -396,7 +396,7 @@ const handleUpdateCert = async () => {
await cert.certUpdate(updateCert.value, updateCertModel.value)
window.$message.success('更新成功')
updateCertModal.value = false
onCertPageChange(1)
onPageChange(1)
updateCertModel.value.domains = []
updateCertModel.value.dns_id = 0
updateCertModel.value.type = 'P256'
Expand All @@ -411,7 +411,7 @@ const handleDeployCert = async () => {
deployCertModal.value = false
deployCertModel.value.id = 0
deployCertModel.value.website_id = 0
onCertPageChange(1)
onPageChange(1)
}
const handleShowModalClose = () => {
Expand All @@ -420,7 +420,14 @@ const handleShowModalClose = () => {
}
onMounted(() => {
onCertPageChange(1)
onPageChange(pagination.page)
window.$bus.on('cert:refresh-cert', () => {
onPageChange(pagination.page)
})
})
onUnmounted(() => {
window.$bus.off('cert:refresh-cert')
})
</script>

Expand All @@ -431,12 +438,12 @@ onMounted(() => {
remote
:scroll-x="1000"
:loading="false"
:columns="certColumns"
:data="certData"
:columns="columns"
:data="data"
:row-key="(row: any) => row.id"
:pagination="certPagination"
@update:page="onCertPageChange"
@update:page-size="onCertPageSizeChange"
:pagination="pagination"
@update:page="onPageChange"
@update:page-size="onPageSizeChange"
/>
</n-space>
<n-modal
Expand Down
2 changes: 2 additions & 0 deletions web/src/views/cert/CreateAccountModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ const handleCreateAccount = async () => {
cert
.accountCreate(model.value)
.then(() => {
show.value = false
window.$message.success('创建成功')
model.value.email = ''
model.value.hmac_encoded = ''
model.value.kid = ''
})
.finally(() => {
messageReactive?.destroy()
window.$bus.emit('cert:refresh-account')
})
}
</script>
Expand Down
2 changes: 2 additions & 0 deletions web/src/views/cert/CreateCertModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const model = ref<any>({
const handleCreateCert = async () => {
await cert.certCreate(model.value)
show.value = false
window.$message.success('创建成功')
model.value = false
model.value.domains = []
Expand All @@ -32,6 +33,7 @@ const handleCreateCert = async () => {
model.value.account_id = 0
model.value.website_id = 0
model.value.auto_renew = true
window.$bus.emit('cert:refresh-cert')
}
</script>

Expand Down
2 changes: 2 additions & 0 deletions web/src/views/cert/CreateDnsModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ const model = ref<any>({
const handleCreateDNS = async () => {
await cert.dnsCreate(model.value)
show.value = false
window.$message.success('创建成功')
show.value = false
model.value.data.ak = ''
model.value.data.sk = ''
model.value.name = ''
window.$bus.emit('cert:refresh-dns')
}
</script>

Expand Down
Loading

0 comments on commit fb88060

Please sign in to comment.