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
<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" @on-edit-load-after="onEditLoadAfter">
        </yrt-editor>
      </div>
    </split-pane>
 
  </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);
      });
    },
    // 保存前事件
    onSaveBefore(formData) {
      const fields = formData["Sys_MvcTableColumn"].rows
        .map(row => {
          return {
            prop: this.common.caseStyle(row.columnName),
            sortNo: row.sortNo,
            label: row.label,
            width: row.width,
            blank: row.blank
          };
        })
        .filter(row => row.label || row.width || row.blank !== undefined || row.sortNo);
      const params = {
        table_Id: formData.table_Id,
        tableView: formData.tableName,
        userJson: {
          fields: fields
        }
      };
 
      const url = "/api/sysMvc/saveUserJson";
      this.common.ajax(
        url,
        params,
        res => {
          this.common.showMsg(res);
          const rows = this.editor.formData["Sys_MvcTableColumn"].rows;
          rows.sort((a, b) => {
            return (a.sortNo || 0) > (b.sortNo || 0) ? -1 : 1;
          });
        },
        true
      );
      return false; // 自定义保存,必须返回false,不执行标准保存
    },
    // 保存后事件
    onSaveAfter(formData) {},
    // 数据加载后
    onEditLoadAfter() {
      const url = "/api/sysMvc/getUserJson";
      const params = {
        table_Id: this.editor.formData.table_Id
      };
      this.common.ajax(
        url,
        params,
        res => {
          const rows = this.editor.formData["Sys_MvcTableColumn"].rows;
          this.common.showMsg(res);
          if (res.result && res.data && res.data.fields) {
            res.data.fields.forEach(item => {
              const row = rows.find(field => this.common.caseStyle(field.columnName) === item.prop);
              if (row) {
                this.$set(row, "sortNo", item.sortNo);
                this.$set(row, "label", item.label);
                this.$set(row, "width", item.width);
                this.$set(row, "blank", item.blank);
              }
            });
          }
          rows.sort((a, b) => {
            return (a.sortNo || 0) > (b.sortNo || 0) ? -1 : 1;
          });
        },
        true
      );
    }
  }
};
</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>