infoMsgContent.vue 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <template>
  2. <div>
  3. <el-table :data="list" :header-cell-style="{background: '#f5f7fa'}" max-height="250">
  4. <el-table-column
  5. prop="name"
  6. label="字段名"
  7. >
  8. <template slot-scope="scope">
  9. <div>{{nameFormat[scope.row.name] || scope.row.name}}</div>
  10. </template>
  11. </el-table-column>
  12. <el-table-column
  13. prop="before"
  14. label="修改前"
  15. >
  16. <template slot-scope="scope">
  17. <div v-if="diff.hasOwnProperty(scope.row.name)">
  18. <el-tag type="danger" v-if="scope.row.before"><s>{{scope.row.before}}</s></el-tag>
  19. </div>
  20. <div v-else>{{scope.row.before}}</div>
  21. </template>
  22. </el-table-column>
  23. <el-table-column
  24. prop="after"
  25. label="修改后"
  26. >
  27. <template slot-scope="scope">
  28. <div v-if="diff.hasOwnProperty(scope.row.name)">
  29. <el-tag type="success" v-if="scope.row.after">{{scope.row.after}}</el-tag>
  30. </div>
  31. <div v-else>{{scope.row.after}}</div>
  32. </template>
  33. </el-table-column>
  34. </el-table>
  35. </div>
  36. </template>
  37. <script>
  38. const nameFormat = {
  39. name: '课程名称',
  40. actualTeacherName: '主教老师',
  41. teachingTeacherNames: '助教老师',
  42. startClassTime: '上课时间',
  43. teachMode: '课程类型',
  44. schoolName: '教学地点',
  45. timers: '课程时长'
  46. }
  47. import ObjectDiff from 'object-diff'
  48. export default {
  49. props: ['before', 'after'],
  50. computed: {
  51. diff() {
  52. return ObjectDiff(this.before, this.after)
  53. },
  54. list() {
  55. const keys = Object.keys(this.before)
  56. const items = []
  57. for (let i = 0; i < keys.length; i++) {
  58. const key = keys[i]
  59. const nextKey = keys[i + 1]
  60. items.push({
  61. name: key,
  62. before: this.before[key],
  63. after: this.before[key],
  64. })
  65. }
  66. return items
  67. }
  68. },
  69. data() {
  70. return {
  71. nameFormat
  72. }
  73. },
  74. mounted() {
  75. console.log(this.diff, this.list)
  76. }
  77. }
  78. </script>
  79. <style lang="less" scoped>
  80. </style>