mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-14 01:34:47 +08:00
182 lines
7.4 KiB
Vue
182 lines
7.4 KiB
Vue
<template>
|
|
<DrawerPro v-model="drawerVisible" :header="title + $t('setting.backupAccount')" :back="handleClose" size="large">
|
|
<el-form @submit.prevent ref="formRef" v-loading="loading" label-position="top" :model="s3Data.rowData">
|
|
<el-form-item :label="$t('commons.table.type')" prop="type" :rules="Rules.requiredSelect">
|
|
<el-tag>{{ $t('setting.' + s3Data.rowData!.type) }}</el-tag>
|
|
</el-form-item>
|
|
<el-form-item label="Access Key ID" prop="accessKey" :rules="Rules.requiredInput">
|
|
<el-input v-model.trim="s3Data.rowData!.accessKey" />
|
|
</el-form-item>
|
|
<el-form-item label="Secret Key" prop="credential" :rules="Rules.requiredInput">
|
|
<el-input show-password clearable v-model.trim="s3Data.rowData!.credential" />
|
|
</el-form-item>
|
|
<el-form-item label="Region" prop="varsJson.region" :rules="Rules.requiredInput">
|
|
<el-input pro v-model.trim="s3Data.rowData!.varsJson['region']" />
|
|
</el-form-item>
|
|
<el-form-item label="Endpoint" prop="varsJson.endpointItem" :rules="Rules.requiredInput">
|
|
<el-input v-model="s3Data.rowData!.varsJson['endpointItem']">
|
|
<template #prepend>
|
|
<el-select v-model.trim="endpointProto" class="p-w-100">
|
|
<el-option label="http" value="http" />
|
|
<el-option label="https" value="https" />
|
|
</el-select>
|
|
</template>
|
|
</el-input>
|
|
</el-form-item>
|
|
<el-form-item label="Bucket" prop="bucket">
|
|
<el-select @change="errBuckets = false" class="!w-4/5" v-model="s3Data.rowData!.bucket">
|
|
<el-option v-for="item in buckets" :key="item" :value="item" />
|
|
</el-select>
|
|
<el-button class="!w-1/5" plain @click="getBuckets(formRef)">
|
|
{{ $t('setting.loadBucket') }}
|
|
</el-button>
|
|
<span v-if="errBuckets" class="input-error">{{ $t('commons.rule.requiredSelect') }}</span>
|
|
</el-form-item>
|
|
<el-form-item :label="$t('setting.scType')" prop="varsJson.scType" :rules="[Rules.requiredSelect]">
|
|
<el-select v-model="s3Data.rowData!.varsJson['scType']">
|
|
<el-option value="STANDARD" :label="$t('setting.scStandard')" />
|
|
<el-option value="STANDARD_IA" :label="$t('setting.scStandard_IA')" />
|
|
<el-option value="GLACIER" :label="$t('setting.scArchive')" />
|
|
<el-option value="DEEP_ARCHIVE" :label="$t('setting.scDeep_Archive')" />
|
|
</el-select>
|
|
<el-alert
|
|
v-if="s3Data.rowData!.varsJson['scType'] === 'Archive' || s3Data.rowData!.varsJson['scType'] === 'ColdArchive'"
|
|
class="mt-2.5"
|
|
:closable="false"
|
|
type="warning"
|
|
:title="$t('setting.archiveHelper')"
|
|
/>
|
|
</el-form-item>
|
|
<el-form-item :label="$t('setting.backupDir')" prop="backupPath">
|
|
<el-input clearable v-model.trim="s3Data.rowData!.backupPath" placeholder="/1panel" />
|
|
</el-form-item>
|
|
</el-form>
|
|
<template #footer>
|
|
<el-button :disabled="loading" @click="handleClose">
|
|
{{ $t('commons.button.cancel') }}
|
|
</el-button>
|
|
<el-button :disabled="loading" type="primary" @click="onSubmit(formRef)">
|
|
{{ $t('commons.button.confirm') }}
|
|
</el-button>
|
|
</template>
|
|
</DrawerPro>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { ref } from 'vue';
|
|
import { Rules } from '@/global/form-rules';
|
|
import i18n from '@/lang';
|
|
import { ElForm } from 'element-plus';
|
|
import { Backup } from '@/api/interface/backup';
|
|
import { addBackup, editBackup, listBucket } from '@/api/modules/setting';
|
|
import { deepCopy, spliceHttp, splitHttp } from '@/utils/util';
|
|
import { MsgSuccess } from '@/utils/message';
|
|
|
|
const loading = ref(false);
|
|
type FormInstance = InstanceType<typeof ElForm>;
|
|
const formRef = ref<FormInstance>();
|
|
const buckets = ref();
|
|
const errBuckets = ref();
|
|
|
|
const endpointProto = ref('http');
|
|
const emit = defineEmits(['search']);
|
|
|
|
interface DialogProps {
|
|
title: string;
|
|
rowData?: Backup.BackupInfo;
|
|
}
|
|
const title = ref<string>('');
|
|
const drawerVisible = ref(false);
|
|
const s3Data = ref<DialogProps>({
|
|
title: '',
|
|
});
|
|
const acceptParams = (params: DialogProps): void => {
|
|
buckets.value = [];
|
|
s3Data.value = params;
|
|
if (params.title === 'create' || (params.title === 'edit' && !s3Data.value.rowData.varsJson['scType'])) {
|
|
s3Data.value.rowData.varsJson['scType'] = 'STANDARD';
|
|
}
|
|
if (s3Data.value.title === 'edit') {
|
|
let httpItem = splitHttp(s3Data.value.rowData!.varsJson['endpoint']);
|
|
s3Data.value.rowData!.varsJson['endpointItem'] = httpItem.url;
|
|
endpointProto.value = httpItem.proto;
|
|
}
|
|
title.value = i18n.global.t('commons.button.' + s3Data.value.title);
|
|
drawerVisible.value = true;
|
|
};
|
|
|
|
const handleClose = () => {
|
|
emit('search');
|
|
drawerVisible.value = false;
|
|
};
|
|
|
|
const getBuckets = async (formEl: FormInstance | undefined) => {
|
|
if (!formEl) return;
|
|
formEl.validate(async (valid) => {
|
|
if (!valid) return;
|
|
loading.value = true;
|
|
let item = deepCopy(s3Data.value.rowData!.varsJson);
|
|
item['endpoint'] = spliceHttp(endpointProto.value, s3Data.value.rowData!.varsJson['endpointItem']);
|
|
listBucket({
|
|
type: s3Data.value.rowData!.type,
|
|
vars: JSON.stringify(item),
|
|
accessKey: s3Data.value.rowData!.accessKey,
|
|
credential: s3Data.value.rowData!.credential,
|
|
})
|
|
.then((res) => {
|
|
loading.value = false;
|
|
buckets.value = res.data;
|
|
})
|
|
.catch(() => {
|
|
buckets.value = [];
|
|
loading.value = false;
|
|
});
|
|
});
|
|
};
|
|
|
|
const onSubmit = async (formEl: FormInstance | undefined) => {
|
|
if (!s3Data.value.rowData.bucket) {
|
|
errBuckets.value = true;
|
|
return;
|
|
}
|
|
if (!formEl) return;
|
|
formEl.validate(async (valid) => {
|
|
if (!valid) return;
|
|
if (!s3Data.value.rowData) return;
|
|
s3Data.value.rowData!.varsJson['endpoint'] = spliceHttp(
|
|
endpointProto.value,
|
|
s3Data.value.rowData!.varsJson['endpointItem'],
|
|
);
|
|
s3Data.value.rowData.vars = JSON.stringify(s3Data.value.rowData!.varsJson);
|
|
loading.value = true;
|
|
if (s3Data.value.title === 'create') {
|
|
await addBackup(s3Data.value.rowData)
|
|
.then(() => {
|
|
loading.value = false;
|
|
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
|
emit('search');
|
|
drawerVisible.value = false;
|
|
})
|
|
.catch(() => {
|
|
loading.value = false;
|
|
});
|
|
return;
|
|
}
|
|
await editBackup(s3Data.value.rowData)
|
|
.then(() => {
|
|
loading.value = false;
|
|
MsgSuccess(i18n.global.t('commons.msg.operationSuccess'));
|
|
emit('search');
|
|
drawerVisible.value = false;
|
|
})
|
|
.catch(() => {
|
|
loading.value = false;
|
|
});
|
|
});
|
|
};
|
|
|
|
defineExpose({
|
|
acceptParams,
|
|
});
|
|
</script>
|