mirror of
https://github.com/continew-org/continew-admin-ui.git
synced 2025-09-09 20:57:17 +08:00
feat: 存储管理S3存储配置填充默认域名 (#21)
This commit is contained in:
@@ -8,3 +8,9 @@ export const isExternal = (path: string) => {
|
|||||||
export function isHttp(url: string) {
|
export function isHttp(url: string) {
|
||||||
return url.includes('http://') || url.includes('https://')
|
return url.includes('http://') || url.includes('https://')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 判断 字符串 是否是 ipv4 */
|
||||||
|
export function isIPv4(ip: string): boolean {
|
||||||
|
const ipv4Pattern = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
|
||||||
|
return ipv4Pattern.test(ip)
|
||||||
|
}
|
||||||
|
@@ -1,12 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<a-drawer
|
<a-drawer
|
||||||
v-model:visible="visible"
|
v-model:visible="visible"
|
||||||
:title="title"
|
:title="title"
|
||||||
:mask-closable="false"
|
:mask-closable="false"
|
||||||
:esc-to-close="false"
|
:esc-to-close="false"
|
||||||
:width="width >= 600 ? 600 : '100%'"
|
:width="width >= 600 ? 600 : '100%'"
|
||||||
@before-ok="save"
|
@before-ok="save"
|
||||||
@close="reset"
|
@close="reset"
|
||||||
>
|
>
|
||||||
<a-form ref="formRef" :model="form" :rules="rules" size="large" auto-label-width>
|
<a-form ref="formRef" :model="form" :rules="rules" size="large" auto-label-width>
|
||||||
<a-form-item label="名称" field="name">
|
<a-form-item label="名称" field="name">
|
||||||
@@ -23,10 +23,9 @@
|
|||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item v-if="form.type === 1" label="私有密钥" field="secretKey">
|
<a-form-item v-if="form.type === 1" label="私有密钥" field="secretKey">
|
||||||
<a-input
|
<a-input
|
||||||
v-model.trim="form.secretKey"
|
v-model.trim="form.secretKey"
|
||||||
placeholder="请输入私有密钥"
|
placeholder="请输入私有密钥"
|
||||||
:max-length="255"
|
:max-length="255"
|
||||||
@input="updateSecretKey"
|
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item v-if="form.type === 1" label="终端节点" field="endpoint">
|
<a-form-item v-if="form.type === 1" label="终端节点" field="endpoint">
|
||||||
@@ -37,12 +36,17 @@
|
|||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item v-if="form.type === 1" label="域名" field="domain">
|
<a-form-item v-if="form.type === 1" label="域名" field="domain">
|
||||||
<a-input v-model.trim="form.domain" placeholder="请输入域名" />
|
<a-input v-model.trim="form.domain" placeholder="请输入域名" />
|
||||||
|
<template #extra>
|
||||||
|
<div v-if="defaultDomain">
|
||||||
|
<span>留空默认域名:{{ defaultDomain }}</span>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item
|
<a-form-item
|
||||||
v-if="form.type === 2"
|
v-if="form.type === 2"
|
||||||
label="域名"
|
label="域名"
|
||||||
field="domain"
|
field="domain"
|
||||||
:rules="[
|
:rules="[
|
||||||
{
|
{
|
||||||
required: true,
|
required: true,
|
||||||
message: '请输入域名',
|
message: '请输入域名',
|
||||||
@@ -56,31 +60,31 @@
|
|||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item label="描述" field="description">
|
<a-form-item label="描述" field="description">
|
||||||
<a-textarea
|
<a-textarea
|
||||||
v-model.trim="form.description"
|
v-model.trim="form.description"
|
||||||
placeholder="请输入描述"
|
placeholder="请输入描述"
|
||||||
show-word-limit
|
show-word-limit
|
||||||
:max-length="200"
|
:max-length="200"
|
||||||
:auto-size="{ minRows: 3, maxRows: 5 }"
|
:auto-size="{ minRows: 3, maxRows: 5 }"
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item label="默认存储" field="isDefault">
|
<a-form-item label="默认存储" field="isDefault">
|
||||||
<a-switch
|
<a-switch
|
||||||
v-model="form.isDefault"
|
v-model="form.isDefault"
|
||||||
type="round"
|
type="round"
|
||||||
:checked-value="true"
|
:checked-value="true"
|
||||||
:unchecked-value="false"
|
:unchecked-value="false"
|
||||||
checked-text="是"
|
checked-text="是"
|
||||||
unchecked-text="否"
|
unchecked-text="否"
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
<a-form-item label="状态" field="status">
|
<a-form-item label="状态" field="status">
|
||||||
<a-switch
|
<a-switch
|
||||||
v-model="form.status"
|
v-model="form.status"
|
||||||
type="round"
|
type="round"
|
||||||
:checked-value="1"
|
:checked-value="1"
|
||||||
:unchecked-value="2"
|
:unchecked-value="2"
|
||||||
checked-text="启用"
|
checked-text="启用"
|
||||||
unchecked-text="禁用"
|
unchecked-text="禁用"
|
||||||
/>
|
/>
|
||||||
</a-form-item>
|
</a-form-item>
|
||||||
</a-form>
|
</a-form>
|
||||||
@@ -94,6 +98,7 @@ import { addStorage, getStorage, updateStorage } from '@/apis'
|
|||||||
import { useForm } from '@/hooks'
|
import { useForm } from '@/hooks'
|
||||||
import { useDict } from '@/hooks/app'
|
import { useDict } from '@/hooks/app'
|
||||||
import { encryptByRsa } from '@/utils/encrypt'
|
import { encryptByRsa } from '@/utils/encrypt'
|
||||||
|
import { isIPv4 } from '@/utils/validate'
|
||||||
|
|
||||||
const emit = defineEmits<{
|
const emit = defineEmits<{
|
||||||
(e: 'save-success'): void
|
(e: 'save-success'): void
|
||||||
@@ -122,6 +127,24 @@ const { form, resetForm } = useForm({
|
|||||||
sort: 999,
|
sort: 999,
|
||||||
status: 1
|
status: 1
|
||||||
})
|
})
|
||||||
|
/** 获取url的protocol和endpoint */
|
||||||
|
const stripProtocol = (url: string): { endpoint: string, protocol: string } => {
|
||||||
|
if (url.startsWith('http://')) {
|
||||||
|
return { endpoint: url.substring(7), protocol: 'http://' }
|
||||||
|
} else if (url.startsWith('https://')) {
|
||||||
|
return { endpoint: url.substring(8), protocol: 'https://' }
|
||||||
|
}
|
||||||
|
return { endpoint: url, protocol: 'http://' }
|
||||||
|
}
|
||||||
|
/** 按规则拼接当前默认domain */
|
||||||
|
const defaultDomain = computed(() => {
|
||||||
|
const { endpoint: initialEndpoint, bucketName, domain, type } = form
|
||||||
|
if (domain || type !== 1 || !initialEndpoint || !bucketName) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const { endpoint, protocol } = stripProtocol(initialEndpoint)
|
||||||
|
return isIPv4(endpoint) ? `${protocol}${endpoint}/${bucketName}/` : `${protocol}${bucketName}.${endpoint}/`
|
||||||
|
})
|
||||||
|
|
||||||
// 重置
|
// 重置
|
||||||
const reset = () => {
|
const reset = () => {
|
||||||
@@ -153,7 +176,8 @@ const save = async () => {
|
|||||||
if (isInvalid) return false
|
if (isInvalid) return false
|
||||||
const data = {
|
const data = {
|
||||||
...form,
|
...form,
|
||||||
secretKey: form.type === 1 && !form.secretKey.includes('*') ? encryptByRsa(form.secretKey) : null
|
secretKey: form.type === 1 && !form.secretKey.includes('*') ? encryptByRsa(form.secretKey) : null,
|
||||||
|
domain: form.domain || defaultDomain.value
|
||||||
}
|
}
|
||||||
if (isUpdate.value) {
|
if (isUpdate.value) {
|
||||||
await updateStorage(data, dataId.value)
|
await updateStorage(data, dataId.value)
|
||||||
|
Reference in New Issue
Block a user