cert.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. <template>
  2. <el-container>
  3. <el-header class="header">
  4. <h3>证书链管理</h3>
  5. </el-header>
  6. <el-main class="main">
  7. <div class="btnbox">
  8. <el-button size="small" class="upload-demo" type="text" @click="certs">上传证书密钥</el-button>
  9. <el-button size="small" class="upload-demo" type="text" @click="reqs">生成申请书</el-button>
  10. </div>
  11. <el-table :data="sigdata" border style="width: 100%">
  12. <el-table-column label="名称" width="200">
  13. <template slot-scope="scope">
  14. <span style="margin-left: 10px">{{ scope.row.name }}</span>
  15. </template>
  16. </el-table-column>
  17. <el-table-column label="DN" width="400">
  18. <template slot-scope="scope">
  19. <span style="margin-left: 10px">{{ scope.row.dn }}</span>
  20. </template>
  21. </el-table-column>
  22. <el-table-column label="算法类型" width="200">
  23. <template slot-scope="scope">
  24. <span style="margin-left: 10px">{{ scope.row.pwatype }}</span>
  25. </template>
  26. </el-table-column>
  27. <el-table-column label="操作">
  28. <template slot-scope="scope">
  29. <div class="czbox">
  30. <el-button size="mini" type="text" @click="handleDelete(scope.row)">删除</el-button>
  31. <el-button size="mini" type="text" v-if="scope.row.state == 0" @click="reqdw(scope.row)">下载申请书</el-button>
  32. <el-upload
  33. v-if="scope.row.state == 0"
  34. class="upload-demo"
  35. action="/api/sigcacertupload"
  36. :multiple="false"
  37. :limit="1"
  38. :data="{ uuid: scope.row.uuid }"
  39. :on-success="handleSuccess"
  40. :on-error="handleError"
  41. :headers="{ Authorization: 'Bearer ' + token}"
  42. :show-file-list="false">
  43. <el-button size="small" type="text">导入证书</el-button>
  44. </el-upload>
  45. <el-button v-if="scope.row.state == 1" size="mini" type="text" @click="certdw(scope.row)">下载证书</el-button>
  46. </div>
  47. </template>
  48. </el-table-column>
  49. </el-table>
  50. </el-main>
  51. <!-- 弹窗 -->
  52. <el-dialog :title="title" :visible.sync="dialogFormVisible">
  53. <el-form :model="form" label-width="120px">
  54. <el-form-item label="证书名称">
  55. <el-input v-model="form.name" ></el-input>
  56. </el-form-item>
  57. <el-form-item v-if="type == 'cert'" label="加密密码">
  58. <el-input v-model="form.password"></el-input>
  59. </el-form-item>
  60. <el-form-item v-if="type == 'req'" label="算法类型">
  61. <el-radio v-model="form.pwatype" label="sm2">SM2</el-radio>
  62. <el-radio v-model="form.pwatype" label="rsa">RSA</el-radio>
  63. </el-form-item>
  64. <el-form-item label="DN" v-if="type == 'req'">
  65. <el-input v-model="form.dn" ></el-input>
  66. </el-form-item>
  67. <el-form-item v-if="type == 'cert'">
  68. <el-upload
  69. ref="upload"
  70. class="upload-demo"
  71. action="/api/enccertupload"
  72. :multiple="false"
  73. :limit="1"
  74. :on-success="handleSuccess"
  75. :on-error="handleError"
  76. :data="{ password: form.password, name: form.name }"
  77. :headers="{ Authorization: 'Bearer ' + token}"
  78. :file-list="fileList"
  79. :auto-upload="false">
  80. <el-button size="small" type="primary">选择证书</el-button>
  81. </el-upload>
  82. </el-form-item>
  83. </el-form>
  84. <!-- 提交按钮 -->
  85. <div slot="footer" class="dialog-footer">
  86. <el-button @click="dialogFormVisible = false">取 消</el-button>
  87. <el-button type="primary" @click="submit">提 交</el-button>
  88. </div>
  89. </el-dialog>
  90. </el-container>
  91. </template>
  92. <script>
  93. import { mapActions, mapState } from 'vuex'
  94. const token = sessionStorage.getItem('token')
  95. export default {
  96. name: 'cert',
  97. components: {},
  98. data () {
  99. return {
  100. token,
  101. dialogFormVisible: false,
  102. title: null,
  103. type: 'req',
  104. form: {
  105. pwatype: 'sm2',
  106. name: null,
  107. password: null,
  108. dn: null
  109. },
  110. fileList: []
  111. }
  112. },
  113. computed: {
  114. ...mapState(['sigdata'])
  115. },
  116. mounted () {
  117. this.query()
  118. },
  119. methods: {
  120. ...mapActions(['sigcacertquery', 'sigcertdelete', 'sigcertreq']),
  121. async query () {
  122. await this.sigcacertquery()
  123. },
  124. // 文件上传成功钩子
  125. handleSuccess () {
  126. this.$message.success('上传成功')
  127. this.query()
  128. this.$refs.upload.clearFiles()
  129. this.form = {
  130. pwatype: 'sm2',
  131. name: null,
  132. password: null,
  133. dn: null
  134. }
  135. },
  136. // 上传失败钩子
  137. handleError () {
  138. this.$message.error('上传失败')
  139. },
  140. // 删除数据
  141. async handleDelete (e) {
  142. const res = await this.sigcertdelete({ uuid: e.uuid })
  143. if (res.errcode === 0) {
  144. this.$message.success('删除成功')
  145. this.query()
  146. }
  147. },
  148. // 下载证书
  149. certdw (e) {
  150. window.open(`/api/sigcertdownload?uuid=${e.uuid}`)
  151. },
  152. // 下载申请书
  153. reqdw (e) {
  154. window.open(`/api/reqdownload?uuid=${e.uuid}`)
  155. },
  156. // 上传加密证书
  157. certs () {
  158. this.title = '上传证书密钥'
  159. this.type = 'cert'
  160. this.dialogFormVisible = true
  161. },
  162. // 生成申请书
  163. reqs () {
  164. this.title = '生成申请书'
  165. this.type = 'req'
  166. this.dialogFormVisible = true
  167. },
  168. // 表单提交
  169. async submit () {
  170. if (this.type === 'cert') {
  171. // 上传p12
  172. if (this.form.password == null) {
  173. this.$message.error('请填写密码')
  174. return false
  175. }
  176. if (this.form.name == null) {
  177. this.$message.error('请填写名称')
  178. return false
  179. }
  180. if (this.$refs.upload.uploadFiles >= 0) {
  181. this.$message.error('请选择证书')
  182. return false
  183. }
  184. this.$refs.upload.submit()
  185. } else {
  186. // 生成申请书
  187. if (this.form.pwatype == null) {
  188. this.$message.error('请选择算法类型')
  189. return false
  190. }
  191. if (this.form.name == null) {
  192. this.$$message.error('请填写名称')
  193. return false
  194. }
  195. if (this.form.dn == null) {
  196. this.$message.error('请填写DN')
  197. return false
  198. }
  199. const res = await this.sigcertreq(this.form)
  200. if (res.errcode === 0) {
  201. this.$message.success('生成成功')
  202. this.query()
  203. this.form = {
  204. pwatype: 'sm2',
  205. name: null,
  206. password: null,
  207. dn: null
  208. }
  209. this.dialogFormVisible = false
  210. }
  211. }
  212. }
  213. }
  214. }
  215. </script>
  216. <style lang="less" scoped>
  217. h3 {
  218. width: 90%;
  219. text-align: left;
  220. text-indent: 1em;
  221. line-height: 3em;
  222. border-bottom: 2px solid #999;
  223. }
  224. .main {
  225. width: 90%;
  226. margin: 0 auto;
  227. .btnbox {
  228. width: 100%;
  229. overflow: hidden;
  230. margin: 3% auto;
  231. .upload-demo {
  232. float: right;
  233. margin-left: 1%;
  234. }
  235. }
  236. /deep/ .czbox {
  237. display: flex;
  238. .el-button {
  239. margin-left: 8px;
  240. }
  241. }
  242. }
  243. </style>