sqlModeStep2.vue 7.97 KB
<template>
  <div class="step2">
    <div style="margin-top: 20px; margin-bottom: 20px; margin-left: 10px; display: flex">
      配置模式&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Select
        class="selectCss"
        v-model:value="optionValue1"
        show-search
        placeholder="input search text"
        :options="options1"
        @search="handleSearch"
      />
      <div style="margin-left: 20px" v-if="optionValue1 === '脚本模式'">
        脚本语言&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<Select
          class="selectCss"
          v-model:value="optionValue3"
          show-search
          placeholder="input search text"
          :options="options3"
          @search="handleSearch"
        />
      </div>
      <a-button
        style="margin-left: 20px"
        type="primary"
        @click="mappingButton"
        v-if="optionValue1 !== '脚本模式'"
        >一键映射</a-button
      >
    </div>

    <div v-if="optionValue1 !== '脚本模式'">
      <div
        style="
          font-size: 16px;
          font-weight: bold;
          margin-top: 20px;
          margin-bottom: 20px;
          margin-left: 10px;
        "
      >
        开放入参定义
      </div>

      <div style="margin-top: 20px; margin-bottom: 20px; margin-left: 10px">
        参数配置方式&nbsp;&nbsp;&nbsp;<Select
          class="selectCss"
          v-model:value="optionValue2"
          show-search
          placeholder="input search text"
          :options="options2"
          @search="handleSearch"
        />
      </div>

      <div
        style="display: flex; margin-top: 20px; margin-bottom: 20px; margin-left: 10px"
        v-if="optionValue2 === '自动解析'"
      >
        <div style="font-size: 16px">json</div
        >&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
        <Textarea rows="4" style="width: 35%" :value="json" />
        <a-button type="primary" style="margin-top: 5%; margin-left: 10px" @click="typeManageButton"
          >解析</a-button
        >
      </div>

      <BasicTable @register="registerTable1">
        <template #toolbar>
          <BasicUpload
            v-if="optionValue2 !== '自动解析'"
            :maxSize="20"
            :maxNumber="10"
            @change="handleChange"
            :api="uploadApi"
            :accept="['image/*']"
          >
            <template #uploadBtnName>
              <span>导入原始入参</span>
            </template>
          </BasicUpload>
          <a-button type="primary" @click="addParamButton">添加参数</a-button>
        </template>
        <template #bodyCell="{ column, record }">
          <template v-if="column.key === 'action'">
            <TableAction
              :actions="[
                {
                  icon: 'ant-design:delete-outlined',
                  // label: '删除',
                  color: 'error',
                  popConfirm: {
                    title: '是否确认删除',
                    placement: 'left',
                    confirm: deleteButton.bind(null, record),
                  },
                },
              ]"
            />
          </template>
        </template>
      </BasicTable>
      <div v-if="show">
        <BasicTable @register="registerTable2">
          <template #toolbar>
            <a-button type="primary" @click="typeManageButton">自动映射</a-button>
          </template>
        </BasicTable>
      </div>
    </div>
    <div v-if="optionValue1 === '脚本模式'">
      <CodeEditor v-model:value="sql" />
    </div>
    <div style="display: flex; justify-content: flex-end; margin-top: 20px">
      <a-button style="margin-right: 20px" type="primary" @click="customResetFunc">上一步</a-button>
      <a-button style="margin-right: 10px" type="primary" @click="customSubmitFunc"
        >下一步</a-button
      >
    </div>
  </div>
