feat:存储配置添加测试连接功能

This commit is contained in:
czhqwer
2025-03-27 23:59:04 +08:00
parent a867376581
commit 7f121a0d6d
11 changed files with 190 additions and 44 deletions
@@ -27,15 +27,18 @@
<input v-model="config.bucket" type="text" placeholder="请输入Bucket" />
</div>
<div class="form-actions">
<button type="button" @click="saveConfig">保存</button>
<button type="button" @click="close">取消</button>
<button type="button" @click="testConfig" :disabled="testing">
{{ testing ? '测试中...' : '测试连接' }}
</button>
<button type="button" @click="saveConfig" :disabled="testing">保存</button>
<button type="button" @click="close" :disabled="testing">取消</button>
</div>
</div>
</div>
</template>
<script>
import { getStorageConfig, setStorageConfig } from '@/utils/api';
import { getStorageConfig, setStorageConfig, testStorageConfig } from '@/utils/api';
export default {
name: 'StorageConfigModal',
@@ -51,7 +54,8 @@ export default {
accessKey: '',
secretKey: '',
bucket: ''
}
},
testing: false
};
},
methods: {
@@ -81,6 +85,22 @@ export default {
this.$message.error('保存存储配置失败');
}
},
async testConfig() {
this.testing = true;
try {
const response = await testStorageConfig(this.config);
if (response.code === 200) {
this.$message.success('存储配置测试成功!');
} else {
this.$message.error(`${response.msg || '未知错误'}`);
}
} catch (error) {
console.error('存储配置测试失败:', error);
this.$message.error(`${error.message || '服务器错误'}`);
} finally {
this.testing = false;
}
},
close() {
this.$emit('close');
},
@@ -162,6 +182,11 @@ export default {
}
.form-actions button:first-child {
background: #ff9800;
color: white;
}
.form-actions button:nth-child(2) {
background: #1976d2;
color: white;
}
@@ -171,4 +196,9 @@ export default {
color: #1976d2;
border: 1px solid #d0e4fc;
}
.form-actions button:disabled {
background: #cccccc;
cursor: not-allowed;
}
</style>
+21
View File
@@ -160,6 +160,26 @@ const setStorageConfig = ({ id, type, endpoint, accessKey, secretKey, bucket })
});
}
/**
* 测试存储配置
* @param {Object} params 参数对象
* @param {string} params.type 类型
* @param {string} params.endpoint endpoint
* @param {string} params.accessKey accessKey
* @param {string} params.secretKey secretKey
* @param {string} params.bucket bucket
* @returns
*/
const testStorageConfig = ({ type, endpoint, accessKey, secretKey, bucket }) => {
return http.post('/config/test', {
type,
endpoint,
accessKey,
secretKey,
bucket
});
}
export {
getUploadProgress,
createMultipartUpload,
@@ -170,5 +190,6 @@ export {
pageFiles,
getStorageConfig,
setStorageConfig,
testStorageConfig,
httpExtra
};