form.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. <template>
  2. <div class="apps-form">
  3. <el-dialog :title="'修改'" width="880" v-model="visible" :close-on-click-modal="false" :destroy-on-close="true" draggable>
  4. <el-form ref="menuDialogFormRef"
  5. :inline="true"
  6. :model="state.ruleForm"
  7. class="demo-form-inline"
  8. style="margin-bottom: -25px;"
  9. v-loading="loading">
  10. <el-form-item :label="'营销开关'" prop="isMarketing">
  11. <el-switch v-model="state.ruleForm.isMarketing" style="--el-switch-on-color: rgb(48, 185, 113);" inline-prompt :active-value="1" :inactive-value="0" />
  12. </el-form-item>
  13. <el-form-item :label="'域名限制'" prop="isHttp">
  14. <el-switch v-model="state.ruleForm.isHttp" style="--el-switch-on-color: rgb(48, 185, 113);" inline-prompt :active-value="1" :inactive-value="0" />
  15. </el-form-item>
  16. </el-form>
  17. <div class="title">IP集合</div>
  18. <JCollapse />
  19. <div class="title">域名集合</div>
  20. <JCollapse />
  21. <div class="title">备注</div>
  22. <el-input
  23. :rows="4"
  24. type="textarea"
  25. ></el-input>
  26. <template #footer>
  27. <span class="dialog-footer">
  28. <el-button @click="visible = false">{{ $t('common.cancelButtonText') }}</el-button>
  29. <el-button type="primary" @click="onSubmit" :disabled="loading">{{ $t('common.confirmButtonText') }}</el-button>
  30. </span>
  31. </template>
  32. </el-dialog>
  33. </div>
  34. </template>
  35. <script setup lang="ts" name="systemMenuDialog">
  36. import {useI18n} from 'vue-i18n';
  37. import {save} from '/@/api/marketing/config';
  38. import {useMessage} from '/@/hooks/message';
  39. import JCollapse from '/@/components/JCollapse/index.vue';
  40. // 定义子组件向父组件传值/事件
  41. const emit = defineEmits(['refresh']);
  42. const {t} = useI18n();
  43. // 定义变量内容
  44. const visible = ref(false);
  45. const loading = ref(false);
  46. const sign = ref('domain')
  47. const add = ref(false);
  48. const menuDialogFormRef = ref();
  49. // 定义需要的数据
  50. const state = reactive({
  51. ruleForm: {
  52. list: [''],
  53. https: [''], // 域名集合
  54. ips: [''], // ip集合
  55. },
  56. appList: [] as any[], // 应用下拉框列表
  57. });
  58. // 分页参数
  59. const pagination = reactive({
  60. current: 1,
  61. size: 10,
  62. total: 0
  63. })
  64. // 打开弹窗
  65. const openDialog = async (type: string, row: any, str: string = 'domain') => {
  66. visible.value = true;
  67. sign.value = str;
  68. nextTick(() => {
  69. menuDialogFormRef.value?.resetFields();
  70. });
  71. state.ruleForm = JSON.parse(JSON.stringify(row));
  72. str === 'domain' ? state.ruleForm.list = row.https.map(e => ({val: e})) : state.ruleForm.list = row.ips.map(e => ({val: e}));
  73. };
  74. // 保存数据
  75. const onSubmit = async () => {
  76. sign.value === 'domain' ? state.ruleForm.https = state.ruleForm.list.map(e => e.val) : state.ruleForm.ips = state.ruleForm.list.map(e => e.val);
  77. delete state.ruleForm.list;
  78. try {
  79. loading.value = true;
  80. await save(state.ruleForm);
  81. useMessage().success(t(state.ruleForm.id ? 'common.editSuccessText' : 'common.addSuccessText'));
  82. visible.value = false;
  83. emit('refresh');
  84. } catch (err: any) {
  85. useMessage().error(err.msg);
  86. } finally {
  87. loading.value = false;
  88. }
  89. };
  90. // 暴露变量 只有暴漏出来的变量 父组件才能使用
  91. defineExpose({
  92. openDialog,
  93. });
  94. </script>
  95. <style lang="scss">
  96. .config-container {
  97. display: flex;
  98. align-items: center;
  99. margin-bottom: 10px;
  100. font-size: 14px;
  101. font-weight: 400;
  102. width: 100%;
  103. justify-content: start;
  104. }
  105. .config-actions {
  106. width: 50px;
  107. display: flex;
  108. align-items: center;
  109. justify-content: space-between;
  110. }
  111. .apps-loadmore.el-select-dropdown .el-scrollbar__wrap {
  112. height: 330px !important;
  113. }
  114. .apps-form {
  115. .el-overlay {
  116. .el-overlay-dialog {
  117. .el-dialog {
  118. .el-dialog__body {
  119. padding: 0 !important;
  120. }
  121. }
  122. }
  123. }
  124. .demo-form-inline .el-switch {
  125. margin-right: 50px;
  126. }
  127. .title {
  128. line-height: 20px;
  129. font-family: Source Han Sans SC;
  130. font-size: 14px;
  131. color: rgba(18, 18, 18, 1);
  132. margin: 30px 0 12px;
  133. }
  134. }
  135. </style>