hyb
2026-01-30 15bc7727b58bf9ca0c8f21702fa893daac232b8d
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
<template>
    <el-table
        highlight-current-row
        :height="height"
        :data="tableData"
        style="width: 100%"
        :border="false"
        @cell-mouse-enter="cellMouseEnter"
        @cell-mouse-leave="cellMouseLeave"
        :cell-style="{ paddingTop: '4px', paddingBottom: '4px' }"
    >
        <el-table-column label="数据Key" width="400">
            <template v-slot="scope">
                <el-input
                    type="textarea"
                    :autosize="{ minRows: 2, maxRows: 8 }"
                    clearable
                    v-model="scope.row.key"
                    placeholder="key 、 key-key1"
                ></el-input>
            </template>
        </el-table-column>
 
        <el-table-column label="数据内容" width="700">
            <template v-slot="scope">
                <el-input
                    type="textarea"
                    :autosize="{ minRows: 2, maxRows: 8 }"
                    clearable
                    v-model="scope.row.value"
                    placeholder="${ func() } 、 [ value ] 、 [ [ value1, value2] ]"
                ></el-input>
            </template>
        </el-table-column>
 
        <el-table-column label="参数描述" width="400">
            <template v-slot="scope">
                <el-input
                    type="textarea"
                    clearable
                    v-model="scope.row.desc"
                    placeholder="参数简要描述"
                ></el-input>
            </template>
        </el-table-column>
 
        <el-table-column>
            <template v-slot="scope">
                <el-row v-show="scope.row === currentRow">
                    <el-button
                        icon="el-icon-circle-plus-outline"
                        size="mini"
                        type="info"
                        @click="handleEdit"
                    ></el-button>
                    <el-button
                        icon="el-icon-delete"
                        size="mini"
                        type="danger"
                        v-show="scope.$index !== 0"
                        @click="handleDelete(scope.$index)"
                    ></el-button>
                </el-row>
            </template>
        </el-table-column>
    </el-table>
</template>
 
<script>
export default {
    name: "Parameters",
    data() {
        return {
            currentRow: "",
            tableData: [{ key: "", value: "", desc: "" }]
        };
    },
    props: {
        save: Boolean,
        parameters: {
            required: false
        }
    },
    computed: {
        height() {
            return window.screen.height - 440;
        }
    },
    watch: {
        save() {
            this.$emit("parameters", this.parseParameters(), this.tableData);
        },
        parameters: {
            deep: true,
            handler(newVal) {
                if (newVal.length !== 0) {
                    this.tableData = JSON.parse(JSON.stringify(newVal));
                }
            }
        }
    },
    methods: {
        parseParameters() {
            let parameters = {
                parameters: [],
                desc: {}
            };
            for (let content of this.tableData) {
                let value = content["value"];
                const key = content["key"];
                let obj = {};
                if (key !== "" && value !== "") {
                    try {
                        value = JSON.parse(value);
                    } catch (err) {}
                    obj[key] = value;
                    parameters.parameters.push(obj);
                    parameters.desc[key] = content.desc;
                }
            }
            return parameters;
        },
        cellMouseEnter(row) {
            this.currentRow = row;
        },
        cellMouseLeave() {
            this.currentRow = "";
        },
        handleEdit() {
            this.tableData.push({
                key: "",
                value: "",
                desc: ""
            });
        },
        handleDelete(index) {
            this.tableData.splice(index, 1);
        }
    }
};
</script>
 
<style scoped></style>