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
<template>
<el-row class="page-container dict">
<el-tabs v-model="activeName" @tab-click="handleTabClick">
<el-tab-pane
:label="item.name"
:name="'index' + index"
v-for="(item, index) in dbList"
:key="item.id"
>{{
}}</el-tab-pane>
</el-tabs>
<el-container class="page-main" :gutter="20">
<el-aside width="220px" class="left-content">
<el-col :span="24" class="left-title">
<span>数据库表</span>
<span class="left-add" @click="handleAdd()" title="新增"
><i class="el-icon-circle-plus-outline"></i
></span>
</el-col>
<el-col :span="24" class="left-search">
<el-input
v-model.trim="searchVal"
clearable
:placeholder="placeholder"
>
</el-input>
</el-col>
<el-col
class="dict-list"
ref="dict"
style="height: calc(100vh - 280px)"
>
<el-col
v-for="(item, index) in tableData"
:key="item.id"
class="dict-item"
>
<span
@click="handClick(index, item)"
:class="{ active: index == isActive }"
style="cursor: pointer; word-break: break-word"
>
{{ item.name }} <br />{{ item.code }}
</span>
<span class="item-del">
<!-- <i class="el-icon-edit-outline" @click="handleAdd(item)"></i> -->
</span>
</el-col>
</el-col>
</el-aside>
<el-main>
<FieldList
:table-code="tableCode"
:tableId="tableId"
:dbId="dbId"
></FieldList>
</el-main>
</el-container>
<dialog-form
ref="dialog"
:width="'450px'"
:title="formEdit.id ? '编辑' : '新增'"
:form-data="formData"
:form-edit="formEdit"
@handleConfirm="handleConfirm"
/>
</el-row>
</template>
<script>
import { getDbList, getTableList, addDbTable } from "@/api/database"
import FieldList from "./FieldList.vue"
export default {
name: "FieldConfig",
components: { FieldList },
data() {
return {
dbId: null,
activeName: "index0",
dbList: [],
tableList: [],
tableCode: null,
isActive: -1,
tableId: "",
searchVal: "",
placeholder: "请输入关键字",
listLoading: false,
formEdit: {},
formData: [
{
type: "input",
label: "表名称",
prop: "name",
rules: [{ required: true, message: "表名称必填" }],
},
{
type: "input",
label: "表code",
rules: [{ required: true, message: "表code必填" }],
prop: "code",
slot: "prepend",
unit: "",
},
{
type: "input",
label: "说明",
prop: "note",
},
],
}
},
computed: {
tableData() {
const list = this.tableList.filter(
(_) => !this.searchVal || _.name.includes(this.searchVal)
)
this.isActive = this.getListIdx(list, this.tableId)
return list
},
filterTableData() {
return this.tabData.filter(
(_) => !this.cacheForm.name || _.name.includes(this.cacheForm.name)
)
},
},
methods: {
handleAdd(row = {}) {
if (!this.dbId) {
this.$message.error("未选择数据库")
return
}
const db = this.dbList.find((_) => _.id === this.dbId)
this.formData[1].unit = db.prefix + "_"
this.formEdit = { ...row }
this.$refs.dialog.open()
},
handleConfirm(form) {
addDbTable({ ...form, dbId: this.dbId })
.then((res) => {
this.$message.success(res.msg)
this.getTableList()
this.$refs.dialog.close()
})
.finally(() => {
this.$refs.dialog.loading = false
})
},
handleTabClick({ index }) {
this.dbId = this.dbList[index].id
this.tableCode = null
this.tableId = null
this.getTableList()
},
getTableList() {
if (!this.dbId) return
getTableList(this.dbId).then((res) => {
this.tableList = res.data
})
},
// 点击左侧列表
handClick(index, { code, name, id }) {
this.name = name
this.isActive = index
this.tableCode = code
this.tableId = id
},
getDbList() {
getDbList().then((res) => {
this.dbList = res.data
if (this.dbList[0]) {
this.dbId = this.dbList[0].id
this.getTableList()
}
})
},
getListIdx(list, id) {
let listIdx = -1
for (var i = 0; i < list.length; i++) {
if (list[i].id === id) {
listIdx = i
break
}
}
return listIdx
},
},
mounted() {
this.getDbList()
},
}
</script>
<style lang="scss" scoped>
.el-main {
padding: 0 20px;
}
.page-main {
align-items: flex-start;
}
</style>