From 5557efe0a54d4c12cee86fb99a886dd0a5800356 Mon Sep 17 00:00:00 2001 From: Fam Zheng Date: Sat, 1 Mar 2025 12:48:34 +0000 Subject: [PATCH] link chat and camera --- .../components/contentstream/contentstream.js | 7 +- .../contentstream/contentstream.wxml | 2 +- .../contentstream/contentstream.wxss | 5 ++ scanner/pages/camera/camera.js | 17 ++++- scanner/pages/chat/chat.js | 67 +++++++++++++------ scanner/pages/chat/chat.wxml | 4 +- 6 files changed, 74 insertions(+), 28 deletions(-) diff --git a/scanner/components/contentstream/contentstream.js b/scanner/components/contentstream/contentstream.js index 04695e7..df0aa74 100644 --- a/scanner/components/contentstream/contentstream.js +++ b/scanner/components/contentstream/contentstream.js @@ -35,6 +35,11 @@ Component({ }); return; } + this.setData({ + visible_content: [], + next_index: 0, + next_offset: 0, + }); setTimeout(() => { this.update_interval = setInterval(() => { this.update_visible_content(); @@ -49,12 +54,12 @@ Component({ } }, 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) { clearInterval(this.update_interval); return; } var next_entry = this.properties.content[this.data.next_index]; - console.log('next_entry', next_entry); if (next_entry.type != 'text') { // just add the next entry to the visible content this.setData({ diff --git a/scanner/components/contentstream/contentstream.wxml b/scanner/components/contentstream/contentstream.wxml index b01eacc..7de1367 100644 --- a/scanner/components/contentstream/contentstream.wxml +++ b/scanner/components/contentstream/contentstream.wxml @@ -4,7 +4,7 @@ - + {{ item.content }} diff --git a/scanner/components/contentstream/contentstream.wxss b/scanner/components/contentstream/contentstream.wxss index fc5e419..a0d0f06 100644 --- a/scanner/components/contentstream/contentstream.wxss +++ b/scanner/components/contentstream/contentstream.wxss @@ -89,4 +89,9 @@ view.text.margin-bottom-10 { view.text.bold { font-weight: bold; +} + +view.text.link { + color: #ef4823; + text-decoration: underline; } \ No newline at end of file diff --git a/scanner/pages/camera/camera.js b/scanner/pages/camera/camera.js index 8a3ff97..528addb 100644 --- a/scanner/pages/camera/camera.js +++ b/scanner/pages/camera/camera.js @@ -85,6 +85,9 @@ Page({ }, onLoad(options) { + this.setData({ + ai_chat_mode: options.ai_chat_mode, + }); var new_session_id = Date.now(); getApp().globalData.session_id = new_session_id; if (options.env == 'dev') { @@ -280,9 +283,17 @@ Page({ show_result_page(serial_code) { this.busy = true; - wx.redirectTo({ - url: '/pages/productinfo/productinfo?serial_code=' + serial_code, - }); + if (this.data.ai_chat_mode) { + // 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() { diff --git a/scanner/pages/chat/chat.js b/scanner/pages/chat/chat.js index 5e72252..6e55412 100644 --- a/scanner/pages/chat/chat.js +++ b/scanner/pages/chat/chat.js @@ -41,10 +41,15 @@ Page({ * Lifecycle function--Called when page load */ onLoad(options) { - this.show_welcome_response(); - this.show_verify_result(); - this.show_product_details(); - this.show_promotions(); + this.setData({ + serial_code: options.serial_code, + time: options.time, + }); + if (options.serial_code) { + this.show_verify_result(true); + } else { + this.show_welcome_response(); + } }, /** @@ -98,7 +103,7 @@ Page({ goto_camera() { wx.navigateTo({ - url: '/pages/camera/camera', + url: '/pages/camera/camera?ai_chat_mode=1', }) }, @@ -120,7 +125,7 @@ Page({ }) }, show_verify_tech() { - this.setData({ + this.set_content({ prompt: [ { type: 'text', @@ -161,7 +166,7 @@ Page({ type: 'suggestion', title: '重看验证结果', 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 = [ { type: 'text', @@ -203,12 +210,17 @@ Page({ }, { type: 'text', - content: '验证编码: xxxxx', - classes: 'margin-bottom-10', + content: '验证编码: ' + serial_code, + classes: 'margin-bottom-10 link', + onclick: () => { + wx.navigateTo({ + url: '/pages/productinfo/productinfo?serial_code=' + serial_code, + }); + } }, { type: 'text', - content: '验证时间: 2025-02-24 14:30' + content: '验证时间: ' + time, }, { type: 'splitline', @@ -240,16 +252,18 @@ Page({ } }, ] - this.setData({ - prompt: [{ - type: 'text', - content: '查看验证结果' - }], + var prompt = is_first_time ? [] : [{ + type: 'text', + content: '查看验证结果' + }]; + this.set_content({ + prompt: prompt, response: resp, }) }, show_welcome_response() { - this.setData({ + this.set_content({ + prompt: [], response: this.data.welcome_response, }) }, @@ -295,7 +309,7 @@ Page({ type: 'suggestion', title: '重看验证结果', onclick: () => { - this.show_verify_result(); + this.show_verify_result(false); } }, { @@ -313,7 +327,7 @@ Page({ } } ] - this.setData({ + this.set_content({ prompt: [{ type: 'text', content: '这个产品怎么样' @@ -357,7 +371,7 @@ Page({ type: 'suggestion', title: '重看验证结果', onclick: () => { - this.show_verify_result(); + this.show_verify_result(false); } }, { @@ -375,7 +389,7 @@ Page({ } } ] - this.setData({ + this.set_content({ prompt: [{ type: 'text', content: '有什么福利活动吗?' @@ -383,4 +397,15 @@ Page({ 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(); + } + } }) \ No newline at end of file diff --git a/scanner/pages/chat/chat.wxml b/scanner/pages/chat/chat.wxml index 175f549..c3deee8 100644 --- a/scanner/pages/chat/chat.wxml +++ b/scanner/pages/chat/chat.wxml @@ -1,7 +1,7 @@ - - + +