Selaa lähdekoodia

feat(machine): enhance listMachines API and improve machine index view

- Updated the `listMachines` function to accept additional parameters for keyword search, enabled status, and sorting options.
- Modified the machine index view to construct and utilize the new query parameters for fetching machine data.
- Improved the overall user experience by allowing more flexible filtering and sorting of machine listings.
yb 2 viikkoa sitten
vanhempi
commit
d228003459

+ 8 - 1
src/api/machine.ts

@@ -9,7 +9,14 @@ import type {
 } from '@/types'
 
 // 获取机器列表
-export function listMachines(params?: { page?: number; pageSize?: number }): Promise<IResponse<MachineDTO>> {
+export function listMachines(params?: {
+  page?: number
+  size?: number
+  keyword?: string
+  enabled?: boolean
+  sortBy?: string
+  sortDir?: 'ASC' | 'DESC'
+}): Promise<IResponse<MachineDTO>> {
   return get('/admin/machines/list', params)
 }
 

+ 3 - 1
src/assets/styles/theme/element-override.scss

@@ -37,7 +37,9 @@
 }
 
 // Default 按钮 hover - 单色系配色(排除其他类型按钮)
-.el-button--default:not(.is-disabled):not(.el-button--primary):not(.el-button--danger):not(.el-button--success):not(.el-button--warning):not(.el-button--info) {
+.el-button--default:not(.is-disabled):not(.el-button--primary):not(.el-button--danger):not(.el-button--success):not(
+    .el-button--warning
+  ):not(.el-button--info) {
   &:hover,
   &:focus {
     --el-button-hover-bg-color: var(--color-primary-light-9);

+ 1 - 1
src/locales/en.json

@@ -154,4 +154,4 @@
   "重置": "Reset",
   "静音": "Muted",
   "项": "items"
-}
+}

+ 22 - 1
src/views/machine/index.vue

@@ -314,7 +314,26 @@ const rules: FormRules = {
 async function getList() {
   loading.value = true
   try {
-    const res = await listMachines({ page: currentPage.value, pageSize: pageSize.value })
+    // 构建查询参数
+    const params: Record<string, any> = {
+      page: currentPage.value,
+      size: pageSize.value
+    }
+    // 搜索关键词(机器ID或名称)
+    if (searchForm.machineId || searchForm.name) {
+      params.keyword = searchForm.machineId || searchForm.name
+    }
+    // 启用状态过滤
+    if (searchForm.enabled !== '') {
+      params.enabled = searchForm.enabled
+    }
+    // 排序
+    if (sortState.prop && sortState.order) {
+      params.sortBy = sortState.prop
+      params.sortDir = sortState.order === 'ascending' ? 'ASC' : 'DESC'
+    }
+
+    const res = await listMachines(params)
     if (res.success) {
       machineList.value = res.data.list
       total.value = res.data.total || 0
@@ -338,12 +357,14 @@ function handleReset() {
   // 重置排序
   sortState.prop = ''
   sortState.order = null
+  getList()
 }
 
 // 排序变化处理
 function handleSortChange({ prop, order }: { prop: string; order: 'ascending' | 'descending' | null }) {
   sortState.prop = prop || ''
   sortState.order = order
+  getList()
 }
 
 // 选择变化处理