index.vue
2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<script lang="ts" setup>
  import { Tabs } from 'ant-design-vue';
  import { RuleChainConversionScript } from './RuleChainConversionScript';
  import { TcpConversionScript } from './TcpConversionScript';
  import { BasicForm, useForm } from '/@/components/Form';
  import { searchFormSchema } from './config/config.data';
  import { nextTick, ref, unref } from 'vue';
  enum ActiveKey {
    RULE = 'rule',
    TCP = 'tco',
  }
  const ruleChainTableRefEl = ref<Nullable<InstanceType<typeof RuleChainConversionScript>>>(null);
  const tcpTableRefEl = ref<Nullable<InstanceType<typeof TcpConversionScript>>>(null);
  const searchInfo = ref<Recordable>({});
  const activeKey = ref(ActiveKey.TCP);
  const syncValue = (value: Recordable) => {
    searchInfo.value = { ...unref(searchInfo), ...value };
  };
  const [register, { getFieldsValue }] = useForm({
    schemas: searchFormSchema(syncValue),
    labelWidth: 120,
    showAdvancedButton: true,
    compact: true,
    fieldMapToTime: [['createTime', ['startTime', 'endTime'], 'x']],
    submitFunc: async () => {
      const value = getFieldsValue();
      searchInfo.value = value;
      await nextTick();
      if (unref(activeKey) === ActiveKey.RULE) {
        unref(ruleChainTableRefEl)?.reload();
      } else {
        unref(tcpTableRefEl)?.reload();
      }
    },
    resetFunc: async () => {
      searchInfo.value = {};
      await nextTick();
      if (unref(activeKey) === ActiveKey.RULE) {
        unref(ruleChainTableRefEl)?.reload();
      } else {
        unref(tcpTableRefEl)?.reload();
      }
    },
  });
</script>
<template>
  <section class="w-full h-full p-4">
    <BasicForm
      @register="register"
      class="rule-script-manage-form w-full bg-light-50 !pt-4 dark:bg-dark-900"
    />
    <main class="mt-4">
      <Tabs
        v-model:activeKey="activeKey"
        type="card"
        class="w-full h-full bg-light-50 !p-4 dark:bg-dark-900"
      >
        <Tabs.TabPane tab="TCP转换脚本" :key="ActiveKey.TCP">
          <TcpConversionScript
            ref="tcpTableRefEl"
            :search-info="searchInfo"
            class="p-4 bg-neutral-100 dark:bg-dark-700"
          />
        </Tabs.TabPane>
        <Tabs.TabPane tab="规则链转换脚本" :key="ActiveKey.RULE">
          <RuleChainConversionScript
            ref="ruleChainTableRefEl"
            :search-info="searchInfo"
            class="p-4 bg-neutral-100 dark:bg-dark-700"
          />
        </Tabs.TabPane>
      </Tabs>
    </main>
  </section>
</template>
<style lang="less" scoped>
  .rule-script-manage-form {
    :deep(.ant-row) {
      @apply w-full;
    }
  }
</style>