cwg-tabel.vue 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766
  1. <template>
  2. <view>
  3. <!-- 统一表格容器,根据屏幕宽度自适应 -->
  4. <view class="table-container" :class="{ 'mobile-table': isMobile }">
  5. <uni-table :type="selectionType" :border="false" @selection-change="handleSelectionChange" emptyText="">
  6. <!-- 表头:根据设备类型显示不同的列 -->
  7. <uni-tr class="table-header">
  8. <uni-th v-for="column in displayColumns" :key="column.prop" :align="column.align || 'center'"
  9. :width="column.width || '200'" :class="[headerClass, { sortable: column.sortable }]"
  10. :style="getHeaderStyle(column)" @click="column.sortable && handleSort(column)">
  11. <view class="header-content">
  12. {{ column.label }}
  13. <view v-if="column.sortable" class="sort-icon">
  14. <uni-icons :type="getSortIcon(column)" :size="14" color="#999" />
  15. </view>
  16. </view>
  17. </uni-th>
  18. </uni-tr>
  19. <!-- 表格主体 -->
  20. <template v-for="(row, rowIndex) in tableData" :key="rowIndex">
  21. <uni-tr>
  22. <!-- 数据列:根据设备类型动态渲染 -->
  23. <uni-td v-for="column in displayColumns" :key="column.prop" :align="column.align || 'center'"
  24. :class="getCellClass(column, row)" :style="getCellStyle(column, row)"
  25. @click="openRowDetail(row)">
  26. <template v-if="column.slot">
  27. <slot :name="column.slot" :row="row" :column="column" :index="rowIndex">
  28. {{ row[column.prop] }}
  29. </slot>
  30. </template>
  31. <uni-tag v-else-if="column.type === 'tag'" :text="formatTagText(row[column.prop], column)"
  32. :type="formatTagType(row[column.prop], column)" size="small" />
  33. <view v-else-if="column.type === 'file'">
  34. <cwg-file :path="row[column.prop]" />
  35. </view>
  36. <cwg-icon v-else-if="column.type === 'more'" name="crm-chevron-down"
  37. class="crm-chevron-down" :size="16" color="#007" />
  38. <template v-else>
  39. {{ formatCellValue(row[column.prop], column, row) }}
  40. </template>
  41. </uni-td>
  42. </uni-tr>
  43. <!-- 桌面端展开行(仅当非移动端且行展开时显示) -->
  44. <uni-tr v-if="!isMobile && expandedRows[rowIndex]" class="expand-row">
  45. <uni-td :colspan="columnSpan" class="expand-cell">
  46. <slot name="expand" :row="row" :rowIndex="rowIndex">
  47. <view class="default-expand-content">
  48. <text class="no-content">暂无展开内容</text>
  49. </view>
  50. </slot>
  51. </uni-td>
  52. </uni-tr>
  53. </template>
  54. </uni-table>
  55. </view>
  56. <!-- 空状态 -->
  57. <view v-if="tableData.length === 0">
  58. <cwg-empty-state />
  59. </view>
  60. <!-- 分页 -->
  61. <view class="pagination-container" v-if="showPagination && tableData.length > 0">
  62. <view class="pagination-info">
  63. <text>共 {{ pagination.total }} 条记录</text>
  64. <view v-if="showPageSize" class="page-size-select">
  65. <text>每页显示</text>
  66. <picker @change="handlePageSizeChange" :value="pageSizeIndex" :range="pageSizes">
  67. <view class="page-size-value">{{ pagination.pageSize }}条/页</view>
  68. </picker>
  69. </view>
  70. </view>
  71. <view class="pagination">
  72. <view class="page-item prev" :class="{ disabled: pagination.current === 1 }"
  73. @click="handlePageChange('prev')">
  74. <uni-icons type="arrowleft" size="16" color="#666" />
  75. <text>上一页</text>
  76. </view>
  77. <view class="page-numbers">
  78. <view v-for="page in visiblePages" :key="page" class="page-number"
  79. :class="{ active: pagination.current === page }" @click="handlePageChange(page)">
  80. {{ page }}
  81. </view>
  82. </view>
  83. <view class="page-item next" :class="{ disabled: pagination.current === pagination.pages }"
  84. @click="handlePageChange('next')">
  85. <text>下一页</text>
  86. <uni-icons type="arrowright" size="16" color="#666" />
  87. </view>
  88. </view>
  89. </view>
  90. <!-- 移动端详情弹窗 -->
  91. <cwg-detail-popup v-model:visible="detailVisible" title="详情" :items="detailItems" />
  92. </view>
  93. </template>
  94. <script setup>
  95. import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
  96. const props = defineProps({
  97. /**
  98. * 表格列配置(columns 数组中每一项是一个列配置对象)
  99. * - prop: 字段名,对应 row[prop],用于取值/排序/详情展示
  100. * - label: 表头显示文本(也会作为详情弹窗的 label)
  101. * - align: 对齐方式('left' | 'center' | 'right')
  102. * - width: 列宽(设置后该列固定宽度;未设置则自适应
  103. * - slot: 自定义渲染插槽名(<template #xxx="{ row, column, index }">),优先级最高
  104. * - formatter: ({ value, row }) => string | number,自定义格式化显示值(无 slot 时生效)
  105. * - sortable: 是否可排序(点击表头切换 asc/desc)
  106. * - headerStyle: 表头样式(对象),会合并到表头 style
  107. * - cellStyle: 单元格样式(对象或函数({ row, column }) => style)
  108. * - cellClass: 单元格 class(string 或函数({ row, column }) => string | string[])
  109. * - isTabel: false 时不在表格中显示该列,但仍会在“详情弹窗”中显示
  110. * - type: 内置渲染类型
  111. * - 'tag': 使用 uni-tag 渲染,搭配 tagMap/tagTypeMap
  112. * - 'file': 使用 cwg-file 渲染
  113. * - 'more': 展示“更多”图标(用于移动端点击查看详情等)
  114. * - 'date': 日期格式化(搭配 dateFormat)
  115. * - tagMap: 标签映射对象
  116. * - tagTypeMap: 标签类型映射对象
  117. * - dateFormat: 日期格式
  118. * */
  119. columns: { type: Array, required: true, default: () => [] },
  120. // 移动端配置
  121. mobilePrimaryCount: { type: Number, default: 3 },
  122. // 参数如columns
  123. mobilePrimaryFields: { type: Array, default: () => [] },
  124. // API 请求函数
  125. api: { type: Function, required: true },
  126. // 查询参数
  127. queryParams: { type: Object, default: () => ({}) },
  128. // 是否立即加载
  129. immediate: { type: Boolean, default: true },
  130. // 选择类型:'selection' | null
  131. selectionType: { type: String, default: null },
  132. // 是否显示每页条数选择
  133. showPageSize: { type: Boolean, default: true },
  134. // 是否显示分页
  135. showPagination: { type: Boolean, default: true },
  136. isViewDetail: { type: Boolean, default: true },
  137. // 每页条数选项
  138. pageSizes: { type: Array, default: () => [10, 20, 30, 50, 100] },
  139. // 默认每页条数
  140. defaultPageSize: { type: Number, default: 10 },
  141. // 表头样式自定义
  142. headerBackground: { type: String, default: '#fff' },
  143. headerColor: { type: String, default: 'var(--color-slate-800)' },
  144. headerFontSize: { type: [String, Number], default: '14rpx' },
  145. headerFontWeight: { type: [String, Number], default: 600 },
  146. headerHeight: { type: [String, Number], default: '40rpx' },
  147. headerClass: { type: [String, Array], default: '' },
  148. headerStyle: { type: Object, default: () => ({}) },
  149. stickyHeader: { type: Boolean, default: true },
  150. stickyOffset: { type: [String, Number], default: '0' },
  151. isPages: { type: Boolean, default: false },
  152. })
  153. const emit = defineEmits([
  154. 'selection-change',
  155. 'action-click',
  156. 'page-change',
  157. 'load-success',
  158. 'load-error',
  159. 'sort-change',
  160. 'go-pages'
  161. ])
  162. // ========== 响应式状态 ==========
  163. const tableData = ref([])
  164. const selectedItems = ref([])
  165. const detailVisible = ref(false)
  166. const detailItems = ref([])
  167. const pagination = ref({
  168. current: 1,
  169. pageSize: props.defaultPageSize,
  170. total: 0,
  171. pages: 0
  172. })
  173. const loading = ref(false)
  174. const expandedRows = ref({})
  175. // 移动端检测
  176. const isMobile = ref(false)
  177. // 排序状态
  178. const sortState = ref({ prop: '', order: '' }) // order: 'asc' | 'desc' | ''
  179. // ========== 计算属性 ==========
  180. // 显示的列(根据设备类型)
  181. const displayColumns = computed(() => {
  182. const filterForTable = (cols) => (cols || []).filter((c) => c && c.isTabel !== false)
  183. const normalizeColumns = (cols) => {
  184. if (!Array.isArray(cols)) return []
  185. if (cols.length === 0) return []
  186. const first = cols[0]
  187. if (typeof first === 'string') {
  188. return cols
  189. .map((prop) => props.columns.find((c) => c && c.prop === prop))
  190. .filter(Boolean)
  191. }
  192. return cols
  193. }
  194. if (!isMobile.value) return filterForTable(normalizeColumns(props.columns))
  195. if (props.mobilePrimaryFields && props.mobilePrimaryFields.length) {
  196. return filterForTable(normalizeColumns(props.mobilePrimaryFields))
  197. }
  198. return filterForTable(normalizeColumns(props.columns.slice(0, props.mobilePrimaryCount)))
  199. })
  200. // 列跨度(用于展开行)
  201. const columnSpan = computed(() => {
  202. let span = displayColumns.value.length
  203. if (props.showOperation) span += 1
  204. return span
  205. })
  206. // 每页条数索引
  207. const pageSizeIndex = computed(() => {
  208. return props.pageSizes.indexOf(pagination.value.pageSize)
  209. })
  210. // 可见页码
  211. const visiblePages = computed(() => {
  212. const maxVisible = 5
  213. const half = Math.floor(maxVisible / 2)
  214. let start = Math.max(1, pagination.value.current - half)
  215. let end = Math.min(pagination.value.pages, start + maxVisible - 1)
  216. if (end - start + 1 < maxVisible) {
  217. start = Math.max(1, end - maxVisible + 1)
  218. }
  219. return Array.from({ length: end - start + 1 }, (_, i) => start + i)
  220. })
  221. // ========== 工具函数 ==========
  222. // 获取表头样式
  223. const getHeaderStyle = (column) => {
  224. const baseStyle = {
  225. backgroundColor: props.headerBackground,
  226. color: props.headerColor,
  227. fontSize: typeof props.headerFontSize === 'number' ? props.headerFontSize + 'rpx' : props.headerFontSize,
  228. fontWeight: props.headerFontWeight,
  229. height: typeof props.headerHeight === 'number' ? props.headerHeight + 'rpx' : props.headerHeight,
  230. lineHeight: typeof props.headerHeight === 'number' ? props.headerHeight + 'rpx' : props.headerHeight,
  231. ...props.headerStyle
  232. }
  233. if (props.stickyHeader) {
  234. baseStyle.position = 'sticky'
  235. baseStyle.top = props.stickyOffset
  236. baseStyle.zIndex = 100
  237. }
  238. if (column.width) {
  239. const w = typeof column.width === 'number' ? column.width + 'px' : column.width
  240. baseStyle.width = w
  241. baseStyle.minWidth = w
  242. baseStyle.maxWidth = w
  243. }
  244. if (column.headerStyle) {
  245. Object.assign(baseStyle, column.headerStyle)
  246. }
  247. return baseStyle
  248. }
  249. // 获取单元格样式
  250. const getCellStyle = (column, row) => {
  251. const style = {}
  252. if (column.width) {
  253. const w = typeof column.width === 'number' ? column.width + 'px' : column.width
  254. style.width = w
  255. style.minWidth = w
  256. style.maxWidth = w
  257. style.whiteSpace = 'nowrap'
  258. style.overflow = 'hidden'
  259. style.textOverflow = 'ellipsis'
  260. }
  261. if (column.cellStyle) {
  262. if (typeof column.cellStyle === 'function') {
  263. Object.assign(style, column.cellStyle({ row, column }))
  264. } else {
  265. Object.assign(style, column.cellStyle)
  266. }
  267. }
  268. return style
  269. }
  270. // 获取单元格类名
  271. const getCellClass = (column, row) => {
  272. const classes = []
  273. if (column.cellClass) {
  274. if (typeof column.cellClass === 'function') {
  275. const result = column.cellClass({ row, column })
  276. if (result) {
  277. if (Array.isArray(result)) {
  278. classes.push(...result)
  279. } else {
  280. classes.push(result)
  281. }
  282. }
  283. } else {
  284. classes.push(column.cellClass)
  285. }
  286. }
  287. return classes.join(' ')
  288. }
  289. // 格式化单元格值
  290. const formatCellValue = (value, column, row) => {
  291. if (column.formatter) {
  292. return column.formatter({ value, row })
  293. }
  294. if (column.type === 'date' && value) {
  295. return formatDate(value, column.dateFormat || 'YYYY-MM-DD HH:mm:ss')
  296. }
  297. if (value === null || value === undefined) {
  298. return '-'
  299. }
  300. return value
  301. }
  302. // 格式化标签文本
  303. const formatTagText = (value, column) => {
  304. if (column.tagMap && column.tagMap[value]) {
  305. return column.tagMap[value]
  306. }
  307. return value || '-'
  308. }
  309. // 格式化标签类型
  310. const formatTagType = (value, column) => {
  311. if (column.tagTypeMap && column.tagTypeMap[value]) {
  312. return column.tagTypeMap[value]
  313. }
  314. return 'default'
  315. }
  316. // 格式化日期
  317. const formatDate = (date, format) => {
  318. if (!date) return '-'
  319. const d = new Date(date)
  320. const year = d.getFullYear()
  321. const month = String(d.getMonth() + 1).padStart(2, '0')
  322. const day = String(d.getDate()).padStart(2, '0')
  323. const hour = String(d.getHours()).padStart(2, '0')
  324. const minute = String(d.getMinutes()).padStart(2, '0')
  325. const second = String(d.getSeconds()).padStart(2, '0')
  326. return format
  327. .replace('YYYY', year)
  328. .replace('MM', month)
  329. .replace('DD', day)
  330. .replace('HH', hour)
  331. .replace('mm', minute)
  332. .replace('ss', second)
  333. }
  334. // 排序图标
  335. const getSortIcon = (column) => {
  336. if (sortState.value.prop !== column.prop) return 'arrow-up'
  337. return sortState.value.order === 'asc' ? 'arrow-up' : 'arrow-down'
  338. }
  339. // 处理排序
  340. const handleSort = (column) => {
  341. if (!column.sortable) return
  342. let newOrder = ''
  343. if (sortState.value.prop === column.prop) {
  344. if (sortState.value.order === '') newOrder = 'asc'
  345. else if (sortState.value.order === 'asc') newOrder = 'desc'
  346. else newOrder = ''
  347. } else {
  348. newOrder = 'asc'
  349. }
  350. sortState.value = { prop: newOrder ? column.prop : '', order: newOrder }
  351. emit('sort-change', { prop: sortState.value.prop, order: sortState.value.order })
  352. refreshTable()
  353. }
  354. // 展开行切换
  355. const toggleRowExpand = (rowIndex) => {
  356. const key = rowIndex
  357. if (expandedRows.value[key]) {
  358. expandedRows.value[key] = false
  359. } else {
  360. expandedRows.value = {}
  361. expandedRows.value[key] = true
  362. }
  363. emit('expand-change', { rowIndex, expanded: expandedRows.value[key] })
  364. }
  365. // 打开详情弹窗(移动端使用)
  366. const openRowDetail = (row) => {
  367. if (props.isPages) {
  368. emit('go-pages', row)
  369. } else {
  370. detailItems.value = props.columns
  371. .filter((column) => column && column.prop && column.label)
  372. .map((column) => ({
  373. label: column.label,
  374. value: String(formatCellValue(row[column.prop], column, row))
  375. }))
  376. detailVisible.value = true
  377. }
  378. }
  379. // ========== 数据加载 ==========
  380. const loadData = async () => {
  381. if (loading.value) return
  382. loading.value = true
  383. try {
  384. const applyPaginationFromRes = (res) => {
  385. const page = res && res.page
  386. if (!page) return false
  387. if (typeof page.current === 'number') pagination.value.current = page.current
  388. if (typeof page.row === 'number') pagination.value.pageSize = page.row
  389. if (typeof page.rowTotal === 'number') pagination.value.total = page.rowTotal
  390. if (typeof page.pageTotal === 'number') pagination.value.pages = page.pageTotal
  391. else if (typeof pagination.value.total === 'number' && typeof pagination.value.pageSize === 'number') {
  392. pagination.value.pages = Math.ceil(pagination.value.total / pagination.value.pageSize)
  393. }
  394. return true
  395. }
  396. const params = {
  397. page: {
  398. current: pagination.value.current,
  399. row: pagination.value.pageSize
  400. },
  401. ...props.queryParams
  402. }
  403. // 添加排序参数
  404. if (sortState.value.prop && sortState.value.order) {
  405. params.sort = { field: sortState.value.prop, order: sortState.value.order }
  406. }
  407. const res = await props.api(params)
  408. if (res.code === 200 || res.code === 0) {
  409. const data = res.data || res
  410. const hasPage = applyPaginationFromRes(res)
  411. if (Array.isArray(data)) {
  412. tableData.value = data
  413. if (!hasPage) {
  414. pagination.value.total = data.length
  415. pagination.value.pages = 1
  416. }
  417. } else if (data.list || data.records) {
  418. tableData.value = data.list || data.records
  419. if (!hasPage) {
  420. pagination.value.total = data.total || data.list?.length || 0
  421. pagination.value.pages = data.pages || Math.ceil(pagination.value.total / pagination.value.pageSize)
  422. }
  423. } else {
  424. tableData.value = []
  425. }
  426. emit('load-success', res)
  427. } else {
  428. throw new Error(res.message || '加载失败')
  429. }
  430. } catch (error) {
  431. console.error('表格数据加载失败:', error)
  432. uni.showToast({
  433. title: error.message || '加载失败',
  434. icon: 'none'
  435. })
  436. emit('load-error', error)
  437. } finally {
  438. loading.value = false
  439. }
  440. }
  441. // 刷新表格
  442. const refreshTable = () => {
  443. pagination.value.current = 1
  444. loadData()
  445. }
  446. const reload = () => {
  447. loadData()
  448. }
  449. // 分页变化
  450. const handlePageChange = (page) => {
  451. if (page === 'prev') {
  452. if (pagination.value.current > 1) pagination.value.current--
  453. else return
  454. } else if (page === 'next') {
  455. if (pagination.value.current < pagination.value.pages) pagination.value.current++
  456. else return
  457. } else {
  458. pagination.value.current = page
  459. }
  460. loadData()
  461. emit('page-change', pagination.value)
  462. }
  463. // 每页条数变化
  464. const handlePageSizeChange = (e) => {
  465. const size = props.pageSizes[e.detail.value]
  466. pagination.value.pageSize = size
  467. pagination.value.current = 1
  468. loadData()
  469. }
  470. // 选择变化
  471. const handleSelectionChange = (e) => {
  472. selectedItems.value = e.detail.value
  473. emit('selection-change', selectedItems.value)
  474. }
  475. // 获取选中项
  476. const getSelectedItems = () => selectedItems.value
  477. const clearSelection = () => { selectedItems.value = [] }
  478. // ========== 移动端检测 ==========
  479. const checkIsMobile = () => {
  480. // 适配 uni-app 环境
  481. // #ifdef H5
  482. const width = window.innerWidth
  483. isMobile.value = width < 991
  484. // #endif
  485. // #ifndef H5
  486. const systemInfo = uni.getSystemInfoSync()
  487. isMobile.value = systemInfo.windowWidth < 991
  488. // #endif
  489. }
  490. // 监听窗口大小变化(仅 H5)
  491. // #ifdef H5
  492. const handleResize = () => {
  493. checkIsMobile()
  494. }
  495. // #endif
  496. // ========== 监听参数变化 ==========
  497. watch(() => props.queryParams, () => {
  498. refreshTable()
  499. }, { deep: true })
  500. // ========== 生命周期 ==========
  501. onMounted(() => {
  502. checkIsMobile()
  503. // #ifdef H5
  504. window.addEventListener('resize', handleResize)
  505. // #endif
  506. if (props.immediate) {
  507. loadData()
  508. }
  509. })
  510. onUnmounted(() => {
  511. // #ifdef H5
  512. window.removeEventListener('resize', handleResize)
  513. // #endif
  514. })
  515. // 暴露方法
  516. defineExpose({
  517. refreshTable,
  518. reload,
  519. getSelectedItems,
  520. clearSelection,
  521. loadData,
  522. tableData,
  523. toggleRowExpand,
  524. pagination
  525. })
  526. </script>
  527. <style scoped lang="scss">
  528. @import "@/uni.scss";
  529. .table-container {
  530. width: 100%;
  531. // overflow-x: auto;
  532. // -webkit-overflow-scrolling: touch;
  533. max-height: calc(100vh - 209px);
  534. color: var(--color-slate-800);
  535. :deep(.uni-table-scroll) {
  536. width: 100%;
  537. max-height: calc(100vh - 375px);
  538. // overflow: auto;
  539. }
  540. :deep(.uni-table) {
  541. min-height: px2rpx(100) !important;
  542. .uni-table-th {
  543. position: sticky;
  544. top: 0;
  545. z-index: 100;
  546. transition: all 0.3s;
  547. .header-content {
  548. display: flex;
  549. align-items: center;
  550. justify-content: center;
  551. gap: 4px;
  552. .sort-icon {
  553. display: inline-flex;
  554. cursor: pointer;
  555. }
  556. }
  557. &.sortable {
  558. cursor: pointer;
  559. &:hover .sort-icon .uni-icons {
  560. color: var(--color-primary) !important;
  561. }
  562. }
  563. &::after {
  564. display: none;
  565. }
  566. }
  567. .uni-table-tr {
  568. &:last-child {
  569. border-bottom: none !important;
  570. }
  571. .uni-table-th {
  572. border-bottom: 1px solid #141d22 !important;
  573. }
  574. }
  575. .uni-table-th,
  576. .uni-table-td {
  577. padding: px2rpx(16) px2rpx(5);
  578. color: var(--color-slate-800);
  579. box-sizing: border-box;
  580. }
  581. .expand-cell {
  582. padding: 0 !important;
  583. }
  584. }
  585. }
  586. .crm-chevron-down {
  587. transform: rotate(-90deg);
  588. cursor: pointer;
  589. }
  590. .mobile-table {
  591. :deep(.uni-table) {
  592. min-width: 0 !important;
  593. }
  594. }
  595. .detail-btn-mobile {
  596. background-color: #f0f0f0;
  597. color: #333;
  598. }
  599. /* 分页样式 */
  600. .pagination-container {
  601. margin: px2rpx(20) px2rpx(20);
  602. display: flex;
  603. align-items: center;
  604. justify-content: flex-end;
  605. gap: px2rpx(20);
  606. .pagination {
  607. display: flex;
  608. align-items: center;
  609. padding: px2rpx(10);
  610. }
  611. .page-item {
  612. display: flex;
  613. align-items: center;
  614. padding: 0 px2rpx(12);
  615. height: px2rpx(30);
  616. background-color: var(--color-white);
  617. border: 1px solid #dcdfe6;
  618. border-radius: px2rpx(8);
  619. font-size: px2rpx(16);
  620. color: #606266;
  621. cursor: pointer;
  622. transition: all 0.3s;
  623. margin: 0 px2rpx(6);
  624. }
  625. .page-item.prev {
  626. margin-right: px2rpx(10);
  627. }
  628. .page-item.next {
  629. margin-left: px2rpx(10);
  630. }
  631. .page-item:not(.disabled):hover {
  632. color: #007aff;
  633. border-color: #007aff;
  634. }
  635. .page-item.disabled {
  636. opacity: 0.5;
  637. cursor: not-allowed;
  638. pointer-events: none;
  639. }
  640. .page-numbers {
  641. display: flex;
  642. gap: px2rpx(8);
  643. }
  644. .page-number {
  645. display: flex;
  646. align-items: center;
  647. justify-content: center;
  648. min-width: px2rpx(40);
  649. height: px2rpx(30);
  650. padding: 0 px2rpx(4);
  651. background-color: var(--color-white);
  652. border-radius: px2rpx(8);
  653. font-size: px2rpx(16);
  654. color: #606266;
  655. cursor: pointer;
  656. transition: all 0.3s;
  657. }
  658. .page-number:hover {
  659. color: #007aff;
  660. border-color: #007aff;
  661. }
  662. .page-number.active {
  663. background-color: #007aff;
  664. border-color: #007aff;
  665. color: #fff;
  666. }
  667. .pagination-info {
  668. display: flex;
  669. align-items: center;
  670. gap: px2rpx(30);
  671. font-size: px2rpx(16);
  672. color: #909399;
  673. }
  674. .page-size-select {
  675. display: flex;
  676. align-items: center;
  677. gap: px2rpx(10);
  678. }
  679. .page-size-value {
  680. padding: px2rpx(6) px2rpx(20);
  681. border: 1px solid #dcdfe6;
  682. border-radius: px2rpx(8);
  683. color: #606266;
  684. }
  685. }
  686. @media screen and (max-width: 768px) {
  687. .pagination {
  688. flex-wrap: wrap;
  689. justify-content: center;
  690. }
  691. .page-item {
  692. padding: 0 px2rpx(16);
  693. }
  694. .page-number {
  695. min-width: px2rpx(60);
  696. }
  697. .pagination-info {
  698. flex-direction: column;
  699. gap: px2rpx(10);
  700. }
  701. }
  702. </style>