convertByAes.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. <template>
  2. <el-dialog
  3. :visible.sync="dialogVisible"
  4. :close-on-click-modal="false"
  5. :close-on-press-escape="false"
  6. :show-close="true"
  7. append-to-body
  8. fullscreen
  9. class="dialog tools-dialog"
  10. top="5vh"
  11. @close="closeDialog"
  12. >
  13. <div class="tools-container">
  14. <div class="title">AES加解密</div>
  15. <div class="card">
  16. <div class="item">
  17. <div class="label">明文</div>
  18. <div class="value">
  19. <el-input
  20. v-model="plaintext"
  21. type="textarea"
  22. :rows="10"
  23. placeholder="请输入明文"
  24. />
  25. </div>
  26. </div>
  27. <div class="operate-btn">
  28. <el-button
  29. type="primary"
  30. size="small"
  31. icon="ibps-icon-level-down"
  32. @click="handleEncrypt"
  33. >加密</el-button>
  34. <el-button
  35. type="warning"
  36. size="small"
  37. icon="ibps-icon-level-up"
  38. @click="handleDecrypt"
  39. >解密</el-button>
  40. <el-button
  41. type="info"
  42. size="small"
  43. icon="ibps-icon-copy"
  44. @click="handleCopy"
  45. >复制明文</el-button>
  46. </div>
  47. <div class="item">
  48. <div class="label">密文</div>
  49. <div class="value">
  50. <el-input
  51. v-model="ciphertext"
  52. type="textarea"
  53. :rows="10"
  54. placeholder="请输入密文"
  55. />
  56. </div>
  57. </div>
  58. <!-- <div class="item">
  59. <div class="label">ivBase64</div>
  60. <div class="value">
  61. <el-input
  62. v-model="ivBase64"
  63. type="textarea"
  64. :rows="1"
  65. placeholder="请输入ivBase64"
  66. />
  67. </div>
  68. </div> -->
  69. </div>
  70. </div>
  71. </el-dialog>
  72. </template>
  73. <script>
  74. export default {
  75. props: {
  76. visible: {
  77. type: Boolean,
  78. default: false
  79. }
  80. },
  81. data () {
  82. return {
  83. dialogVisible: this.visible,
  84. plaintext: '',
  85. ivBase64: '',
  86. ciphertext: ''
  87. }
  88. },
  89. watch: {
  90. visible: {
  91. handler (val, oldVal) {
  92. this.dialogVisible = this.visible
  93. }
  94. }
  95. },
  96. methods: {
  97. handleActionEvent (key, type, index) {
  98. switch (key) {
  99. case 'cancel':
  100. this.handleCancel()
  101. break
  102. default:
  103. break
  104. }
  105. },
  106. handleEncrypt () {
  107. if (!this.plaintext) {
  108. return this.$message.warning('明文为空!')
  109. }
  110. this.ciphertext = this.$common.encryptByAes(this.plaintext)
  111. },
  112. handleDecrypt () {
  113. if (!this.ciphertext || typeof this.ciphertext !== 'string') {
  114. return this.$message.warning('无效的密文输入!')
  115. }
  116. // if (!this.ivBase64) {
  117. // return this.$message.warning('请输入ivBase64!')
  118. // }
  119. const temp = this.$common.decryptByAes(this.ciphertext)
  120. if (this.$utils.isEmpty(temp)) {
  121. return this.$message.error('密文无效,无法解密!')
  122. }
  123. this.plaintext = temp
  124. },
  125. handleCopy () {
  126. const text = this.plaintext
  127. if (navigator.clipboard) {
  128. navigator.clipboard.writeText(text).then(() => {
  129. this.$message.success('明文已复制到剪贴板!')
  130. }).catch(() => this.fallbackCopy(text))
  131. } else {
  132. this.fallbackCopy(text)
  133. }
  134. },
  135. fallbackCopy (text) {
  136. const textarea = document.createElement('textarea')
  137. textarea.value = text
  138. textarea.style.position = 'fixed'
  139. document.body.appendChild(textarea)
  140. textarea.select()
  141. try {
  142. document.execCommand('copy')
  143. this.$message.success('明文已复制到剪贴板!')
  144. } catch (err) {
  145. this.$message.warning('复制失败,请手动选择内容复制!')
  146. } finally {
  147. document.body.removeChild(textarea)
  148. }
  149. },
  150. closeDialog () {
  151. this.$emit('close', false)
  152. }
  153. }
  154. }
  155. </script>
  156. <style lang="scss" scoped>
  157. .tools-container {
  158. width: 1080px;
  159. margin: 20px auto;
  160. height: calc(100% - 100px);
  161. padding: 20px;
  162. border: 1px solid #ccc;
  163. border-radius: 10px;
  164. background-color: #f9f9f9;
  165. box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
  166. transition: transform 0.2s;
  167. .title {
  168. font-size: 24px;
  169. font-weight: bold;
  170. margin-bottom: 20px;
  171. text-align: center;
  172. }
  173. .card {
  174. display: flex;
  175. flex-wrap: wrap;
  176. justify-content: space-between;
  177. .item {
  178. width: 100%;
  179. margin-bottom: 20px;
  180. padding: 15px;
  181. // border: 1px solid #ccc;
  182. // border-radius: 5px;
  183. // background-color: #fff;
  184. // transition: transform 0.2s;
  185. // &:hover {
  186. // transform: scale(1.01);
  187. // }
  188. .label {
  189. font-size: 16px;
  190. font-weight: bold;
  191. margin-bottom: 10px;
  192. }
  193. .value {
  194. font-size: 16px;
  195. color: #666;
  196. }
  197. }
  198. .operate-btn {
  199. margin: 0 auto;
  200. }
  201. }
  202. }
  203. </style>