</template>
<script lang="ts" setup>
  import { BasicForm, useForm } from '@/components/Form';
  import { Description } from '@/components/Description';
  import { useMessage } from '@/hooks/web/useMessage';
  import { step2TableData1, step2TableData2, step1SQLData } from './apiData';
  import { ref, reactive, onMounted } from 'vue';
  import { Select, Textarea } from 'ant-design-vue';
  import CodeEditor from '@/components/CodeEditor/src/CodeEditor.vue';
  import { BasicTable, useTable, TableAction } from '@/components/Table';
  import { columns, step2TableColumns1, step2TableColumns2 } from './api.data';
  import { BasicUpload } from '@/components/Upload';

  const { createMessage } = useMessage();
  const emit = defineEmits(['next']);
  const tableData1 = ref(step2TableData1);
  const optionValue1 = ref('');
  const optionValue2 = ref('');
  const optionValue3 = ref('');
  const options1 = ref([
    {
      label: '映射规则',
      value: '映射规则',
    },
    {
      label: '脚本模式',
      value: '脚本模式',
    },
  ]);
  const options2 = ref([
    {
      label: '自动解析',
      value: '自动解析',
    },
    {
      label: '手动添加',
      value: '手动添加',
    },
  ]);
  const options3 = ref([
    {
      label: 'JAVA',
      value: 'JAVA',
    },
    {
      label: 'Groovy',
      value: 'Groovy',
    },
  ]);
  const sql = ref(step1SQLData[0].sql);
  const show = ref(false);
  const json = ref(
    '{ "category": "SERVICE", "page": 1, "size": 10, "searchText": "", "uuid": "5B86749FD7CFB3CFF8100794FE15D3E", "sortRules": [], "filterRules": [], "timeRangeFilters": [], "fieldFuzzySearch": [], "childrenRequest": null, "catalogFlag": false }',
  );
  const [registerTable1, { reload: reload1 }] = useTable({
    title: '',
    api: async (params) => {
      var data = [];
      const response = {
        pageNu: '1',
        pageSize: '10',
        pages: '1',
        total: tableData1.value.length,
        code: '',
        message: '',
        data: [],
      };
      //过滤data中的数据,取出等于params.deptId的数据
      return { ...response, data: tableData1.value };
    },
    columns: step2TableColumns1,
    useSearchForm: false,
    showTableSetting: false,
    showIndexColumn: false,
    bordered: true,
    scroll: { y: 300 },
    actionColumn: {
      width: 100,
      title: '操作',
      dataIndex: 'action',
    },
  });
  const [registerTable2] = useTable({
    title: '入参映射',
    api: async (params) => {
      var data = [];
      const response = {
        pageNu: '1',
        pageSize: '10',
        pages: '1',
        total: step2TableData2.length,
        code: '',
        message: '',
        data: [],
      };
      //过滤data中的数据,取出等于params.deptId的数据
      return { ...response, data: step2TableData2 };
    },
    columns: step2TableColumns2,
    useSearchForm: false,
    showTableSetting: false,
    showIndexColumn: false,
    bordered: true,
    scroll: { y: 300 },
  });

  const deleteList = ref([]);
  /**删除按钮*/
  function deleteButton(record) {
    console.log(record);
    deleteList.value.push(record.Xpath);
    tableData1.value = step2TableData1.filter((item) => !deleteList.value.includes(item.Xpath));
    reload1();
    createMessage.success('删除成功!');
  }

  function customSubmitFunc() {
    try {
      emit('next', '');
    } catch (error) {}
  }

  function customResetFunc() {
    emit('prev');
  }

  /**一键映射 按钮*/
  function mappingButton() {
    show.value = true;
  }

  /**添加参数*/
  function addParamButton() {
    const param = {
      parameterCode: '',
      parameterLocation: '',
      Xpath: '',
      dataType: '',
      comment: '',
      isNeed: '',
      defaultValue: '',
      exampleValue: '',
    };
    tableData1.value.push(param);
    reload1();
  }

  /**初始化*/
  onMounted(() => {
    optionValue1.value = '映射规则';
    optionValue2.value = '手动添加';
    optionValue3.value = 'JAVA';
  });
</script>
<style lang="less" scoped>
  .selectCss {
    ::v-deep(.ant-select-selector) {
      width: 200px !important;
    }
  }
</style>