feat:证书管理新增 基本功能

This commit is contained in:
jackhoo_98 2023-01-10 18:22:30 +08:00
parent bfc98e013b
commit c448f50bf2
4 changed files with 145 additions and 140 deletions

View File

@ -0,0 +1,3 @@
import server from '@/utils/request'
export const save = (data) => server.post(`/network/certificate`, data)

View File

@ -3,3 +3,5 @@ export const BASE_API_PATH = import.meta.env.VITE_APP_BASE_API
export const TOKEN_KEY = 'X-Access-Token' export const TOKEN_KEY = 'X-Access-Token'
export const Version_Code = 'version_code' export const Version_Code = 'version_code'
export const NETWORK_CERTIFICATE_UPLOAD = '/network/certificate/upload'

View File

@ -4,85 +4,88 @@
<a-textarea <a-textarea
:rows="4" :rows="4"
@change="textChange" @change="textChange"
v-model="keystoreBase64" v-model:value="keystoreBase64"
:placeholder=placeholder :placeholder="placeholder"
/> />
<a-upload <a-upload
accept=".pem" accept=".pem"
listType="text" listType="text"
:action="action" :action="`${BASE_API_PATH}${NETWORK_CERTIFICATE_UPLOAD}`"
:headers="headers" :headers="{
[TOKEN_KEY]: LocalStore.get(TOKEN_KEY),
}"
:showUploadList="false" :showUploadList="false"
@change="handleChange" @change="handleChange"
> >
<a-button style="margin-top: 10px"> <a-button style="margin-top: 10px">
<upload-outlined></upload-outlined> <upload-outlined />
上传文件</a-button
上传文件</a-button> >
</a-upload> </a-upload>
</div> </div>
</a-spin> </a-spin>
</template> </template>
<script> <script setup lang="ts" name="CertificateFile">
// import storage from 'store'
// import { ACCESS_TOKEN } from '@/store/mutation-types'
// import { ACCESS_TOKEN_KEY } from '@/utils/consts'
import { UploadOutlined } from '@ant-design/icons-vue'; import { UploadOutlined } from '@ant-design/icons-vue';
import { message } from 'ant-design-vue';
import type { UploadChangeParam } from 'ant-design-vue';
import { LocalStore } from '@/utils/comm';
import {
BASE_API_PATH,
TOKEN_KEY,
NETWORK_CERTIFICATE_UPLOAD,
} from '@/utils/variable';
import type { UploadProps } from 'ant-design-vue';
export default { const emit = defineEmits(['update:modelValue', 'change']);
name: 'CertificateFile',
data () { const props = defineProps({
return { name: {
keystoreBase64: '',
loading: false,
action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
headers:{
authorization: 'authorization-text',
}
// action: process.env.VUE_APP_BASE_API + `/network/certificate/upload`,
// headers: {
// [ACCESS_TOKEN_KEY]: storage.get(ACCESS_TOKEN)
// }
}
},
model: {
prop: 'value',
event: 'change'
},
props: {
value: {
type: String, type: String,
default: () => '' default: () => '',
},
modelValue: {
type: String,
default: () => '',
}, },
placeholder: { placeholder: {
type: String, type: String,
default: () => '' default: () => '',
}
}, },
watch: { });
value: {
handler (v) { const keystoreBase64 = ref(props.modelValue);
this.keystoreBase64 = v const loading = ref(false);
}
} const handleChange = (info: UploadChangeParam) => {
}, loading.value = true;
methods: {
handleChange (info) {
this.loading = true
if (info.file.status === 'done') { if (info.file.status === 'done') {
this.$message.success('上传成功!') message.success('上传成功!');
const result = info.file.response?.result const result = info.file.response?.result;
this.loading = false keystoreBase64.value = result;
this.$emit('change', result) console.log(1114, result);
loading.value = false;
emit('change', result);
emit('update:modelValue', result);
} }
};
const textChange = (val: any) => {
val.name = props.name;
emit('change', val);
// emit('update:modelValue', val);
};
watch(
() => props.modelValue,
(v) => {
keystoreBase64.value = v;
}, },
textChange (val) { {
this.$emit('change', val) deep: true,
} immediate: true,
} },
} );
</script> </script>
<style lang="less" scoped> <style lang="less" scoped></style>
</style>

View File

