hyb
2025-05-14 87453ffd761425b9f363a09a0f8fe07d770cb325
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
<template>
    <el-container>
        <el-header style="padding-top: 10px; height: 50px">
            <div class="config__header">
                <div class="config__header--item">
                    <el-input
                        style="width: 300px"
                        size="small"
                        placeholder="请输入配置名称"
                        v-model="search"
                        clearable
                    >
                    </el-input>
                </div>
 
                <div class="config__header--item">
                    <el-button
                        plain
                        size="small"
                        icon="el-icon-refresh"
                        @click="resetSearch"
                        >重置</el-button
                    >
                </div>
            </div>
        </el-header>
 
        <el-container>
            <el-main style="padding: 0; margin-left: 10px; margin-top: 10px;">
                <div class="config-body-table">
                    <el-table
                        highlight-current-row
                        v-loading="loading"
                        :data="configData.results"
                        stripe
                        height="calc(100%)"
                        @cell-mouse-enter="cellMouseEnter"
                        @cell-mouse-leave="cellMouseLeave"
                        @selection-change="handleSelectionChange"
                    >
                        <el-table-column
                            type="selection"
                            width="55"
                        ></el-table-column>
                        <el-table-column label="配置名称" width="300">
                            <template v-slot="scope">
                                <div
                                    :title="scope.row.name"
                                    style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
                                >
                                    {{ scope.row.name }}
                                </div>
                            </template>
                        </el-table-column>
 
                        <el-table-column label="基础URL">
                            <template v-slot="scope">
                                <div
                                    :title="scope.row.base_url"
                                    style="overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"
                                >
                                    {{
                                        scope.row.base_url === ""
                                            ? "无"
                                            : scope.row.base_url
                                    }}
                                </div>
                            </template>
                        </el-table-column>
 
                        <el-table-column label="是否默认">
                            <template v-slot="scope">
                                <el-switch
                                    disabled
                                    v-model="scope.row.is_default"
                                    active-color="#13ce66"
                                ></el-switch>
                            </template>
                        </el-table-column>
 
                        <el-table-column label="更新时间">
                            <template v-slot="scope">
                                <div>
                                    {{ scope.row.update_time | datetimeFormat }}
                                </div>
                            </template>
                        </el-table-column>
 
                        <el-table-column label="配置操作">
                            <template v-slot="scope">
                                <el-row v-show="currentRow === scope.row">
                                    <el-button
                                        type="info"
                                        icon="el-icon-edit"
                                        title="编辑"
                                        circle
                                        size="mini"
                                        @click="handleEditConfig(scope.row)"
                                    ></el-button>
                                    <el-button
                                        type="success"
                                        icon="el-icon-document"
                                        title="复制"
                                        circle
                                        size="mini"
                                        @click="
                                            handleCopyConfig(
                                                scope.row.id,
                                                scope.row.name
                                            )
                                        "
                                    ></el-button>
                                    <el-button
                                        v-show="configData.count !== 0"
                                        type="danger"
                                        icon="el-icon-delete"
                                        title="删除"
                                        circle
                                        size="mini"
                                        @click="handleDelConfig(scope.row.id)"
                                    ></el-button>
                                </el-row>
                            </template>
                        </el-table-column>
                    </el-table>
                    <div class="pagination-container">
                        <el-pagination
                            v-show="configData.count !== 0"
                            @current-change="handleCurrentChange"
                            @size-change="handleSizeChange"
                            :current-page.sync="localCurrentPage"
                            :page-sizes="[10, 20, 30, 40]"
                            :page-size="localPageSize"
                            :pager-count="5"
                            layout="total, sizes, prev, pager, next, jumper"
                            :total="configData.count"
                            background
                        ></el-pagination>
                    </div>
                </div>
            </el-main>
        </el-container>
    </el-container>
</template>
 
