liukangdong
2024-09-29 b2d360d9113b6955287108ca9e90d76a1f3c1419
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<template>
  <el-dialog
      :title="title"
      width="60%"
      :withFooter="false"
      :visible.sync="visible"
      :confirm-working="isWorking"
      append-to-body
      @confirm="confirm"
  >
    <div class="codeEditBox">
      <json-viewer
          :value="form.formatContent"
          :expand-depth="5"
          copyable
          boxed
          :expanded="false"
          @copied="copyText"
          sort
          :show-array-index="false"
          class="w-100%">
        <template slot="copy">
          <i class="el-icon-document-copy" title="复制">复制代码</i>
        </template>
      </json-viewer>
    </div>
  </el-dialog>
</template>
 
<script>
import BaseOpera from '@/components/base/BaseOpera'
import JsonViewer from 'vue-json-viewer'
 
export default {
  name: 'OperaInterfaceLogWindow',
  extends: BaseOpera,
  components: { JsonViewer },
  data () {
    return {
      // 表单数据
      form: {
        content: '',
        formatContent: {}
      },
      // 验证规则
      rules: {
      },
      copyable: { copyText: 'copy', copiedText: 'copied' }
    }
  },
  created () {
    this.config({
      api: '/business/interfaceLog',
      'field.id': 'id'
    })
  },
  methods: {
    copyText (val) {
      this.$message.success('内容已成功复制到剪切板!')
    },
    open (title, target) {
      this.title = title
      this.visible = true
      // 新建
      if (target == null) {
        this.$nextTick(() => {
          this.$refs.form.resetFields()
          this.form[this.configData['field.id']] = null
        })
        return
      }
      // 编辑
      this.$nextTick(() => {
        for (const key in this.form) {
          this.form[key] = target[key]
        }
        try {
          this.form.formatContent = JSON.parse(this.form.content)
        } catch (e) {
          this.form.formatContent = this.form.content
        }
      })
    }
  }
}
</script>
 
<style lang="scss" scoped>
.codeEditBox {
  width: 100%;
  height: 90%;
  overflow:auto;
  display: block;
  border: 1px solid #dcdee2;
  overflow-y: auto;
}
::v-deep .el-dialog__body{height:70vh;overflow-y: auto}
::v-deep .el-dialog{height:78vh;overflow: hidden}
.jv-container {
  //height: 60vh;
}
</style>