yujinwen 2 mesiacov pred
rodič
commit
5f1b19b040

+ 62 - 15
src/views/user/favorite/components/MoveChart.vue

@@ -17,10 +17,8 @@ const props=defineProps({
 const selectClassify = ref([])
 const keyword = ref('')
 const checkAll = ref(false)
-const indeterminate=computed(()=>{
-  if(checkAll.value) return false
-  if(selectedRowKeys.value.length>0) return true
-})
+const indeterminate=ref(false)
+let unSelectedCharts=[]//当全选时 又取消掉部分的放在这里面
 
 const columns=[
   {
@@ -60,7 +58,11 @@ async function getChartList(){
   pagination.value.total=res.Data.Paging.Totals
   tableData.value=arr
   if(checkAll.value){
-    handleClickCheckAll(checkAll.value)
+    tableData.value.forEach(item=>{
+      if(!selectedRowKeys.value.includes(item.ChartInfoId)&&!unSelectedCharts.includes(item.ChartInfoId)){
+        selectedRowKeys.value.push(item.ChartInfoId)
+      }
+    })
   }
 }
 watch(
@@ -70,6 +72,8 @@ watch(
       keyword.value=''
       selectClassify.value=[]
       newClassify.value=''
+      unSelectedCharts=[]
+      selectedRowKeys.value=[]
       handleRefreshList()
     }
   }
@@ -83,28 +87,71 @@ function handleRefreshList() {
   pagination.value.current = 1
   checkAll.value=false
   selectedRowKeys.value=[]
+  indeterminate.value=false
+  unSelectedCharts=[]
   getChartList()
 }
 
-const selectedRowKeys = ref([]);
-function handleTableSelectChange(value, ctx){
-  selectedRowKeys.value = value
-  if(ctx.type==="uncheck"&&checkAll.value){
-    checkAll.value=false
+const selectedRowKeys = ref([]);//当前表格的选择
+function handleTableSelectChange(value, { type, currentRowKey }) {
+  const isFullSelection = currentRowKey === 'CHECK_ALL_BOX';
+  const isCheckAction = type === 'check';
+
+  if (isFullSelection) {
+    handleFullSelection(isCheckAction);
+  } else {
+    handleSingleSelection(currentRowKey, isCheckAction);
+  }
+
+  updateSelectionState();
+}
+function handleFullSelection(isCheck) {
+  const currentPageIds = new Set(tableData.value.map(item => item.ChartInfoId));
+  
+  if (isCheck) {
+    // 全选时从排除列表移除当前页所有ID
+    unSelectedCharts = unSelectedCharts.filter(id => !currentPageIds.has(id));
+  } else {
+    // 取消全选时添加当前页所有ID到排除列表
+    const newUnselected = [...new Set([...unSelectedCharts, ...currentPageIds])];
+    unSelectedCharts = newUnselected;
   }
-  if(ctx.type==='check'&&selectedRowKeys.value.length===pagination.value.total){
-    checkAll.value=true
+}
+function handleSingleSelection(id, isCheck) {
+  if (isCheck) {
+    // 选中时从排除列表移除
+    unSelectedCharts = unSelectedCharts.filter(item => item !== id);
+  } else {
+    // 取消选中时添加到排除列表(去重)
+    if (!unSelectedCharts.includes(id)) {
+      unSelectedCharts = [...unSelectedCharts, id];
+    }
   }
 }
+function updateSelectionState() {
+  const total = pagination.value.total;
+  const selectedCount = checkAll.value 
+    ? total - unSelectedCharts.length 
+    : selectedRowKeys.value.length;
+
+  checkAll.value = selectedCount === total;
+  indeterminate.value = selectedCount > 0 && selectedCount < total;
+}
+
 function handleClickCheckAll(check) {
   if(check){
     // 全选
-    selectedRowKeys.value=[]
+    indeterminate.value=false
+    unSelectedCharts=[]
     tableData.value.forEach(item=>{
-      selectedRowKeys.value.push(item.ChartInfoId)
+      if(!selectedRowKeys.value.includes(item.ChartInfoId)){
+        selectedRowKeys.value.push(item.ChartInfoId)
+      }
     })
   }else{
+    indeterminate.value=false
     selectedRowKeys.value=[]
+    unSelectedCharts=[]
   }
 }
 
@@ -122,7 +169,7 @@ async function handleSave() {
     SelectAll:checkAll.value,
     CollectClassifyIds:selectClassify.value?selectClassify.value.join(','):'',
     Keyword:keyword.value,
-    ChartInfoIds:checkAll.value ? '' : selectedRowKeys.value.join(','),
+    ChartInfoIds:checkAll.value?unSelectedCharts.join(',') : selectedRowKeys.value.join(','),
     CollectClassifyId:newClassify.value,
   }
   const res=await apiETAChartUser.chartCollectBatchMove(params)