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 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
| <template> <a-layout> <a-layout-content :style="{ background: '#fff', padding: '24px', margin: 0, minHeight: '280px' }" > <a-table :columns="columns" :row-key="record => record.id" :data-source="ebooks" :pagination="pagination" :loading="loading" @change="handleTableChange" > <template #cover="{ text: cover }"> <img v-if="cover" :src="cover" alt="avatar" /> </template> <template v-slot:action="{ text, record }"> <a-space size="small"> <a-button type="primary" @click="edit(record)"> 编辑 </a-button> <a-button type="danger"> 删除 </a-button> </a-space> </template> </a-table> </a-layout-content> </a-layout>
<a-modal title="电子书表单" v-model:visible="modalVisible" :confirm-loading="modalLoading" @ok="handleModalOk" > <a-form :model="ebook" :label-col="{ span: 6 }" :wrapper-col="{ span: 18 }"> <a-form-item label="封面"> <a-input v-model:value="ebook.cover" /> </a-form-item> <a-form-item label="名称"> <a-input v-model:value="ebook.name" /> </a-form-item> <a-form-item label="分类一"> <a-input v-model:value="ebook.category1Id" /> </a-form-item> <a-form-item label="分类二"> <a-input v-model:value="ebook.category2Id" /> </a-form-item> <a-form-item label="描述"> <a-input v-model:value="ebook.desc" type="textarea" /> </a-form-item> </a-form> </a-modal> </template>
<script lang="ts"> import { defineComponent, onMounted, ref } from 'vue'; import axios from 'axios';
export default defineComponent({ name: 'AdminEbook', setup() { const ebooks = ref(); const pagination = ref({ current: 1, pageSize: 4, total: 0 }); const loading = ref(false);
const columns = [ { title: '封面', dataIndex: 'cover', slots: { customRender: 'cover' } }, { title: '名称', dataIndex: 'name' }, { title: '分类一', key: 'category1Id', dataIndex: 'category1Id' }, { title: '分类二', dataIndex: 'category2Id' }, { title: '文档数', dataIndex: 'docCount' }, { title: '阅读数', dataIndex: 'viewCount' }, { title: '点赞数', dataIndex: 'voteCount' }, { title: 'Action', key: 'action', slots: { customRender: 'action' } } ];
/** * 数据查询 **/ const handleQuery = (params: any) => { loading.value = true; axios.get("/ebook/list", { params: { page: params.page, size: params.size } }).then((response) => { loading.value = false; const data = response.data; ebooks.value = data.content.list;
// 重置分页按钮 pagination.value.current = params.page; pagination.value.total = data.content.total; }); };
/** * 表格点击页码时触发 */ const handleTableChange = (pagination: any) => { console.log("看看自带的分页参数都有啥:" + pagination); handleQuery({ page: pagination.current, size: pagination.pageSize }); };
// -------- 表单 --------- const ebook = ref({}); const modalVisible = ref(false); const modalLoading = ref(false); const handleModalOk = () => { modalLoading.value = true; setTimeout(() => { modalVisible.value = false; modalLoading.value = false; }, 2000); };
/** * 编辑 */ const edit = (record: any) => { modalVisible.value = true; ebook.value = record };
onMounted(() => { handleQuery({ page: 1, size: pagination.value.pageSize, }); });
return { ebooks, pagination, columns, loading, handleTableChange,
edit,
ebook, modalVisible, modalLoading, handleModalOk } } }); </script>
<style scoped> img { width: 50px; height: 50px; } </style>
|