Blame view

src/views/generator/Preview.vue 3.83 KB
4424f41c   monkeyhouyi   网信执法、清单管理静态页面
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
  <template>
    <el-dialog :visible.sync="visible" fullscreen lock-scroll class="NCC-full-dialog"
      :show-close="false" :modal="false">
      <div class="NCC-full-dialog-header">
        <div class="header-title">
          <img src="@/assets/images/ncc.png" class="header-logo" />
          <p class="header-txt"> · 代码预览</p>
        </div>
        <div class="options">
          <el-button @click="closeDialog()">{{$t('common.cancelButton')}}</el-button>
        </div>
      </div>
      <div class="NCC-common-layout main" v-loading="loading"
        :element-loading-text="$t('common.loadingText')">
        <div class="NCC-common-layout-left">
          <el-tree :data="treeData" :props="defaultProps" default-expand-all highlight-current
            ref="treeBox" :expand-on-click-node="false" @node-click="handleNodeClick"
            class="NCC-common-el-tree" node-key="id">
            <span class="custom-tree-node" slot-scope="{ node }">
              <el-tooltip :content="node.label" placement="right">
                <span class="text">{{node.label}}</span>
              </el-tooltip>
            </span>
          </el-tree>
        </div>
        <div class="NCC-common-layout-center">
          <div class="NCC-common-layout-main">
            <NCCCodeEditor v-model="currentContent" :options="options" ref="CodeEditor" />
          </div>
        </div>
      </div>
    </el-dialog>
  </template>
  
  <script>
  import { CodePreview } from '@/api/onlineDev/visualDev'
  import NCCCodeEditor from '@/components/NCCEditor/monaco'
  export default {
    components: { NCCCodeEditor },
    data() {
      return {
        loading: false,
        visible: false,
        dataForm: {
          module: 'system',
          description: '',
          subClassName: '',
          className: ''
        },
        defaultProps: {
          children: 'children',
          label: 'fileName'
        },
        treeData: [],
        options: {
          language: 'java'
        },
        currentName: '',
        currentId: '',
        currentContent: ''
      }
    },
    methods: {
      init(tables, id) {
        if (!tables || !id) {
          this.closeDialog()
          return
        }
        let tablesList = JSON.parse(tables)
        this.visible = true
        this.loading = true
        this.$nextTick(() => {
          let subClassName = []
          for (let i = 0; i < tablesList.length; i++) {
            let e = tablesList[i]
            if (e.typeId == '1') {
              this.dataForm.className = e.table
              this.dataForm.description = e.table
            } else {
              subClassName.push(e.table)
            }
          }
          this.dataForm.subClassName = subClassName.join()
          CodePreview(id, this.dataForm).then(res => {
            this.treeData = res.data.list
            this.currentName = this.treeData[0].children[0].fileName
            this.currentId = this.treeData[0].children[0].currentId
            this.currentContent = this.treeData[0].children[0].fileContent
            this.$nextTick(() => {
              this.$refs.treeBox.setCurrentKey(this.currentName);
              this.$refs.CodeEditor.changeEditor({
                value: this.currentContent,
                options: this.options
              })
            });
            this.loading = false
          }).catch(() => {
            this.closeDialog()
            this.loading = false
          })
        })
      },
      closeDialog() {
        this.visible = false
        this.$emit('close')
      },
      handleNodeClick(data) {
        if (this.currentName == data.fileName && this.currentId == data.id ) return
        this.options.language = data.fileType === 'vue' ? 'html' : 'java'
        this.currentName = data.fileName
        this.currentId = data.id
        this.currentContent = data.fileContent
        this.$refs.CodeEditor.changeEditor({
          value: this.currentContent,
          options: this.options
        })
      },
    }
  }
  </script>
  <style lang="scss" scoped>
  >>> .main {
    padding: 10px;
    .NCC-common-layout-main {
      padding: 0;
    }
  }
  </style>