configForm.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <xn-form-container title="区域配置" :width="'500px'" :visible="visible" :destroy-on-close="true" @close="onClose">
  3. <a-form
  4. ref="formRef"
  5. :model="formData"
  6. :rules="formRules"
  7. layout="inline"
  8. :label-col="{ style: { width: '85px', justifyContent: 'end' } }"
  9. >
  10. <!-- <a-form-item label="目标端口" name="code">
  11. <a-input v-model:value="formData.code" placeholder="请输入目标端口" allow-clear />
  12. </a-form-item>
  13. <a-form-item label="设备型号" name="modelName">
  14. <a-select ref="select" v-model:value="formData.modelName" :options="modeOptions"> </a-select>
  15. </a-form-item>
  16. <a-form-item label="目标端口" name="code">
  17. <a-input-number id="inputNumber" v-model:value="formData.code" style="width: 100%" />
  18. </a-form-item> -->
  19. </a-form>
  20. <template #footer>
  21. <a-button class="xn-mr8" @click="onClose">退出</a-button>
  22. <a-button type="primary" @click="onSubmit">保存</a-button>
  23. </template>
  24. </xn-form-container>
  25. </template>
  26. <script setup>
  27. import tool from '@/utils/tool'
  28. import { required } from '@/utils/formRules'
  29. import memApi from '@/api/basicset/memApi'
  30. const emit = defineEmits({ successful: null })
  31. const visible = ref(false) // 默认是关闭状态
  32. const formRef = ref()
  33. const formData = ref({}) // 表单数据
  34. const modeOptions = tool.dictList('COIDCHAIN') // 设备型号
  35. // 默认要校验的
  36. const formRules = {
  37. code: [required('请输入设备名称')]
  38. }
  39. // 打开抽屉
  40. const onOpen = (record) => {
  41. visible.value = true
  42. if (record) {
  43. formData.value = Object.assign({}, record)
  44. } else {
  45. formData.value = {}
  46. }
  47. }
  48. // 关闭抽屉
  49. const onClose = () => {
  50. formRef.value.resetFields()
  51. visible.value = false
  52. }
  53. // 验证并提交数据
  54. const onSubmit = () => {
  55. formRef.value
  56. .validate()
  57. .then(() => {
  58. memApi.submitForm(formData.value, formData.value.id).then(() => {
  59. onClose()
  60. emit('successful')
  61. })
  62. })
  63. .catch((error) => {
  64. console.log(error)
  65. })
  66. }
  67. // 调用这个函数将子组件的一些数据和方法暴露出去
  68. defineExpose({
  69. onOpen
  70. })
  71. </script>
  72. <style lang="less" scoped>
  73. :deep(.ant-form-item) {
  74. width: 100%;
  75. margin-bottom: 10px;
  76. }
  77. </style>