Ben Lin
2024-06-25 3505aa60ad15de91bc9b437ca8d69124c8074974
src/views/tigerprojects/bas/shift/index.vue
@@ -2,27 +2,31 @@
  <div>
    <BasicTable @register="registerTable">
      <template #toolbar>
        <a-button color="primary" @click="handleAdd"> 添加 </a-button>
        <a-button ghost color="primary" @click="aoaToExcel"> 导出 </a-button>
        <a-button type="primary" @click="handleAdd" preIcon="add_02|svg"> 新增 </a-button>
        <a-button ghost color="success" @click="aoaToExcel" preIcon="excel-export|svg">
          导出
        </a-button>
      </template>
      <template #action="{ record }">
        <TableAction :actions="[
      {
        icon: 'clarity:note-edit-line',
        tooltip: '修改',
        onClick: handleEdit.bind(null, record),
      },
      {
        icon: 'ant-design:delete-outlined',
        color: 'error',
        tooltip: '删除',
        popConfirm: {
          title: '是否确认删除?',
          placement: 'left',
          confirm: handleDelete.bind(null, record),
        },
      },
    ]" />
        <TableAction
          :actions="[
            {
              icon: 'clarity:note-edit-line',
              tooltip: '修改',
              onClick: handleEdit.bind(null, record),
            },
            {
              icon: 'ant-design:delete-outlined',
              color: 'error',
              tooltip: '删除',
              popConfirm: {
                title: '是否确认删除?',
                placement: 'left',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
    <Loading :loading="compState.loading" :tip="compState.tip" />
@@ -30,115 +34,111 @@
  </div>
</template>
<script lang="ts" setup>
import { reactive, unref } from 'vue';
import { aoaToSheetXlsx } from '/@/components/Excel';
import { BasicTable, useTable, TableAction } from '/@/components/Table';
import { useDrawer } from '/@/components/Drawer';
import { columns, searchFormSchema } from './shift.data';
import { getListByPage, Delete } from '/@/api/tigerapi/bas/shift';
import { useGo } from '/@/hooks/web/usePage';
import { Loading } from '/@/components/Loading';
import { useMessage } from '/@/hooks/web/useMessage';
import { useI18n } from '/@/hooks/web/useI18n';
import { buildUUID } from '/@/utils/uuid';
  import { reactive, unref } from 'vue';
  import { aoaToSheetXlsx } from '/@/components/Excel';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useDrawer } from '/@/components/Drawer';
  import { columns, searchFormSchema } from './shift.data';
  import { getListByPage, Delete } from '/@/api/tigerapi/bas/shift';
  import { useGo } from '/@/hooks/web/usePage';
  import { Loading } from '/@/components/Loading';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { buildUUID } from '/@/utils/uuid';
const { t } = useI18n();
const { createMessage } = useMessage();
const [registerDrawer, { openDrawer }] = useDrawer();
const go = useGo();
const compState = reactive({
  absolute: false,
  loading: false,
  tip: '加载中...',
});
const [registerTable, { getForm, getPaginationRef, reload }] = useTable({
  title: '生产班制',
  api: getListByPage,
  columns,
  formConfig: {
    labelWidth: 120,
    schemas: searchFormSchema,
  },
  actionColumn: {
    width: 120,
    title: '操作',
    dataIndex: 'action',
    slots: { customRender: 'action' },
    fixed: 'right', //undefined,
  },
  ellipsis: true,
  useSearchForm: true,
  showTableSetting: false,
  bordered: true,
  showIndexColumn: false,
});
let arr: any[] = [];
//导出
function aoaToExcel() {
  const totals = getPaginationRef().total
  if (totals < 30000) {
    arr = [];
    compState.loading = true;
    const col = getForm().getFieldsValue()
    getListByPage(col).then((res) => {
      res.items.forEach(element => {
        arr.push({
          '班制编码': element.SFTS_CODE,
          '班制名称': element.SFTS_NAME,
          '是否启用': element.IS_ACTIVE,
          '备注': element.REMARK,
          '创建人': element.CREATE_USER,
          '创建时间': element.CREATE_TIME,
        });
      });
      const arrHeader = columns.map((column) => column.title);
      const arrData = arr.map((item) => {
        return Object.keys(item).map((key) => item[key]);
      });
      // 保证data顺序与header一致
      if (arr.length < 30000) {
        aoaToSheetXlsx({
          data: arrData,
          header: arrHeader,
          filename: '班制.xlsx',
        });
      } else {
        createMessage.error(t('导出数据不能超过三万条,如需要更多的请联系管理员'));
      }
      compState.loading = false;
    })
  } else {
    createMessage.error(t('导出数据不能超过三万条,如需要更多的请联系管理员'));
  }
}
//添加
function handleAdd() {
  const rule = { SFTS_CODE: '0', ID: buildUUID() };
  go(`/shiftDetail/${encodeURI(JSON.stringify(rule))}`);
}
//编辑
function handleEdit(record: any) {
  const rule = { SFTS_CODE: record.SFTS_CODE, ID: record.ID };
  go(`/shiftDetail/${encodeURI(JSON.stringify(rule))}`);
}
function handleSuccess() {
  reload();
}
//删除
function handleDelete(record: any) {
  const apiAction = Delete(record.ID);
  apiAction.then((action) => {
    if (action.IsSuccessed) {
      createMessage.success(t('已删除'));
      reload();
    } else {
      createMessage.success(t('删除操作失败'));
    }
  const { t } = useI18n();
  const { createMessage } = useMessage();
  const [registerDrawer, { openDrawer }] = useDrawer();
  const go = useGo();
  const compState = reactive({
    absolute: false,
    loading: false,
    tip: '加载中...',
  });
}
  const [registerTable, { getForm, getPaginationRef, reload }] = useTable({
    title: '生产班制',
    api: getListByPage,
    columns,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    actionColumn: {
      width: 120,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right', //undefined,
    },
    ellipsis: true,
    useSearchForm: true,
    showTableSetting: true,
    bordered: true,
    showIndexColumn: false,
  });
  let arr: any[] = [];
  //导出
  function aoaToExcel() {
    const totals = getPaginationRef().total;
    if (totals < 30000) {
      arr = [];
      compState.loading = true;
      const col = getForm().getFieldsValue();
      getListByPage(col).then((res) => {
        res.items.forEach((element) => {
          arr.push({
            班制编码: element.SFTS_CODE,
            班制名称: element.SFTS_NAME,
            是否启用: element.IS_ACTIVE,
            备注: element.REMARK,
            创建人: element.CREATE_USER,
            创建时间: element.CREATE_TIME,
          });
        });
        const arrHeader = columns.map((column) => column.title);
        const arrData = arr.map((item) => {
          return Object.keys(item).map((key) => item[key]);
        });
        // 保证data顺序与header一致
        if (arr.length < 30000) {
          aoaToSheetXlsx({
            data: arrData,
            header: arrHeader,
            filename: '班制.xlsx',
          });
        } else {
          createMessage.error(t('导出数据不能超过三万条,如需要更多的请联系管理员'));
        }
        compState.loading = false;
      });
    } else {
      createMessage.error(t('导出数据不能超过三万条,如需要更多的请联系管理员'));
    }
  }
  //添加
  function handleAdd() {
    const rule = { SFTS_CODE: '0', ID: buildUUID() };
    go(`/shiftDetail/${encodeURI(JSON.stringify(rule))}`);
  }
  //编辑
  function handleEdit(record: any) {
    const rule = { SFTS_CODE: record.SFTS_CODE, ID: record.ID };
    go(`/shiftDetail/${encodeURI(JSON.stringify(rule))}`);
  }
  function handleSuccess() {
    reload();
  }
  //删除
  function handleDelete(record: any) {
    const apiAction = Delete(record.ID);
    apiAction.then((action) => {
      if (action.IsSuccessed) {
        createMessage.success(t('已删除'));
        reload();
      } else {
        createMessage.success(t('删除操作失败'));
      }
    });
  }
</script>