优化分享

This commit is contained in:
linghaihui 2023-03-30 23:25:30 +08:00
parent 73bd78b23f
commit d51623b0bb
11 changed files with 182 additions and 58 deletions

View File

@ -42,6 +42,7 @@ Component({
receiveData: false,
autoIncrConversation: 1,
closeShareOnCopy: closeShareOnCopy,
showShare: false,
},
methods: {
initMessageHistory() {
@ -91,28 +92,17 @@ Component({
})
if (that.data.chatList[index]["type"] == "man" && !that.data.closeShareOnCopy) {
setTimeout(() => {
wx.showModal({
title: "提示",
content: "是否分享搜索内容?",
complete: (res) => {
if (res.confirm) {
that.setData({
showShare: true
})
wx.setStorage({
key: "shareContent",
data: {
q: content,
validTime: new Date().getTime() + 300 * 1000
},
success: (res) => {
wx.showToast({
title: "请点击右上角分享按钮",
icon: "none"
})
}
})
}
}
})
}, 1500)
}, 1200)
}
}
})
@ -224,6 +214,16 @@ Component({
this.setData({
chatList: this.data.chatList
})
},
onPopButtonClick: function (e) {
if (e.detail.t !== "confirm") {
wx.removeStorage({
key: 'shareContent',
})
}
this.setData({
showShare: false
})
}
},
})

View File

@ -1,6 +1,7 @@
{
"component": true,
"usingComponents": {
"mp-html": "mp-html"
"mp-html": "mp-html",
"popup": "../popup/popup"
}
}

View File

@ -1,13 +1,19 @@
<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}}" enable-flex="{{true}}">
<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}}" 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>
<view class="chat-box" style="margin-left: 20rpx;">
<view style="display: flex;flex-direction: row;align-items: center;"><text class="dt" style="flex: 1;">{{item.dt}}</text><view wx:if="{{item.num_in_conversation && item.num_in_conversation != -1}}" style="display:flex;justify-content:flex-end; flex: 1;align-items: center;"><text class="conversation_num">{{item.num_in_conversation}}</text></view></view>
<view class="content bg-white" catchlongpress="copyContent" data-index="{{index}}" catchtap="{{tools.indexOf(item.originContent, '```markdown') ? 'renderMd': ''}}"><view class="{{item.blink ? 'blinking': ''}}"><mp-html content="{{item.content ? item.content: item.originContent}}" preview-img selectable="{{true}}" markdown="{{true}}" img-cache="{{true}}" lazy-load="{{true}}" use-anchor="{{true}}" scroll-table="{{true}}" container-style="margin-top: -1em;" wx:if="{{!item.showOrigin}}"/><text wx:else user-select="{{true}}" decode="{{true}}">{{item.originContent}}</text></view></view>
<view style="display: flex;flex-direction: row;align-items: center;"><text class="dt" style="flex: 1;">{{item.dt}}</text>
<view wx:if="{{item.num_in_conversation && item.num_in_conversation != -1}}" style="display:flex;justify-content:flex-end; flex: 1;align-items: center;"><text class="conversation_num">{{item.num_in_conversation}}</text></view>
</view>
<view class="content bg-white" catchlongpress="copyContent" data-index="{{index}}" catchtap="{{tools.indexOf(item.originContent, '```markdown') ? 'renderMd': ''}}">
<view class="{{item.blink ? 'blinking': ''}}">
<mp-html content="{{item.content ? item.content: item.originContent}}" preview-img selectable="{{true}}" markdown="{{true}}" img-cache="{{true}}" lazy-load="{{true}}" use-anchor="{{true}}" scroll-table="{{true}}" container-style="margin-top: -1em;" wx:if="{{!item.showOrigin}}" /><text wx:else user-select="{{true}}" decode="{{true}}">{{item.originContent}}</text>
</view>
</view>
<view class="suggest">
<view hover-class="suggest-item-hover" class="suggest-item" catchtap="suggestSubmit" data-suggest="{{suggest}}" wx:key="index" wx:for="{{item.suggests}}" wx:for-item="suggest" wx:if="{{suggest && suggest.length > 0}}">{{suggest}}</view>
</view>
@ -22,6 +28,7 @@
</view>
</view>
<view id="{{'item'+ autoIncrConversation + 9999}}" style="height: 1em;"></view>
</scroll-view>
<icon wx:if="{{receiveData}}" type="cancel" catchtap="cancelReceive" style="position: absolute;bottom: 142rpx;right:1%;z-index: 10000;" size="20"></icon>
</scroll-view>
<icon wx:if="{{receiveData}}" type="cancel" catchtap="cancelReceive" style="position: absolute;bottom: 142rpx;right:1%;z-index: 10000;" size="20"></icon>
</view>
<popup message="是否分享搜索内容?" wx:if="{{showShare}}" bindPopButtonClick="onPopButtonClick" openType="share"></popup>

