Fix小程序

This commit is contained in:
linghaihui 2023-03-30 00:37:03 +08:00
parent 4808d164d4
commit 3fc48e1e32
9 changed files with 38 additions and 21 deletions

View File

@ -1,5 +1,4 @@
page {
background-color: #fff;
font-size: 28rpx;
line-height: 1.7em;
}

View File

@ -85,12 +85,15 @@ Component({
var data = this.data.chatList[index]
var content = data.originContent
if (!this.data.chatList[index].content) {
var matches = content.match(/```markdown[\s\S]*(```)?/g)
var matches = content.match(/```markdown[\s\S]*```/g)
if (null == matches) {
matches = content.match(/```markdown[\s\S]*/g)
}
if (null != matches) {
matches.forEach(m => {
var m1 = m.replace('```markdown', '')
if (m1.trim().endsWith('```')) {
m1 = m1.substring(0, m1.trim().length - 3)
var m1 = m.replace('```markdown', '').trim()
if (m1.endsWith('```')) {
m1 = m1.substring(0, m1.length - 3)
}
content = content.replace(m, m1)
})
@ -116,7 +119,7 @@ Component({
"cancelReceive", {}, {}
)
},
deletAllChat: function (e) {
deleteAllChat: function () {
var that = this
wx.showModal({
content: "是否删除全部聊天?",
@ -133,6 +136,21 @@ Component({
},
})
},
longPress: function (e) {
var that = this
wx.showActionSheet({
itemList: ['删除全部聊天记录', '切换聊天请求方式'],
success(res) {
if (res.tapIndex == 0) {
that.deleteAllChat()
} else if (res.tapIndex == 1) {
that.triggerEvent(
"switchRequestMethod", {}, {}
)
}
}
})
},
showOriginContent: function (e) {
var index = e.currentTarget.dataset.index
var data = this.data.chatList[index]

View File

@ -1,6 +1,6 @@
<wxs src="../../tools.wxs" module="tools" />
<view catchlongpress="deletAllChat">
<view wx:if="{{chatList.length == 0}}" style="text-align:center;color: #b4bbc4;font-size: 32rpx;">输入问题开始和New Bing聊天吧~</view>
<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-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}}">
@ -9,7 +9,7 @@
<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" bindtap="suggestSubmit" data-suggest="{{suggest}}" wx:key="index" wx:for="{{item.suggests}}" wx:for-item="suggest" wx:if="{{suggest && suggest.length > 0}}">{{suggest}}</view>
<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>
</view>
</view>
@ -23,5 +23,5 @@
</view>
<view id="{{'item'+ chatList.length + 9999}}" style="margin-top: 2em;"></view>
</scroll-view>
<icon wx:if="{{receiveData}}" type="cancel" bindtap="cancelReceive" style="position: absolute;bottom: 140rpx;right:1%;z-index: 10000;" size="20"></icon>
<icon wx:if="{{receiveData}}" type="cancel" catchtap="cancelReceive" style="position: absolute;bottom: 140rpx;right:1%;z-index: 10000;" size="20"></icon>
</view>

View File

@ -35,6 +35,7 @@
word-break: break-all;
white-space: pre-wrap;
margin-top: 10rpx;
line-height: 1.65em;
}
.bg-green {

View File

@ -1,8 +1,8 @@
"use strict";function e(t){"@babel/helpers - typeof";return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t,i){return t=n(t),t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function n(t){var n=i(t,"string");return"symbol"===e(n)?n:String(n)}function i(t,n){if("object"!==e(t)||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var o=i.call(t,n||"default");if("object"!==e(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}function o(e){return e.replace(/</g,"&lt;").replace(/>/g,"&gt;")}/*!
"use strict";function e(t){"@babel/helpers - typeof";return(e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(t)}function t(e,t,i){return t=n(t),t in e?Object.defineProperty(e,t,{value:i,enumerable:!0,configurable:!0,writable:!0}):e[t]=i,e}function n(t){var n=i(t,"string");return"symbol"===e(n)?n:String(n)}function i(t,n){if("object"!==e(t)||null===t)return t;var i=t[Symbol.toPrimitive];if(void 0!==i){var o=i.call(t,n||"default");if("object"!==e(o))return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===n?String:Number)(t)}function o(e){return a.forEach(function(t){var n=e.match(new RegExp("<"+t+".*>"));null!=n&&n.forEach(function(t){e=e.replace(t,t.replace("<","&lt;").replace(">","&gt;"))}),-1!=e.indexOf("</"+t+">")&&(e=e.replace("</"+t+">","&lt;/"+t+"&gt;"))}),e}/*!
* mp-html v2.4.1
* https://github.com/jin-yufeng/mp-html
*
* Released under the MIT license
* Author: Jin Yufeng
*/
var r=require("./parser"),a=[require("./markdown/index.js"),require("./emoji/index.js"),require("./highlight/index.js"),require("./latex/index.js"),require("./style/index.js")];Component({data:{nodes:[]},properties:{markdown:Boolean,containerStyle:String,content:{type:String,value:"",observer:function(e){this.setContent(e)}},copyLink:{type:Boolean,value:!0},domain:String,errorImg:String,lazyLoad:Boolean,loadingImg:String,pauseVideo:{type:Boolean,value:!0},previewImg:{type:Boolean,value:!0},scrollTable:Boolean,selectable:null,setTitle:{type:Boolean,value:!0},showImgMenu:{type:Boolean,value:!0},tagStyle:Object,useAnchor:null},created:function(){this.plugins=[];for(var e=a.length;e--;)this.plugins.push(new a[e](this))},detached:function(){this._hook("onDetached")},methods:{in:function(e,t,n){e&&t&&n&&(this._in={page:e,selector:t,scrollTop:n})},navigateTo:function(e,n){var i=this;return e=this._ids[decodeURI(e)]||e,new Promise(function(o,r){if(!i.data.useAnchor)return void r(Error("Anchor is disabled"));var a=wx.createSelectorQuery().in(i._in?i._in.page:i).select((i._in?i._in.selector:"._root")+(e?"".concat(">>>","#").concat(e):"")).boundingClientRect();i._in?a.select(i._in.selector).scrollOffset().select(i._in.selector).boundingClientRect():a.selectViewport().scrollOffset(),a.exec(function(e){if(!e[0])return void r(Error("Label not found"));var a=e[1].scrollTop+e[0].top-(e[2]?e[2].top:0)+(n||parseInt(i.data.useAnchor)||0);i._in?i._in.page.setData(t({},i._in.scrollTop,a)):wx.pageScrollTo({scrollTop:a,duration:300}),o()})})},getText:function(e){var t="";return function e(n){for(var i=0;i<n.length;i++){var o=n[i];if("text"===o.type)t+=o.text.replace(/&amp;/g,"&");else if("br"===o.name)t+="\n";else{var r="p"===o.name||"div"===o.name||"tr"===o.name||"li"===o.name||"h"===o.name[0]&&o.name[1]>"0"&&o.name[1]<"7";r&&t&&"\n"!==t[t.length-1]&&(t+="\n"),o.children&&e(o.children),r&&"\n"!==t[t.length-1]?t+="\n":"td"!==o.name&&"th"!==o.name||(t+="\t")}}}(e||this.data.nodes),t},getRect:function(){var e=this;return new Promise(function(t,n){wx.createSelectorQuery().in(e).select("._root").boundingClientRect().exec(function(e){return e[0]?t(e[0]):n(Error("Root label not found"))})})},pauseMedia:function(){for(var e=(this._videos||[]).length;e--;)this._videos[e].pause()},setPlaybackRate:function(e){this.playbackRate=e;for(var t=(this._videos||[]).length;t--;)this._videos[t].playbackRate(e)},setContent:function(e,t){var n=this;e=o(e),this.imgList&&t||(this.imgList=[]),this._videos=[];var i={},a=new r(this).parse(e);if(t)for(var s=this.data.nodes.length,l=a.length;l--;)i["nodes[".concat(s+l,"]")]=a[l];else i.nodes=a;if(this.setData(i,function(){n._hook("onLoad"),n.triggerEvent("load")}),this.data.lazyLoad||this.imgList._unloadimgs<this.imgList.length/2){var c=0,u=function e(t){t&&t.height||(t={}),t.height===c?n.triggerEvent("ready",t):(c=t.height,setTimeout(function(){n.getRect().then(e).catch(e)},350))};this.getRect().then(u).catch(u)}else this.imgList._unloadimgs||this.getRect().then(function(e){n.triggerEvent("ready",e)}).catch(function(){n.triggerEvent("ready",{})})},_hook:function(e){for(var t=a.length;t--;)this.plugins[t][e]&&this.plugins[t][e]()},_add:function(e){e.detail.root=this}}});
var r=require("./parser"),a=["a","abbr","address","area","article","aside","audio","b","base","bdi","bdo","blockquote","body","br","button","canvas","caption","cite","code","col","colgroup","data","datalist","dd","del","details","dfn","dialog","div","dl","dt","em","embed","fieldset","figcaption","figure","footer","form","h1","h2","h3","h4","h5","h6","head","header","hr","html","i","iframe","img","input","ins","kbd","label","legend","li","link","main","map","mark","meta","meter","nav","noscript","object","ol","optgroup","option","output","p","param","picture","pre","progress","q","rp","rt","ruby","s","samp","script","section","select","small","source","span","strong","style","sub","summary","sup","svg","table","tbody","td","template","textarea","tfoot","th","thead","time","title","tr","track","u","ul","var","video","wbr"],l=[require("./markdown/index.js"),require("./emoji/index.js"),require("./highlight/index.js"),require("./latex/index.js"),require("./style/index.js")];Component({data:{nodes:[]},properties:{markdown:Boolean,containerStyle:String,content:{type:String,value:"",observer:function(e){this.setContent(e)}},copyLink:{type:Boolean,value:!0},domain:String,errorImg:String,lazyLoad:Boolean,loadingImg:String,pauseVideo:{type:Boolean,value:!0},previewImg:{type:Boolean,value:!0},scrollTable:Boolean,selectable:null,setTitle:{type:Boolean,value:!0},showImgMenu:{type:Boolean,value:!0},tagStyle:Object,useAnchor:null},created:function(){this.plugins=[];for(var e=l.length;e--;)this.plugins.push(new l[e](this))},detached:function(){this._hook("onDetached")},methods:{in:function(e,t,n){e&&t&&n&&(this._in={page:e,selector:t,scrollTop:n})},navigateTo:function(e,n){var i=this;return e=this._ids[decodeURI(e)]||e,new Promise(function(o,r){if(!i.data.useAnchor)return void r(Error("Anchor is disabled"));var a=wx.createSelectorQuery().in(i._in?i._in.page:i).select((i._in?i._in.selector:"._root")+(e?"".concat(">>>","#").concat(e):"")).boundingClientRect();i._in?a.select(i._in.selector).scrollOffset().select(i._in.selector).boundingClientRect():a.selectViewport().scrollOffset(),a.exec(function(e){if(!e[0])return void r(Error("Label not found"));var a=e[1].scrollTop+e[0].top-(e[2]?e[2].top:0)+(n||parseInt(i.data.useAnchor)||0);i._in?i._in.page.setData(t({},i._in.scrollTop,a)):wx.pageScrollTo({scrollTop:a,duration:300}),o()})})},getText:function(e){var t="";return function e(n){for(var i=0;i<n.length;i++){var o=n[i];if("text"===o.type)t+=o.text.replace(/&amp;/g,"&");else if("br"===o.name)t+="\n";else{var r="p"===o.name||"div"===o.name||"tr"===o.name||"li"===o.name||"h"===o.name[0]&&o.name[1]>"0"&&o.name[1]<"7";r&&t&&"\n"!==t[t.length-1]&&(t+="\n"),o.children&&e(o.children),r&&"\n"!==t[t.length-1]?t+="\n":"td"!==o.name&&"th"!==o.name||(t+="\t")}}}(e||this.data.nodes),t},getRect:function(){var e=this;return new Promise(function(t,n){wx.createSelectorQuery().in(e).select("._root").boundingClientRect().exec(function(e){return e[0]?t(e[0]):n(Error("Root label not found"))})})},pauseMedia:function(){for(var e=(this._videos||[]).length;e--;)this._videos[e].pause()},setPlaybackRate:function(e){this.playbackRate=e;for(var t=(this._videos||[]).length;t--;)this._videos[t].playbackRate(e)},setContent:function(e,t){var n=this;-1!=e.indexOf("python代码")&&-1==e.indexOf("```")&&(e="```\n\n"+e+"\n\n```"),this.imgList&&t||(this.imgList=[]),this._videos=[];var i={},o=new r(this).parse(e);if(t)for(var a=this.data.nodes.length,l=o.length;l--;)i["nodes[".concat(a+l,"]")]=o[l];else i.nodes=o;if(this.setData(i,function(){n._hook("onLoad"),n.triggerEvent("load")}),this.data.lazyLoad||this.imgList._unloadimgs<this.imgList.length/2){var s=0,c=function e(t){t&&t.height||(t={}),t.height===s?n.triggerEvent("ready",t):(s=t.height,setTimeout(function(){n.getRect().then(e).catch(e)},350))};this.getRect().then(c).catch(c)}else this.imgList._unloadimgs||this.getRect().then(function(e){n.triggerEvent("ready",e)}).catch(function(){n.triggerEvent("ready",{})})},_hook:function(e){for(var t=l.length;t--;)this.plugins[t][e]&&this.plugins[t][e]()},_add:function(e){e.detail.root=this}}});

View File

@ -1 +1 @@
"use strict";function t(t){this.vm=t,t._ids={}}var a=require("./marked.min"),e=0;t.prototype.onUpdate=function(t){if(this.vm.data.markdown)return(0,a.marked)(t,{silent:!0,smartypants:!0,breaks:!0})},t.prototype.onParse=function(t,a){if(a.options.markdown){if(a.options.useAnchor&&t.attrs&&/[\u4e00-\u9fa5]/.test(t.attrs.id)){var n="t"+e++;this.vm._ids[t.attrs.id]=n,t.attrs.id=n}"p"!==t.name&&"table"!==t.name&&"tr"!==t.name&&"th"!==t.name&&"td"!==t.name&&"blockquote"!==t.name&&"pre"!==t.name&&"code"!==t.name||(t.attrs.class="md-".concat(t.name," ").concat(t.attrs.class||""))}},module.exports=t;
"use strict";function t(t){this.vm=t,t._ids={}}var a=require("./marked.min"),e=0;t.prototype.onUpdate=function(t){if(this.vm.data.markdown)return(0,a.marked)(t,{breaks:!0,smartypants:!0,silent:!0})},t.prototype.onParse=function(t,a){if(a.options.markdown){if(a.options.useAnchor&&t.attrs&&/[\u4e00-\u9fa5]/.test(t.attrs.id)){var n="t"+e++;this.vm._ids[t.attrs.id]=n,t.attrs.id=n}"p"!==t.name&&"table"!==t.name&&"tr"!==t.name&&"th"!==t.name&&"td"!==t.name&&"blockquote"!==t.name&&"pre"!==t.name&&"code"!==t.name||(t.attrs.class="md-".concat(t.name," ").concat(t.attrs.class||""))}},module.exports=t;

View File

@ -1 +0,0 @@
{"spec_dir":"test","spec_files":["**/*-spec.js"],"helpers":["helpers/helpers.js"],"jsLoader":"import","stopSpecOnExpectationFailure":false,"random":true}

View File

@ -6,7 +6,7 @@ import {
const systemInfo = wx.getSystemInfoSync()
// 各平台对话分离
const sid_prefix = systemInfo.platform == "ios" || systemInfo.platform == "android" ? "" : systemInfo.platform
const initHeight = inputPop() ? 20 : 5
const initHeight = inputPop() ? 22 : 5
// 是否使用websocket请求
var useWebsocket = true
try {
@ -410,7 +410,7 @@ Page({
})
}
},
swithRequestMethod: function (e) {
switchRequestMethod: function (e) {
var that = this
if (this.data.useWebsocket) {
wx.setStorage({
@ -421,7 +421,7 @@ Page({
useWebsocket: false
})
wx.showToast({
title: "已切换成Https接口",
title: "已切换成Https",
icon: "none"
})
}
@ -434,7 +434,7 @@ Page({
useWebsocket: true
})
wx.showToast({
title: "已切换成Websocket接口",
title: "已切换成Websocket",
icon: "none"
})
}

View File

@ -1,5 +1,5 @@
<chat-box bindsuggestSubmit="onSuggestSubmit" bindcancelReceive="onCancelReceive"></chat-box>
<chat-box bindsuggestSubmit="onSuggestSubmit" bindcancelReceive="onCancelReceive" bindswitchRequestMethod="switchRequestMethod"></chat-box>
<view style="bottom:{{inputBottom}}px; border-radius: 20rpx;margin-left: 1%;width: 98%;min-height: 100rpx;position: fixed;background-color: #f4f6f8;display: flex;align-items:flex-start; justify-content: space-between;{{textareaFocus ? 'border: 1rpx solid #b4bbc4;': ''}}">
<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" bindtap="focus" bindinput="inputData" bindlongpress="swithRequestMethod"></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;" bindtap="submit" wx:if="{{systemInfo.platform != 'ios'}}">发送</view>
<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>