commit
e98c66cc09
@ -1,9 +1,8 @@
|
|||||||
export type TableData = {
|
export interface TableData {
|
||||||
id: string
|
ProjectId: string
|
||||||
author: string
|
ProjectStage: string
|
||||||
title: string
|
CarType: string
|
||||||
content: string
|
Creator: string
|
||||||
importance: number
|
CreateTime: string
|
||||||
display_time: string
|
id?: number
|
||||||
pageviews: number
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,20 +1,125 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="tsx">
|
||||||
import { ElInput } from 'element-plus'
|
|
||||||
import { ContentWrap } from '@/components/ContentWrap'
|
import { ContentWrap } from '@/components/ContentWrap'
|
||||||
import { useI18n } from '@/hooks/web/useI18n'
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
|
import { Table, TableColumn } from '@/components/Table'
|
||||||
|
import { getTableListApi } from '@/api/table'
|
||||||
|
import { TableData } from '@/api/table/types'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
import { ElTag, ElPagination } from 'element-plus'
|
||||||
|
import { BaseButton } from '@/components/Button'
|
||||||
|
import TableColumns from './modules/TableColumn'
|
||||||
|
|
||||||
defineOptions({
|
interface Params {
|
||||||
name: 'Menu2'
|
pageIndex?: number
|
||||||
})
|
pageSize?: number
|
||||||
|
}
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
const text = ref('')
|
const columns: TableColumn[] = [
|
||||||
|
...TableColumns,
|
||||||
|
{
|
||||||
|
field: 'action',
|
||||||
|
label: '操作',
|
||||||
|
slots: {
|
||||||
|
default: (data) => {
|
||||||
|
return (
|
||||||
|
<div class="flex gap-2">
|
||||||
|
<BaseButton type="primary" onClick={() => actionFn(data)}>
|
||||||
|
操作
|
||||||
|
</BaseButton>
|
||||||
|
<BaseButton type="danger" onClick={() => handleDelete(data)}>
|
||||||
|
删除
|
||||||
|
</BaseButton>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const loading = ref(true)
|
||||||
|
|
||||||
|
const tableDataList = ref<TableData[]>([])
|
||||||
|
|
||||||
|
// 分页相关数据
|
||||||
|
const currentPage = ref(1)
|
||||||
|
const pageSize = ref(10)
|
||||||
|
const total = ref(0)
|
||||||
|
|
||||||
|
const getTableList = async (params?: Params) => {
|
||||||
|
loading.value = true
|
||||||
|
const res = await getTableListApi(
|
||||||
|
params || {
|
||||||
|
pageIndex: currentPage.value,
|
||||||
|
pageSize: pageSize.value
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch(() => {})
|
||||||
|
.finally(() => {
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
if (res) {
|
||||||
|
tableDataList.value = res.data.list
|
||||||
|
total.value = res.data.total // 设置总数
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 分页方法
|
||||||
|
const handleSizeChange = (val: number) => {
|
||||||
|
pageSize.value = val
|
||||||
|
getTableList()
|
||||||
|
}
|
||||||
|
|
||||||
|
const handleCurrentChange = (val: number) => {
|
||||||
|
currentPage.value = val
|
||||||
|
getTableList()
|
||||||
|
}
|
||||||
|
|
||||||
|
// 初始加载
|
||||||
|
getTableList()
|
||||||
|
|
||||||
|
const actionFn = (data: any) => {
|
||||||
|
console.log(data)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 添加删除方法
|
||||||
|
const handleDelete = (data: any) => {
|
||||||
|
console.log('删除', data)
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<ContentWrap :title="t('levelDemo.menu')">
|
<ContentWrap :title="t('tableDemo.table')" :message="t('tableDemo.tableDes')">
|
||||||
<div class="flex items-center"> Menu2: <ElInput v-model="text" class="pl-20px" /> </div>
|
<div class="table-container">
|
||||||
|
<Table
|
||||||
|
:columns="columns"
|
||||||
|
:data="tableDataList"
|
||||||
|
:loading="loading"
|
||||||
|
:defaultSort="{ prop: 'display_time', order: 'descending' }"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div class="pagination-container">
|
||||||
|
<el-pagination
|
||||||
|
v-model:current-page="currentPage"
|
||||||
|
v-model:page-size="pageSize"
|
||||||
|
:page-sizes="[10, 20, 50, 100]"
|
||||||
|
:total="total"
|
||||||
|
layout="total, sizes, prev, pager, next, jumper"
|
||||||
|
@size-change="handleSizeChange"
|
||||||
|
@current-change="handleCurrentChange"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</ContentWrap>
|
</ContentWrap>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
<style lang="less" scoped>
|
||||||
|
.table-container {
|
||||||
|
.pagination-container {
|
||||||
|
margin-top: 20px;
|
||||||
|
display: flex;
|
||||||
|
justify-content: flex-end;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@ -0,0 +1,26 @@
|
|||||||
|
import { ElTag } from 'element-plus'
|
||||||
|
|
||||||
|
const columns = [
|
||||||
|
{
|
||||||
|
field: 'ProjectId',
|
||||||
|
label: '項目ID'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'ProjectStage',
|
||||||
|
label: '項目階段'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'CarType',
|
||||||
|
label: '車輛類型'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'Creator',
|
||||||
|
label: '創建人'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'CreateTime',
|
||||||
|
label: '創建時間'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
export default columns
|
||||||
@ -0,0 +1,105 @@
|
|||||||
|
<script setup lang="tsx">
|
||||||
|
import { ContentWrap } from '@/components/ContentWrap'
|
||||||
|
import { useI18n } from '@/hooks/web/useI18n'
|
||||||
|
import { Table, TableColumn } from '@/components/Table'
|
||||||
|
import { getTableListApi } from '@/api/table'
|
||||||
|
import { TableData } from '@/api/table/types'
|
||||||
|
import { ref, h } from 'vue'
|
||||||
|
import { ElTag } from 'element-plus'
|
||||||
|
import { BaseButton } from '@/components/Button'
|
||||||
|
|
||||||
|
interface Params {
|
||||||
|
pageIndex?: number
|
||||||
|
pageSize?: number
|
||||||
|
}
|
||||||
|
|
||||||
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
const columns: TableColumn[] = [
|
||||||
|
{
|
||||||
|
field: 'title',
|
||||||
|
label: t('tableDemo.title')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'author',
|
||||||
|
label: t('tableDemo.author')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'display_time',
|
||||||
|
label: t('tableDemo.displayTime'),
|
||||||
|
sortable: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'importance',
|
||||||
|
label: t('tableDemo.importance'),
|
||||||
|
formatter: (_: Recordable, __: TableColumn, cellValue: number) => {
|
||||||
|
return h(
|
||||||
|
ElTag,
|
||||||
|
{
|
||||||
|
type: cellValue === 1 ? 'success' : cellValue === 2 ? 'warning' : 'danger'
|
||||||
|
},
|
||||||
|
() =>
|
||||||
|
cellValue === 1
|
||||||
|
? t('tableDemo.important')
|
||||||
|
: cellValue === 2
|
||||||
|
? t('tableDemo.good')
|
||||||
|
: t('tableDemo.commonly')
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'pageviews',
|
||||||
|
label: t('tableDemo.pageviews')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
field: 'action',
|
||||||
|
label: t('tableDemo.action'),
|
||||||
|
slots: {
|
||||||
|
default: (data) => {
|
||||||
|
return (
|
||||||
|
<BaseButton type="primary" onClick={() => actionFn(data)}>
|
||||||
|
{t('tableDemo.action')}
|
||||||
|
</BaseButton>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
|
||||||
|
const loading = ref(true)
|
||||||
|
|
||||||
|
const tableDataList = ref<TableData[]>([])
|
||||||
|
|
||||||
|
const getTableList = async (params?: Params) => {
|
||||||
|
const res = await getTableListApi(
|
||||||
|
params || {
|
||||||
|
pageIndex: 1,
|
||||||
|
pageSize: 10
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.catch(() => {})
|
||||||
|
.finally(() => {
|
||||||
|
loading.value = false
|
||||||
|
})
|
||||||
|
if (res) {
|
||||||
|
tableDataList.value = res.data.list
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
getTableList()
|
||||||
|
|
||||||
|
const actionFn = (data: any) => {
|
||||||
|
console.log(data)
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<ContentWrap :title="t('tableDemo.table')" :message="t('tableDemo.tableDes')">
|
||||||
|
<Table
|
||||||
|
:columns="columns"
|
||||||
|
:data="tableDataList"
|
||||||
|
:loading="loading"
|
||||||
|
:defaultSort="{ prop: 'display_time', order: 'descending' }"
|
||||||
|
/>
|
||||||
|
</ContentWrap>
|
||||||
|
</template>
|
||||||
Loading…
Reference in New Issue