Refactor(云灵AI):以图搜索接口对接
This commit is contained in:
@@ -116,7 +116,7 @@ export default {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
performRecognition(imageUrl) {
|
performRecognition(imageUrl) {
|
||||||
// 存储识别到的图片 URL,并返回上一页
|
// 存储识别到的图片URL
|
||||||
uni.setStorageSync('recognitionImage', imageUrl)
|
uni.setStorageSync('recognitionImage', imageUrl)
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: '/aiChat/views/imageRecognitionResult'
|
url: '/aiChat/views/imageRecognitionResult'
|
||||||
|
|||||||
@@ -1,18 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="image-recognition-result-page">
|
<view class="image-recognition-result-page">
|
||||||
<hx-navbar
|
|
||||||
:back="true"
|
|
||||||
:fixed="true"
|
|
||||||
:statusBar="true"
|
|
||||||
left-icon="arrowleft"
|
|
||||||
color="#333"
|
|
||||||
transparent="auto"
|
|
||||||
barPlaceholder="hidden"
|
|
||||||
title="识别结果"
|
|
||||||
/>
|
|
||||||
<view
|
<view
|
||||||
class="page-body"
|
class="page-body"
|
||||||
:style="{ 'padding-top': (44 + statusBarHeight) + 'px' }"
|
|
||||||
>
|
>
|
||||||
<view class="header">
|
<view class="header">
|
||||||
<view
|
<view
|
||||||
@@ -37,14 +26,17 @@
|
|||||||
<view class="sheet">
|
<view class="sheet">
|
||||||
<view class="sheet-thumb-row">
|
<view class="sheet-thumb-row">
|
||||||
<image
|
<image
|
||||||
v-if="imageUrl"
|
v-if="imageUrl && confidence > 0"
|
||||||
:src="imageUrl"
|
:src="imageUrl"
|
||||||
class="sheet-thumb"
|
class="sheet-thumb"
|
||||||
mode="aspectFill"
|
mode="aspectFill"
|
||||||
/>
|
/>
|
||||||
|
<view v-else class="empty-state">
|
||||||
|
<view class="empty-text">未识别到物品,请重新尝试</view>
|
||||||
|
<view class="empty-title">为你推荐</view>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
<view class="sheet-divider" />
|
<view class="sheet-divider" />
|
||||||
|
|
||||||
<view class="goods-grid">
|
<view class="goods-grid">
|
||||||
<view
|
<view
|
||||||
v-for="(item, index) in goodsList"
|
v-for="(item, index) in goodsList"
|
||||||
@@ -58,19 +50,17 @@
|
|||||||
mode="aspectFill"
|
mode="aspectFill"
|
||||||
/>
|
/>
|
||||||
<view class="goods-title">
|
<view class="goods-title">
|
||||||
{{ item.title }}
|
{{ item.name }}
|
||||||
</view>
|
</view>
|
||||||
<view class="goods-price-row">
|
<view class="goods-price-row">
|
||||||
<view class="price-left">
|
<view class="price-left">
|
||||||
<text class="price-symbol">¥</text>
|
<text class="price-symbol">¥</text>
|
||||||
<text class="price-val">{{ item.price }}</text>
|
<text class="price-val">{{ item.price }}</text>
|
||||||
<text v-if="item.originPrice" class="origin-price">¥{{ item.originPrice }}</text>
|
|
||||||
</view>
|
</view>
|
||||||
<image
|
<image
|
||||||
:src="webUrl + '/home/icon-cart.png'"
|
:src="webUrl + '/home/icon-cart.png'"
|
||||||
class="cart-btn"
|
class="cart-btn"
|
||||||
mode="aspectFit"
|
mode="aspectFit"
|
||||||
@click.stop="addToCart(item)"
|
|
||||||
/>
|
/>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -81,71 +71,50 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import { getAnalyzeByImageV3 } from '@/api/chat'
|
||||||
|
import Recommend from '@/components/Recommend'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'AiChatImageRecognitionResultPage',
|
name: 'AiChatImageRecognitionResultPage',
|
||||||
|
components: {
|
||||||
|
Recommend
|
||||||
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
webUrl: this.$VUE_APP_RESOURCES_URL,
|
webUrl: this.$VUE_APP_RESOURCES_URL,
|
||||||
statusBarHeight: 20,
|
statusBarHeight: 20,
|
||||||
imageUrl: '',
|
imageUrl: '',
|
||||||
goodsList: []
|
goodsList: [],
|
||||||
|
confidence: 0
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
this.initSystemInfo()
|
|
||||||
const urlFromQuery = options.imageUrl || ''
|
const urlFromQuery = options.imageUrl || ''
|
||||||
const urlFromStorage = uni.getStorageSync('recognitionImage') || ''
|
const urlFromStorage = uni.getStorageSync('recognitionImage') || ''
|
||||||
this.imageUrl = urlFromQuery || urlFromStorage || ''
|
this.imageUrl = urlFromQuery || urlFromStorage || ''
|
||||||
if (urlFromStorage) {
|
if (urlFromStorage) {
|
||||||
uni.removeStorageSync('recognitionImage')
|
// uni.removeStorageSync('recognitionImage')
|
||||||
}
|
}
|
||||||
this.goodsList = this.buildMockGoods(this.imageUrl)
|
this.init()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
initSystemInfo() {
|
init() {
|
||||||
uni.getSystemInfo({
|
this.loaded = false
|
||||||
success: (e) => {
|
getAnalyzeByImageV3({
|
||||||
this.statusBarHeight = e.statusBarHeight || 20
|
imageUrl: this.imageUrl
|
||||||
|
}).then(res => {
|
||||||
|
const { data, success } = res
|
||||||
|
if (success) {
|
||||||
|
this.goodsList = data.cards || []
|
||||||
}
|
}
|
||||||
|
}).finally(() => {
|
||||||
|
this.loaded = true
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
buildMockGoods(fallbackImg) {
|
|
||||||
const img = fallbackImg || (this.webUrl + '/home/no-data-bg.png')
|
|
||||||
return [
|
|
||||||
{
|
|
||||||
id: 0,
|
|
||||||
img,
|
|
||||||
title: '西双版纳独有酸蚀蜂种一年一采 不一样的美味',
|
|
||||||
price: '39.8',
|
|
||||||
originPrice: '40.00'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 1,
|
|
||||||
img,
|
|
||||||
title: '西双版纳独有酸蚀蜂种一年一采 不一样的美味',
|
|
||||||
price: '39.8',
|
|
||||||
originPrice: '40.00'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2,
|
|
||||||
img,
|
|
||||||
title: '西双版纳独有酸蚀蜂种一年一采 不一样的美味',
|
|
||||||
price: '39.8',
|
|
||||||
originPrice: '40.00'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 3,
|
|
||||||
img,
|
|
||||||
title: '西双版纳独有酸蚀蜂种一年一采 不一样的美味',
|
|
||||||
price: '39.8',
|
|
||||||
originPrice: '40.00'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
},
|
|
||||||
goGoods(item) {
|
goGoods(item) {
|
||||||
if (!item || !item.productId) return
|
if (!item || !item.id) return
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: `/pages/shop/GoodsCon/index?id=${item.productId}`
|
url: `/pages/shop/GoodsCon/index?id=${item.id}`
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
addToCart() {
|
addToCart() {
|
||||||
@@ -165,7 +134,7 @@ export default {
|
|||||||
|
|
||||||
.header {
|
.header {
|
||||||
position: relative;
|
position: relative;
|
||||||
height: 520rpx;
|
height: 480rpx;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -194,19 +163,21 @@ export default {
|
|||||||
.scan-wrap {
|
.scan-wrap {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
top: 50%;
|
top: 45%;
|
||||||
width: 320rpx;
|
width: 320rpx;
|
||||||
height: 320rpx;
|
height: 320rpx;
|
||||||
transform: translate(-50%, -52%);
|
transform: translate(-50%, -52%);
|
||||||
border-radius: 24rpx;
|
border-radius: 24rpx;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
box-shadow: 0 18rpx 48rpx rgba(0, 0, 0, 0.18);
|
// box-shadow: 0 18rpx 48rpx rgba(0, 0, 0, 0.18);
|
||||||
}
|
}
|
||||||
|
|
||||||
.scan-image {
|
.scan-image {
|
||||||
|
display: block;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
display: block;
|
border-radius: 12rpx;
|
||||||
|
transform: scale(0.8);
|
||||||
}
|
}
|
||||||
|
|
||||||
.corner {
|
.corner {
|
||||||
@@ -214,7 +185,6 @@ export default {
|
|||||||
width: 44rpx;
|
width: 44rpx;
|
||||||
height: 44rpx;
|
height: 44rpx;
|
||||||
border: 6rpx solid rgba(255, 255, 255, 0.95);
|
border: 6rpx solid rgba(255, 255, 255, 0.95);
|
||||||
border-radius: 10rpx;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.corner.tl {
|
.corner.tl {
|
||||||
@@ -271,6 +241,22 @@ export default {
|
|||||||
margin: 0 32rpx;
|
margin: 0 32rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-text {
|
||||||
|
font-size: 28rpx;
|
||||||
|
color: #999;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
.empty-title {
|
||||||
|
font-size: 32rpx;
|
||||||
|
font-weight: bold;
|
||||||
|
color: #333;
|
||||||
|
margin-bottom: 20rpx;
|
||||||
|
}
|
||||||
|
|
||||||
.goods-grid {
|
.goods-grid {
|
||||||
padding: 28rpx 24rpx 0 24rpx;
|
padding: 28rpx 24rpx 0 24rpx;
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -54,3 +54,8 @@ export function getCompletionsV3(params) {
|
|||||||
export function getAnalyzeKeywordsChangeV3(data) {
|
export function getAnalyzeKeywordsChangeV3(data) {
|
||||||
return request.post('/v1/chat/goods/refresh', data, { login: true })
|
return request.post('/v1/chat/goods/refresh', data, { login: true })
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 以图搜索商品
|
||||||
|
export function getAnalyzeByImageV3(data) {
|
||||||
|
return request.post('/v1/chat/image/recognition', data, { login: true })
|
||||||
|
}
|
||||||
|
|||||||
+1
-3
@@ -909,9 +909,7 @@
|
|||||||
{
|
{
|
||||||
"path": "views/imageRecognitionResult",
|
"path": "views/imageRecognitionResult",
|
||||||
"style": {
|
"style": {
|
||||||
"navigationBarTitleText": "识别结果",
|
"navigationBarTitleText": "云灵"
|
||||||
"navigationStyle": "custom",
|
|
||||||
"navigationBarTextStyle": "white"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user