支持分享
This commit is contained in:
parent
89e2607a86
commit
73bd78b23f
@ -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,
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<wxs src="../../tools.wxs" module="tools" />
|
||||
<view catchlongpress="longPress">
|
||||
<view wx:if="{{chatList.length == 0}}" style="text-align:center;color: #b4bbc4;font-size: 30rpx;">输入问题开始和New Bing聊天吧~</view>
|
||||
<scroll-view class="chat" scroll-y="{{true}}" scroll-into-view="{{scrollId}}" style="height:{{systemInfo.windowHeight - 70}}px;" enable-back-to-top="{{true}}" scroll-anchoring="{{true}}" enhanced="{{true}}" enable-passive="{{true}}" show-scrollbar="{{false}}">
|
||||
<scroll-view class="chat" scroll-y="{{true}}" scroll-into-view="{{scrollId}}" style="height:{{systemInfo.windowHeight - 70}}px;" enable-back-to-top="{{true}}" scroll-anchoring="{{true}}" enhanced="{{true}}" enable-passive="{{true}}" show-scrollbar="{{false}}" enable-flex="{{true}}">
|
||||
<view wx:for="{{chatList}}" wx:key="index" wx:for-item="item" id="{{'item'+index}}">
|
||||
<view class="chat-item left" wx:if="{{item.type != 'man'}}" id="msg-{{index}}">
|
||||
<image class="avatar" src="{{item.avatarUrl}}" style="display: flex;" catchlongpress="clearChat" data-index="{{index}}" catchtap="showOriginContent" data-index="{{index}}"></image>
|
||||
|
||||
@ -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"
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user