IdpSamlXml.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <div class="idp-saml-xml-dialog">
  3. <div>
  4. <code-mirror v-model="metadata" :options="cmOptions" />
  5. </div>
  6. <div class="text-right mt-2">
  7. <a-button type="primary" :loading="loading" @click="downloadXml">{{$t('common_502')}}</a-button>
  8. </div>
  9. </div>
  10. </template>
  11. <script>
  12. import 'codemirror/theme/monokai.css'
  13. import 'codemirror/mode/xml/xml.js'
  14. import 'codemirror/mode/htmlmixed/htmlmixed.js'
  15. import vkbeautify from '@/utils/vkbeautify'
  16. export default {
  17. name: 'IdpSamlXml',
  18. props: {
  19. data: {
  20. type: Object,
  21. required: true,
  22. },
  23. },
  24. data () {
  25. return {
  26. loading: false,
  27. metadata: '',
  28. cmOptions: {
  29. tabSize: 2,
  30. indentUnit: 4,
  31. htmlMode: true,
  32. smartIndent: true,
  33. matchClosing: true,
  34. alignCDATA: true,
  35. lineWrapping: true,
  36. lineNumbers: true,
  37. readOnly: true,
  38. mode: 'application/xml',
  39. theme: 'monokai',
  40. },
  41. }
  42. },
  43. created () {
  44. this.authManager = new this.$Manager('auth/idp', 'v1')
  45. this.queryMetadata()
  46. },
  47. methods: {
  48. async queryMetadata () {
  49. this.loading = true
  50. try {
  51. const { data } = await this.authManager.getSpecific({
  52. id: this.data.id,
  53. spec: 'saml-metadata',
  54. })
  55. this.metadata = vkbeautify.xml(data.metadata)
  56. } catch (err) {
  57. throw err
  58. } finally {
  59. this.loading = false
  60. }
  61. },
  62. downloadXml () {
  63. const eleLink = document.createElement('a')
  64. eleLink.download = `${this.data.name}.xml`
  65. const blob = new Blob([this.metadata])
  66. eleLink.href = URL.createObjectURL(blob)
  67. document.body.appendChild(eleLink)
  68. eleLink.click()
  69. },
  70. },
  71. }
  72. </script>
  73. <style scoped lang="less">
  74. .idp-saml-xml-dialog {
  75. ::v-deep {
  76. .ant-modal-body{
  77. padding: 0;
  78. }
  79. .CodeMirror{
  80. height: 500px;
  81. }
  82. // .CodeMirror-gutter{
  83. // width: 0 !important;
  84. // }
  85. }
  86. }
  87. </style>