feat: 增加其他TAB页

This commit is contained in:
zhengkunwang223 2022-11-08 17:21:13 +08:00 committed by zhengkunwang223
parent d5aee147f4
commit 38a439e0d6
9 changed files with 178 additions and 9 deletions

View file

@ -52,6 +52,34 @@ func (b *BaseApi) DeleteWebSite(c *gin.Context) {
helper.SuccessWithData(c, nil)
}
func (b *BaseApi) UpdateWebSite(c *gin.Context) {
var req dto.WebSiteUpdate
if err := c.ShouldBindJSON(&req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
return
}
if err := websiteService.UpdateWebsite(req); err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, nil)
}
func (b *BaseApi) GetWebSite(c *gin.Context) {
id, err := helper.GetParamID(c)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
return
}
website, err := websiteService.GetWebsite(id)
if err != nil {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
return
}
helper.SuccessWithData(c, website)
}
func (b *BaseApi) GetWebDomains(c *gin.Context) {
websiteId, err := helper.GetIntParamByKey(c, "websiteId")

View file

@ -28,6 +28,13 @@ type WebSiteCreate struct {
WebSiteGroupID uint `json:"webSiteGroupID" validate:"required"`
}
type WebSiteUpdate struct {
ID uint `json:"id" validate:"required"`
PrimaryDomain string `json:"primaryDomain" validate:"required"`
Remark string `json:"remark"`
WebSiteGroupID uint `json:"webSiteGroupID" validate:"required"`
}
type NewAppInstall struct {
Name string `json:"name"`
AppDetailId uint `json:"appDetailID"`

View file

@ -87,6 +87,26 @@ func (w WebsiteService) CreateWebsite(create dto.WebSiteCreate) error {
return nil
}
func (w WebsiteService) UpdateWebsite(req dto.WebSiteUpdate) error {
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID))
if err != nil {
return err
}
website.PrimaryDomain = req.PrimaryDomain
website.WebSiteGroupID = req.WebSiteGroupID
website.Remark = req.Remark
return websiteRepo.Save(context.TODO(), &website)
}
func (w WebsiteService) GetWebsite(id uint) (model.WebSite, error) {
website, err := websiteRepo.GetFirst(commonRepo.WithByID(id))
if err != nil {
return website, err
}
return website, nil
}
func (w WebsiteService) DeleteWebSite(req dto.WebSiteDel) error {
website, err := websiteRepo.GetFirst(commonRepo.WithByID(req.ID))

View file

@ -16,6 +16,8 @@ func (a *WebsiteRouter) InitWebsiteRouter(Router *gin.RouterGroup) {
baseApi := v1.ApiGroupApp.BaseApi
{
groupRouter.POST("", baseApi.CreateWebsite)
groupRouter.POST("/update", baseApi.UpdateWebSite)
groupRouter.GET("/:id", baseApi.GetWebSite)
groupRouter.POST("/search", baseApi.PageWebsite)
groupRouter.POST("/del", baseApi.DeleteWebSite)
groupRouter.GET("/domains/:websiteId", baseApi.GetWebDomains)

View file

@ -41,6 +41,13 @@ export namespace WebSite {
otherDomains: string;
}
export interface WebSiteUpdateReq {
id: number;
primaryDomain: string;
remark: string;
webSiteGroupID: number;
}
export interface Group extends CommonModel {
name: string;
default: boolean;

View file

@ -10,6 +10,14 @@ export const CreateWebsite = (req: WebSite.WebSiteCreateReq) => {
return http.post<any>(`/websites`, req);
};
export const UpdateWebsite = (req: WebSite.WebSiteUpdateReq) => {
return http.post<any>(`/websites/update`, req);
};
export const GetWebsite = (id: number) => {
return http.get<WebSite.WebSite>(`/websites/${id}`);
};
export const DeleteWebsite = (req: WebSite.WebSiteDel) => {
return http.post<any>(`/websites/del`, req);
};

View file

@ -9,12 +9,10 @@
<el-tab-pane :label="$t('website.rate')">
<LimitConn :id="id" v-if="index == '2'"></LimitConn>
</el-tab-pane>
<el-tab-pane label="HTTPS">Role</el-tab-pane>
<el-tab-pane label="域名跳转">Task</el-tab-pane>
<el-tab-pane label="错误页面">Task</el-tab-pane>
<el-tab-pane label="过期时间">Task</el-tab-pane>
<el-tab-pane label="默认文档">Task</el-tab-pane>
<el-tab-pane label="其他">
<Other :id="id" v-if="index == '4'"></Other>
</el-tab-pane>
</el-tabs>
</template>
@ -24,6 +22,7 @@ import { computed, ref } from 'vue';
import Doamin from './domain/index.vue';
import Default from './default-doc/index.vue';
import LimitConn from './limit-conn/index.vue';
import Other from './other/index.vue';
const props = defineProps({
id: {

View file

@ -0,0 +1,102 @@
<template>
<el-row :gutter="20">
<el-col :span="8" :offset="2">
<el-form
ref="websiteForm"
label-position="right"
label-width="80px"
:model="form"
:rules="rules"
:loading="loading"
>
<el-form-item :label="$t('website.primaryDomain')" prop="primaryDomain">
<el-input v-model="form.primaryDomain"></el-input>
</el-form-item>
<el-form-item :label="$t('website.group')" prop="webSiteGroupID">
<el-select v-model="form.webSiteGroupID">
<el-option
v-for="(group, index) in groups"
:key="index"
:label="group.name"
:value="group.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item :label="$t('website.remark')" prop="remark">
<el-input v-model="form.remark"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submit(websiteForm)" :loading="loading">
{{ $t('commons.button.save') }}
</el-button>
</el-form-item>
</el-form>
</el-col>
</el-row>
</template>
<script lang="ts" setup>
import { WebSite } from '@/api/interface/website';
import { GetWebsite, UpdateWebsite } from '@/api/modules/website';
import { Rules } from '@/global/form-rules';
import { computed, onMounted, reactive, ref } from 'vue';
import { ListGroups } from '@/api/modules/website';
import { ElMessage, FormInstance } from 'element-plus';
import i18n from '@/lang';
const websiteForm = ref<FormInstance>();
const props = defineProps({
id: {
type: Number,
default: 0,
},
});
const websiteId = computed(() => {
return Number(props.id);
});
let loading = ref(false);
let form = reactive({
id: websiteId.value,
primaryDomain: '',
remark: '',
webSiteGroupID: 0,
});
let rules = ref({
primaryDomain: [Rules.requiredInput],
webSiteGroupID: [Rules.requiredSelect],
});
let groups = ref<WebSite.Group[]>([]);
const submit = async (formEl: FormInstance | undefined) => {
if (!formEl) return;
await formEl.validate((valid) => {
if (!valid) {
return;
}
loading.value = true;
UpdateWebsite(form)
.then(() => {
ElMessage.success(i18n.global.t('commons.msg.updateSuccess'));
search();
})
.finally(() => {
loading.value = false;
});
});
};
const search = () => {
ListGroups().then((res) => {
groups.value = res.data;
GetWebsite(websiteId.value).then((res) => {
// form.id = res.data.id;
form.primaryDomain = res.data.primaryDomain;
form.remark = res.data.remark;
form.webSiteGroupID = res.data.webSiteGroupID;
});
});
};
onMounted(() => {
search();
});
</script>

View file

@ -4,11 +4,7 @@
<el-tab-pane label="基本">
<Basic :id="id"></Basic>
</el-tab-pane>
<el-tab-pane label="优化">优化</el-tab-pane>
<el-tab-pane label="反代">反代</el-tab-pane>
<el-tab-pane label="安全">反代</el-tab-pane>
<el-tab-pane label="备份">反代</el-tab-pane>
<el-tab-pane label="日志">反代</el-tab-pane>
<el-tab-pane label="源文">反代</el-tab-pane>
</el-tabs>
</LayoutContent>