schangxiang@126.com
2025-09-10 3d43ffa3152110b7823f9fa6320c08a6ae02358a
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
<template>
  <div ref="container" class="page-list-container">
    <split-pane :max-width="500" :default-width="260" split="vertical">
      <div slot="paneL" class="left-container">
        <el-form class="form-tool">
          <el-form-item class="margin-bottom-0">
            <el-input v-model="filterText" placeholder="搜索名称" prefix-icon="el-icon-search" class="search-input">
            </el-input>
            <el-button title="刷新" class="btn-refresh" icon="el-icon-yrt-shuaxin" @click.native="treeRefresh"></el-button>
          </el-form-item>
          <el-form-item class="padding-right-0 margin-bottom-0">
            <el-scrollbar :noresize="false" :native="false" wrap-class="tree scrollbar-wrap">
              <!--数据tree-->
              <el-tree ref="tree" :data="dataTree" :expand-on-click-node="false" :load="(node, resolve)=>{loadTreeNode(node, resolve)}" :filter-node-method="filterTreeNode" :props="props" :default-expand-all="false" highlight-current lazy node-key="table_Id" @node-click="nodeClick">
                <span slot-scope="{ node, data }" class="custom-tree-node">
                  <span>
                    <i v-if="data.hasChild" class="el-icon-menu"></i>
                    <i v-else class="el-icon-tickets"></i>
                    {{ node.label }}
                  </span>
                </span>
              </el-tree>
            </el-scrollbar>
          </el-form-item>
        </el-form>
      </div>
 
      <!--右侧主区-->
      <div slot="paneR" class="right-container">
        <!--数据编辑器Editor-->
        <yrt-editor :ref="editorRef" :edit-type="'inner'" :data-list-ref="dataListRef" v-bind="editorOptions" :data-options="dataOptions" :action.sync="editorOptions.action" :visible.sync="editorOptions.config.visible" :auth-nodes="authNodes" :on-save-before="onSaveBefore" :detail-button-click="detailButtonClick" @on-save-after="onSaveAfter">
          <!--自定义按钮插槽-->
          <template slot="footer-button-region" slot-scope="{ formData, details }">
            <!--生成model文件-->
            <el-button type="success" icon="el-icon-yrt-liebiao" @click.native="createModel(formData, details)">生成model</el-button>
            <!--提取表字段-->
            <el-button type="success" icon="el-icon-yrt-zanwushourumingxi" @click.native="showFieldDialog">提取字段</el-button>
            <el-button type="success" icon="el-icon-yrt-liebiaolist46" @click.native="createFolder">创建文件夹</el-button>
          </template>
        </yrt-editor>
      </div>
    </split-pane>
 
    <!--提取表字段-->
    <el-dialog v-dialogDrag :visible.sync="dialogFieldVisible" :append-to-body="true" width="600px" title="提取表字段">
      <el-form ref="form" :model="formField" label-width="140px" class="w-500">
        <el-form-item label="数据库">
          <el-select v-model="formField.dbServer" placeholder="请选择数据库" class="w-100pc">
            <el-option label="Rattan.Sys" value="Rattan.Sys"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="项目名称">
          <el-select v-model="formField.projectName" placeholder="请选择项目名称" class="w-100pc">
            <el-option label="Rattan.Core" value="Rattan.Core"></el-option>
            <el-option label="Rattan.Sys" value="Rattan.Sys"></el-option>
            <el-option label="Rattan.BasicInfo" value="Rattan.BasicInfo"></el-option>
            <el-option label="Rattan.ERP.Outbound" value="Rattan.ERP.Outbound"></el-option>
            <el-option label="Rattan.ERP.Inbound" value="Rattan.ERP.Inbound"></el-option>
            <el-option label="Rattan.ERP.Storage" value="Rattan.ERP.Storage"></el-option>
            <el-option label="Rattan.TMS" value="Rattan.TMS"></el-option>
            <el-option label="Rattan.tms" value="Rattan.tms"></el-option>
            <el-option label="Rattan.Finance" value="Rattan.Finance"></el-option>
            <el-option label="Rattan.CRM" value="Rattan.CRM"></el-option>
            <el-option label="Rattan.Interface" value="Rattan.Interface"></el-option>
            <el-option label="Rattan.Interface.Express" value="Rattan.Interface.Express"></el-option>
            <el-option label="Rattan.Interface.Common" value="Rattan.Interface.Common"></el-option>
            <el-option label="Rattan.OA" value="Rattan.OA"></el-option>
            <el-option label="Rattan.Cms" value="Rattan.Cms"></el-option>
            <el-option label="Rattan.Stat" value="Rattan.Stat"></el-option>
            <el-option label="Rattan.Messager" value="Rattan.Messager"></el-option>
            <el-option label="Rattan.Promotion" value="Rattan.Promotion"></el-option>
            <el-option label="Rattan.Tms" value="Rattan.Tms"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="表(视图)名称">
          <el-input v-model="formField.tableName" @change="formField.enName=formField.tableName"></el-input>
        </el-form-item>
        <el-form-item label="表(视图)中文名称">
          <el-input v-model="formField.cnName"></el-input>
        </el-form-item>
        <el-form-item label="表(视图)英文名称">
          <el-input v-model="formField.enName"></el-input>
        </el-form-item>
        <el-form-item label="文件夹">
          <el-input v-model="formField.folderName"></el-input>
        </el-form-item>
        <el-form-item label="父级ID">
          <el-input v-model.number="formField.parentId" type="number"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-loading.fullscreen.lock="isLoading" type="primary" @click="createField">提取字段</el-button>
        <el-button @click="dialogFieldVisible = false">关闭</el-button>
      </div>
    </el-dialog>
 
  </div>
