Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
53ba21d
update:前端-优化useTerm实现代码
4linuxfun Jan 17, 2025
2143ded
update:后端-简化scheduler任务,删除不必要代码
4linuxfun Jan 21, 2025
8daef2b
update:后端-scheduler完善
4linuxfun Jan 21, 2025
ae16ea1
update:后端-排除websocket权限验证
4linuxfun Jan 21, 2025
19e8bad
update:后端-实现“任务管理”模块功能
4linuxfun Jan 21, 2025
f2bf6d5
update:前端-重构usePagination
4linuxfun Jan 21, 2025
bf8f03c
update:前端-实现“执行任务”功能
4linuxfun Jan 21, 2025
c3c18b5
update:前端usePagination分页增加initialPageSize参数
4linuxfun Feb 10, 2025
7647004
update:前端-任务管理分页日志默认改为5
4linuxfun Feb 10, 2025
3544264
update:service.sh脚本增加部分逻辑判断
4linuxfun Feb 10, 2025
c75e188
update:前端usePagination补全async写法
4linuxfun Feb 11, 2025
9091c98
update:前端-补全缺失组件引用
4linuxfun Feb 11, 2025
ac23b67
fix:前端-修复主机选择关联带出bug
4linuxfun Feb 11, 2025
f9f57b1
fix:前端-修复翻页多选状态保持问题
4linuxfun Feb 12, 2025
e6a1b58
update:后端-更新config配置模式
4linuxfun Feb 12, 2025
23865ae
update:后端-修改yaml配置后的参数
4linuxfun Feb 12, 2025
e9c7183
update:后端-更新服务控制脚本
4linuxfun Feb 12, 2025
e493d2c
update:后端-修改redis过期时间
4linuxfun Feb 12, 2025
28ba966
update:后端-任务管理功能模块实现
4linuxfun Feb 12, 2025
0413a51
update:更新README.md
4linuxfun Feb 13, 2025
fd9180a
update:后端-增加生产环境配置模板
4linuxfun Feb 13, 2025
9cb6b59
update:其他
4linuxfun Feb 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix:前端-修复翻页多选状态保持问题
  • Loading branch information
4linuxfun committed Feb 12, 2025
commit f9f57b1a5d3dee746307bba17e7d37bc58aeceb7
101 changes: 79 additions & 22 deletions www/src/views/jobs/components/AddTargetsDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
clearable
@change="handleSearch"/>
<el-table ref="tableRef" :data="tableData" border style="margin-top: 10px"
@selection-change="handleSelectionChange">
@select="handleSelect"
@select-all="handleSelectAll">
<el-table-column type="selection" label="#" align="center"/>
<el-table-column prop="name" label="主机名" align="center"/>
<el-table-column prop="ansible_host" label="主机IP" align="center"/>
Expand All @@ -37,7 +38,7 @@
</template>

<script setup>
import {ref} from 'vue'
import {ref, watch, nextTick} from 'vue'
import {GetAllGroup} from '@/api/host.js'
import usePagination from '@/composables/usePagination.js'

Expand All @@ -46,7 +47,7 @@
const visible = ref(false)
const allGroups = ref([])
const selectedHosts = ref([])
const initialSelected = ref([])
const isProgramSelect = ref(false)

const searchForm = {
name: null,
Expand Down Expand Up @@ -81,16 +82,55 @@
}

/**
* 处理表格选择变化
* 处理单行选择
*/
function handleSelectionChange(selection) {
// 如果是初始加载,使用initialSelected的值
if (initialSelected.value.length > 0) {
selectedHosts.value = initialSelected.value
initialSelected.value = []
function handleSelect(selection, row) {
console.log('handleSelect', selection, row)
if (isProgramSelect.value) {
isProgramSelect.value = false
return
}
selectedHosts.value = selection

// 检查是选中还是取消选中
const isSelected = selection.some(item => item.id === row.id)
if (isSelected) {
// 添加新选择的主机
if (!selectedHosts.value.some(host => host.id === row.id)) {
selectedHosts.value.push(row)
}
} else {
// 移除取消选择的主机
selectedHosts.value = selectedHosts.value.filter(host => host.id !== row.id)
}
console.log('selectedHosts', selectedHosts.value)
}

/**
* 处理全选
*/
function handleSelectAll(selection) {
console.log('handleSelectAll', selection)
if (isProgramSelect.value) {
isProgramSelect.value = false
return
}

// 获取当前页面上的所有主机ID
const currentPageIds = tableData.value.map(row => row.id)

if (selection.length > 0) {
// 全选:添加当前页面所有未选择的主机
const newSelection = tableData.value.filter(
row => !selectedHosts.value.some(host => host.id === row.id)
)
selectedHosts.value = [...selectedHosts.value, ...newSelection]
} else {
// 取消全选:移除当前页面的所有主机
selectedHosts.value = selectedHosts.value.filter(
host => !currentPageIds.includes(host.id)
)
}
console.log('selectedHosts', selectedHosts.value)
}

/**
Expand All @@ -104,32 +144,49 @@
return false
}

// 保存初始选中的主机到两个变量
initialSelected.value = JSON.parse(JSON.stringify(selected || []))
// 保存初始选中的主机
isProgramSelect.value = false
selectedHosts.value = JSON.parse(JSON.stringify(selected || []))

// 查询数据
await handleSearch()

console.log(tableData.value)
// 设置选中状态
setTableSelection()

visible.value = true
}

/**
* 设置表格选中状态
*/
function setTableSelection() {
if (!tableRef.value) return

isProgramSelect.value = true
// 先清除所有选中状态
tableData.value.forEach(row => {
tableRef.value?.toggleRowSelection(row, false)
tableRef.value.toggleRowSelection(row, false)
})

console.log('start to selected', selectedHosts.value)
// 设置选中状态
selectedHosts.value.forEach(item => {
console.log(item)
const found = tableData.value.find(data => data.id === item.id)
if (found) {
tableRef.value?.toggleRowSelection(found, true)
tableData.value.forEach(row => {
if (selectedHosts.value.some(selected => selected.id === row.id)) {
tableRef.value.toggleRowSelection(row, true)
}
})

visible.value = true
isProgramSelect.value = false
}

// 监听表格数据变化,重新设置选中状态
watch(tableData, () => {
if (visible.value) {
nextTick(() => {
setTableSelection()
})
}
})

defineExpose({add})
</script>

Expand Down