feat 平台配置

This commit is contained in:
DaxPay
2024-09-20 17:12:22 +08:00
parent 93dd6f9079
commit 00f89e66e5
2 changed files with 99 additions and 2 deletions

View File

@@ -0,0 +1,21 @@
import { defHttp } from '@/utils/http/axios'
import { Result } from '#/axios'
import { BaseEntity } from '#/web'
/**
* 获取配置
*/
export function get(){
return defHttp.get<Result<PlatformConfig>>({ url: '/platform/config/get' })
}
export function update(data: PlatformConfig) {
return defHttp.post<Result>({ url: '/platform/config/update', data })
}
/**
* 平台配置
*/
export interface PlatformConfig extends BaseEntity {
// 网关地址
gatewayServiceUrl?: string
}

View File

@@ -1,7 +1,83 @@
<template>
<div> 设计开发中 </div>
<div>
<div class="m-3 p-3 pt-5 bg-white">
<div class="flex justify-center" style="flex-wrap: wrap">
<a-spin :spinning="confirmLoading">
<a-form
class="small-from-item w-40vw"
ref="formRef"
:model="form"
:rules="rules"
:labelCol="{ span: 6 }"
:wrapperCol="{ span: 18 }"
:validate-trigger="['blur', 'change']"
>
<a-form-item label="网关地址" name="gatewayServiceUrl">
<a-input
:disabled="!edit"
v-model:value="form.gatewayServiceUrl"
placeholder="请输入网关地址"
/>
</a-form-item>
</a-form>
<div class="flex justify-center">
<a-button v-if="edit" @click="initData">取消</a-button>
<a-button v-if="edit" style="margin-left: 50px" type="primary" @click="updateConfig"
>更新</a-button
>
<a-button v-if="!edit" @click="edit = true">编辑信息</a-button>
</div>
</a-spin>
</div>
</div>
</div>
</template>
<script setup lang="ts"></script>
<script setup lang="ts">
import { FormInstance, Rule } from 'ant-design-vue/lib/form'
import { onMounted, ref } from 'vue'
import { get, PlatformConfig, update } from './PlatformConfig.api'
import { useMessage } from '@/hooks/web/useMessage'
const { createMessage } = useMessage()
const confirmLoading = ref(false)
const formRef = ref<FormInstance>()
const form = ref<PlatformConfig>({})
const edit = ref<boolean>(false)
const rules = {
gatewayServiceUrl: [{ required: true, message: '请输入网关地址' }],
} as Record<string, Rule[]>
onMounted(() => {
initData()
})
/**
* 获取配置
*/
function initData() {
confirmLoading.value = true
edit.value = false
get().then(({ data }) => {
form.value = data
confirmLoading.value = false
})
}
/**
* 更新
*/
function updateConfig() {
formRef.value?.validate().then(async () => {
confirmLoading.value = true
update(form.value)
.then(() => {
createMessage.success('更新成功')
initData()
})
.finally(() => (confirmLoading.value = false))
})
}
</script>
<style scoped lang="less"></style>