View File

@ -0,0 +1,45 @@
// components/popup/popup.js
Component({
/**
* 组件的属性列表
*/
properties: {
message: String,
openType: {
type: String,
value: ""
},
title: {
type: String,
value: "提示"
},
cancelText: {
type: String,
value: "取消"
},
confirmText: {
type: String,
value: "确定"
}
},
/**
* 组件的初始数据
*/
data: {
},
/**
* 组件的方法列表
*/
methods: {
closePop: function (e) {
this.triggerEvent(
"PopButtonClick", {
t: e.currentTarget.dataset.t,
}, {}
)
},
}
})

View File

@ -0,0 +1,4 @@
{
"component": true,
"usingComponents": {}
}

View File

@ -0,0 +1,8 @@
<view class="sharePop">
<view class="title">{{title}}</view>
<view class="message">{{message}}</view>
<view class="bt-wrap">
<button bindtap="closePop" style="color: gray;" data-t="cancel" class="bt" hover-class="btn-click">{{cancelText}}</button>
<button open-type="{{openType}}" bindtap="closePop" data-t="confirm" class="bt" style="color: #161823;" hover-class="btn-click">{{confirmText}}</button>
</view>
</view>

View File

@ -0,0 +1,49 @@
.sharePop {
position: fixed;
left: 12%;
top: 25%;
width: 76%;
background-color: #f4f6f8;
text-align: center;
border-radius: 25rpx;
padding: 20rpx 30rpx 20rpx 30rpx;
box-sizing: border-box;
z-index: 10000;
border: 1rpx dashed;
}
.bt {
background-color: #f4f6f8;
font-size: 32rpx;
cursor: pointer;
}
.title {
font-size: 30rpx;
font-weight: 700;
}
.message {
font-size: 30rpx;
margin-top: 15rpx;
color: #161823;
line-height: 1.6em;
max-height: 4.8em;
text-overflow: ellipsis;
overflow: hidden;
display: -webkit-box;
-webkit-line-clamp: 3;
-webkit-box-orient: vertical;
}
.bt-wrap {
background-color: #f4f6f8;
display: flex;
flex-direction: row;
margin-top: 15rpx;
}
.btn-click {
color: #ff502c;
font-weight: bold;
}

View File

@ -72,6 +72,8 @@ Page({
isOpen: false,
},
useWebsocket: useWebsocket,
showSearchPop: false,
searchPopMessage: "",
},
inputFocus(e) {
if (inputPop()) {
@ -100,22 +102,28 @@ Page({
})
})
},
onShow() {
getOptions: function () {
var pages = getCurrentPages()
var currentPage = pages[pages.length - 1]
var options = currentPage.options
var that = this
return currentPage.options
},
onPopButtonClick: function (e) {
if (e.detail.t === "confirm") {
this.submitContent(e.currentTarget.dataset.q)
}
this.setData({
showSearchPop: false,
q: ""
})
},
onShow() {
var options = this.getOptions()
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)
}
}
this.setData({
searchPopMessage: "即将搜索“" + q + "”",
showSearchPop: true,
q: q,
})
}
const cht = app.globalData.cht

View File

@ -1,4 +1,5 @@
{
"usingComponents": {
"popup": "../../components/popup/popup"
}
}

View File

@ -3,3 +3,4 @@
<textarea bindfocus="inputFocus" bindblur="inputBlur" value="{{content}}" adjust-position="{{false}}" focus="{{textareaFocus}}" maxlength="2000" auto-height="{{true}}" cursor-spacing="10" bindconfirm="submit" fixed="{{true}}" show-confirm-bar="{{false}}" confirm-type="send" placeholder="{{systemInfo.platform == 'mac' || systemInfo.platform == 'windows' ? '请输入问题,输入>>>提交...': '请输入问题...'}}" style="padding: 10rpx;flex: 9;line-height: normal;" placeholder-style="color: #b4bbc4" catchtap="focus" bindinput="inputData"></textarea>
<view style="background-color: #f4f6f8;color: {{content ? black : '#b4bbc4'}};border-radius: 0 20rpx 20rpx 0;height: 90rpx;cursor: pointer;margin-right: 15rpx;padding-top:10rpx;font-size: 32rpx;" catchtap="submit" wx:if="{{systemInfo.platform != 'ios'}}">发送</view>
</view>
<popup message="{{searchPopMessage}}" wx:if="{{showSearchPop}}" bindPopButtonClick="onPopButtonClick" data-q="{{q}}"></popup>