|
| 1 | +<template> |
| 2 | + <MkDialog |
| 3 | + v-model="dialogVisible" |
| 4 | + title="设置变量" |
| 5 | + width="600" |
| 6 | + append-to-body |
| 7 | + :close-on-click-modal="false" |
| 8 | + :close-on-press-escape="false" |
| 9 | + > |
| 10 | + <el-form ref="formRef" label-position="top" :model="form" require-asterisk-position="right"> |
| 11 | + <el-form-item |
| 12 | + v-for="item in inputFieldList" |
| 13 | + :key="item" |
| 14 | + :label="item" |
| 15 | + :prop="item" |
| 16 | + :rules="{ required: true, message: '该项必填', trigger: 'blur' }" |
| 17 | + > |
| 18 | + <el-input v-model="form[item]" /> |
| 19 | + </el-form-item> |
| 20 | + </el-form> |
| 21 | + <template #footer> |
| 22 | + <span class="dialog-footer"> |
| 23 | + <el-button @click.prevent="dialogVisible = false">取消</el-button> |
| 24 | + <el-button type="primary" :loading="loading" @click="submit(formRef)">保存</el-button> |
| 25 | + </span> |
| 26 | + </template> |
| 27 | + </MkDialog> |
| 28 | +</template> |
| 29 | +<script setup lang="ts"> |
| 30 | +import { ref, useTemplateRef, reactive } from 'vue' |
| 31 | +import type { FormInstance } from 'element-plus' |
| 32 | +
|
| 33 | +defineOptions({ name: 'McpServerInputDialog' }) |
| 34 | +
|
| 35 | +const emit = defineEmits<{ refresh: [value: Record<string, string>] }>() |
| 36 | +
|
| 37 | +const dialogVisible = ref(false) |
| 38 | +const loading = ref(false) |
| 39 | +const formRef = useTemplateRef<FormInstance>('formRef') |
| 40 | +const form = reactive<Record<string, string>>({}) |
| 41 | +
|
| 42 | +const inputFieldList = ref<string[]>([]) |
| 43 | +
|
| 44 | +function open(vars: string[]) { |
| 45 | + Object.keys(form).forEach((key) => delete form[key]) |
| 46 | + inputFieldList.value = vars |
| 47 | + dialogVisible.value = true |
| 48 | +} |
| 49 | +
|
| 50 | +const submit = async (formEl: FormInstance | null) => { |
| 51 | + if (!formEl) return |
| 52 | + await formEl.validate((valid) => { |
| 53 | + if (valid) { |
| 54 | + emit('refresh', { ...form }) |
| 55 | + dialogVisible.value = false |
| 56 | + } |
| 57 | + }) |
| 58 | +} |
| 59 | +
|
| 60 | +defineExpose({ open }) |
| 61 | +</script> |
| 62 | +<style lang="scss" scoped></style> |
0 commit comments