diff --git a/components/page-nav/page-nav.vue b/components/page-nav/page-nav.vue
index 63da0f1..b1b6590 100644
--- a/components/page-nav/page-nav.vue
+++ b/components/page-nav/page-nav.vue
@@ -53,6 +53,12 @@
},
toHome() {
console.log('跳转到首页');
+ const pages = getCurrentPages();
+ const currentRoute = pages.length ? `/${pages[pages.length - 1].route || ''}` : '';
+ if (currentRoute === '/pages/index/index') {
+ console.log('当前已在首页,取消重复跳转');
+ return;
+ }
// 根据你的路由配置调整首页路径
// 假设首页是 tabBar 页面
diff --git a/core/router/index.js b/core/router/index.js
index 418a4f1..cd62a49 100644
--- a/core/router/index.js
+++ b/core/router/index.js
@@ -84,7 +84,9 @@ router.beforeEach(async (to, from, next) => {
return;
}
}
- if(to.path==from.path){
+ const hasFromPath = !!from.path;
+ const isSameRoute = hasFromPath && to.path === from.path && to.fullPath === from.fullPath;
+ if(isSameRoute){
console.log('路由重复,取消跳转:', to.path);
next(false);
}else{
diff --git a/core/utils/tool.js b/core/utils/tool.js
index 55ab889..e67cc90 100644
--- a/core/utils/tool.js
+++ b/core/utils/tool.js
@@ -5,6 +5,24 @@ import {
router
} from '@/core/router'
export default {
+ normalizeRoutePath(path = '') {
+ return String(path || '')
+ .trim()
+ .split('?')[0]
+ .split('#')[0]
+ .replace(/^\/+/, '/');
+ },
+ getCurrentRoutePath() {
+ const pages = typeof getCurrentPages === 'function' ? getCurrentPages() : [];
+ const currentPage = pages[pages.length - 1];
+ const route = currentPage?.route || '';
+ return this.normalizeRoutePath(route ? `/${route}` : '');
+ },
+ isSameCurrentRoute(path = '') {
+ const targetPath = this.normalizeRoutePath(path);
+ const currentPath = this.getCurrentRoutePath();
+ return !!targetPath && !!currentPath && targetPath === currentPath;
+ },
/**
* 跳转再封装,主要是为了兼容外链。
@@ -13,6 +31,11 @@ export default {
*/
routerTo(path, isTabbar) {
if (path) {
+ if (this.isSameCurrentRoute(path)) {
+ console.log('检测到重复跳转,已拦截:', path);
+ return false;
+ }
+
// 是否跳转外部链接
if (~path.indexOf('http') || ~path.indexOf('www')) {
// #ifdef H5
diff --git a/pages/home/edit-quick-actions.vue b/pages/home/edit-quick-actions.vue
index 0d6812a..c6dacb6 100644
--- a/pages/home/edit-quick-actions.vue
+++ b/pages/home/edit-quick-actions.vue
@@ -326,10 +326,7 @@
return;
}
- uni.navigateTo({
- url: targetPath,
- animationType: 'slide-in-right'
- });
+ this.$tools.routerTo(targetPath);
},
goBack() {
uni.navigateBack({
diff --git a/pages/index/index.vue b/pages/index/index.vue
index 5699895..6fd4568 100644
--- a/pages/index/index.vue
+++ b/pages/index/index.vue
@@ -1134,10 +1134,7 @@
return;
}
- uni.navigateTo({
- url: targetPath,
- animationType: 'slide-in-right'
- });
+ this.$tools.routerTo(targetPath);
},
toMessagePage() {
diff --git a/pages/work/product/query.vue b/pages/work/product/query.vue
index 3b6493f..20d5005 100644
--- a/pages/work/product/query.vue
+++ b/pages/work/product/query.vue
@@ -4,15 +4,26 @@
-
+
+
+
+
+
+
+
+
+ 搜索
+
+
+
@@ -164,8 +175,37 @@
normalizeKeyword(value) {
return String(value || '').replace(/\s+/g, '');
},
+ normalizeScanResult(scanResult) {
+ if (!scanResult) {
+ return '';
+ }
+
+ if (typeof scanResult === 'string') {
+ return this.normalizeKeyword(scanResult);
+ }
+
+ if (typeof scanResult.result === 'string') {
+ return this.normalizeKeyword(scanResult.result);
+ }
+
+ if (Array.isArray(scanResult.result)) {
+ const firstResult = scanResult.result.find(item => item);
+ if (typeof firstResult === 'string') {
+ return this.normalizeKeyword(firstResult);
+ }
+ if (firstResult && typeof firstResult.data === 'string') {
+ return this.normalizeKeyword(firstResult.data);
+ }
+ }
+
+ if (typeof scanResult.data === 'string') {
+ return this.normalizeKeyword(scanResult.data);
+ }
+
+ return '';
+ },
handleBroadcastResult(result) {
- const scanResult = this.normalizeKeyword((result && result.data) || '');
+ const scanResult = this.normalizeScanResult(result);
if (!scanResult) {
return;
}
@@ -173,6 +213,36 @@
this.keyword = scanResult;
this.handleSearch();
},
+ handleCameraScan() {
+ uni.scanCode({
+ onlyFromCamera: true,
+ scanType: ['barCode', 'qrCode', 'datamatrix', 'pdf417'],
+ success: (res) => {
+ const scanResult = this.normalizeScanResult(res);
+ if (!scanResult) {
+ uni.showToast({
+ title: '未识别到有效条码',
+ icon: 'none'
+ });
+ return;
+ }
+
+ this.keyword = scanResult;
+ this.handleSearch();
+ },
+ fail: (error) => {
+ const errMsg = String(error?.errMsg || '').toLowerCase();
+ if (errMsg.includes('cancel')) {
+ return;
+ }
+
+ uni.showToast({
+ title: '扫码失败,请重试',
+ icon: 'none'
+ });
+ }
+ });
+ },
getBarcodeText(item) {
if (!item || typeof item !== 'object') {
return '--';
@@ -460,6 +530,71 @@
z-index: 2;
}
+ .search-input-wrap {
+ position: relative;
+
+ ::v-deep .u-search {
+ width: 100%;
+ }
+
+ ::v-deep .u-search__content {
+ padding-right: 200rpx;
+ }
+
+ ::v-deep .u-search__content__close {
+ margin-right: 12rpx;
+ }
+ }
+
+ .search-actions {
+ position: absolute;
+ right: 24rpx;
+ top: 50%;
+ transform: translateY(-50%);
+ height: 68rpx;
+ display: flex;
+ align-items: center;
+ }
+
+ .scan-btn {
+ height: 68rpx;
+ padding: 0 8rpx 0 4rpx;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+
+ &:active {
+ opacity: 0.88;
+ }
+ }
+
+ .search-divider {
+ width: 1rpx;
+ height: 28rpx;
+ background: #dcdfe6;
+ margin: 0 16rpx 0 10rpx;
+ }
+
+ .search-btn {
+ height: 68rpx;
+ padding: 0 8rpx;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ flex-shrink: 0;
+
+ &__text {
+ font-size: 30rpx;
+ font-weight: 500;
+ color: #2979ff;
+ line-height: 1;
+ }
+
+ &:active {
+ opacity: 0.88;
+ }
+ }
+
.list-content {
flex: 1;
min-height: 0;
diff --git a/pages/work/storage/receiving/receiving.vue b/pages/work/storage/receiving/receiving.vue
index 5a93e35..0f88b71 100644
--- a/pages/work/storage/receiving/receiving.vue
+++ b/pages/work/storage/receiving/receiving.vue
@@ -9,8 +9,14 @@
-
-
+
+
+
+
+
+
+ 搜索
+
@@ -634,29 +640,68 @@
margin-bottom: 20rpx;
.search-box-inner {
- display: flex;
- align-items: center;
- gap: 16rpx;
+ position: relative;
::v-deep .u-search {
- flex: 1;
+ width: 100%;
}
- .scan-camera-btn {
- width: 76rpx;
- height: 76rpx;
- border-radius: 38rpx;
- background: #eef4ff;
+ ::v-deep .u-search__content {
+ padding-right: 200rpx;
+ }
+
+ ::v-deep .u-search__content__close {
+ margin-right: 12rpx;
+ }
+
+ .search-actions {
+ position: absolute;
+ right: 24rpx;
+ top: 50%;
+ transform: translateY(-50%);
+ height: 68rpx;
display: flex;
align-items: center;
- justify-content: center;
- flex-shrink: 0;
- box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.12);
+ }
+
+ .scan-btn {
+ height: 68rpx;
+ padding: 0 8rpx 0 4rpx;
+ display: flex;
+ align-items: center;
+ justify-content: center;
&:active {
- opacity: 0.85;
+ opacity: 0.88;
}
}
+
+ .search-divider {
+ width: 1rpx;
+ height: 28rpx;
+ background: #dcdfe6;
+ margin: 0 16rpx 0 10rpx;
+ }
+
+ .search-btn {
+ height: 68rpx;
+ padding: 0 8rpx;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ flex-shrink: 0;
+
+ &__text {
+ font-size: 30rpx;
+ font-weight: 500;
+ color: #2979ff;
+ line-height: 1;
+ }
+
+ &:active {
+ opacity: 0.88;
+ }
+ }
}
}
diff --git a/pages/work/storage/relocation.vue b/pages/work/storage/relocation.vue
index 44d82d7..1be9f9c 100644
--- a/pages/work/storage/relocation.vue
+++ b/pages/work/storage/relocation.vue
@@ -1,6 +1,152 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 库位信息
+
+
+
+
+
+
+
+
+ 已识别:{{ formData.sourceSpaceName }}
+
+
+
+
+
+
+
+
+
+ 已识别:{{ formData.targetSpaceName }}
+
+
+
+
+ 商品信息
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 条码:
+ {{ getStockBarcode(selectedStock) }}
+
+
+ 当前库位:
+ {{ getStockSpace(selectedStock) }}
+
+
+ 可用库存:
+ {{ getStockQuantity(selectedStock) }}
+
+
+
+
+
+
+
+ 全部
+
+
+
+
+
+ 按仓位移库
+ 当前模式下无需选择商品和数量,提交时默认按原库位整体移至目标库位。
+
+
+
+
+
+
+
+
+
+
+ 确认移库
+ 重置
+
+
+
+
+
+
+
+
@@ -8,15 +154,632 @@
export default {
data() {
return {
-
+ loading: false,
+ submitting: false,
+ activeScanField: 'productKeyword',
+ relocationModeOptions: [
+ { label: '按商品', value: 'product' },
+ { label: '按仓位', value: 'space' }
+ ],
+ selectorVisible: false,
+ selectorType: '',
+ selectorField: '',
+ selectorList: [],
+ selectedStock: null,
+ formData: {
+ relocationMode: 'product',
+ sourceSpaceKeyword: '',
+ sourceSpaceId: null,
+ sourceSpaceName: '',
+ targetSpaceKeyword: '',
+ targetSpaceId: null,
+ targetSpaceName: '',
+ productKeyword: '',
+ moveQuantity: '',
+ remark: ''
+ }
}
},
+ onLoad() {
+ this.safeDispatchBroadcast('setCallbacks', {
+ onResult: this.handleBroadcastResult
+ });
+ this.safeDispatchBroadcast('start');
+ },
+ onShow() {
+ this.safeDispatchBroadcast('setCallbacks', {
+ onResult: this.handleBroadcastResult
+ });
+ this.safeDispatchBroadcast('resume');
+ },
+ onHide() {
+ this.safeDispatchBroadcast('pause');
+ },
+ onUnload() {
+ 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(`[Relocation] broadcast/${action} 调用失败:`, error);
+ });
+ }
+ } catch (error) {
+ console.warn(`[Relocation] broadcast/${action} 调用异常:`, error);
+ }
+ },
+ normalizeUniScanResult(scanResult) {
+ if (!scanResult) {
+ return '';
+ }
+
+ if (typeof scanResult === 'string') {
+ return scanResult.trim();
+ }
+
+ if (typeof scanResult.result === 'string') {
+ return scanResult.result.trim();
+ }
+
+ if (Array.isArray(scanResult.result)) {
+ const firstResult = scanResult.result.find(item => item);
+ if (typeof firstResult === 'string') {
+ return firstResult.trim();
+ }
+ if (firstResult && typeof firstResult.data === 'string') {
+ return firstResult.data.trim();
+ }
+ }
+
+ if (typeof scanResult.data === 'string') {
+ return scanResult.data.trim();
+ }
+
+ return '';
+ },
+ setActiveScanField(field) {
+ this.activeScanField = field;
+ },
+ handleModeChange(mode) {
+ this.formData.relocationMode = mode;
+ if (mode === 'space') {
+ this.selectedStock = null;
+ this.formData.productKeyword = '';
+ this.formData.moveQuantity = '';
+ this.activeScanField = 'sourceSpace';
+ return;
+ }
+
+ this.activeScanField = 'productKeyword';
+ },
+ handleBroadcastResult(result) {
+ const rawCode = this.normalizeUniScanResult(result);
+ if (!rawCode) {
+ return;
+ }
+
+ this.applyScanResult(rawCode, this.activeScanField || 'productKeyword');
+ },
+ handleFieldScan(field) {
+ this.setActiveScanField(field);
+ uni.scanCode({
+ onlyFromCamera: false,
+ scanType: ['qrCode', 'barCode', 'datamatrix', 'pdf417'],
+ success: (res) => {
+ const rawCode = this.normalizeUniScanResult(res);
+ if (!rawCode) {
+ uni.showToast({
+ title: '未识别到有效内容',
+ icon: 'none'
+ });
+ return;
+ }
+
+ this.applyScanResult(rawCode, field);
+ },
+ fail: (error) => {
+ const errMsg = String(error?.errMsg || '').toLowerCase();
+ if (errMsg.includes('cancel')) {
+ return;
+ }
+
+ uni.showToast({
+ title: '扫码失败,请重试',
+ icon: 'none'
+ });
+ }
+ });
+ },
+ applyScanResult(rawCode, field) {
+ if (field === 'sourceSpace' || field === 'targetSpace') {
+ const keywordKey = field === 'sourceSpace' ? 'sourceSpaceKeyword' : 'targetSpaceKeyword';
+ this.formData[keywordKey] = rawCode;
+ this.searchSpace(field, rawCode);
+ return;
+ }
+
+ this.formData.productKeyword = rawCode;
+ this.searchStock(rawCode);
+ },
+ handleSpaceBlur(field) {
+ const keyword = field === 'sourceSpace' ? this.formData.sourceSpaceKeyword : this.formData.targetSpaceKeyword;
+ if (keyword) {
+ this.searchSpace(field, keyword);
+ }
+ },
+ handleProductBlur() {
+ if (this.formData.productKeyword) {
+ this.searchStock(this.formData.productKeyword);
+ }
+ },
+ async searchSpace(field, keyword) {
+ const rawKeyword = String(keyword || '').trim();
+ if (!rawKeyword) {
+ return;
+ }
+
+ this.loading = true;
+ try {
+ const res = await this.$http('common.searchSpace', {
+ keyword: rawKeyword
+ });
+
+ if (res.code !== 200) {
+ throw new Error(res.message || '库位搜索失败');
+ }
+
+ const list = Array.isArray(res.data) ? res.data : [];
+ if (Number(res.total || list.length) === 1 && list[0]) {
+ this.applySpaceSelection(field, list[0]);
+ return;
+ }
+
+ if (list.length > 1) {
+ this.selectorType = 'space';
+ this.selectorField = field;
+ this.selectorList = list;
+ this.selectorVisible = true;
+ return;
+ }
+
+ uni.showToast({
+ title: '未找到匹配库位',
+ icon: 'none'
+ });
+ } catch (error) {
+ console.error('搜索库位失败:', error);
+ uni.showToast({
+ title: '库位查询失败',
+ icon: 'none'
+ });
+ } finally {
+ this.loading = false;
+ }
+ },
+ applySpaceSelection(field, item) {
+ const isSource = field === 'sourceSpace';
+ this.formData[isSource ? 'sourceSpaceId' : 'targetSpaceId'] = item?.id || item?.space_id || null;
+ this.formData[isSource ? 'sourceSpaceName' : 'targetSpaceName'] = this.getSpaceName(item);
+ this.formData[isSource ? 'sourceSpaceKeyword' : 'targetSpaceKeyword'] = this.getSpaceCode(item);
+ },
+ async searchStock(keyword) {
+ const rawKeyword = String(keyword || '').trim();
+ if (!rawKeyword) {
+ return;
+ }
+
+ this.loading = true;
+ try {
+ const res = await this.$http('stock.warehouse.search', {
+ keyword: rawKeyword
+ });
+
+ if (res.code !== 200) {
+ throw new Error(res.message || '库存查询失败');
+ }
+
+ const list = Array.isArray(res.data) ? res.data : [];
+ if (Number(res.total || list.length) === 1 && list[0]) {
+ this.applyStockSelection(list[0]);
+ return;
+ }
+
+ if (list.length > 1) {
+ this.selectorType = 'stock';
+ this.selectorField = 'stock';
+ this.selectorList = list;
+ this.selectorVisible = true;
+ return;
+ }
+
+ this.selectedStock = null;
+ uni.showToast({
+ title: '未找到匹配库存',
+ icon: 'none'
+ });
+ } catch (error) {
+ console.error('搜索库存失败:', error);
+ uni.showToast({
+ title: '库存查询失败',
+ icon: 'none'
+ });
+ } finally {
+ this.loading = false;
+ }
+ },
+ applyStockSelection(item) {
+ this.selectedStock = item;
+ this.formData.productKeyword = this.getStockBarcode(item) || this.getStockName(item);
+ if (!this.formData.moveQuantity) {
+ const quantity = this.getStockQuantity(item);
+ this.formData.moveQuantity = quantity && quantity !== '--' ? String(quantity) : '';
+ }
+ },
+ handleSelectorConfirm(item) {
+ if (this.selectorType === 'stock') {
+ this.applyStockSelection(item);
+ } else {
+ this.applySpaceSelection(this.selectorField, item);
+ }
+ this.selectorVisible = false;
+ },
+ getSpaceName(item) {
+ return item?.name || item?.space_name || item?.title || item?.barcode || item?.code || '未命名库位';
+ },
+ getSpaceCode(item) {
+ return item?.barcode || item?.code || item?.space_code || item?.name || '';
+ },
+ getStockName(item) {
+ return item?.item_name || item?.product_name || item?.name || item?.goods_name || '未命名商品';
+ },
+ getStockBarcode(item) {
+ if (Array.isArray(item?.barcodes) && item.barcodes.length) {
+ return item.barcodes.filter(Boolean).join(';');
+ }
+ return item?.barcode || item?.goods_code || item?.item_code || '--';
+ },
+ getStockSpace(item) {
+ return item?.space?.name || item?.space_name || item?.space_barcode || item?.space?.barcode || '--';
+ },
+ getStockQuantity(item) {
+ return item?.available_quantity || item?.actual_quantity || item?.quantity || item?.stock || '--';
+ },
+ getAvailableStockNumber() {
+ if (!this.selectedStock) {
+ return 0;
+ }
+
+ const quantity = this.getStockQuantity(this.selectedStock);
+ const normalizedQuantity = Number(String(quantity).replace(/,/g, '').trim());
+ return Number.isFinite(normalizedQuantity) && normalizedQuantity > 0 ? normalizedQuantity : 0;
+ },
+ normalizeMoveQuantity(value) {
+ const sanitized = String(value || '').replace(/\D/g, '');
+ if (!sanitized) {
+ return '';
+ }
+
+ return sanitized.replace(/^0+(?=\d)/, '');
+ },
+ handleMoveQuantityInput(value) {
+ this.formData.moveQuantity = this.normalizeMoveQuantity(value);
+ },
+ handleMoveQuantityBlur() {
+ this.formData.moveQuantity = this.normalizeMoveQuantity(this.formData.moveQuantity);
+ this.validateMoveQuantity(true);
+ },
+ validateMoveQuantity(showToast = false) {
+ if (this.formData.relocationMode !== 'product') {
+ return true;
+ }
+
+ const quantity = String(this.formData.moveQuantity || '').trim();
+ if (!quantity) {
+ if (showToast) {
+ uni.showToast({ title: '请输入移库数量', icon: 'none' });
+ }
+ return false;
+ }
+
+ if (!/^[1-9]\d*$/.test(quantity)) {
+ if (showToast) {
+ uni.showToast({ title: '移库数量需为正整数', icon: 'none' });
+ }
+ return false;
+ }
+
+ const maxQuantity = this.getAvailableStockNumber();
+ if (maxQuantity > 0 && Number(quantity) > maxQuantity) {
+ if (showToast) {
+ uni.showToast({ title: '移库数量不能大于可用库存', icon: 'none' });
+ }
+ return false;
+ }
+
+ return true;
+ },
+ handleFillAllQuantity() {
+ if (!this.selectedStock) {
+ uni.showToast({
+ title: '请先选择移库商品',
+ icon: 'none'
+ });
+ return;
+ }
+
+ const quantity = this.getStockQuantity(this.selectedStock);
+ if (quantity === '--' || quantity === '' || quantity === null || quantity === undefined) {
+ uni.showToast({
+ title: '未获取到可用库存',
+ icon: 'none'
+ });
+ return;
+ }
+
+ this.formData.moveQuantity = String(quantity);
+ },
+ async handleSubmit() {
+ if (!this.formData.sourceSpaceKeyword || !this.formData.sourceSpaceName) {
+ uni.showToast({ title: '请先识别移出库位', icon: 'none' });
+ return;
+ }
+ if (!this.formData.targetSpaceKeyword || !this.formData.targetSpaceName) {
+ uni.showToast({ title: '请先识别移入库位', icon: 'none' });
+ return;
+ }
+ if (this.formData.relocationMode === 'product' && !this.selectedStock) {
+ uni.showToast({ title: '请选择移库商品', icon: 'none' });
+ return;
+ }
+ if (this.formData.relocationMode === 'product' && !this.validateMoveQuantity(true)) {
+ return;
+ }
+ if (this.formData.sourceSpaceId && this.formData.targetSpaceId && this.formData.sourceSpaceId === this.formData.targetSpaceId) {
+ uni.showToast({ title: '移出库位和移入库位不能相同', icon: 'none' });
+ return;
+ }
+
+ uni.showModal({
+ title: '提示',
+ content: `当前项目暂未配置${this.formData.relocationMode === 'product' ? '按商品' : '按仓位'}移库提交接口,页面和扫码流程已接入。`,
+ showCancel: false
+ });
+ },
+ handleReset() {
+ this.formData = {
+ relocationMode: 'product',
+ sourceSpaceKeyword: '',
+ sourceSpaceId: null,
+ sourceSpaceName: '',
+ targetSpaceKeyword: '',
+ targetSpaceId: null,
+ targetSpaceName: '',
+ productKeyword: '',
+ moveQuantity: '',
+ remark: ''
+ };
+ this.selectedStock = null;
+ this.selectorVisible = false;
+ this.selectorType = '';
+ this.selectorField = '';
+ this.selectorList = [];
+ this.activeScanField = 'productKeyword';
+ }
}
}
-