form.stub 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <!-- 对话框表单 -->
  3. <el-dialog
  4. class="ba-operate-dialog"
  5. :close-on-click-modal="false"
  6. :model-value="['add', 'edit'].includes(baTable.form.operate!)"
  7. @close="baTable.toggleForm"{%bigDialog%}
  8. >
  9. <template #header>
  10. <div class="title" v-drag="['.ba-operate-dialog', '.el-dialog__header']" v-zoom="'.ba-operate-dialog'">
  11. {{ baTable.form.operate ? t(baTable.form.operate) : '' }}
  12. </div>
  13. </template>
  14. <el-scrollbar v-loading="baTable.form.loading" class="ba-table-form-scrollbar">
  15. <div
  16. class="ba-operate-form"
  17. :class="'ba-' + baTable.form.operate + '-form'"
  18. :style="'width: calc(100% - ' + baTable.form.labelWidth! / 2 + 'px)'"
  19. >
  20. <el-form
  21. v-if="!baTable.form.loading"
  22. ref="formRef"
  23. @submit.prevent=""
  24. @keyup.enter="baTable.onSubmit(formRef)"
  25. :model="baTable.form.items"
  26. label-position="right"
  27. :label-width="baTable.form.labelWidth + 'px'"
  28. :rules="rules"
  29. >{%formFields%}
  30. </el-form>
  31. </div>
  32. </el-scrollbar>
  33. <template #footer>
  34. <div :style="'width: calc(100% - ' + baTable.form.labelWidth! / 1.8 + 'px)'">
  35. <el-button @click="baTable.toggleForm('')">{{ t('Cancel') }}</el-button>
  36. <el-button v-blur :loading="baTable.form.submitLoading" @click="baTable.onSubmit(formRef)" type="primary">
  37. {{ baTable.form.operateIds && baTable.form.operateIds.length > 1 ? t('Save and edit next item') : t('Save') }}
  38. </el-button>
  39. </div>
  40. </template>
  41. </el-dialog>
  42. </template>
  43. <script setup lang="ts">
  44. import { reactive, ref, inject } from 'vue'
  45. import { useI18n } from 'vue-i18n'
  46. import type baTableClass from '/@/utils/baTable'
  47. import FormItem from '/@/components/formItem/index.vue'
  48. import type { ElForm, FormItemRule } from 'element-plus'
  49. import { buildValidatorData } from '/@/utils/validate'
  50. const formRef = ref<InstanceType<typeof ElForm>>()
  51. const baTable = inject('baTable') as baTableClass
  52. const { t } = useI18n()
  53. const rules: Partial<Record<string, FormItemRule[]>> = reactive({{%formItemRules%}})
  54. </script>
  55. <style scoped lang="scss"></style>