@ -11,18 +11,9 @@
:wrapper-col="{ span: 16 }" :wrapper-col="{ span: 16 }"
autocomplete="off" autocomplete="off"
@finish="onFinish" @finish="onFinish"
@finishFailed="onFinishFailed" :rules="formRules"
>
<a-form-item
label="证书标准"
name="type"
:rules="[
{
required: true,
message: '请选择证书标准',
},
]"
> >
<a-form-item label="证书标准" name="type">
<a-radio-group v-model:value="formData.type"> <a-radio-group v-model:value="formData.type">
<a-radio-button <a-radio-button
class="form-radio-button" class="form-radio-button"
@ -33,46 +24,25 @@
</a-radio-group> </a-radio-group>
</a-form-item> </a-form-item>
<a-form-item <a-form-item label="证书名称" name="name">
label="证书名称"
name="name"
:rules="[
{
required: true,
message: '请输入证书名称',
},
]"
>
<a-input <a-input
placeholder="请输入证书名称" placeholder="请输入证书名称"
v-model:value="formData.name" v-model:value="formData.name"
/> />
</a-form-item> </a-form-item>
<a-form-item <a-form-item label="证书文件" name="cert">
label="证书文件"
name="cert"
:rules="[
{
required: true,
message: '上传证书文件',
},
]"
>
<CertificateFile <CertificateFile
name="cert"
v-model:modelValue="formData.cert"
@change="changeFileValue"
placeholder='证书格式以"-----BEGIN CERTIFICATE-----"开头,以"-----END CERTIFICATE-----"结尾"' placeholder='证书格式以"-----BEGIN CERTIFICATE-----"开头,以"-----END CERTIFICATE-----"结尾"'
/> />
</a-form-item> </a-form-item>
<a-form-item <a-form-item label="证书私钥" name="key">
label="证书私钥"
name="key"
:rules="[
{
required: true,
message: '请上传证书私钥',
},
]"
>
<CertificateFile <CertificateFile
name="key"
v-model:modelValue="formData.key"
@change="changeFileValue"
placeholder='证书私钥格式以"-----BEGIN (RSA|EC) PRIVATE KEY-----"开头,以"-----END(RSA|EC) PRIVATE KEY-----"结尾。' placeholder='证书私钥格式以"-----BEGIN (RSA|EC) PRIVATE KEY-----"开头,以"-----END(RSA|EC) PRIVATE KEY-----"结尾。'
/> />
</a-form-item> </a-form-item>
@ -117,46 +87,73 @@
</a-row> </a-row>
</a-card> </a-card>
</template> </template>
<!-- export const ACCESS_TOKEN_KEY = 'X-Access-Token' -->
<!-- export const ACCESS_TOKEN = 'device_token' -->
<script lang="ts" setup name="CertificateDetail"> <script lang="ts" setup name="CertificateDetail">
import { message } from 'ant-design-vue'; import { message } from 'ant-design-vue';
import { getImage } from '@/utils/comm'; import { getImage } from '@/utils/comm';
import CertificateFile from './CertificateFile.vue'; import CertificateFile from './CertificateFile.vue';
import type { UploadChangeParam } from 'ant-design-vue';
import { LocalStore } from '@/utils/comm';
import {
BASE_API_PATH,
TOKEN_KEY,
NETWORK_CERTIFICATE_UPLOAD,
} from '@/utils/variable';
import { save } from '@/api/link/certificate';
const loading = ref(false);
const formData = reactive({ const formData = reactive({
type: 'common', type: 'common',
name: '', name: '',
configs: {
cert: '', cert: '',
key: '', key: '',
}, // configs: {
// cert: '',
// key: '',
// },
description: '', description: '',
}); });
const onFinish = (values: any) => { const formRules = {
console.log('Success:', values); type: [{ required: true, message: '请选择证书标准', trigger: 'blur' }],
}; name: [
const onFinishFailed = (errorInfo: any) => { { required: true, message: '请输入证书名称', trigger: 'blur' },
console.log('Failed:', errorInfo); { max: 64, message: '最多可输入64个字符' },
],
cert: [{ required: true, message: '请输入或上传文件', trigger: 'blur' }],
key: [{ required: true, message: '请输入或上传文件', trigger: 'blur' }],
description: [{ max: 200, message: '最多可输入200个字符' }],
}; };
const headers = { const onFinish = async (values: any) => {
authorization: 'authorization-text', values.configs = {
cert: formData.cert,
key: formData.key,
}; };
delete values.cert;
delete values.key;
const handleChange = (info: any) => { const response = await save(values)
if (info.file.status !== 'uploading') { if (response.status === 200) {
console.log(info.file, info.fileList); message.success('操作成功')
} }
};
const changeFileValue = (v: any) => {
formData[v.name] = v.data;
};
const handleChange = (info: UploadChangeParam) => {
loading.value = true;
if (info.file.status === 'done') { if (info.file.status === 'done') {
message.success(`${info.file.name} file uploaded successfully`); message.success('上传成功!');
} else if (info.file.status === 'error') { const result = info.file.response?.result;
message.error(`${info.file.name} file upload failed.`); formData.cert = result;
loading.value = false;
} }
}; };
const fileList = ref([]);
</script> </script>
<style lang="less" scoped> <style lang="less" scoped>