Skip to content

Commit

Permalink
feat: 数据库服务器支持修改
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Nov 26, 2024
1 parent c2ae9dc commit 8d729aa
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internal/http/request/database_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type DatabaseServerCreate struct {

type DatabaseServerUpdate struct {
ID uint `form:"id" json:"id" validate:"required,exists=database_servers id"`
Name string `form:"name" json:"name" validate:"required,not_exists=database_servers name"`
Name string `form:"name" json:"name" validate:"required"`
Host string `form:"host" json:"host" validate:"required"`
Port uint `form:"port" json:"port" validate:"required,number,gte=1,lte=65535"`
Username string `form:"username" json:"username"`
Expand Down
34 changes: 31 additions & 3 deletions web/src/views/database/ServerList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { NButton, NInput, NInputGroup, NPopconfirm, NTag } from 'naive-ui'
import database from '@/api/panel/database'
import { formatDateTime } from '@/utils'
import UpdateServerModal from '@/views/database/UpdateServerModal.vue'
const updateModal = ref(false)
const updateID = ref(0)
const columns: any = [
{
Expand Down Expand Up @@ -114,7 +118,7 @@ const columns: any = [
{
title: '操作',
key: 'actions',
width: 200,
width: 300,
align: 'center',
hideInExcel: true,
render(row: any) {
Expand Down Expand Up @@ -148,10 +152,33 @@ const columns: any = [
}
}
),
h(
NButton,
{
size: 'small',
type: 'primary',
style: 'margin-left: 15px;',
onClick: () => {
updateID.value = row.id
updateModal.value = true
}
},
{
default: () => '修改',
icon: renderIcon('material-symbols:edit-outline', { size: 14 })
}
),
h(
NPopconfirm,
{
onPositiveClick: () => handleDelete(row.id)
onPositiveClick: () => {
// 防手贱
if (['local_mysql', 'local_postgresql'].includes(row.name)) {
window.$message.error('内置服务器不能删除,如需删除请卸载对应应用')
return
}
handleDelete(row.id)
}
},
{
default: () => {
Expand Down Expand Up @@ -215,7 +242,7 @@ onUnmounted(() => {
<n-data-table
striped
remote
:scroll-x="1500"
:scroll-x="1600"
:loading="loading"
:columns="columns"
:data="data"
Expand All @@ -232,6 +259,7 @@ onUnmounted(() => {
pageSizes: [20, 50, 100, 200]
}"
/>
<update-server-modal v-model:id="updateID" v-model:show="updateModal" />
</template>

<style scoped lang="scss"></style>
113 changes: 113 additions & 0 deletions web/src/views/database/UpdateServerModal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
<script setup lang="ts">
import database from '@/api/panel/database'
import { NButton, NInput } from 'naive-ui'
const show = defineModel<boolean>('show', { type: Boolean, required: true })
const id = defineModel<number>('id', { type: Number, required: true })
const updateModel = ref({
name: '',
host: '127.0.0.1',
port: 3306,
username: '',
password: '',
remark: ''
})
const handleUpdate = () => {
useRequest(() => database.serverUpdate(id.value, updateModel.value)).onSuccess(() => {
show.value = false
window.$message.success('修改成功')
window.$bus.emit('database-user:refresh')
})
}
watch(
() => show.value,
(value) => {
if (value && id.value) {
database.serverGet(id.value).then((data: any) => {
updateModel.value.name = data.name
updateModel.value.host = data.host
updateModel.value.port = data.port
updateModel.value.username = data.username
updateModel.value.password = data.password
updateModel.value.remark = data.remark
})
}
}
)
</script>

<template>
<n-modal
v-model:show="show"
preset="card"
title="修改服务器"
style="width: 60vw"
size="huge"
:bordered="false"
:segmented="false"
@close="show = false"
>
<n-form :model="updateModel">
<n-form-item path="name" label="名称">
<n-input
v-model:value="updateModel.name"
type="text"
@keydown.enter.prevent
placeholder="输入数据库服务器名称"
/>
</n-form-item>
<n-row :gutter="[0, 24]">
<n-col :span="15">
<n-form-item path="host" label="主机">
<n-input
v-model:value="updateModel.host"
type="text"
@keydown.enter.prevent
placeholder="输入数据库服务器主机"
/>
</n-form-item>
</n-col>
<n-col :span="2"></n-col>
<n-col :span="7">
<n-form-item path="port" label="端口">
<n-input-number
w-full
v-model:value="updateModel.port"
@keydown.enter.prevent
placeholder="输入数据库服务器端口"
/>
</n-form-item>
</n-col>
</n-row>
<n-form-item path="username" label="用户名">
<n-input
v-model:value="updateModel.username"
type="text"
@keydown.enter.prevent
placeholder="输入数据库服务器用户名"
/>
</n-form-item>
<n-form-item path="password" label="密码">
<n-input
v-model:value="updateModel.password"
type="password"
@keydown.enter.prevent
placeholder="输入数据库服务器密码"
/>
</n-form-item>
<n-form-item path="remark" label="备注">
<n-input
v-model:value="updateModel.remark"
type="textarea"
@keydown.enter.prevent
placeholder="输入数据库服务器备注"
/>
</n-form-item>
</n-form>
<n-button type="info" block @click="handleUpdate">提交</n-button>
</n-modal>
</template>

<style scoped lang="scss"></style>
4 changes: 2 additions & 2 deletions web/src/views/database/UpdateUserModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const updateModel = ref({
const handleUpdate = () => {
useRequest(() => database.userUpdate(id.value, updateModel.value)).onSuccess(() => {
show.value = false
window.$message.success('更新成功')
window.$message.success('修改成功')
window.$bus.emit('database-user:refresh')
})
}
Expand All @@ -36,7 +36,7 @@ watch(
<n-modal
v-model:show="show"
preset="card"
title="更新用户"
title="修改用户"
style="width: 60vw"
size="huge"
:bordered="false"
Expand Down
4 changes: 2 additions & 2 deletions web/src/views/database/UserList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ const columns: any = [
}
},
{
default: () => '编辑',
icon: renderIcon('material-symbols:edit', { size: 14 })
default: () => '修改',
icon: renderIcon('material-symbols:edit-outline', { size: 14 })
}
),
h(
Expand Down

0 comments on commit 8d729aa

Please sign in to comment.