mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-23 23:19:19 +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 java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 发布草稿 VO。
|
||||
|
||||
+1
-1
@@ -237,7 +237,7 @@ public class PddGoodsPublishDeskServiceImpl implements PddGoodsPublishDeskServic
|
||||
Long companyId = currentUserContext.getCurrentCompanyId();
|
||||
Long userId = currentUserContext.getCurrentUserId();
|
||||
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()) {
|
||||
throw new BusinessException("部分草稿不存在");
|
||||
}
|
||||
|
||||
+1
@@ -19,5 +19,6 @@ public class ProductSkuFilterDTO {
|
||||
|
||||
private String skuCode;
|
||||
|
||||
/** 模糊匹配:SKU 名称、SKU 编码、所属商品名称、商品编码 */
|
||||
private String keywords;
|
||||
}
|
||||
|
||||
+17
-4
@@ -231,10 +231,23 @@ public class ProductSkuServiceImpl extends ServiceImpl<ProductSkuMapper, Product
|
||||
}
|
||||
if (filter.getKeywords() != null && !filter.getKeywords().trim().isEmpty()) {
|
||||
String keywords = filter.getKeywords().trim();
|
||||
wrapper.and(w -> w
|
||||
.like(ProductSkuPO::getName, keywords)
|
||||
.or()
|
||||
.like(ProductSkuPO::getSkuCode, keywords));
|
||||
LambdaQueryWrapper<ProductPO> productKw = new LambdaQueryWrapper<>();
|
||||
productKw.select(ProductPO::getId)
|
||||
.eq(ProductPO::getCompanyId, companyId)
|
||||
.and(p -> p.like(ProductPO::getName, keywords)
|
||||
.or()
|
||||
.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 {
|
||||
if (filter.getName() != null && !filter.getName().trim().isEmpty()) {
|
||||
wrapper.like(ProductSkuPO::getName, filter.getName());
|
||||
|
||||
+30
-4
@@ -9,6 +9,8 @@ import type { CascaderProps, UploadFile, UploadProps } from 'ant-design-vue';
|
||||
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref, watch } from 'vue';
|
||||
|
||||
import { useDebounceFn } from '@vueuse/core';
|
||||
|
||||
import type { Sortable } from '@vben/hooks';
|
||||
|
||||
import { useSortable } from '@vben/hooks';
|
||||
@@ -836,16 +838,40 @@ async function loadProducts(keyword = '') {
|
||||
}
|
||||
}
|
||||
|
||||
/** 最近一次已请求/在途的关键字,避免 focus+search 或重复 search 打两次 */
|
||||
let skuSearchKeywordKey = '\0';
|
||||
let skuSearchSeq = 0;
|
||||
|
||||
async function loadSkuCandidates(keyword = '') {
|
||||
const kw = keyword.trim();
|
||||
if (kw === skuSearchKeywordKey) return;
|
||||
skuSearchKeywordKey = kw;
|
||||
const seq = ++skuSearchSeq;
|
||||
try {
|
||||
const data = await getProductSkuPageApi({
|
||||
page: 1,
|
||||
pageSize: 100,
|
||||
filters: keyword ? { keywords: keyword } : {},
|
||||
filters: kw ? { keywords: kw } : {},
|
||||
});
|
||||
if (seq !== skuSearchSeq) return;
|
||||
skuOptions.value = data.records ?? [];
|
||||
} catch {
|
||||
message.error('加载 SKU 失败');
|
||||
if (seq === skuSearchSeq) {
|
||||
skuSearchKeywordKey = '\0';
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3490,8 +3516,8 @@ onBeforeUnmount(() => {
|
||||
placeholder="搜索并多选内部 SKU"
|
||||
:filter-option="false"
|
||||
:options="skuSelectOptions"
|
||||
@search="(kw: string) => loadSkuCandidates(kw)"
|
||||
@focus="() => loadSkuCandidates()"
|
||||
@search="debouncedLoadSkuCandidates"
|
||||
@dropdown-visible-change="onSkuSelectDropdownOpen"
|
||||
/>
|
||||
<Button type="primary" @click="applyInternalSkusInOrder">
|
||||
按行序填入
|
||||
|
||||
Reference in New Issue
Block a user