<script>
export default {
    name: "ConfigList",
    props: {
        back: Boolean,
        project: {
            required: true
        },
        pageSize: Number,
        currentPage: Number,
        del: Boolean,
        isSelectConfig: Boolean
    },
    data() {
        return {
            localCurrentPage: this.currentPage || 1,
            localPageSize: this.pageSize || 10,
            search: "",
            searchDebounce: null,
            selectConfig: [],
            currentRow: "",
            configData: {
                count: 0,
                results: []
            },
            loading: true
        };
    },
    watch: {
        currentPage(newValue) {
            this.localCurrentPage = newValue;
        },
        pageSize(newValue) {
            this.localPageSize = newValue;
        },
        search() {
            this.debouncedGetConfigList();
        },
        configData(newValue) {
            this.$emit("configDataChanged", newValue);
        },
        back() {
            this.getConfigList();
        },
        del() {
            if (this.selectConfig.length !== 0) {
                this.$confirm("此操作将永久删除配置,是否继续?", "提示", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                }).then(() => {
                    this.$api
                        .delAllConfig({ data: this.selectConfig })
                        .then(resp => {
                            if (resp.success) {
                                this.$message.success(resp.msg);
                                this.getConfigList();
                            } else {
                                this.$message.error(resp.msg);
                            }
                        });
                });
            } else {
                this.$notify.warning({
                    title: "提示",
                    message: "请至少勾选一个配置",
                    duration: this.$store.state.duration
                });
            }
        }
    },
    methods: {
        debouncedGetConfigList() {
            clearTimeout(this.searchDebounce);
            this.searchDebounce = setTimeout(() => {
                this.localCurrentPage = 1;
                this.getConfigList();
            }, 300);
        },
        handleSelectionChange(val) {
            this.selectConfig = val;
            // 更新是否已经选择Config, 父组件依赖这个属性来判断是否禁用批量删除按钮
            if (this.selectConfig.length > 0) {
                this.$emit("update:isSelectConfig", true);
            } else {
                this.$emit("update:isSelectConfig", false);
            }
        },
        handleCurrentChange() {
            this.$api
                .getConfigPaginationByPage({
                    params: {
                        page: this.localCurrentPage,
                        size: this.localPageSize,
                        project: this.project,
                        search: this.search
                    }
                })
                .then(resp => {
                    this.configData = resp;
                    this.$emit("update:currentPage", this.localCurrentPage);
                });
        },
        handleSizeChange(newSize) {
            this.localPageSize = newSize;
            // 计算新的最大页码
            let maxPage = Math.ceil(this.configData.count / newSize);
            if (this.localCurrentPage > maxPage) {
                // 如果当前页码超出了范围,请将其设置为最大页面
                this.localCurrentPage = maxPage;
            }
            this.$api
                .getConfigPaginationByPage({
                    params: {
                        page: this.localCurrentPage,
                        size: newSize,
                        project: this.project,
                        search: this.search
                    }
                })
                .then(resp => {
                    this.configData = resp;
                    this.$emit("update:pageSize", this.localPageSize);
                });
        },
        handleDelConfig(index) {
            this.$confirm("此操作将永久删除该配置, 是否继续?", "提示", {
                confirmButtonText: "确定",
                cancelButtonText: "取消",
                type: "warning"
            }).then(() => {
                this.$api.delConfig(index).then(resp => {
                    if (resp.success) {
                        this.$message.success(resp.msg);
                        this.getConfigList();
                    } else {
                        this.$message.error(resp.msg);
                    }
                });
            });
        },
        handleEditConfig(row) {
            this.$emit("respConfig", row);
        },
        handleCopyConfig(id, name) {
            this.$prompt("请输入配置名称", "提示", {
                closeOnClickModal: false,
                confirmButtonText: "确定",
                inputPattern: /^[\s\S]*.*[^\s][\s\S]*$/,
                inputErrorMessage: "配置名称不能为空",
                inputValue: name
            }).then(({ value }) => {
                this.$api
                    .copyConfig(id, {
                        name: value
                    })
                    .then(resp => {
                        if (resp.success) {
                            this.$message.success("配置复制成功");
                            this.getConfigList();
                        } else {
                            this.$message.error(resp.msg);
                        }
                    });
            });
        },
        cellMouseEnter(row) {
            this.currentRow = row;
        },
        cellMouseLeave() {
            this.currentRow = "";
        },
        getConfigList() {
            this.$api
                .configList({
                    params: {
                        page: this.localCurrentPage,
                        size: this.localPageSize,
                        project: this.project,
                        search: this.search
                    }
                })
                .then(resp => {
                    this.configData = resp;
                    this.loading = false;
                });
        },
        resetSearch() {
            this.search = "";
            this.localPageSize = 10;
            this.localCurrentPage = 1;
            this.getConfigList();
        }
    },
 
    mounted() {
        this.getConfigList();
    }
};
</script>
 
<style scoped>
.config__header {
    display: flex;
    align-items: center;
    margin-left: -30px;
}
 
.config__header--item {
    display: flex;
    margin-left: 10px;
}
 
.config-body-table {
    position: fixed;
    bottom: 0;
    right: 0;
    left: 220px;
    top: 150px;
    margin-left: -10px;
    padding-bottom: 60px;
}
</style>