diff --git a/src/api/modules/card.ts b/src/api/modules/card.ts index 9d043b7..241b707 100644 --- a/src/api/modules/card.ts +++ b/src/api/modules/card.ts @@ -315,7 +315,7 @@ export class CardService extends BaseService { * @param params 查询参数 */ static getStandaloneIotCards(params?: any): Promise> { - return this.getPage('/api/admin/iot-cards/standalone', { is_standalone: true, ...params }) + return this.getPage('/api/admin/iot-cards/standalone', params) } /** diff --git a/src/views/polling-management/manual-trigger/index.vue b/src/views/polling-management/manual-trigger/index.vue index 7cefc95..b407cd1 100644 --- a/src/views/polling-management/manual-trigger/index.vue +++ b/src/views/polling-management/manual-trigger/index.vue @@ -81,10 +81,11 @@ - + - - + +
+ +
+ 已选择 {{ selectedBatchCards.length }} 张卡 + + 最多选择1000张卡 + +
+ + + + + + + + + + +
@@ -334,10 +398,137 @@ // 批量触发表单 const batchForm = reactive({ - task_type: '' as TaskType | '', - card_ids_text: '' + task_type: '' as TaskType | '' }) + // 批量触发弹窗中的卡列表相关数据 + const batchCardList = ref([]) + const batchCardLoading = ref(false) + const batchCardPagination = reactive({ + page: 1, + pageSize: 20, + total: 0 + }) + const cardSearchKeyword = ref('') + const cardSearchForm = reactive({ + keyword: '', + card_status: undefined as number | undefined + }) + const selectedBatchCards = ref([]) + const batchCardTableRef = ref() + + // 搜索防抖定时器 + let cardSearchTimer: any = null + + // 获取批量触发弹窗中的卡列表 + const getBatchCardList = async () => { + batchCardLoading.value = true + try { + const params: any = { + page: batchCardPagination.page, + page_size: batchCardPagination.pageSize, + ...cardSearchForm + } + Object.keys(params).forEach((key) => { + if (params[key] === '' || params[key] === undefined) { + delete params[key] + } + }) + const res = await CardService.getStandaloneIotCards(params) + if (res.code === 0) { + batchCardList.value = res.data.items || [] + batchCardPagination.total = res.data.total || 0 + } + } catch (error) { + console.error(error) + } finally { + batchCardLoading.value = false + } + } + + // 卡搜索输入(防抖) + const handleCardSearchInput = () => { + if (cardSearchTimer) { + clearTimeout(cardSearchTimer) + } + cardSearchTimer = setTimeout(() => { + cardSearchForm.keyword = cardSearchKeyword.value + batchCardPagination.page = 1 + getBatchCardList() + }, 300) + } + + // 卡搜索 + const handleCardSearch = () => { + cardSearchForm.keyword = cardSearchKeyword.value + batchCardPagination.page = 1 + getBatchCardList() + } + + // 卡搜索重置 + const handleCardSearchReset = () => { + cardSearchKeyword.value = '' + cardSearchForm.keyword = '' + cardSearchForm.card_status = undefined + batchCardPagination.page = 1 + getBatchCardList() + } + + // 批量卡选择变化 + const handleBatchCardSelectionChange = (selection: any[]) => { + if (selection.length > 1000) { + ElMessage.warning('最多只能选择1000张卡') + // 取消最后一个选择 + const lastSelected = selection[selection.length - 1] + batchCardTableRef.value?.toggleRowSelection(lastSelected, false) + return + } + selectedBatchCards.value = selection + } + + // 批量卡分页大小变化 + const handleBatchCardPageSizeChange = () => { + batchCardPagination.page = 1 + getBatchCardList() + } + + // 批量卡分页页码变化 + const handleBatchCardPageChange = () => { + getBatchCardList() + } + + // 关闭批量触发弹窗 + const handleBatchDialogClose = () => { + selectedBatchCards.value = [] + cardSearchKeyword.value = '' + cardSearchForm.keyword = '' + cardSearchForm.card_status = undefined + batchCardPagination.page = 1 + batchCardPagination.pageSize = 20 + } + + // 获取卡状态类型 + const getCardStatusType = (status: number) => { + const typeMap: Record = { + 0: 'info', + 1: 'success', + 2: 'warning', + 3: 'danger' + } + return typeMap[status] || 'info' + } + + // 获取卡状态名称 + const getCardStatusName = (status: number) => { + const nameMap: Record = { + 0: '未激活', + 1: '已激活', + 2: '停机', + 3: '异常' + } + return nameMap[status] || '未知' + } + // 条件触发表单 const conditionForm = reactive({ task_type: '' as TaskType | '', @@ -544,12 +735,18 @@ const showBatchTriggerDialog = () => { Object.assign(batchForm, { - task_type: '', - card_ids_text: '' + task_type: '' }) + selectedBatchCards.value = [] + batchCardPagination.page = 1 + batchCardPagination.pageSize = 20 + cardSearchKeyword.value = '' + cardSearchForm.keyword = '' + cardSearchForm.card_status = undefined batchDialogVisible.value = true nextTick(() => { batchFormRef.value?.clearValidate() + getBatchCardList() }) } @@ -588,13 +785,12 @@ if (!valid) return try { - // 解析卡ID列表 - const cardIds = batchForm.card_ids_text - .split(/[,\n]/) - .map((id) => id.trim()) - .filter((id) => id) - .map((id) => parseInt(id)) - .filter((id) => !isNaN(id)) + const cardIds = selectedBatchCards.value.map((card) => card.id) + + if (cardIds.length === 0) { + ElMessage.warning('请选择要触发的卡') + return + } if (cardIds.length > 1000) { ElMessage.warning('卡ID数量不能超过1000个') @@ -766,5 +962,18 @@ display: flex; flex-direction: column; height: 100%; + + .card-selection-wrapper { + .card-search-bar { + display: flex; + align-items: center; + } + + .card-table-info { + margin-top: 10px; + font-size: 14px; + color: var(--el-text-color-primary); + } + } }