From 73bd78b23f1d3bdd5f681b785e54e122ec1b4059 Mon Sep 17 00:00:00 2001
From: linghaihui <75124771@qq.com>
Date: Thu, 30 Mar 2023 18:37:35 +0800
Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E5=88=86=E4=BA=AB?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
bingchat/components/chatbox/index.js | 69 ++++++++++++++++++++++++--
bingchat/components/chatbox/index.wxml | 2 +-
bingchat/pages/index/index.js | 37 +++++++++++++-
3 files changed, 101 insertions(+), 7 deletions(-)
diff --git a/bingchat/components/chatbox/index.js b/bingchat/components/chatbox/index.js
index d575c61..720f143 100644
--- a/bingchat/components/chatbox/index.js
+++ b/bingchat/components/chatbox/index.js
@@ -1,5 +1,14 @@
const app = getApp()
+var closeShareOnCopy = false
+try {
+ if (wx.getStorageSync("closeShareOnCopy")) {
+ closeShareOnCopy = true
+ }
+} catch (e) {
+ closeShareOnCopy = false
+}
+
Component({
options: {
addGlobalClass: true,
@@ -32,6 +41,7 @@ Component({
chatList: [],
receiveData: false,
autoIncrConversation: 1,
+ closeShareOnCopy: closeShareOnCopy,
},
methods: {
initMessageHistory() {
@@ -71,6 +81,7 @@ Component({
},
copyContent: function (e) {
var index = e.currentTarget.dataset.index
+ var that = this
var content = this.data.chatList[index].originContent
wx.setClipboardData({
data: content,
@@ -78,7 +89,32 @@ Component({
wx.showToast({
title: "复制成功",
})
- },
+ if (that.data.chatList[index]["type"] == "man" && !that.data.closeShareOnCopy) {
+ setTimeout(() => {
+ wx.showModal({
+ title: "提示",
+ content: "是否分享搜索内容?",
+ complete: (res) => {
+ if (res.confirm) {
+ wx.setStorage({
+ key: "shareContent",
+ data: {
+ q: content,
+ validTime: new Date().getTime() + 300 * 1000
+ },
+ success: (res) => {
+ wx.showToast({
+ title: "请点击右上角分享按钮",
+ icon: "none"
+ })
+ }
+ })
+ }
+ }
+ })
+ }, 1500)
+ }
+ }
})
},
renderMd: function (e) {
@@ -92,8 +128,8 @@ Component({
}
if (null != matches) {
matches.forEach(m => {
- var m1 = m.replace('```markdown', '').trim()
- if (m1.endsWith('```')) {
+ var m1 = m.replace("```markdown", "").trim()
+ if (m1.endsWith("```")) {
m1 = m1.substring(0, m1.length - 3)
}
content = content.replace(m, m1)
@@ -140,7 +176,7 @@ Component({
longPress: function (e) {
var that = this
wx.showActionSheet({
- itemList: ['删除全部聊天记录', '切换聊天请求方式'],
+ itemList: ["删除全部聊天记录", "切换聊天接口方式", that.data.closeShareOnCopy ? "打开复制后分享" : "关闭复制后分享"],
success(res) {
if (res.tapIndex == 0) {
that.deleteAllChat()
@@ -148,6 +184,31 @@ Component({
that.triggerEvent(
"switchRequestMethod", {}, {}
)
+ } else if (res.tapIndex == 2) {
+ if (that.data.closeShareOnCopy) {
+ that.setData({
+ closeShareOnCopy: false,
+ })
+ wx.showToast({
+ title: "已打开复制后分享",
+ icon: "none"
+ })
+ wx.removeStorage({
+ key: "closeShareOnCopy",
+ })
+ } else {
+ that.setData({
+ closeShareOnCopy: true,
+ })
+ wx.showToast({
+ title: "已关闭复制后分享",
+ icon: "none"
+ })
+ wx.setStorage({
+ key: "closeShareOnCopy",
+ data: 1,
+ })
+ }
}
}
})
diff --git a/bingchat/components/chatbox/index.wxml b/bingchat/components/chatbox/index.wxml
index d728c71..9b4b8f3 100644
--- a/bingchat/components/chatbox/index.wxml
+++ b/bingchat/components/chatbox/index.wxml
@@ -1,7 +1,7 @@
输入问题开始和New Bing聊天吧~
-
+
diff --git a/bingchat/pages/index/index.js b/bingchat/pages/index/index.js
index f4e3566..54ea34b 100644
--- a/bingchat/pages/index/index.js
+++ b/bingchat/pages/index/index.js
@@ -101,6 +101,23 @@ Page({
})
},
onShow() {
+ var pages = getCurrentPages()
+ var currentPage = pages[pages.length - 1]
+ var options = currentPage.options
+ var that = this
+ if (options && options["q"]) {
+ var q = decodeURIComponent(options["q"])
+ wx.showModal({
+ title: "提示",
+ content: "即将搜索“" + q + "” ?",
+ success(res) {
+ if (res.confirm) {
+ options["q"] = null
+ that.submitContent(q)
+ }
+ }
+ })
+ }
const cht = app.globalData.cht
if (cht.data.chatList.length > 1) {
cht.setData({
@@ -256,9 +273,25 @@ Page({
this.submitContent(content)
},
onShareAppMessage() {
+ var title = "New Bing Bot 🤖"
+ var content = this.data.content.trim()
+ if (content.length > 0) {
+ title = content
+ } else {
+ var cache = wx.getStorageSync("shareContent")
+ if (cache) {
+ if (cache["validTime"] > (new Date()).getTime()) {
+ content = cache["q"]
+ title = content
+ wx.removeStorage({
+ key: "shareContent",
+ })
+ }
+ }
+ }
return {
- title: "New Bing Bot 🤖",
- path: "/pages/index/index",
+ title: title,
+ path: "/pages/index/index?q=" + encodeURIComponent(content),
imageUrl: "../../image/newBing.png"
}
},