ipEdit.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <el-dialog :title="sign === 'domain' ? '修改域名集合' : '修改ip集合'" width="600" v-model="visible"
  3. :close-on-click-modal="false" :destroy-on-close="true" draggable>
  4. <el-form ref="menuDialogFormRef" :model="state.ruleForm"
  5. label-width="90px" v-loading="loading">
  6. <el-form-item :label="sign === 'domain' ? '域名集合' : 'ip集合'" prop="configs">
  7. <div v-for="(item, index) in state.ruleForm.list" :key="item.index" class="flex items-center mb-2 text-sm font-normal justify-start w-full">
  8. <el-input style="width: 300px; margin-right: 20px;" v-model="item.val" clearable :placeholder="t('marketingConfig.inputIPTip')"></el-input>
  9. <div class="config-actions w-[50px] flex items-center justify-between ">
  10. <svg
  11. v-if="index === state.ruleForm.list.length - 1"
  12. @click="state.ruleForm.list.push({val: ''})"
  13. style="cursor: pointer;" width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  14. <path d="M19.5 3H4.5C3.67157 3 3 3.67157 3 4.5V19.5C3 20.3284 3.67157 21 4.5 21H19.5C20.3284 21 21 20.3284 21 19.5V4.5C21 3.67157 20.3284 3 19.5 3Z" stroke="#646464" stroke-linejoin="round"/>
  15. <path d="M12 8V16" stroke="#646464" stroke-linecap="round" stroke-linejoin="round"/>
  16. <path d="M8 12H16" stroke="#646464" stroke-linecap="round" stroke-linejoin="round"/>
  17. </svg>
  18. <svg
  19. v-if="state.ruleForm.list.length > 1" style="cursor: pointer;"
  20. @click="state.ruleForm.list.splice(index, 1)"
  21. width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
  22. <path d="M19.5 3H4.5C3.67157 3 3 3.67157 3 4.5V19.5C3 20.3284 3.67157 21 4.5 21H19.5C20.3284 21 21 20.3284 21 19.5V4.5C21 3.67157 20.3284 3 19.5 3Z" stroke="#646464" stroke-linejoin="round"/>
  23. <path d="M8 12H16" stroke="#646464" stroke-linecap="round" stroke-linejoin="round"/>
  24. </svg>
  25. </div>
  26. </div>
  27. </el-form-item>
  28. </el-form>
  29. <template #footer>
  30. <span class="dialog-footer">
  31. <el-button @click="visible = false">{{ t('common.cancelButtonText') }}</el-button>
  32. <el-button type="primary" @click="onSubmit" :disabled="loading">{{ t('common.confirmButtonText') }}</el-button>
  33. </span>
  34. </template>
  35. </el-dialog>
  36. </template>
  37. <script setup name="systemMenuDialog">
  38. import {useI18n} from 'vue-i18n';
  39. import {info, getAppList, save} from '/@/api/marketing/config';
  40. import {useMessage} from '/@/hooks/message';
  41. import {rule} from '/@/utils/validate';
  42. // 定义子组件向父组件传值/事件
  43. const emit = defineEmits(['refresh']);
  44. const { t } = useI18n();
  45. // 定义变量内容
  46. const visible = ref(false);
  47. const loading = ref(false);
  48. const sign = ref('domain')
  49. const menuDialogFormRef = ref();
  50. // 定义需要的数据
  51. const state = reactive({
  52. ruleForm: {
  53. list: [''],
  54. https: [''], // 域名集合
  55. ips: [''], // ip集合
  56. // {
  57. // id: '1',
  58. // ip: '美国',
  59. // appId: '1',
  60. // appUrl: 'www.baidu.com',
  61. // appName: 'adsa'
  62. // },
  63. },
  64. appList: [], // 应用下拉框列表
  65. });
  66. // // 表单校验规则
  67. // const dataRules = reactive({
  68. // domain: [
  69. // {required: true, message: '域名不能为空', trigger: 'blur'},
  70. // // { validator: rule.url, trigger: 'blur' }
  71. // ],
  72. // });
  73. // 分页参数
  74. const pagination = reactive({
  75. current: 1,
  76. size: 10,
  77. total: 0
  78. })
  79. // 打开弹窗
  80. const openDialog = async (type, row, str = 'domain') => {
  81. visible.value = true;
  82. sign.value = str;
  83. nextTick(() => {
  84. menuDialogFormRef.value?.resetFields();
  85. });
  86. state.ruleForm = JSON.parse(JSON.stringify(row));
  87. str === 'domain' ? state.ruleForm.list = row.https.map(e => ({val: e})) : state.ruleForm.list = row.ips.map(e => ({val: e}));
  88. // if (row?.id && type === 'edit') {
  89. // await getConfigDetail(row.id);
  90. // } else {
  91. // state.ruleForm = {
  92. // id: null,
  93. // domain: '',
  94. // configs: [
  95. // {
  96. // id: '',
  97. // ip: '',
  98. // appId: '',
  99. // appUrl: '',
  100. // appName: ''
  101. // }
  102. // ],
  103. // };
  104. // }
  105. // pagination.current = 1;
  106. // // 获取应用列表
  107. // getAllAppData();
  108. };
  109. // 获取当条配置信息
  110. const getConfigDetail = (id) => {
  111. info(id).then((res) => {
  112. Object.assign(state.ruleForm, res.data);
  113. });
  114. };
  115. // 保存数据
  116. const onSubmit = async () => {
  117. // const valid = await menuDialogFormRef.value.validate().catch(() => {
  118. // });
  119. // if (!valid) return false;
  120. sign.value === 'domain' ? state.ruleForm.https = state.ruleForm.list.map(e => e.val) : state.ruleForm.ips = state.ruleForm.list.map(e => e.val);
  121. delete state.ruleForm.list;
  122. try {
  123. loading.value = true;
  124. await save(state.ruleForm);
  125. useMessage().success(t(state.ruleForm.id ? 'common.editSuccessText' : 'common.addSuccessText'));
  126. visible.value = false;
  127. emit('refresh');
  128. } catch (err) {
  129. useMessage().error(err.msg);
  130. } finally {
  131. loading.value = false;
  132. }
  133. };
  134. // 暴露变量 只有暴漏出来的变量 父组件才能使用
  135. defineExpose({
  136. openDialog,
  137. });
  138. </script>
  139. <style>
  140. .apps-loadmore.el-select-dropdown .el-scrollbar__wrap {
  141. height: 330px !important;
  142. }
  143. </style>