</template>
 
<script>
import baseLayout from "@/components/common/base-layout.vue";
import splitPane from "@/components/splitPane";
 
export default {
  name: "sys-dev-sys_mvctableinfo",
  components: {
    splitPane // 分割器
  },
  mixins: [baseLayout],
  data() {
    return {
      filterText: "",
      dataTree: [],
      props: {
        label: "label",
        children: "children",
        isLeaf: "isLeaf"
      },
      dialogFieldVisible: false, // 提取表字段
      formField: {
        dbServer: "Sys",
        projectName: null,
        tableName: null,
        cnName: null,
        enName: null,
        folderName: null,
        parentId: null
      },
      // 当前tree行数据
      currentTreeNode: {},
      // 正在提取
      isLoading: false
    };
  },
  methods: {
    // 明细按钮事件
    detailButtonClick(authNode, detail, btnOpts) {
      switch (authNode) {
        case "detailAdd":
          // 批量添加
          this.editor.addDetailDataRow([{ isManagerDataSet: 1, nullable: 1, dataType: "String" }], detail.subTableView);
          return true;
      }
    },
    // 获得左侧类目导航节点数据
    loadTreeNode(node, resolve) {
      this.currentTreeNode = {};
      var the = this;
      the.$nextTick(() => {
        var where = "";
        // var userInfo = this.common.getUserInfo();
        if (node.level === 0) {
          where = {
            parentId: 0
          };
        } else {
          where = {
            parentId: node.data.table_Id
          };
        }
 
        var url = "/api/common/loadTreeNode";
        var params = {
          DBServer: "Sys",
          tableName: "Sys_MvcTableInfo",
          tableView: "Sys_MvcTableInfo",
          keyName: "table_Id",
          nodeName: "cnName",
          fixHasChild: false,
          isBreakWay: false,
          displayBreakWay: false,
          parentName: "parentId",
          orderBy: "orderNo desc, table_Id",
          where: where,
          extendColumns: "Namespace as projectName, folderName",
          folder: "sys/core"
        };
        the.common.ajax(
          url,
          params,
          res => {
            if (res.result) {
              if (node.level === 0) {
                res.data.push({
                  table_Id: -1,
                  hasChild: "1",
                  cnName: "[未使用节点]"
                });
              }
              res.data.forEach(element => {
                element.label = element["cnName"];
                element.isLeaf = !element.hasChild;
              });
              resolve(res.data);
            } else {
              the.$message.error(res.msg);
            }
          },
          true
        );
      });
    },
    // 搜索导航
    filterTreeNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 点击tree导航节点
    nodeClick(data, node, el) {
      this.currentTreeNode = data;
      this.editor.editData(data.table_Id);
    },
 
    // 刷新tree
    treeRefresh() {
      this.filterText = "";
      var root = this.$refs.tree.store.root;
      while (root.childNodes.length) {
        this.$refs.tree.remove(root.childNodes[0]);
      }
      this.loadTreeNode(root, data => {
        root.doCreateChildren(data);
      });
    },
    // 生成model
    createModel(formData, details) {
      const url = "/api/sysmvc/createModel";
      const params = {
        table_Id: formData.table_Id
      };
      this.common.ajax(
        url,
        params,
        res => {
          this.common.showMsg(res);
        },
        true
      );
    },
    // 保存前事件
    onSaveBefore(formData) {
      formData["Sys_MvcTableColumn"].rows.forEach(item => {
        if (item.tableView !== formData.tableView) {
          item.tableView = formData.tableView;
          item.__ischange__ = true;
        }
      });
    },
    // 显示提取字段对话框
    showFieldDialog() {
      var node = this.currentTreeNode;
      if (node) {
        this.formField.parentId = node.parentId;
        this.formField.projectName = node.projectName || this.formField.projectName;
        this.formField.folderName = node.folderName;
      }
 
      this.dialogFieldVisible = true;
    },
    // 提取字段
    createField() {
      if (!this.formField.dbServer) {
        this.$message.error("数据库不能为空");
        return;
      }
      if (!this.formField.projectName) {
        this.$message.error("项目名称不能为空");
        return;
      }
      if (!this.formField.tableName) {
        this.$message.error("表(视图)名称不能为空");
        return;
      }
      if (!this.formField.cnName) {
        this.$message.error("数据库不能为空");
        return;
      }
      if (!this.formField.enName) {
        this.$message.error("表(视图)英文名称不能为空");
        return;
      }
      if (!this.formField.folderName) {
        this.$message.error("文件夹不能为空");
        return;
      }
      if (!this.formField.parentId) {
        this.$message.error("父级ID不能为空");
        return;
      }
 
      this.isLoading = true;
      const url = "/api/sysmvc/createField";
      const params = this.formField;
      this.common.ajax(url, params, res => {
        this.isLoading = false;
        this.common.showMsg(res);
        if (res.result) {
          this.dialogFieldVisible = false;
          var findNode = this.$refs.tree.getNode(res.data.table_Id);
          if (findNode) {
            this.editor.editData(res.data.table_Id);
            return;
          }
 
          var parentNode = this.$refs.tree.getNode(this.currentTreeNode.parentId);
          this.$refs.tree.append(
            {
              hasChild: "0",
              isLeaf: true,
              table_Id: res.data.table_Id,
              projectName: this.formField.projectName,
              folderName: res.data.folderName,
              cnName: res.data.cnName,
              label: res.data.cnName
            },
            parentNode
          );
          this.$refs.tree.setCurrentKey(res.data.table_Id);
          this.nodeClick(res.data);
        }
      });
    },
    // 保存后事件
    onSaveAfter(formData) {
      var node = this.$refs.tree.getCurrentNode();
      if (node.table_Id !== formData.table_Id) {
        var parentNode = this.$refs.tree.getNode(node.parentId);
        if (this.addLevel === "son") {
          parentNode = this.$refs.tree.getNode(node.table_Id);
        } else {
          node.cnName = formData.cnName;
          node.label = formData.cnName;
        }
        this.$refs.tree.append(
          {
            hasChild: "0",
            isLeaf: true,
            table_Id: formData.table_Id,
            sql: formData.sql,
            cnName: formData.cnName,
            label: formData.cnName
          },
          parentNode
        );
        this.$refs.tree.setCurrentKey(formData.table_Id);
        this.nodeClick(formData);
      } else {
        node.cnName = formData.cnName;
        node.label = formData.cnName;
      }
    },
    // 创建同级
    createBrotherNode(formData, details) {
      const parentId = formData.parentId;
      const folderName = formData.folderName;
      formData = this.editor.addData();
      formData.table_Id = 0;
      formData.parentId = parentId;
      formData.folderName = folderName;
      formData.cnName = null;
      formData.sql = null;
      this.addLevel = "brother";
    },
    // 创建子级同级
    createSonNode(formData, details) {
      const table_Id = formData.table_Id;
      const folderName = formData.folderName;
      formData = this.editor.addData();
      formData.parentId = table_Id;
      formData.folderName = folderName;
      formData.table_Id = 0;
      formData.cnName = null;
      this.addLevel = "son";
    },
    // 删除节点
    deleteNode(formData, details) {
      const _deleteNode = () => {
        var url = "/api/common/deleteTreeData";
        var params = {
          DBServer: "Sys",
          tableName: "Sys_MvcTableInfo",
          tableView: "Sys_MvcTableInfo",
          keyName: "table_Id",
          keyValue: formData.table_Id,
          nodeName: "cnName",
          parentName: "parentId",
          extendColumns: "",
          folder: "sys/core"
        };
        this.common.ajax(
          url,
          params,
          res => {
            this.common.showMsg(res);
            if (res.result) {
              this.$refs.tree.remove(formData.table_Id);
            }
          },
          true
        );
      };
      this.$confirm("此操作将永久删除该节点, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      })
        .then(() => {
          _deleteNode();
        })
        .catch(() => {
          this.$message({
            type: "info",
            message: "已取消删除"
          });
        });
    },
    // 复制节点
    copyNode(formData, details) {
      var url = "/api/common/copy";
      var params = {
        tableName: "Sys_MvcTableInfo",
        keyName: "table_Id",
        keyValue: formData.table_Id,
        nodeName: "cnName",
        parentName: "parentId",
        folder: "sys/core",
        where: {
          table_Id: formData.table_Id
        }
      };
      this.common.ajax(
        url,
        params,
        res => {
          this.common.showMsg(res);
          if (res.result) {
            var node = this.$refs.tree.getCurrentNode();
            var parentNode = this.$refs.tree.getNode(node.parentId);
            var dataInfo = res.data[0];
            this.$refs.tree.append(
              {
                hasChild: "0",
                isLeaf: true,
                table_Id: dataInfo.table_Id,
                sql: formData.sql,
                cnName: dataInfo.cnName,
                label: dataInfo.cnName
              },
              parentNode
            );
            this.$refs.tree.setCurrentKey(dataInfo.table_Id);
            this.nodeClick(dataInfo);
          }
        },
        true
      );
    },
    // 创建文件夹
    createFolder() {
      this.editor.addData();
    }
  }
};
</script>
 
<style lang="scss" scoped>
.page-list-container {
  position: relative;
  margin: 0px;
  min-height: calc(100vh - 165px);
  overflow-x: hidden;
 
  .left-container {
    width: 100%;
    height: 100%;
    background-color: white;
    border-radius: 4px;
    .form-tool {
      padding-top: 10px;
      .el-form-item {
        padding: 0 10px;
      }
      .search-input {
        width: calc(100% - 40px);
      }
      .btn-search,
      .btn-refresh {
        padding: 10px;
      }
      .btn-refresh {
        margin-left: 0px;
      }
    }
    /deep/ .el-tree-node.is-current > .el-tree-node__content {
      background-color: #a7ccf7;
      color: white;
      .el-button--text {
        color: white;
      }
    }
    .custom-tree-node {
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      padding-right: 8px;
    }
    /deep/ .tree.scrollbar-wrap {
      max-height: calc(100vh - 138px);
      overflow-x: hidden;
      padding: 10px 10px 20px;
      .el-tree {
        margin-bottom: 10px;
      }
    }
  }
 
  .right-container {
    border-radius: 4px;
    min-height: 100%;
    background-color: white;
    padding: 0 10px;
  }
}
</style>