123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183 |
- <template>
- <div class="h-full overflow-hidden">
- <n-card title="字段管理" :bordered="false" class="rounded-16px shadow-sm">
- <n-space class="pb-12px" justify="space-between">
- <n-space>
- <n-button type="primary" @click="handleAddTable">
- <icon-ic-round-plus class="mr-4px text-20px" />
- 新增
- </n-button>
- <n-button type="success">
- <icon-uil:export class="mr-4px text-20px" />
- 导出Excel
- </n-button>
- </n-space>
- <n-space align="center" :size="18">
- <n-input-group>
- <n-input v-model:value="fieldName" />
- <n-button type="primary" @click="handleSearch">搜索</n-button>
- </n-input-group>
- <n-button size="small" type="primary" @click="getTableData">
- <icon-mdi-refresh class="mr-4px text-16px" :class="{ 'animate-spin': loading }" />
- 刷新表格
- </n-button>
- </n-space>
- </n-space>
- <n-data-table :columns="columns" :data="tableData" :loading="loading" :pagination="pagination" />
- <table-action-modal v-model:visible="visible" :type="modalType" :edit-data="editData" />
- </n-card>
- </div>
- </template>
- <script setup lang="tsx">
- import { reactive, ref } from 'vue';
- import type { Ref } from 'vue';
- import { NButton, NPopconfirm, NSpace } from 'naive-ui';
- import type { DataTableColumns, PaginationProps } from 'naive-ui';
- import { useBoolean, useLoading } from '@/hooks';
- import { fetchFieldList } from '@/service/api/event';
- import TableActionModal from './components/table-action-modal.vue';
- import type { ModalType } from './components/table-action-modal.vue';
- const { loading, startLoading, endLoading } = useLoading(false);
- const { bool: visible, setTrue: openModal } = useBoolean();
- const fieldName = ref('');
- const tableData = ref<BackgroundField.Field[]>([]);
- function setTableData(data: BackgroundField.Field[]) {
- tableData.value = data;
- }
- async function getTableData() {
- startLoading();
- const { data } = await fetchFieldList();
- if (data) {
- setTimeout(() => {
- setTableData(data);
- endLoading();
- }, 1000);
- }
- }
- const columns: Ref<DataTableColumns<BackgroundField.Field>> = ref([
- {
- type: 'selection',
- align: 'center'
- },
- {
- key: 'index',
- title: '序号',
- align: 'center'
- },
- {
- key: 'fieldName',
- title: '字段名称',
- align: 'center'
- },
- {
- key: 'fieldType',
- title: '字段类型',
- align: 'center'
- },
- {
- key: 'componentsType',
- title: '组件类型',
- align: 'center'
- },
- {
- key: 'filedLen',
- title: '字段长度',
- align: 'center'
- },
- {
- key: 'minValue',
- title: '最小值',
- align: 'center'
- },
- {
- key: 'maxValue',
- title: '最大值',
- align: 'center'
- },
- {
- key: 'actions',
- title: '操作',
- align: 'center',
- render: row => {
- return (
- <NSpace justify={'center'}>
- <NButton size={'small'} onClick={() => handleEditTable(row.id)}>
- 编辑
- </NButton>
- <NPopconfirm onPositiveClick={() => handleDeleteTable(row.id)}>
- {{
- default: () => '确认删除',
- trigger: () => <NButton size={'small'}>删除</NButton>
- }}
- </NPopconfirm>
- </NSpace>
- );
- }
- }
- ]) as Ref<DataTableColumns<BackgroundField.Field>>;
- const modalType = ref<ModalType>('add');
- function setModalType(type: ModalType) {
- modalType.value = type;
- }
- const editData = ref<BackgroundField.Field | null>(null);
- function setEditData(data: BackgroundField.Field | null) {
- editData.value = data;
- }
- function handleAddTable() {
- openModal();
- setModalType('add');
- }
- function handleEditTable(rowId: number) {
- const findItem = tableData.value.find(item => item.id === rowId);
- if (findItem) {
- setEditData(findItem);
- }
- setModalType('edit');
- openModal();
- }
- function handleDeleteTable(rowId: number) {
- window.$message?.info(`点击了删除,rowId为${rowId}`);
- }
- const pagination: PaginationProps = reactive({
- page: 1,
- pageSize: 10,
- showSizePicker: true,
- pageSizes: [10, 15, 20, 25, 30],
- onChange: (page: number) => {
- pagination.page = page;
- },
- onUpdatePageSize: (pageSize: number) => {
- pagination.pageSize = pageSize;
- pagination.page = 1;
- }
- });
- function handleSearch() {
- if (!fieldName.value) {
- window.$message?.warning('请输入字段名称');
- } else {
- console.log(fieldName.value);
- }
- }
- function init() {
- getTableData();
- }
- // 初始化
- init();
- </script>
- <style scoped></style>
|