feat: optimize product query and detail pages

This commit is contained in:
zm2000 2026-03-30 15:23:28 +08:00
parent 6d7a1bd28d
commit 3762a36433
3 changed files with 352 additions and 120 deletions

View File

@ -80,7 +80,7 @@ const actions = {
commit,
state
}) {
if (!state.initialized) {
if (!state || !state.initialized) {
console.error('[Broadcast] 请先初始化模块');
return false;
}
@ -109,7 +109,7 @@ const actions = {
commit,
state
}) {
if (!state.enabled) {
if (!state || !state.enabled) {
return true;
}
@ -124,10 +124,12 @@ const actions = {
* 暂停监听
*/
pause({
commit
commit,
state
}) {
return actions.stop({
commit
commit,
state: state || {}
});
},
@ -155,7 +157,7 @@ const actions = {
throw new Error('配置必须包含broadcastAction');
}
if (!state.enabled) {
if (!state || !state.enabled) {
console.warn('[Broadcast] 广播功能已禁用,配置更新无效');
return false;
}
@ -199,7 +201,7 @@ const actions = {
throw new Error('Action不能为空');
}
if (!state.enabled) {
if (!state || !state.enabled) {
console.warn('[Broadcast] 广播功能已禁用,Action更新无效');
return false;
}
@ -222,11 +224,12 @@ const actions = {
state
}) {
const scannerStatus = scanner.getStatus();
const safeState = state || {};
return {
...scannerStatus,
moduleEnabled: state.enabled,
moduleInitialized: state.initialized,
moduleActive: state.active
moduleEnabled: !!safeState.enabled,
moduleInitialized: !!safeState.initialized,
moduleActive: !!safeState.active
};
},

View File

@ -5,47 +5,89 @@
<scroll-view class="detail-content" scroll-y>
<view class="detail-card" v-if="item">
<view class="image-section">
<u-image
class="main-image"
:src="getImageUrl(item)"
mode="aspectFit"
width="100%"
height="360rpx"
@click="previewProductImage(item)"
>
<template #error>
<view class="image-placeholder">
<u-icon name="photo" size="42" color="#c0c4cc"></u-icon>
<view class="detail-header">
<view class="item-title-row">
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
</view>
<view class="item-main-row">
<view class="item-thumb" @click="previewProductImage(item)">
<u-image
v-if="getImageList(item).length <= 1"
class="goods-image"
:src="getImageUrl(item)"
mode="aspectFill"
width="90rpx"
height="90rpx"
>
<template #error>
<view class="image-placeholder">
<u-icon name="photo" size="24" color="#c0c4cc"></u-icon>
</view>
</template>
</u-image>
<view v-else class="goods-image-grid">
<view
class="grid-cell"
v-for="(img, imgIndex) in getImageThumbList(item)"
:key="img + '-' + imgIndex"
>
<u-image
class="grid-image"
:src="img"
mode="aspectFill"
width="44rpx"
height="44rpx"
>
<template #error>
<view class="image-placeholder image-placeholder-small">
<u-icon name="photo" size="18" color="#c0c4cc"></u-icon>
</view>
</template>
</u-image>
<view v-if="imgIndex === 3 && getExtraImageCount(item) > 0" class="more-mask">
<text class="more-text">+{{ getExtraImageCount(item) }}</text>
</view>
</view>
</view>
</template>
</u-image>
</view>
<view class="item-info">
<view class="compact-row">
<text class="compact-label">商品编码:</text>
<text class="compact-value">{{ item.goods_code || item.item_code || '--' }}</text>
</view>
<view class="compact-row">
<text class="compact-label">条码:</text>
<text class="compact-value">{{ getBarcodeText(item) }}</text>
</view>
</view>
</view>
</view>
<view class="info-section">
<view class="name-row">
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
<view class="info-row">
<text class="label">名称:</text>
<text class="value">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
</view>
<view class="info-row">
<text class="label">货主:</text>
<text class="value">{{ getStoreOwnerText(item) }}</text>
</view>
<view class="info-row">
<text class="label">商品编码:</text>
<text class="value">{{ item.goods_code || item.item_code || '--' }}</text>
<text class="label">毛重:</text>
<text class="value">{{ item.gross_weight || '--' }}</text>
</view>
<view class="info-row">
<text class="label">条码:</text>
<text class="value">{{ getBarcodeText(item) }}</text>
<text class="label">品牌:</text>
<text class="value">{{ item.brand_name || '--' }}</text>
</view>
<view class="info-row">
<text class="label">违禁品类型:</text>
<text class="value">{{ (item.prohibited && item.prohibited.type_name) || '--' }}</text>
</view>
<view class="info-row">
<text class="label">SKU规格:</text>
<text class="value">{{ item.sku_property || '--' }}</text>
</view>
<view class="info-row">
<text class="label">库存单位:</text>
<text class="value">{{ item.stock_unit || '--' }}</text>
</view>
<view class="info-row">
<text class="label">库存数量:</text>
<text class="value">{{ getValueOrDash(item.quantity) }}</text>
@ -54,6 +96,46 @@
<text class="label">锁定量:</text>
<text class="value">{{ getValueOrDash(item.locked_quantity) }}</text>
</view>
<view class="info-row">
<text class="label">可用库存:</text>
<text class="value">{{ item.available_quantity || '--' }}</text>
</view>
<view class="info-row">
<text class="label">锁定率:</text>
<text class="value">{{ item.lock_rate_display || '--' }}</text>
</view>
<view class="info-row">
<text class="label">库存单位:</text>
<text class="value">{{ item.stock_unit || '--' }}</text>
</view>
<view class="info-row">
<text class="label">标价:</text>
<text class="value">
<text v-if="item.tag_price !== null && item.tag_price !== undefined && item.tag_price !== ''">¥</text>{{ item.tag_price || '--' }}
</text>
</view>
<view class="info-row">
<text class="label">零售价:</text>
<text class="value">
<text v-if="item.retail_price !== null && item.retail_price !== undefined && item.retail_price !== ''">¥</text>{{ item.retail_price || '--' }}
</text>
</view>
<view class="info-row">
<text class="label">ABC分类:</text>
<text class="value">{{ item.level || '--' }}</text>
</view>
<view class="info-row">
<text class="label">体积:</text>
<text class="value">{{ item.box_volume || '--' }}</text>
</view>
<view class="info-row">
<text class="label">创建时间:</text>
<text class="value">{{ item.create_at_display || '--' }}</text>
</view>
<view class="info-row">
<text class="label">更新时间:</text>
<text class="value">{{ item.update_at_display || '--' }}</text>
</view>
</view>
</view>
@ -147,6 +229,13 @@ export default {
const single = this.getImageUrl(item);
return single ? [single] : [];
},
getImageThumbList(item) {
return this.getImageList(item).slice(0, 4);
},
getExtraImageCount(item) {
const total = this.getImageList(item).length;
return total > 4 ? total - 4 : 0;
},
previewProductImage(item) {
const urls = this.getImageList(item);
if (!urls.length) {
@ -215,26 +304,16 @@ export default {
padding: 20rpx;
}
.image-section {
margin-bottom: 16rpx;
.detail-header {
padding-bottom: 18rpx;
border-bottom: 2rpx solid #e5e7eb;
}
.main-image {
border-radius: 10rpx;
overflow: hidden;
background: #f5f7fa;
.info-section {
padding-top: 16rpx;
}
.image-placeholder {
width: 100%;
height: 360rpx;
display: flex;
align-items: center;
justify-content: center;
background: #f5f7fa;
}
.name-row {
.item-title-row {
margin-bottom: 10rpx;
}
@ -244,6 +323,112 @@ export default {
color: #303133;
}
.item-main-row {
display: flex;
align-items: center;
}
.item-thumb {
width: 90rpx;
margin-right: 20rpx;
flex-shrink: 0;
}
.goods-image {
border-radius: 10rpx;
overflow: hidden;
background: #f5f7fa;
}
.goods-image-grid {
width: 90rpx;
height: 90rpx;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-content: space-between;
}
.grid-cell {
position: relative;
width: 44rpx;
height: 44rpx;
border-radius: 8rpx;
overflow: hidden;
background: #f5f7fa;
}
.grid-image {
border-radius: 8rpx;
overflow: hidden;
}
.image-placeholder {
width: 90rpx;
height: 90rpx;
display: flex;
align-items: center;
justify-content: center;
background: #f5f7fa;
}
.image-placeholder-small {
width: 44rpx;
height: 44rpx;
}
.more-mask {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
background: rgba(0, 0, 0, 0.45);
display: flex;
align-items: center;
justify-content: center;
}
.more-text {
font-size: 18rpx;
color: #fff;
font-weight: 600;
}
.item-info {
flex: 1;
min-width: 0;
}
.compact-row {
display: flex;
align-items: center;
line-height: 1.4;
margin-bottom: 2rpx;
}
.compact-row:last-child {
margin-bottom: 0;
}
.compact-label {
width: auto;
margin-right: 6rpx;
font-size: 24rpx;
color: #909399;
white-space: nowrap;
flex-shrink: 0;
}
.compact-value {
flex: 1;
font-size: 24rpx;
color: #000;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.info-row {
display: flex;
align-items: center;
@ -256,7 +441,8 @@ export default {
}
.label {
width: 120rpx;
width: auto;
margin-right: 6rpx;
font-size: 24rpx;
color: #909399;
flex-shrink: 0;
@ -265,7 +451,7 @@ export default {
.value {
flex: 1;
font-size: 24rpx;
color: #606266;
color: #000;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;

View File

@ -15,7 +15,7 @@
></u-search>
</view>
<scroll-view class="list-content" scroll-y :scroll-top="listScrollTop" @scroll="handleListScroll">
<scroll-view class="list-content" scroll-y :scroll-top="restoreScrollTop" @scroll="handleListScroll">
<view v-if="!loading && list.length === 0" class="empty-state">
<u-icon name="search" size="88" color="#c0c4cc"></u-icon>
<text class="empty-text">暂无商品数据</text>
@ -23,17 +23,19 @@
</view>
<view v-else class="list-wrap">
<view class="goods-item" v-for="(item, index) in list" :key="item.id || index" @click="goProductDetail(item)">
<view class="goods-item" v-for="(item, index) in list" :key="item.id || index">
<view class="item-title-row">
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
</view>
<view class="item-main-row">
<view class="item-thumb">
<view class="item-thumb" @click.stop="previewProductImage(item)">
<u-image
v-if="getImageList(item).length <= 1"
class="goods-image"
:src="getImageUrl(item)"
mode="aspectFill"
width="180rpx"
height="180rpx"
@click.stop="previewProductImage(item)"
width="90rpx"
height="90rpx"
>
<template #error>
<view class="image-placeholder">
@ -44,7 +46,6 @@
<view
v-else
class="goods-image-grid"
@click.stop="previewProductImage(item)"
>
<view
class="grid-cell"
@ -55,8 +56,8 @@
class="grid-image"
:src="img"
mode="aspectFill"
width="88rpx"
height="88rpx"
width="44rpx"
height="44rpx"
>
<template #error>
<view class="image-placeholder image-placeholder-small">
@ -71,9 +72,6 @@
</view>
</view>
<view class="item-info">
<view class="item-title-row">
<text class="goods-name">{{ item.item_name || item.product_name || item.name || '未命名商品' }}</text>
</view>
<view class="item-row">
<text class="label">货主:</text>
<text class="value">{{ getStoreOwnerText(item) }}</text>
@ -90,23 +88,16 @@
<text class="label">SKU规格:</text>
<text class="value">{{ item.sku_property || '--' }}</text>
</view>
<view class="item-row">
<text class="label">库存单位:</text>
<text class="value">{{ item.stock_unit || '--' }}</text>
</view>
<view class="item-row">
<text class="label">库存数量:</text>
<text class="value">{{ getValueOrDash(item.quantity) }}</text>
</view>
<view class="item-row">
<text class="label">锁定量:</text>
<text class="value">{{ getValueOrDash(item.locked_quantity) }}</text>
</view>
</view>
<view class="item-arrow" @click.stop="goProductDetail(item)">
<u-icon name="arrow-right" size="18" color="#c0c4cc" :custom-style="{ pointerEvents: 'none' }"></u-icon>
</view>
</view>
</view>
</view>
<view v-if="!loading && list.length > 0" class="end-tip">没有更多了</view>
<view class="safe-area-bottom"></view>
</scroll-view>
</view>
@ -123,37 +114,52 @@
keyword: '',
loading: false,
list: [],
listScrollTop: 0
restoreScrollTop: 0,
listScrollTopCache: 0
}
},
onLoad() {
this.$store.dispatch('broadcast/setCallbacks', {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.$store.dispatch('broadcast/start');
this.safeDispatchBroadcast('start');
this.list = [];
},
onShow() {
this.$store.dispatch('broadcast/setCallbacks', {
this.safeDispatchBroadcast('setCallbacks', {
onResult: this.handleBroadcastResult
});
this.$store.dispatch('broadcast/resume');
this.safeDispatchBroadcast('resume');
const cachedTop = Number(uni.getStorageSync('product_query_scroll_top') || 0);
this.$nextTick(() => {
this.listScrollTop = cachedTop > 0 ? cachedTop : 0;
const top = cachedTop > 0 ? cachedTop : 0;
this.restoreScrollTop = top;
this.listScrollTopCache = top;
});
},
onHide() {
uni.setStorageSync('product_query_scroll_top', this.listScrollTop || 0);
this.$store.dispatch('broadcast/pause');
uni.setStorageSync('product_query_scroll_top', this.listScrollTopCache || 0);
this.safeDispatchBroadcast('pause');
},
onUnload() {
this.$store.dispatch('broadcast/stop');
this.safeDispatchBroadcast('stop');
},
methods: {
safeDispatchBroadcast(action, payload) {
try {
const task = this.$store.dispatch(`broadcast/${action}`, payload);
if (task && typeof task.catch === 'function') {
task.catch(error => {
console.warn(`[ProductQuery] broadcast/${action} 调用失败:`, error);
});
}
} catch (error) {
console.warn(`[ProductQuery] broadcast/${action} 调用异常:`, error);
}
},
handleListScroll(event) {
const top = event && event.detail ? Number(event.detail.scrollTop || 0) : 0;
this.listScrollTop = top;
this.listScrollTopCache = top;
},
normalizeKeyword(value) {
return String(value || '').replace(/\s+/g, '');
@ -280,6 +286,24 @@
return (list || []).filter(item => this.extractBarcodeList(item).includes(target));
},
getProductName(item) {
if (!item || typeof item !== 'object') {
return '';
}
return String(item.item_name || item.product_name || item.name || '').trim();
},
filterByNameContains(list, keyword) {
const target = String(keyword || '').trim().toLowerCase();
if (!target) {
return list;
}
return (list || []).filter(item => {
const nameText = this.getProductName(item).toLowerCase();
return nameText.includes(target);
});
},
getImageUrl(item) {
if (!item || typeof item !== 'object') {
return '';
@ -357,17 +381,23 @@
return;
}
const isBarcodeKeyword = this.isBarcodeLike(keyword);
const queryParams = {
pagination: {
page: 1,
pageSize: 100
},
keyword
};
if (isBarcodeKeyword) {
queryParams.barcode = keyword;
queryParams.barcodes = [keyword];
}
this.loading = true;
try {
const res = await this.$http('stock.warehouse.list', {
pagination: {
page: 1,
pageSize: 100
},
keyword,
barcode: keyword,
barcodes: [keyword]
});
const res = await this.$http('stock.warehouse.list', queryParams);
if (res && res.code === 200) {
const responseData = res.data;
@ -380,9 +410,9 @@
nextList = responseData.rows;
}
this.list = this.isBarcodeLike(keyword)
this.list = isBarcodeKeyword
? this.filterByBarcodeExact(nextList, keyword)
: nextList;
: this.filterByNameContains(nextList, keyword);
} else {
this.list = [];
uni.showToast({
@ -437,38 +467,30 @@
}
.list-wrap {
padding: 20rpx;
padding: 20rpx 8rpx;
}
.goods-item {
background: #fff;
border-radius: 12rpx;
padding: 10rpx 20rpx;
padding: 10rpx 16rpx;
margin-bottom: 20rpx;
border: 1rpx solid #e9edf3;
box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.08);
position: relative;
&::before {
content: '';
position: absolute;
left: 0;
top: 18rpx;
bottom: 18rpx;
width: 6rpx;
background: #2979ff;
border-radius: 0 6rpx 6rpx 0;
}
}
.item-main-row {
display: flex;
align-items: flex-start;
align-items: center;
position: relative;
padding-right: 20rpx;
}
.item-thumb {
width: 180rpx;
width: 90rpx;
margin-right: 20rpx;
margin-top: 0;
flex-shrink: 0;
}
@ -479,8 +501,8 @@
}
.goods-image-grid {
width: 180rpx;
height: 180rpx;
width: 90rpx;
height: 90rpx;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
@ -489,8 +511,8 @@
.grid-cell {
position: relative;
width: 88rpx;
height: 88rpx;
width: 44rpx;
height: 44rpx;
border-radius: 8rpx;
overflow: hidden;
background: #f5f7fa;
@ -503,7 +525,7 @@
.image-placeholder {
width: 100%;
height: 180rpx;
height: 90rpx;
display: flex;
align-items: center;
justify-content: center;
@ -511,7 +533,7 @@
}
.image-placeholder-small {
height: 88rpx;
height: 44rpx;
}
.more-mask {
@ -537,11 +559,24 @@
min-width: 0;
}
.item-arrow {
position: absolute;
right: 0;
top: 50%;
transform: translateY(-50%);
display: flex;
align-items: center;
justify-content: center;
width: 44rpx;
height: 44rpx;
z-index: 1;
}
.item-title-row {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 6rpx;
margin-bottom: 10rpx;
}
.goods-name {
@ -565,7 +600,8 @@
}
.label {
width: 116rpx;
width: auto;
margin-right: 6rpx;
font-size: 24rpx;
color: #909399;
white-space: nowrap;
@ -575,7 +611,7 @@
.value {
flex: 1;
font-size: 24rpx;
color: #606266;
color: #000;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
@ -599,4 +635,11 @@
color: #c0c4cc;
margin-top: 10rpx;
}
.end-tip {
padding: 8rpx 0 20rpx;
text-align: center;
font-size: 22rpx;
color: #c0c4cc;
}
</style>