mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-25 17:49:20 +08:00
fix: 内部 SKU 拉入选择器防抖并去掉 focus 重复请求
This commit is contained in:
-1
@@ -3,7 +3,6 @@ package top.xyquan.ecomdmbbackend.modules.channel.pdd.goods.publishdesk.model.vo
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发布草稿 VO。
|
* 发布草稿 VO。
|
||||||
|
|||||||
+1
-1
@@ -237,7 +237,7 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic
|
|||||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||||
Long userId = currentUserContext.getCurrentUserId();
|
Long userId = currentUserContext.getCurrentUserId();
|
||||||
List<Long> ids = dto.getDraftIds().stream().distinct().toList();
|
List<Long> ids = dto.getDraftIds().stream().distinct().toList();
|
||||||
List<PddGoodsPublishDraftPO> drafts = draftMapper.selectBatchIds(ids);
|
List<PddGoodsPublishDraftPO> drafts = draftMapper.selectByIds(ids);
|
||||||
if (drafts.size() != ids.size()) {
|
if (drafts.size() != ids.size()) {
|
||||||
throw new BusinessException("部分草稿不存在");
|
throw new BusinessException("部分草稿不存在");
|
||||||
}
|
}
|
||||||
|
|||||||
+1
@@ -19,5 +19,6 @@ public class ProductSkuFilterDTO {
|
|||||||
|
|
||||||
private String skuCode;
|
private String skuCode;
|
||||||
|
|
||||||
|
/** 模糊匹配:SKU 名称、SKU 编码、所属商品名称、商品编码 */
|
||||||
private String keywords;
|
private String keywords;
|
||||||
}
|
}
|
||||||
|
|||||||
+16
-3
@@ -231,10 +231,23 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
|||||||
}
|
}
|
||||||
if (filter.getKeywords() != null && !filter.getKeywords().trim().isEmpty()) {
|
if (filter.getKeywords() != null && !filter.getKeywords().trim().isEmpty()) {
|
||||||
String keywords = filter.getKeywords().trim();
|
String keywords = filter.getKeywords().trim();
|
||||||
wrapper.and(w -> w
|
LambdaQueryWrapper<ProductPO> productKw = new LambdaQueryWrapper<>();
|
||||||
.like(ProductSkuPO::getName, keywords)
|
productKw.select(ProductPO::getId)
|
||||||
|
.eq(ProductPO::getCompanyId, companyId)
|
||||||
|
.and(p -> p.like(ProductPO::getName, keywords)
|
||||||
.or()
|
.or()
|
||||||
.like(ProductSkuPO::getSkuCode, keywords));
|
.like(ProductPO::getProductCode, keywords));
|
||||||
|
List<Long> matchedProductIds = productService.list(productKw).stream()
|
||||||
|
.map(ProductPO::getId)
|
||||||
|
.toList();
|
||||||
|
wrapper.and(w -> {
|
||||||
|
w.like(ProductSkuPO::getName, keywords)
|
||||||
|
.or()
|
||||||
|
.like(ProductSkuPO::getSkuCode, keywords);
|
||||||
|
if (!matchedProductIds.isEmpty()) {
|
||||||
|
w.or().in(ProductSkuPO::getProductId, matchedProductIds);
|
||||||
|
}
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
if (filter.getName() != null && !filter.getName().trim().isEmpty()) {
|
if (filter.getName() != null && !filter.getName().trim().isEmpty()) {
|
||||||
wrapper.like(ProductSkuPO::getName, filter.getName());
|
wrapper.like(ProductSkuPO::getName, filter.getName());
|
||||||
|
|||||||
+29
-3
@@ -9,6 +9,8 @@ import type { CascaderProps, UploadFile, UploadProps } from 'ant-design-vue';
|
|||||||
|
|
||||||
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
|
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
|
||||||
|
|
||||||
|
import { useDebounceFn } from '@vueuse/core';
|
||||||
|
|
||||||
import type { Sortable } from '@vben/hooks';
|
import type { Sortable } from '@vben/hooks';
|
||||||
|
|
||||||
import { useSortable } from '@vben/hooks';
|
import { useSortable } from '@vben/hooks';
|
||||||
@@ -836,18 +838,42 @@ async function loadProducts(keyword = '') {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 最近一次已请求/在途的关键字,避免 focus+search 或重复 search 打两次 */
|
||||||
|
let skuSearchKeywordKey = '\0';
|
||||||
|
let skuSearchSeq = 0;
|
||||||
|
|
||||||
async function loadSkuCandidates(keyword = '') {
|
async function loadSkuCandidates(keyword = '') {
|
||||||
|
const kw = keyword.trim();
|
||||||
|
if (kw === skuSearchKeywordKey) return;
|
||||||
|
skuSearchKeywordKey = kw;
|
||||||
|
const seq = ++skuSearchSeq;
|
||||||
try {
|
try {
|
||||||
const data = await getProductSkuPageApi({
|
const data = await getProductSkuPageApi({
|
||||||
page: 1,
|
page: 1,
|
||||||
pageSize: 100,
|
pageSize: 100,
|
||||||
filters: keyword ? { keywords: keyword } : {},
|
filters: kw ? { keywords: kw } : {},
|
||||||
});
|
});
|
||||||
|
if (seq !== skuSearchSeq) return;
|
||||||
skuOptions.value = data.records ?? [];
|
skuOptions.value = data.records ?? [];
|
||||||
} catch {
|
} catch {
|
||||||
|
if (seq === skuSearchSeq) {
|
||||||
|
skuSearchKeywordKey = '\0';
|
||||||
message.error('加载 SKU 失败');
|
message.error('加载 SKU 失败');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 远程搜索防抖:连打只打最后一次 */
|
||||||
|
const debouncedLoadSkuCandidates = useDebounceFn((keyword: string) => {
|
||||||
|
void loadSkuCandidates(keyword);
|
||||||
|
}, 300);
|
||||||
|
|
||||||
|
/** 下拉打开时若尚无选项再拉首屏(替代 focus,避免与 search 叠一次空请求) */
|
||||||
|
function onSkuSelectDropdownOpen(open: boolean) {
|
||||||
|
if (open && skuOptions.value.length === 0) {
|
||||||
|
void loadSkuCandidates();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
() => form.primaryProductId,
|
() => form.primaryProductId,
|
||||||
@@ -3490,8 +3516,8 @@ onBeforeUnmount(() => {
|
|||||||
placeholder="搜索并多选内部 SKU"
|
placeholder="搜索并多选内部 SKU"
|
||||||
:filter-option="false"
|
:filter-option="false"
|
||||||
:options="skuSelectOptions"
|
:options="skuSelectOptions"
|
||||||
@search="(kw: string) => loadSkuCandidates(kw)"
|
@search="debouncedLoadSkuCandidates"
|
||||||
@focus="() => loadSkuCandidates()"
|
@dropdown-visible-change="onSkuSelectDropdownOpen"
|
||||||
/>
|
/>
|
||||||
<Button type="primary" @click="applyInternalSkusInOrder">
|
<Button type="primary" @click="applyInternalSkusInOrder">
|
||||||
按行序填入
|
按行序填入
|
||||||
|
|||||||
Reference in New Issue
Block a user