domainForm.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <template>
  2. <div class="apps-form">
  3. <el-dialog
  4. append-to-body :title="t('marketingApps.editDomain')" width="880" v-model="visible" :close-on-click-modal="false" :destroy-on-close="true"
  5. draggable>
  6. <DomainCollapse :data=domains @domains="updateDomains"
  7. @delDomains="handleDelDomains"></DomainCollapse>
  8. <template #footer>
  9. <span class="dialog-footer">
  10. <el-button @click="visible = false">{{ t('common.cancelButtonText') }}</el-button>
  11. <el-button type="primary" @click="onSubmit" :disabled="loading">{{ t('common.confirmButtonText')
  12. }}</el-button>
  13. </span>
  14. </template>
  15. </el-dialog>
  16. </div>
  17. </template>
  18. <script setup lang="ts" name="domainForm">
  19. import { useMessage } from '/@/hooks/message';
  20. import { useI18n } from 'vue-i18n';
  21. import { updateModDomains } from '/@/api/marketing/apps';
  22. import { DomainItem } from '../types';
  23. const DomainCollapse = defineAsyncComponent(() => import('./domainCollapse.vue'));
  24. // 定义子组件向父组件传值/事件
  25. const emit = defineEmits(['refresh']);
  26. const { t } = useI18n();
  27. // 定义变量内容
  28. const visible = ref(false);
  29. const loading = ref(false);
  30. const domains = ref<DomainItem[]>([]);
  31. const childDomains = ref();
  32. const delDomains = ref<string[]>([]);
  33. const rowData = ref();
  34. // 打开弹窗
  35. const openDialog = async (data: any, row) => {
  36. visible.value = true;
  37. domains.value = data;
  38. childDomains.value = [];
  39. delDomains.value = [];
  40. rowData.value = row;
  41. };
  42. const updateDomains = (data: DomainItem[])=>{
  43. childDomains.value = data;
  44. }
  45. const handleDelDomains = (data: string[]) => {
  46. delDomains.value = data;
  47. }
  48. // 保存数据
  49. const onSubmit = async () => {
  50. try {
  51. updateModDomains({ domains: childDomains.value, delDomains: delDomains.value, id: rowData.value.id})
  52. emit('refresh');
  53. useMessage().success(t('marketingApps.submitSuccess'));
  54. visible.value = false;
  55. } catch (error) {
  56. useMessage().error(t('marketingApps.submitFail'));
  57. console.error(error);
  58. }
  59. };
  60. // 暴露变量 只有暴漏出来的变量 父组件才能使用
  61. defineExpose({
  62. openDialog,
  63. });
  64. </script>
  65. <style lang="scss">
  66. .el-overlay {
  67. .el-overlay-dialog {
  68. .el-dialog {
  69. .el-dialog__body {
  70. padding: 0 !important;
  71. }
  72. }
  73. }
  74. }
  75. </style>