-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathFunctionDebugDrawer.vue
More file actions
160 lines (150 loc) · 4.65 KB
/
FunctionDebugDrawer.vue
File metadata and controls
160 lines (150 loc) · 4.65 KB
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
<template>
<el-drawer v-model="debugVisible" size="60%" :append-to-body="true">
<template #header>
<div class="flex align-center" style="margin-left: -8px">
<el-button class="cursor mr-4" link @click.prevent="debugVisible = false">
<el-icon :size="20">
<Back />
</el-icon>
</el-button>
<h4>{{ $t('common.debug') }}</h4>
</div>
</template>
<div>
<div v-if="form.debug_field_list.length > 0" class="mb-16">
<h4 class="title-decoration-1 mb-16">
{{ $t('common.param.inputParam') }}
</h4>
<el-card shadow="never" class="card-never" style="--el-card-padding: 12px">
<el-form
ref="FormRef"
:model="form"
label-position="top"
require-asterisk-position="right"
hide-required-asterisk
v-loading="loading"
>
<template v-for="(item, index) in form.debug_field_list" :key="index">
<el-form-item
:label="item.name"
:prop="'debug_field_list.' + index + '.value'"
:rules="{
required: item.is_required,
message: $t('views.functionLib.functionForm.form.param.inputPlaceholder'),
trigger: 'blur'
}"
>
<template #label>
<div class="flex">
<span
>{{ item.name }} <span class="danger" v-if="item.is_required">*</span></span
>
<el-tag type="info" class="info-tag ml-4">{{ item.type }}</el-tag>
</div>
</template>
<el-input
v-model="item.value"
:placeholder="$t('views.functionLib.functionForm.form.param.inputPlaceholder')"
/>
</el-form-item>
</template>
</el-form>
</el-card>
</div>
<el-button type="primary" @click="submit(FormRef)" :loading="loading">
{{ $t('views.functionLib.functionForm.form.debug.run') }}
</el-button>
<div v-if="showResult" class="mt-8">
<h4 class="title-decoration-1 mb-16 mt-16">
{{ $t('views.functionLib.functionForm.form.debug.runResult') }}
</h4>
<div class="mb-16">
<el-alert
v-if="isSuccess"
:title="$t('views.functionLib.functionForm.form.debug.runSuccess')"
type="success"
show-icon
:closable="false"
/>
<el-alert
v-else
:title="$t('views.functionLib.functionForm.form.debug.runFailed')"
type="error"
show-icon
:closable="false"
/>
</div>
<p class="lighter mb-8">{{ $t('views.functionLib.functionForm.form.debug.output') }}</p>
<el-card
:class="isSuccess ? '' : 'danger'"
class="pre-wrap"
shadow="never"
style="max-height: 350px; overflow: scroll"
>
{{ String(result) == '0' ? 0 : result || '-' }}
</el-card>
</div>
</div>
</el-drawer>
</template>
<script setup lang="ts">
import { ref, reactive, watch } from 'vue'
import functionLibApi from '@/api/function-lib'
import type { FormInstance } from 'element-plus'
const FormRef = ref()
const loading = ref(false)
const debugVisible = ref(false)
const showResult = ref(false)
const isSuccess = ref(false)
const result = ref('')
const form = ref<any>({
debug_field_list: [],
code: '',
input_field_list: []
})
watch(debugVisible, (bool) => {
if (!bool) {
showResult.value = false
isSuccess.value = false
result.value = ''
form.value = {
debug_field_list: [],
code: '',
input_field_list: []
}
}
})
const submit = async (formEl: FormInstance | undefined) => {
const validate = formEl ? formEl.validate() : Promise.resolve()
validate.then(() => {
functionLibApi.postFunctionLibDebug(form.value, loading).then((res) => {
if (res.code === 500) {
showResult.value = true
isSuccess.value = false
result.value = res.message
} else {
showResult.value = true
isSuccess.value = true
result.value = res.data
}
})
})
}
const open = (data: any) => {
if (data.input_field_list.length > 0) {
data.input_field_list.forEach((item: any) => {
form.value.debug_field_list.push({
value: '',
...item
})
})
}
form.value.code = data.code
form.value.input_field_list = data.input_field_list
debugVisible.value = true
}
defineExpose({
open
})
</script>
<style lang="scss"></style>