link chat and camera

This commit is contained in:
Fam Zheng 2025-03-01 12:48:34 +00:00
parent f2c461935a
commit 5557efe0a5
6 changed files with 74 additions and 28 deletions

View File

@ -35,6 +35,11 @@ Component({
}); });
return; return;
} }
this.setData({
visible_content: [],
next_index: 0,
next_offset: 0,
});
setTimeout(() => { setTimeout(() => {
this.update_interval = setInterval(() => { this.update_interval = setInterval(() => {
this.update_visible_content(); this.update_visible_content();
@ -49,12 +54,12 @@ Component({
} }
}, },
update_visible_content() { update_visible_content() {
console.log('update_visible_content', this.data.next_index, this.properties.content.length);
if (this.data.next_index >= this.properties.content.length) { if (this.data.next_index >= this.properties.content.length) {
clearInterval(this.update_interval); clearInterval(this.update_interval);
return; return;
} }
var next_entry = this.properties.content[this.data.next_index]; var next_entry = this.properties.content[this.data.next_index];
console.log('next_entry', next_entry);
if (next_entry.type != 'text') { if (next_entry.type != 'text') {
// just add the next entry to the visible content // just add the next entry to the visible content
this.setData({ this.setData({

View File

@ -4,7 +4,7 @@
</view> </view>
<view class="content {{ is_prompt ? 'prompt' : '' }}"> <view class="content {{ is_prompt ? 'prompt' : '' }}">
<view wx:for="{{ visible_content }}" wx:key="index"> <view wx:for="{{ visible_content }}" wx:key="index">
<view wx:if="{{ item.type == 'text'}}" class="text {{ item.classes }}"> <view wx:if="{{ item.type == 'text'}}" class="text {{ item.classes }}" data-index="{{ index }}" bindtap="handle_onclick">
<text wx:if="{{ item.mark == 'tick' }}" class="green">✓</text><text class="{{ item.classes }}">{{ item.content }}</text> <text wx:if="{{ item.mark == 'tick' }}" class="green">✓</text><text class="{{ item.classes }}">{{ item.content }}</text>
</view> </view>
<view wx:if="{{ item.type == 'scanguidecss' }}" class="media"> <view wx:if="{{ item.type == 'scanguidecss' }}" class="media">

View File

@ -89,4 +89,9 @@ view.text.margin-bottom-10 {
view.text.bold { view.text.bold {
font-weight: bold; font-weight: bold;
}
view.text.link {
color: #ef4823;
text-decoration: underline;
} }

View File

@ -85,6 +85,9 @@ Page({
}, },
onLoad(options) { onLoad(options) {
this.setData({
ai_chat_mode: options.ai_chat_mode,
});
var new_session_id = Date.now(); var new_session_id = Date.now();
getApp().globalData.session_id = new_session_id; getApp().globalData.session_id = new_session_id;
if (options.env == 'dev') { if (options.env == 'dev') {
@ -280,9 +283,17 @@ Page({
show_result_page(serial_code) { show_result_page(serial_code) {
this.busy = true; this.busy = true;
wx.redirectTo({ if (this.data.ai_chat_mode) {
url: '/pages/productinfo/productinfo?serial_code=' + serial_code, // YYYY-MM-DD HH:MM:SS
}); var time = new Date().toISOString().replace('T', ' ').replace('Z', '');
wx.redirectTo({
url: '/pages/chat/chat?serial_code=' + serial_code + '&time=' + time,
});
} else {
wx.redirectTo({
url: '/pages/productinfo/productinfo?serial_code=' + serial_code,
});
}
}, },
show_verifyfailed() { show_verifyfailed() {

View File

@ -41,10 +41,15 @@ Page({
* Lifecycle function--Called when page load * Lifecycle function--Called when page load
*/ */
onLoad(options) { onLoad(options) {
this.show_welcome_response(); this.setData({
this.show_verify_result(); serial_code: options.serial_code,
this.show_product_details(); time: options.time,
this.show_promotions(); });
if (options.serial_code) {
this.show_verify_result(true);
} else {
this.show_welcome_response();
}
}, },
/** /**
@ -98,7 +103,7 @@ Page({
goto_camera() { goto_camera() {
wx.navigateTo({ wx.navigateTo({
url: '/pages/camera/camera', url: '/pages/camera/camera?ai_chat_mode=1',
}) })
}, },
@ -120,7 +125,7 @@ Page({
}) })
}, },
show_verify_tech() { show_verify_tech() {
this.setData({ this.set_content({
prompt: [ prompt: [
{ {
type: 'text', type: 'text',
@ -161,7 +166,7 @@ Page({
type: 'suggestion', type: 'suggestion',
title: '重看验证结果', title: '重看验证结果',
onclick: () => { onclick: () => {
this.show_verify_result(); this.show_verify_result(false);
} }
}, },
{ {
@ -181,7 +186,9 @@ Page({
] ]
}) })
}, },
show_verify_result() { show_verify_result(is_first_time) {
var serial_code = this.data.serial_code || "";
var time = this.data.time || "2025-01-01 14:30";
var resp = [ var resp = [
{ {
type: 'text', type: 'text',
@ -203,12 +210,17 @@ Page({
}, },
{ {
type: 'text', type: 'text',
content: '验证编码: xxxxx', content: '验证编码: ' + serial_code,
classes: 'margin-bottom-10', classes: 'margin-bottom-10 link',
onclick: () => {
wx.navigateTo({
url: '/pages/productinfo/productinfo?serial_code=' + serial_code,
});
}
}, },
{ {
type: 'text', type: 'text',
content: '验证时间: 2025-02-24 14:30' content: '验证时间: ' + time,
}, },
{ {
type: 'splitline', type: 'splitline',
@ -240,16 +252,18 @@ Page({
} }
}, },
] ]
this.setData({ var prompt = is_first_time ? [] : [{
prompt: [{ type: 'text',
type: 'text', content: '查看验证结果'
content: '查看验证结果' }];
}], this.set_content({
prompt: prompt,
response: resp, response: resp,
}) })
}, },
show_welcome_response() { show_welcome_response() {
this.setData({ this.set_content({
prompt: [],
response: this.data.welcome_response, response: this.data.welcome_response,
}) })
}, },
@ -295,7 +309,7 @@ Page({
type: 'suggestion', type: 'suggestion',
title: '重看验证结果', title: '重看验证结果',
onclick: () => { onclick: () => {
this.show_verify_result(); this.show_verify_result(false);
} }
}, },
{ {
@ -313,7 +327,7 @@ Page({
} }
} }
] ]
this.setData({ this.set_content({
prompt: [{ prompt: [{
type: 'text', type: 'text',
content: '这个产品怎么样' content: '这个产品怎么样'
@ -357,7 +371,7 @@ Page({
type: 'suggestion', type: 'suggestion',
title: '重看验证结果', title: '重看验证结果',
onclick: () => { onclick: () => {
this.show_verify_result(); this.show_verify_result(false);
} }
}, },
{ {
@ -375,7 +389,7 @@ Page({
} }
} }
] ]
this.setData({ this.set_content({
prompt: [{ prompt: [{
type: 'text', type: 'text',
content: '有什么福利活动吗?' content: '有什么福利活动吗?'
@ -383,4 +397,15 @@ Page({
response: resp, response: resp,
}) })
}, },
set_content({prompt, response}) {
this.setData({
prompt: prompt,
response: response,
})
this.selectComponent('#response').restart_content_output();
var x = this.selectComponent('#prompt');
if (x) {
x.restart_content_output();
}
}
}) })

View File

@ -1,7 +1,7 @@
<view class="container"> <view class="container">
<view class="chatlog {{ show_modal.length > 0 ? 'hidden' : '' }}"> <view class="chatlog {{ show_modal.length > 0 ? 'hidden' : '' }}">
<contentstream wx:if="{{ prompt.length > 0 }}" content="{{ prompt }}" is_prompt="1"></contentstream> <contentstream id="prompt" wx:if="{{ prompt.length > 0 }}" content="{{ prompt }}" is_prompt="1"></contentstream>
<contentstream content="{{ response }}"></contentstream> <contentstream id="response" content="{{ response }}"></contentstream>
</view> </view>
<view class="bottom"> <view class="bottom">
<view class="quick-actions"> <view class="quick-actions">