Explorar o código

feat:扫码溯源功能

liujt hai 8 meses
pai
achega
927ea528b0
Modificáronse 4 ficheiros con 69 adicións e 1 borrados
  1. 1 0
      App.vue
  2. 8 0
      pages.json
  3. 24 1
      pages/index/index.vue
  4. 36 0
      pages/traceability/scanCode/index.vue

+ 1 - 0
App.vue

@@ -17,6 +17,7 @@
 			const apiInfo = uni.getStorageSync('apiInfo')
 			if (apiInfo.protocal) {
 				Vue.prototype.apiUrl = `${apiInfo.protocal}${apiInfo.hostname}:${apiInfo.port}/api`
+				Vue.prototype.webviewUrl = `${apiInfo.protocal}${apiInfo.hostname}:${apiInfo.port}`
 			}
 			setTimeout(() => {
 				plus.navigator.closeSplashscreen()

+ 8 - 0
pages.json

@@ -2239,6 +2239,14 @@
 				"navigationBarTextStyle": "white"
 			}
 		},
+		{
+			"path": "pages/traceability/scanCode/index",
+			"style": {
+				"navigationBarTitleText": "溯源",
+				"navigationStyle": "custom",
+				"navigationBarTextStyle": "white"
+			}
+		},
 		{
 			"path" : "pages/traceability/traceabilityCode/purchase",
 			"style" : 

+ 24 - 1
pages/index/index.vue

@@ -292,7 +292,30 @@
 				let _this = this
 				uni.scanCode({
 					success: function(res) {
-						_this.scantoRouter(res.result)
+						console.log(res)
+						// 获取扫描结果中的URL
+						const scanResult = res.result
+						// 检查URL是否包含traceability
+						if(scanResult && scanResult.includes('/traceability')) {
+							// 从扫描结果中提取id参数
+							let id = ''
+							if(scanResult.includes('id=')) {
+								// 分割URL获取id参数值
+								const idPart = scanResult.split('id=')[1]
+								// 如果id后面还有其他参数,只取到第一个&之前的部分
+								if(idPart.includes('&')) {
+									id = idPart.split('&')[0]
+								} else {
+									id = idPart
+								}
+							}
+							// 跳转到溯源页面并传递id
+							uni.navigateTo({
+								url: `pages/traceability/scanCode/index?id=${id}`
+							})
+							return
+						}
+						_this.scantoRouter(scanResult)
 					}
 				})
 			},

+ 36 - 0
pages/traceability/scanCode/index.vue

@@ -0,0 +1,36 @@
+<template>
+	<view>
+		<web-view :webview-styles="webviewStyles" :src="path"></web-view>
+	</view>
+</template>
+
+<script>
+import Vue from 'vue'
+	export default {
+		data() {
+			return {
+				webviewStyles: {
+					progress: {
+						color: '#FF3333'
+					}
+				},
+                path: '/traceability',
+			}
+		},
+        onLoad({id}) {
+            console.log(id)
+            this.path = `${Vue.prototype.webviewUrl}/traceability?id=${id}`
+        },
+        computed: {
+            webviewUrl() {
+                console.log('webviewUrl', Vue.prototype.webviewUrl)
+                // http://aiot.zoomwin.com.cn:51007/traceability?id=1970310344451657730
+                return Vue.prototype.webviewUrl + '/traceability'
+            }
+        },
+	}
+</script>
+
+<style>
+
+</style>