<!-- Description: 算法数据 Author: 李亚光 Date: 2024-11-07 --> <script lang="ts" setup name="ModelManagePage"> import { ElMessage, ElMessageBox } from 'element-plus' import addDialog from './components/addDialog.vue' import { getModelList, removeModel } from '@/api/page/model' // 获取页面高度 const pageHeight = ref(window.innerHeight - 50 - 60 - 20 - 20 - 10 - 30 - 15 - 15 - 20) window.addEventListener('resize', () => { pageHeight.value = window.innerHeight - 50 - 60 - 20 - 20 - 10 - 30 - 15 - 15 - 20 }) const loadingTable = ref(true) const total = ref(0) const list = ref<any[]>([]) const columns = ref([ { text: '算法名称', value: 'name', align: 'center' }, { text: '算法ID', value: 'id', align: 'center' }, { text: '版本号', value: 'version', align: 'center' }, { text: '算法简述', value: 'remark', align: 'center' }, { text: '使用状态', value: 'usage_status', align: 'center' }, ]) // 查询条件 const listQuery = ref({ limit: 20, offset: 1, name: '', }) // 获取数据 const fetchData = () => { loadingTable.value = true getModelList(listQuery.value).then((res) => { console.log(res.data, '算法数据') list.value = res.data.items total.value = res.data.total loadingTable.value = false }).catch(() => { loadingTable.value = false }) } fetchData() // 重置 const reset = () => { // datetimerange.value = [] listQuery.value = { limit: 20, offset: 1, name: '', } fetchData() } // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写 const changePage = (val: { size: number; page: number }) => { if (val && val.size) { listQuery.value.limit = val.size } if (val && val.page) { listQuery.value.offset = val.page } fetchData() } const addRef = ref() const addRow = (row: any, type: string) => { addRef.value.initDialog(row, type) } // 删除 const deleteRow = (row: any) => { ElMessageBox.confirm( '确定要该数据吗?', '确认操作', { confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning', }, ).then(() => { removeModel(row.id).then(() => { ElMessage.success('操作成功') fetchData() }) }) } </script> <template> <!-- 布局 --> <app-container> <add-dialog ref="addRef" @refresh="fetchData" /> <search-area :need-clear="true" @search="fetchData" @clear="reset"> <search-item> <el-input v-model.trim="listQuery.name" placeholder="算法名称" clearable /> </search-item> </search-area> <table-container> <template #btns-right> <!-- 操作 --> <div> <el-button type="primary" @click="addRow({}, 'create')"> 新建 </el-button> </div> </template> <!-- 查询结果Table显示 --> <normal-table :data="list" :total="total" :columns="columns" :query="listQuery" :list-loading="loadingTable" :height="pageHeight" @change="changePage" > <template #preColumns> <el-table-column label="序号" width="90" align="center"> <template #default="scope"> {{ (listQuery.offset - 1) * listQuery.limit + scope.$index + 1 }} </template> </el-table-column> </template> <template #columns> <el-table-column label="操作" align="center" width="160"> <template #default="scope"> <el-button type="primary" link size="small" @click="addRow(scope.row, 'update')"> 编辑 </el-button> <el-button type="danger" link size="small" @click="deleteRow(scope.row)"> 删除 </el-button> </template> </el-table-column> </template> </normal-table> </table-container> </app-container> </template>