CodeDifferencePlate.vue 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. <template>
  2. <div class="container">
  3. <ElCollapse v-model="activeNames" v-for="item in data" :key="item.newPath">
  4. <ElCollapseItem name="item.newPath">
  5. <template v-slot:title><i class="el-icon-s-order"/>{{item.newPath}}</template>
  6. <!-- <el-input type="textarea" :autosize="{maxRows: 25}" v-model="item.diff" readonly></el-input> -->
  7. <table class="code-area" cellspacing="0" v-for="msg in item.diff.split('\n')" :key="item.diff.indexOf(msg)">
  8. <tr class="normal-line" v-if="getLineType(msg) === 0">{{msg}}</tr>
  9. <tr class="delete-line" v-if="getLineType(msg) === 1">{{msg}}</tr>
  10. <tr class="insert-line" v-if="getLineType(msg) === 2">{{msg}}</tr>
  11. </table>
  12. </ElCollapseItem>
  13. </ElCollapse>
  14. </div>
  15. </template>
  16. <script lang="ts">
  17. import { defineComponent, PropType } from 'vue';
  18. interface DifferenceMsg {
  19. a_mode: string;
  20. b_mode: string;
  21. deleteFile: boolean;
  22. diff: string;
  23. newFile: boolean;
  24. newPath: string;
  25. oldPath: string;
  26. renamedFile: boolean;
  27. }
  28. export default defineComponent({
  29. name: 'CodeDifferencePlate',
  30. props: {
  31. data: Array as PropType<DifferenceMsg[]>,
  32. },
  33. setup() {
  34. const getLineType = (msg: string) => {
  35. if (msg.startsWith('+++') || msg.startsWith('---')) return 3;
  36. if (msg.startsWith('+')) return 2;
  37. if (msg.startsWith('-')) return 1;
  38. if (msg.startsWith('\\') || msg.startsWith('@')) return 3;
  39. if (msg.length === 0) return 3;
  40. return 0;
  41. };
  42. const activeNames: string[] = [];
  43. return {
  44. activeNames,
  45. getLineType,
  46. };
  47. },
  48. });
  49. </script>
  50. <style lang="scss" scoped>
  51. ::v-deep {
  52. .el-collapse {
  53. .el-collapse-item__header {
  54. font-size: 17px;
  55. font-weight: 500;
  56. }
  57. }
  58. }
  59. .el-icon-s-order {
  60. margin-right: 5px;
  61. color: gray;
  62. }
  63. .code-area {
  64. font-family: "Lucida Console";
  65. width: 100%;
  66. margin-top: 0px;
  67. margin-bottom: 0px;
  68. .tr {
  69. height: 100%;
  70. }
  71. }
  72. .delete-line {
  73. background-color: #fbe9eb;
  74. }
  75. .insert-line {
  76. background-color: #ecfdf0;
  77. }
  78. </style>