commit
aa6b6e7788
|
@ -0,0 +1,3 @@
|
||||||
|
import server from '@/utils/request'
|
||||||
|
|
||||||
|
export const save = (data) => server.post(`/network/certificate`, data)
|
|
@ -2,4 +2,6 @@ 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'
|
|
@ -1,88 +1,91 @@
|
||||||
<template>
|
<template>
|
||||||
<a-spin :spinning="loading">
|
<a-spin :spinning="loading">
|
||||||
<div>
|
<div>
|
||||||
<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="{
|
||||||
:showUploadList="false"
|
[TOKEN_KEY]: LocalStore.get(TOKEN_KEY),
|
||||||
@change="handleChange"
|
}"
|
||||||
>
|
:showUploadList="false"
|
||||||
<a-button style="margin-top: 10px">
|
@change="handleChange"
|
||||||
<upload-outlined></upload-outlined>
|
>
|
||||||
|
<a-button style="margin-top: 10px">
|
||||||
上传文件</a-button>
|
<upload-outlined />
|
||||||
</a-upload>
|
上传文件</a-button
|
||||||
</div>
|
>
|
||||||
</a-spin>
|
</a-upload>
|
||||||
|
</div>
|
||||||
|
</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: '',
|
type: String,
|
||||||
loading: false,
|
default: () => '',
|
||||||
action: 'https://www.mocky.io/v2/5cc8019d300000980a055e76',
|
},
|
||||||
headers:{
|
modelValue: {
|
||||||
authorization: 'authorization-text',
|
type: String,
|
||||||
}
|
default: () => '',
|
||||||
// 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,
|
|
||||||
default: () => ''
|
|
||||||
},
|
},
|
||||||
placeholder: {
|
placeholder: {
|
||||||
type: String,
|
type: String,
|
||||||
default: () => ''
|
default: () => '',
|
||||||
}
|
|
||||||
},
|
|
||||||
watch: {
|
|
||||||
value: {
|
|
||||||
handler (v) {
|
|
||||||
this.keystoreBase64 = v
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
handleChange (info) {
|
|
||||||
this.loading = true
|
|
||||||
if (info.file.status === 'done') {
|
|
||||||
this.$message.success('上传成功!')
|
|
||||||
const result = info.file.response?.result
|
|
||||||
this.loading = false
|
|
||||||
this.$emit('change', result)
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
textChange (val) {
|
});
|
||||||
this.$emit('change', val)
|
|
||||||
|
const keystoreBase64 = ref(props.modelValue);
|
||||||
|
const loading = ref(false);
|
||||||
|
|
||||||
|
const handleChange = (info: UploadChangeParam) => {
|
||||||
|
loading.value = true;
|
||||||
|
if (info.file.status === 'done') {
|
||||||
|
message.success('上传成功!');
|
||||||
|
const result = info.file.response?.result;
|
||||||
|
keystoreBase64.value = 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;
|
||||||
|
},
|
||||||
|
{
|
||||||
|
deep: true,
|
||||||
|
immediate: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less" scoped>
|
<style lang="less" scoped></style>
|
||||||
</style>
|
|
||||||
|
|
|
@ -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
|
<a-form-item label="证书标准" name="type">
|
||||||
label="证书标准"
|
|
||||||
name="type"
|
|
||||||
:rules="[
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '请选择证书标准',
|
|
||||||
},
|
|
||||||
]"
|
|
||||||
>
|
|
||||||
<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 response = await save(values)
|
||||||
|
if (response.status === 200) {
|
||||||
|
message.success('操作成功')
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (info: any) => {
|
const changeFileValue = (v: any) => {
|
||||||
if (info.file.status !== 'uploading') {
|
formData[v.name] = v.data;
|
||||||
console.log(info.file, info.fileList);
|
};
|
||||||
}
|
|
||||||
|
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>
|
||||||
|
|
|
@ -18,8 +18,9 @@
|
||||||
"paths": {
|
"paths": {
|
||||||
"@/*": ["./src/*"]
|
"@/*": ["./src/*"]
|
||||||
},
|
},
|
||||||
"types": ["ant-design-vue/typings/global"]
|
"types": ["ant-design-vue/typings/global"],
|
||||||
|
"suppressImplicitAnyIndexErrors": true
|
||||||
},
|
},
|
||||||
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
|
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
|
||||||
"references": [{ "path": "./tsconfig.node.json" }]
|
"references": [{ "path": "./tsconfig.node.json" }],
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue