1
lzhe
2024-05-13 3350b56a1d143eb12c987cd6cf07eea2119294e5
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
<!--
 * @Author: lzhe lzhe@example.com
 * @Date: 2024-03-26 10:28:33
 * @LastEditors: lzhe lzhe@example.com
 * @LastEditTime: 2024-05-13 16:28:30
 * @FilePath: /smart-web/src/views/master/person/main/index.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
    <div class="aposcope-main">
        <div class="aposcope-left">
            <div class="left-title">业务列表</div>
            <el-tree :data="tableData" node-key="id" :props="defalutProps" @node-click="handleNodeClick" ref="treeRef" default-expand-all :highlight-current="true" :expand-on-click-node="false"/>
        </div>
        <div class="aposcope-right">
            <div class="right-content">
                <div class="content-title"><span>*</span>所在物理表</div>
                <el-select v-model="metaForm.tableName" style="width: 30%" :disabled="isDis">
                    <el-option v-for="item in tableNameList" :key="item.tableName" :label="item.tableName" :value="item.tableName"/>
                </el-select>
            </div>
            <div class="right-content">
                <div class="content-title"><span>*</span>字段1</div>
                <el-select v-model="metaForm.refCode" style="width: 30%">
                    <el-option v-for="item in testList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                </el-select>
            </div>
            <div class="right-content">
                <div class="content-title"><span>*</span>字段2</div>
                <el-select v-model="metaForm.refName" style="width: 30%">
                    <el-option v-for="item in testList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                </el-select>
            </div>
            <div class="right-content">
                <div class="content-title">编码字段</div>
                <el-select v-model="metaForm.test" style="width: 30%">
                    <el-option v-for="item in testList" :key="item.dictKey" :label="item.dictValue" :value="item.dictKey"/>
                </el-select>
            </div>
            <div class="right-content">
                <div class="content-title">参数设置</div>
                <el-button type="primary">添加参数</el-button>
            </div>
            <el-table ref="searchDataListRef" :data="searchDataList" border style="width: 100%;margin-top: 20px;" class="multipleTableRef">
                <el-table-column prop="fcode" label="字段编码"></el-table-column>
                <el-table-column prop="fname" label="字段标题"></el-table-column>
                <el-table-column prop="field" label="实体属性"></el-table-column>
                <el-table-column prop="elementTypeName" label="元素类型"></el-table-column>
                <el-table-column prop="enumType" label="枚举类型"></el-table-column>
                <el-table-column prop="seq" label="字段顺序"></el-table-column>
                <el-table-column prop="refObjectTypeId" label="引用关系"></el-table-column>
                <el-table-column label="操作">
                    <template #default="scope">
                        <el-icon><Edit /></el-icon>
                        <el-icon><Edit /></el-icon>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>
<script>
    import * as ElementPlusIconsVue from '@element-plus/icons-vue'
    let icons = []
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
        icons.push(key)
    }
    export default {
        name: "metaObject",
        data(){
            return {
                isDis: true,
                testList: [],
                tableNameList: [],
                metaForm: {
                    tableName: "",
                    refCode: "",
                    refName: ""
                },
                classificationRules: {
                    classify: [
                        { required: true, message: "请选择分类字段" }
                    ]
                },
                classificationForm: {
                    classify: "",
                    dictionary: ""
                },
                isSaveing: false,
                searchDataList: [],  //右侧数据list
                defalutProps: {
                    label: 'dictValue',
                      children: 'children',
                    isLeaf: 'hasChildren'
                },
                tableData: [],
                firstChild: [],   //一级菜单
                dictKey: "",
                dictionaryType: []  //字典类型
            }
        },
        created(){
            
        },
        mounted(){
            this.getDictionary();  //字典类型
        },
        components: {
            ...ElementPlusIconsVue
        },
        methods: {
            getDictionary() {  //字典类型
                this.$HTTP.get("/api/blade-system/dict/dictionary?code=element_type").then(res=> {  //物理表
                    if(res.code == 200) {
                        this.dictionaryType = res.data;
                        this.getMenuList();
                    }
                })
            },
            getList() {
                this.$HTTP.get(`/api/blade-system/bascoderule/count?type=${this.dictKey}`).then(res=> {  //是否可选
                    if(res.code == 200) {
                        if(res.data == 1) {
                            this.isDis = true;
                        }else {
                            this.isDis = false;
                        }
                    }
                })
                this.$HTTP.get("/api/blade-system/meta-object-type/tableDetail").then(res=> {  //物理表
                    if(res.code == 200) {
                        this.tableNameList = res.data;
                        this.gettableName();  //获取字段
                    }
                })
                this.getSearchDataList(); //表格数据
            },
            gettableName() {
                this.$HTTP.get(`/api/blade-system/meta-object-type/detail?fId=${this.dictKey}`).then(res=> {  //物理表数据
                    if(res.code == 200) {
                        this.metaForm.tableName = res.data.tableName;
                        this.metaForm.refCode = res.data.refCode;
                        this.metaForm.refName = res.data.refName;
                    }
                })
            },
            getSearchDataList() {
                this.$HTTP.get(`/api/blade-system/meta-object-type-field/list?objectId=${this.dictKey}`).then(res=> {  //表格数据
                    if(res.code == 200) {
                        this.searchDataList = res.data;
                        this.dictionaryType.forEach(item=> {
                            this.searchDataList.forEach(item1=> {
                                if(item1.elementType == item.dictKey) {
                                    console.log(item.code,99)
                                    item1.elementTypeName = item.dictValue;
                                }
                            })
                        })
                        console.log(this.searchDataList,12345)
                    }
                })
            },
            closeVisible(flag) {
                if(flag == "closed") {
                    this.classificationForm = {
                        classify: "",
                        dictionary: ""
                    }
                    this.$refs.dialogForm.resetFields();
                };
            },
            classificationSubmit() {
                this.$refs.dialogForm.validate(async (valid) => {
                    if (valid) {
                        this.isSaveing = false;
                        // this.$HTTP.post("/api/blade-system/data-scope/submit",obj).then(res=> {
                        //     this.isSaveing = false;
                        //     if(res.code == 200) {
                        //         this.$emit('success', this.addDictForm, this.mode);
                        //         this.visible = false;
                        //         this.$message.success("操作成功");
                        //     }else {
                        //         this.$alert(res.message, "提示", {type: 'error'});
                        //     }
                        // })
                    }else{
                        return false;
                    }
                })
            },
            handleNodeClick(data) {
                if(!this.firstChild.includes(data.id)) {
                    console.log(data,234);
                    this.dictKey = data.dictKey;
                    this.getList();  //所在物理表、是否可选
                }
                // this.drawerPath = data.name;
                // this.$HTTP.get("/api/blade-system/api-scope/list",this.searchData).then(res=> {
                //     if(res.code == 200) {
                //         this.searchDataList = res.data.records;
                //     }
                // })
            },
            extractLastLevelIds(array) {  //递归获取children最后一级的id的数组
                let ids = []; 
                for (let i = 0; i < array.length; i++) {  
                    const obj = array[i];  
                    if (obj.children) {  
                        // 递归调用以提取更深层级的children中的id  
                        ids = ids.concat(this.extractLastLevelIds(obj.children));  
                    } else {  
                        // 如果没有children属性,则假定当前对象是最后一级  
                        if (obj.id) {  
                            ids.push(obj);  
                        }  
                    }  
                }  
                return ids; 
            },
            getMenuList() {
                this.$HTTP.get("/api/blade-system/dict/dictionary-tree?code=code_rule_for_biz_objects").then(res=> {
                    if(res.code == 200) {
                        this.tableData = res.data;
                        var menuGrantList = res.data.filter(item=> { //过滤掉没有children的
                            return item.children;
                        });
                        var lastId = this.extractLastLevelIds(menuGrantList[0].children);  //获取最后一级id
                        this.firstChild = res.data.map(item=> {
                            return item.id;
                        })
                        this.$nextTick(()=> {
                            this.dictKey = lastId[0].dictKey;
                            this.$refs.treeRef.setCurrentKey(lastId[0].id);  //设置选中数据
                            this.getList();  //所在物理表、是否可选
                        })
                    }
                })
            }
        }
    }
</script>
<style scoped>
.aposcope-main {
    display: flex;
    min-height: 100%;
    margin: 8px;
}
.aposcope-left {
    width: 240px;
    margin-right: 8px;
    padding: 4px;
    background-color: #fff;
}
.aposcope-right {
    flex: 1;
    padding: 8px;
    background-color: #fff;
}
.left-title {
    font-size: 16px;
    text-align: center;
    height: 38px;
    line-height: 38px;
    border-bottom: 1px solid #e2e2e2;
    background-color: #409eff;
    color: #fff;
    border-radius: 2px 2px 0 0;
    margin-bottom: 12px;
}
.right-content {
    margin-bottom: 12px;
}
.content-title {
    margin-bottom: 12px;
}
.content-title span {
    margin-right: 4px;
    color: red;
}
</style>