123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- <template>
- <el-container>
- <el-header class="header">
- <h3>证书链管理</h3>
- </el-header>
- <el-main class="main">
- <div class="btnbox">
- <el-button size="small" class="upload-demo" type="text" @click="certs">上传证书密钥</el-button>
- <el-button size="small" class="upload-demo" type="text" @click="reqs">生成申请书</el-button>
- </div>
- <el-table :data="sigdata" border style="width: 100%">
- <el-table-column label="名称" width="200">
- <template slot-scope="scope">
- <span style="margin-left: 10px">{{ scope.row.name }}</span>
- </template>
- </el-table-column>
- <el-table-column label="DN" width="400">
- <template slot-scope="scope">
- <span style="margin-left: 10px">{{ scope.row.dn }}</span>
- </template>
- </el-table-column>
- <el-table-column label="算法类型" width="200">
- <template slot-scope="scope">
- <span style="margin-left: 10px">{{ scope.row.pwatype }}</span>
- </template>
- </el-table-column>
- <el-table-column label="操作">
- <template slot-scope="scope">
- <div class="czbox">
- <el-button size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
- <el-button size="mini" type="text" v-if="scope.row.state == 0" @click="reqdw(scope.row)">下载申请书</el-button>
- <el-upload
- v-if="scope.row.state == 0"
- class="upload-demo"
- action="/api/sigcacertupload"
- :multiple="false"
- :limit="1"
- :data="{ uuid: scope.row.uuid }"
- :on-success="handleSuccess"
- :on-error="handleError"
- :headers="{ Authorization: 'Bearer ' + token}"
- :show-file-list="false">
- <el-button size="small" type="text">导入证书</el-button>
- </el-upload>
- <el-button v-if="scope.row.state == 1" size="mini" type="text" @click="certdw(scope.row)">下载证书</el-button>
- </div>
- </template>
- </el-table-column>
- </el-table>
- </el-main>
- <!-- 弹窗 -->
- <el-dialog :title="title" :visible.sync="dialogFormVisible">
- <el-form :model="form" label-width="120px">
- <el-form-item label="证书名称">
- <el-input v-model="form.name" ></el-input>
- </el-form-item>
- <el-form-item v-if="type == 'cert'" label="加密密码">
- <el-input v-model="form.password"></el-input>
- </el-form-item>
- <el-form-item v-if="type == 'req'" label="算法类型">
- <el-radio v-model="form.pwatype" label="sm2">SM2</el-radio>
- <el-radio v-model="form.pwatype" label="rsa">RSA</el-radio>
- </el-form-item>
- <el-form-item label="DN" v-if="type == 'req'">
- <el-input v-model="form.dn" ></el-input>
- </el-form-item>
- <el-form-item v-if="type == 'cert'">
- <el-upload
- ref="upload"
- class="upload-demo"
- action="/api/enccertupload"
- :multiple="false"
- :limit="1"
- :on-success="handleSuccess"
- :on-error="handleError"
- :data="{ password: form.password, name: form.name }"
- :headers="{ Authorization: 'Bearer ' + token}"
- :file-list="fileList"
- :auto-upload="false">
- <el-button size="small" type="primary">选择证书</el-button>
- </el-upload>
- </el-form-item>
- </el-form>
- <!-- 提交按钮 -->
- <div slot="footer" class="dialog-footer">
- <el-button @click="dialogFormVisible = false">取 消</el-button>
- <el-button type="primary" @click="submit">提 交</el-button>
- </div>
- </el-dialog>
- </el-container>
- </template>
- <script>
- import { mapActions, mapState } from 'vuex'
- const token = sessionStorage.getItem('token')
- export default {
- name: 'cert',
- components: {},
- data () {
- return {
- token,
- dialogFormVisible: false,
- title: null,
- type: 'req',
- form: {
- pwatype: 'sm2',
- name: null,
- password: null,
- dn: null
- },
- fileList: []
- }
- },
- computed: {
- ...mapState(['sigdata'])
- },
- mounted () {
- this.query()
- },
- methods: {
- ...mapActions(['sigcacertquery', 'sigcertdelete', 'sigcertreq']),
- async query () {
- await this.sigcacertquery()
- },
- // 文件上传成功钩子
- handleSuccess () {
- this.$message.success('上传成功')
- this.query()
- this.$refs.upload.clearFiles()
- this.form = {
- pwatype: 'sm2',
- name: null,
- password: null,
- dn: null
- }
- },
- // 上传失败钩子
- handleError () {
- this.$message.error('上传失败')
- },
- // 删除数据
- async handleDelete (e) {
- const res = await this.sigcertdelete({ uuid: e.uuid })
- if (res.errcode === 0) {
- this.$message.success('删除成功')
- this.query()
- }
- },
- // 下载证书
- certdw (e) {
- window.open(`/api/sigcertdownload?uuid=${e.uuid}`)
- },
- // 下载申请书
- reqdw (e) {
- window.open(`/api/reqdownload?uuid=${e.uuid}`)
- },
- // 上传加密证书
- certs () {
- this.title = '上传证书密钥'
- this.type = 'cert'
- this.dialogFormVisible = true
- },
- // 生成申请书
- reqs () {
- this.title = '生成申请书'
- this.type = 'req'
- this.dialogFormVisible = true
- },
- // 表单提交
- async submit () {
- if (this.type === 'cert') {
- // 上传p12
- if (this.form.password == null) {
- this.$message.error('请填写密码')
- return false
- }
- if (this.form.name == null) {
- this.$message.error('请填写名称')
- return false
- }
- if (this.$refs.upload.uploadFiles >= 0) {
- this.$message.error('请选择证书')
- return false
- }
- this.$refs.upload.submit()
- } else {
- // 生成申请书
- if (this.form.pwatype == null) {
- this.$message.error('请选择算法类型')
- return false
- }
- if (this.form.name == null) {
- this.$$message.error('请填写名称')
- return false
- }
- if (this.form.dn == null) {
- this.$message.error('请填写DN')
- return false
- }
- const res = await this.sigcertreq(this.form)
- if (res.errcode === 0) {
- this.$message.success('生成成功')
- this.query()
- this.form = {
- pwatype: 'sm2',
- name: null,
- password: null,
- dn: null
- }
- this.dialogFormVisible = false
- }
- }
- }
- }
- }
- </script>
- <style lang="less" scoped>
- h3 {
- width: 90%;
- text-align: left;
- text-indent: 1em;
- line-height: 3em;
- border-bottom: 2px solid #999;
- }
- .main {
- width: 90%;
- margin: 0 auto;
- .btnbox {
- width: 100%;
- overflow: hidden;
- margin: 3% auto;
- .upload-demo {
- float: right;
- margin-left: 1%;
- }
- }
- /deep/ .czbox {
- display: flex;
- .el-button {
- margin-left: 8px;
- }
- }
- }
- </style>
|