213 lines
5.6 KiB
Plaintext
213 lines
5.6 KiB
Plaintext
<template>
|
|
<div>
|
|
<div class="n-layout-page-header">
|
|
<a-card :bordered="false" title="导出示例"> 可以选择导出格式 </a-card>
|
|
</div>
|
|
<a-card :bordered="false" class="mt-4 proCard">
|
|
<BasicTable
|
|
leftTitle="表格列表"
|
|
leftTitleTooltip="这是一个提示"
|
|
:columns="columns"
|
|
:request="loadDataTable"
|
|
:row-key="(row) => row.id"
|
|
ref="actionRef"
|
|
:actionColumn="actionColumn"
|
|
@update:checked-row-keys="onCheckedRow"
|
|
>
|
|
<template #toolbar>
|
|
<a-button type="primary" @click="openModal">导出数据</a-button>
|
|
</template>
|
|
<template #bodyCell="{ column, record }">
|
|
<template v-if="column.key === 'action'">
|
|
<TableAction
|
|
:actions="[
|
|
{
|
|
label: '删除',
|
|
danger: true,
|
|
type: 'primary',
|
|
size: 'middle',
|
|
icon: renderIcon(DeleteOutlined),
|
|
popConfirm: {
|
|
title: '您真的,确定要删除吗?',
|
|
okText: '确定',
|
|
cancelText: '取消',
|
|
confirm: handleDelete.bind(null, record),
|
|
},
|
|
},
|
|
{
|
|
label: '编辑',
|
|
type: 'primary',
|
|
size: 'middle',
|
|
icon: renderIcon(FormOutlined),
|
|
onClick: handleEdit.bind(null, record),
|
|
},
|
|
]"
|
|
/>
|
|
</template>
|
|
</template>
|
|
</BasicTable>
|
|
</a-card>
|
|
|
|
<basicModal @register="modalRegister" ref="modalRef" class="basicModal" @on-ok="okModal">
|
|
<template #default>
|
|
<BasicForm
|
|
@register="register"
|
|
@submit="handleSubmit"
|
|
@reset="handleReset"
|
|
class="basicForm"
|
|
>
|
|
<template #statusSlot="{ model, field }">
|
|
<a-input v-model:value="model[field]" />
|
|
</template>
|
|
</BasicForm>
|
|
</template>
|
|
</basicModal>
|
|
</div>
|
|
</template>
|
|
|
|
<script lang="ts" setup>
|
|
import { reactive, unref, ref } from 'vue';
|
|
import { BasicTable, TableAction } from '@/components/Table';
|
|
import { basicModal, useModal } from '@/components/Modal';
|
|
import { BasicForm, FormSchema, useForm } from '@/components/Form/index';
|
|
import { getTableList } from '@/api/table/list';
|
|
import { columns } from '../../comp/table/basicColumns';
|
|
import { jsonToSheetXlsx } from '@/components/Excel';
|
|
import { Modal, message } from 'ant-design-vue';
|
|
import { DeleteOutlined, FormOutlined } from '@ant-design/icons-vue';
|
|
import { renderIcon } from '@/utils';
|
|
|
|
const schemas: FormSchema[] = [
|
|
{
|
|
name: 'filename',
|
|
component: 'Input',
|
|
label: '文件名',
|
|
labelMessage: '导出的文件以该名称命名',
|
|
componentProps: {
|
|
placeholder: '请输入文件名称',
|
|
onInput: (e: any) => {
|
|
console.log(e);
|
|
},
|
|
},
|
|
rules: [{ required: true, message: '请输入导出的文件名称', trigger: ['blur'] }],
|
|
},
|
|
{
|
|
name: 'bookType',
|
|
component: 'Select',
|
|
label: '文件类型',
|
|
componentProps: {
|
|
placeholder: '请选择文件类型',
|
|
options: [
|
|
{
|
|
label: 'xlsx',
|
|
value: 'xlsx',
|
|
},
|
|
{
|
|
label: 'html',
|
|
value: 'html',
|
|
},
|
|
{
|
|
label: 'csv',
|
|
value: 'csv',
|
|
},
|
|
{
|
|
label: 'txt',
|
|
value: 'txt',
|
|
},
|
|
],
|
|
onUpdateValue: (e: any) => {
|
|
console.log(e);
|
|
},
|
|
},
|
|
rules: [{ required: true, message: '请选择文件类型', trigger: ['change'] }],
|
|
},
|
|
];
|
|
|
|
const actionRef = ref();
|
|
const modalRef = ref();
|
|
const tableData = ref();
|
|
|
|
const params = reactive({
|
|
pageSize: 5,
|
|
name: 'xiaoMa',
|
|
});
|
|
|
|
const [modalRegister, { openModal }] = useModal({
|
|
title: '导出数据',
|
|
});
|
|
|
|
const [register, { submit }] = useForm({
|
|
// submitButtonText: '提交预约',
|
|
showActionButtonGroup: false,
|
|
schemas,
|
|
});
|
|
|
|
const actionColumn = reactive({
|
|
width: 150,
|
|
title: '操作',
|
|
key: 'action',
|
|
fixed: 'right',
|
|
align: 'center',
|
|
});
|
|
|
|
async function okModal() {
|
|
const formRes = await submit();
|
|
if (formRes) {
|
|
modalRef.value.closeModal();
|
|
message.success('提交成功');
|
|
} else {
|
|
message.error('验证失败,请填写完整信息');
|
|
modalRef.value.setSubLoading(false);
|
|
}
|
|
}
|
|
|
|
function handleReset(values: Recordable) {
|
|
console.log(values);
|
|
}
|
|
|
|
const loadDataTable = async (res) => {
|
|
const result = await getTableList({ ...params, ...res });
|
|
tableData.value = result.list;
|
|
return result;
|
|
};
|
|
|
|
function onCheckedRow(rowKeys) {
|
|
console.log(rowKeys);
|
|
}
|
|
|
|
function handleDelete(record) {
|
|
console.log(record);
|
|
Modal.confirm({
|
|
title: '提示',
|
|
content: `您想删除${record.name}`,
|
|
okText: '确认',
|
|
cancelText: '取消',
|
|
onOk() {
|
|
message.success('删除成功');
|
|
},
|
|
onCancel() {},
|
|
});
|
|
}
|
|
|
|
function handleEdit(record) {
|
|
console.log(record);
|
|
message.success('您点击了编辑按钮');
|
|
}
|
|
|
|
function handleSubmit(values: Recordable) {
|
|
console.log(values);
|
|
// 默认Object.keys(data[0])作为header
|
|
const { filename, bookType } = values;
|
|
jsonToSheetXlsx({
|
|
data: unref(tableData),
|
|
filename: `${filename.split('.').shift()}.${bookType}`,
|
|
write2excelOpts: {
|
|
bookType,
|
|
},
|
|
});
|
|
message.success(JSON.stringify(values));
|
|
}
|
|
</script>
|
|
|
|
<style lang="less" scoped></style>
|