Przeglądaj źródła

feat: enhance repository selection and book activation process

- Added repository management to the code-storage-add component, allowing for better handling of repository data.
- Implemented repository selection in the code-storage component, including a new UI for selecting repositories.
- Improved data persistence by storing the selected repository in local storage.
- Enhanced error handling to ensure users are prompted when repository information is missing during book activation.
- Updated CSS styles for better layout and user experience in the repository selection interface.
ylong 1 miesiąc temu
rodzic
commit
09c1151d56

+ 15 - 1
pages/index/wms/code-storage-add.vue

@@ -48,6 +48,11 @@
 		"imgUrl": ""
 	});
 
+	const repository = ref({
+		id: '',
+		repositoryName: ''
+	});
+
 	// 书籍信息
 	const bookInfo = ref({});
 
@@ -67,6 +72,8 @@
 		resetForm();
 		const storedInfo = uni.getStorageSync('bookInfo');
 		bookInfo.value = storedInfo || {};
+		const storedRepository = uni.getStorageSync('codeStorageCurrentRepository');
+		repository.value = storedRepository || {};
 	});
 
 	onShow(() => {
@@ -78,6 +85,7 @@
 
 	onUnload(() => {
 		uni.removeStorageSync('bookInfo');
+		uni.removeStorageSync('codeStorageCurrentRepository');
 	});
 
 	// 图片上传成功回调
@@ -99,6 +107,11 @@
 			return;
 		}
 
+		if (!repository.value?.id) {
+			uni.$u.toast('仓库信息缺失,请重新选择仓库');
+			return;
+		}
+
 		if (!form.value.imgUrl || form.value.imgUrl.length === 0) {
 			uni.$u.toast('请先上传图片');
 			return;
@@ -112,7 +125,8 @@
 		isSubmitting.value = true;
 		uni.$u.http.post('/activation/bookActivationInfo/activationAdd', {
 			isbn: bookInfo.value.isbn,
-			img: form.value.imgUrl[0]
+			img: form.value.imgUrl[0],
+			repositoryId: repository.value.id
 		}).then(res => {
 			if (res.code == 200) {
 				uni.$u.toast('提交成功')

+ 72 - 14
pages/index/wms/code-storage.vue

@@ -1,11 +1,17 @@
 <template>
     <view class="container">
         <view class="main-content">
+            <view class="input-group">
+                <u-input :customStyle="customStyle" :placeholder-style="placeholderStyle"
+                    v-model="repository.repositoryName" placeholder="请选择仓库" readonly border="surround" />
+                <u-button :customStyle="customStyle" type="info" color="#a4adb3" @click="selectRepository"
+                    text="选择" />
+            </view>
             <view class="input-group">
                 <u-input :customStyle="customStyle" :placeholder-style="placeholderStyle" v-model="form.isbn"
-                    placeholder="扫描/输入ISBN" border="surround" />
+                    placeholder="扫描/输入ISBN" border="surround" clearable />
                 <u-button :customStyle="customStyle" type="info" color="#a4adb3" @click="handleBarcode(form.isbn)"
-                    text="确定" />
+                    text="查询" />
             </view>
         </view>
 
@@ -19,20 +25,27 @@
 import {
     reactive,
     ref,
+    onMounted,
     onUnmounted
 } from 'vue';
 import {
-    onLoad,
     onShow
 } from '@dcloudio/uni-app'
 
+const STORAGE_KEY = 'codeStorageLastRepository'
+
 const placeholderStyle = "font-size:32rpx"
 const customStyle = reactive({
     height: '90rpx'
 })
 
+const repository = ref({
+    id: '',
+    repositoryName: ''
+})
+
 const form = ref({
-    "isbn": ""
+    isbn: ""
 })
 
 let barcodeLock = false
@@ -40,43 +53,68 @@ let lastBarcode = ''
 let lastBarcodeAt = 0
 const BARCODE_DEBOUNCE_MS = 2000
 
+function loadLastRepository() {
+    const lastRepository = uni.getStorageSync(STORAGE_KEY)
+    if (lastRepository) {
+        repository.value = {
+            id: lastRepository.id || '',
+            repositoryName: lastRepository.repositoryName || ''
+        }
+    }
+}
+
+function selectRepository() {
+    uni.navigateTo({
+        url: '/pages/index/wms/warehouse-select?type=repository&repositoryId=' + (repository.value.id || ''),
+        fail: (err) => {
+            console.error('跳转仓库选择页失败', err)
+            uni.$u.toast('打开仓库选择页失败')
+        }
+    })
+}
+
 function scanCode() {
+    if (!repository.value.id) {
+        return uni.$u.toast('请先选择仓库')
+    }
     uni.scanCode({
         success: (res) => {
             form.value.isbn = res.result;
             handleBarcode(res.result)
         },
-        fail: (err) => {
+        fail: () => {
             uni.$u.toast('扫码失败')
         }
     });
 }
 
-//isbn正则校验是否符合
 function checkIsbn(isbn) {
     const isbn13Regex = /^(?:97[89]-?\d{1,5}-?\d{1,7}-?\d{1,6}-?\d)$/;
-    if (isbn13Regex.test(isbn)) {
-        return true;
-    }
-    return false;
+    return isbn13Regex.test(isbn);
 }
 
 function handleBarcode(code) {
+    if (!repository.value.id) {
+        return uni.$u.toast('请先选择仓库')
+    }
     if (!code) return uni.$u.toast('请输入ISBN')
 
     const now = Date.now()
     if (barcodeLock) return
     if (code === lastBarcode && now - lastBarcodeAt < BARCODE_DEBOUNCE_MS) return
 
-    // 验证ISBN格式
     if (!checkIsbn(code)) {
         return uni.$u.ttsModule.speak('不是正确的ISBN码')
     }
 
     barcodeLock = true
     uni.$u.http.post('/activation/bookActivationInfo/queryBookBasicByIsbn/' + code).then(res => {
-        if (res.code == 200) {
+        if (res.code == 200 && res.data) {
             uni.setStorageSync('bookInfo', res.data)
+            uni.setStorageSync('codeStorageCurrentRepository', {
+                id: repository.value.id,
+                repositoryName: repository.value.repositoryName
+            })
             uni.navigateTo({
                 url: '/pages/index/wms/code-storage-add?isbn=' + encodeURIComponent(code)
             })
@@ -84,13 +122,32 @@ function handleBarcode(code) {
             lastBarcode = code
             lastBarcodeAt = Date.now()
         } else {
-            uni.$u.toast('未找到该书籍')
+            uni.$u.toast(res.msg)
+            uni.$u.ttsModule.speak(res.msg)
         }
     }).finally(() => {
         barcodeLock = false
     })
 }
 
+onMounted(() => {
+    loadLastRepository()
+    uni.$on('updateRepository', (data) => {
+        repository.value = {
+            id: data.id,
+            repositoryName: data.repositoryName
+        }
+        uni.setStorageSync(STORAGE_KEY, {
+            id: data.id,
+            repositoryName: data.repositoryName
+        })
+    })
+})
+
+onShow(() => {
+    loadLastRepository()
+})
+
 // #ifdef APP-PLUS
 const { unregister } = uni.$u.useEventListener((e) => {
     form.value.isbn = e.barcode
@@ -99,6 +156,7 @@ const { unregister } = uni.$u.useEventListener((e) => {
 // #endif
 
 onUnmounted(() => {
+    uni.$off('updateRepository')
     // #ifdef APP-PLUS
     unregister();
     // #endif
@@ -128,4 +186,4 @@ onUnmounted(() => {
 .scan-button {
     width: 100%;
 }
-</style>
+</style>

+ 80 - 25
pages/index/wms/warehouse-select.vue

@@ -1,18 +1,17 @@
 <template>
     <view class="container" @click="playGlobalSound">
-        <!-- 搜索框 -->
         <view class="search-area">
             <u-search v-model="searchText" placeholder="请输入仓库名称" :show-action="false" :clearabled="true"
                 @change="onSearch" height="40" placeholder-style="font-size:16px"></u-search>
         </view>
 
-        <!-- 仓库列表 -->
         <view class="warehouse-list">
-            <view v-for="(item, index) in warehouses" :key="index" 
+            <view v-for="(item, index) in displayList" :key="item.id"
                 :class="['warehouse-item', { 'warehouse-item-active': item.id == selectedId }]"
                 hover-class="warehouse-item-hover" @click="selectWarehouse(item)">
-                <text>{{ index + 1 }}.{{ item.godownName }}</text>
+                <text>{{ index + 1 }}.{{ getItemName(item) }}</text>
             </view>
+            <view v-if="isRepositoryMode && !loading && displayList.length === 0" class="empty-tip">暂无仓库数据</view>
         </view>
     </view>
 </template>
@@ -21,51 +20,100 @@
 import { ref, computed } from 'vue'
 import { onLoad } from '@dcloudio/uni-app'
 
-// 点击全局音效
-function playGlobalSound(){
+const STORAGE_KEY = 'codeStorageLastRepository'
+
+function playGlobalSound() {
     uni.$u.playClickSound()
 }
 
-// 搜索文本
 const searchText = ref('')
-
-// 仓库列表数据
 const warehouses = ref([])
+const loading = ref(false)
+const selectedId = ref()
+const pageType = ref('godown')
+
+const isRepositoryMode = computed(() => pageType.value === 'repository')
+
+const displayList = computed(() => {
+    if (!isRepositoryMode.value) {
+        return warehouses.value
+    }
+    const keyword = searchText.value.trim()
+    if (!keyword) return warehouses.value
+    return warehouses.value.filter(item => getItemName(item)?.includes(keyword))
+})
+
+function getItemName(item) {
+    return isRepositoryMode.value ? item.repositoryName : item.godownName
+}
 
-//根据name查询仓库列表 /app/appUser/searchGodown
-function getGodownListByName(name = "") {
+function getGodownListByName(name = '') {
     uni.$u.http.post('/app/appUser/searchGodown?name=' + name).then(res => {
         if (res.code == 200) {
-            warehouses.value = res.data
+            warehouses.value = res.data || []
         }
     })
 }
-getGodownListByName()
 
+function getRepositoryList() {
+    loading.value = true
+    uni.$u.http.get('/activation/bookActivationInfo/getRepositoryList').then(res => {
+        if (res.code == 200) {
+            warehouses.value = res.data || []
+        } else {
+            uni.$u.toast(res.msg || '获取仓库列表失败')
+        }
+    }).finally(() => {
+        loading.value = false
+    })
+}
 
-// 搜索处理
-const onSearch = () => {
-    getGodownListByName(searchText.value)
+function loadList() {
+    if (isRepositoryMode.value) {
+        getRepositoryList()
+    } else {
+        getGodownListByName(searchText.value)
+    }
 }
 
-// 选择仓库
-const selectWarehouse = (item) => {
-    // 使用事件总线传递数据
-    uni.$emit('updateWarehouse', item)
+function onSearch() {
+    if (!isRepositoryMode.value) {
+        getGodownListByName(searchText.value)
+    }
+}
 
-    // 返回上一页
+function selectWarehouse(item) {
+    if (isRepositoryMode.value) {
+        uni.$emit('updateRepository', item)
+        uni.setStorageSync(STORAGE_KEY, {
+            id: item.id,
+            repositoryName: item.repositoryName
+        })
+    } else {
+        uni.$emit('updateWarehouse', item)
+    }
     uni.navigateBack()
 }
 
-const selectedId = ref()
 onLoad((options) => {
-    if (options.godownId) {
-        selectedId.value = options.godownId       
+    if (options.type === 'repository') {
+        pageType.value = 'repository'
     }
+    if (options.repositoryId) {
+        selectedId.value = options.repositoryId
+    } else if (options.godownId) {
+        selectedId.value = options.godownId
+    }
+    loadList()
 })
 </script>
 
 <style scoped>
+.search-area {
+    padding: 12px;
+    background-color: #fff;
+}
+
 .warehouse-list {
     margin-top: 12px;
 }
@@ -85,4 +133,11 @@ onLoad((options) => {
 .warehouse-item-hover {
     background-color: #f5f5f5;
 }
-</style>
+
+.empty-tip {
+    text-align: center;
+    padding: 40px 0;
+    color: #999;
+    font-size: 14px;
+}
+</style>

Plik diff jest za duży
+ 0 - 0
unpackage/dist/build/app-plus/app-service.js


Plik diff jest za duży
+ 0 - 0
unpackage/dist/build/app-plus/pages/index/wms/code-storage-add.css


Plik diff jest za duży
+ 0 - 0
unpackage/dist/build/app-plus/pages/index/wms/code-storage.css


Plik diff jest za duży
+ 0 - 0
unpackage/dist/build/app-plus/pages/index/wms/warehouse-select.css


Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików