提交 4db900f8 编写于 作者: DCloud_JSON's avatar DCloud_JSON

1.0.0

上级 e5cfb4e5
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"configurations": [{ "configurations": [{
"app-plus" : "app-plus" :
{ {
"launchtype" : "local" "launchtype" : "remote"
}, },
"default" : "default" :
{ {
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
}, },
"mp-weixin" : "mp-weixin" :
{ {
"launchtype" : "local" "launchtype" : "remote"
}, },
"type" : "uniCloud" "type" : "uniCloud"
} }
......
<template> <template>
<view class="rich-text-box" :class="{'show-cursor':showCursor}"> <view class="rich-text-box" :class="{'show-cursor':showCursor}" ref="rich-text-box">
<rich-text v-if="nodes&&nodes.length" space="nbsp" :nodes="nodes"></rich-text> <rich-text v-if="nodes&&nodes.length" space="nbsp" :nodes="nodes"></rich-text>
<!-- #ifdef H5 -->
<view class="copy-box" :style="{left,top}">
<text class="copy" @click="copy">复制</text>
<!-- <view v-if="left != '-100px'" class="copy-mask" @click="left = '-100px'"></view> -->
</view>
<!-- #endif -->
</view> </view>
</template> </template>
...@@ -14,19 +20,46 @@ ...@@ -14,19 +20,46 @@
highlight: function(str, lang) { highlight: function(str, lang) {
if (lang && hljs.getLanguage(lang)) { if (lang && hljs.getLanguage(lang)) {
try { try {
return '<pre class="hljs"><code>' + return '<pre class="hljs" style="padding: 5px 8px;margin: 5px 0;overflow: auto;"><code>' +
hljs.highlight(lang, str, true).value + hljs.highlight(lang, str, true).value +
'</code></pre>'; '</code></pre>';
} catch (__) {} } catch (__) {}
} }
return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + '</code></pre>'; return '<pre class="hljs" style="padding: 5px 8px;margin: 5px 0;overflow: auto;"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
} }
}) })
export default { export default {
name: "msg", name: "msg",
data() { data() {
return {}; return {
left:"-100px",
top:"-100px"
};
},
mounted() {
// #ifdef H5
// web端限制不选中文字时出现系统右键菜单
let richTextBox = this.$refs['rich-text-box']
if (richTextBox) {
richTextBox.$el.addEventListener('contextmenu', (e) => {
if (!document.getSelection().toString()) {
console.log(e);
this.top = e.y+'px'
this.left = e.x+'px'
console.log(e.x);
console.log(e.y);
e.preventDefault()
}
})
}
document.addEventListener('click',()=>{
this.left = "-100px"
})
// #endif
}, },
props: { props: {
md: { md: {
...@@ -44,12 +77,23 @@ ...@@ -44,12 +77,23 @@
}, },
computed: { computed: {
html() { html() {
// req.body.content 代表md代码 let html = md.render(this.md + '<span class="cursor">|</span>')
return md.render(this.md + '<span class="cursor">|</span>') return html
}, },
nodes() { nodes() {
return parseHtml(this.html) return parseHtml(this.html)
} }
},
methods:{
// #ifdef H5
copy(){
uni.setClipboardData({
data:this.md,
showToast:false,
})
this.left = "-100px"
}
// #endif
} }
} }
</script> </script>
...@@ -59,10 +103,10 @@ ...@@ -59,10 +103,10 @@
@import "highlight.js/styles/a11y-dark.css"; @import "highlight.js/styles/a11y-dark.css";
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
pre.hljs{ .rich-text-box ::v-deep pre.hljs{
padding: 5px 8px; padding: 5px 8px;
margin: 5px 0; margin: 5px 0;
overflow: scroll; overflow: auto;
} }
.cursor{ .cursor{
...@@ -84,6 +128,34 @@ ...@@ -84,6 +128,34 @@
opacity: 0.0; opacity: 0.0;
} }
} }
/* #endif */
/* #ifdef H5 */
.copy-box{
position: fixed;
}
// .copy-mask{
// background-color: rgba(255,255,255,0.5);
// width: 100vw;
// height: 100vh;
// position: fixed;
// top: 0;
// left: 0;
// z-index: 9;
// }
.copy{
position: fixed;
background-color: #fff;
box-shadow: 0 0 3px #aaa;
padding: 5px;
border-radius: 5px;
z-index: 999;
cursor: pointer;
font-size: 14px;
color: #222;
}
.copy:hover{
color: #00a953;
}
/* #endif */ /* #endif */
</style> </style>
\ No newline at end of file
...@@ -71,7 +71,7 @@ ...@@ -71,7 +71,7 @@
"vueVersion" : "3", "vueVersion" : "3",
"h5" : { "h5" : {
"unipush" : { "unipush" : {
"enable" : false "enable" : true
} }
} }
} }
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
<image class="avatar" :src="msg.isAi?'../../static/uni-ai.png':'../../static/avatar.png'" mode="widthFix"></image> <image class="avatar" :src="msg.isAi?'../../static/uni-ai.png':'../../static/avatar.png'" mode="widthFix"></image>
</view> </view>
<view class="content"> <view class="content">
<!-- <text class="copy" @click="copy">复制</text> -->
<uni-ai-msg :md="msg.content" :show-cursor="index == msgList.length-1 && msg.isAi && sseIndex"></uni-ai-msg> <uni-ai-msg :md="msg.content" :show-cursor="index == msgList.length-1 && msg.isAi && sseIndex"></uni-ai-msg>
</view> </view>
<uni-icons v-if="index == msgList.length-1 && !msg.isAi && msg.state != 100 && msgStateIcon(msg)" <uni-icons v-if="index == msgList.length-1 && !msg.isAi && msg.state != 100 && msgStateIcon(msg)"
...@@ -155,7 +156,7 @@ ...@@ -155,7 +156,7 @@
fail:()=> { fail:()=> {
this.stream = false this.stream = false
uni.showModal({ uni.showModal({
content: '暂未开通uni-push。不支持此功能', content: '应用暂未开通uni-push。不支持此功能',
confirmText:"查看详情", confirmText:"查看详情",
complete(e) { complete(e) {
if(!e.confirm){ if(!e.confirm){
...@@ -183,7 +184,8 @@ ...@@ -183,7 +184,8 @@
}); });
console.log('你暂未开通uni-push。不支持此功能。详情:https://uniapp.dcloud.net.cn/uniCloud/uni-ai-chat.html#%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9'); console.log('你暂未开通uni-push。不支持此功能。详情:https://uniapp.dcloud.net.cn/uniCloud/uni-ai-chat.html#%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9');
}, },
success:()=>{ success:(e)=>{
console.log('success',e);
this.changeStream.check = ()=>{} this.changeStream.check = ()=>{}
} }
}) })
...@@ -234,7 +236,7 @@ ...@@ -234,7 +236,7 @@
async send() { async send() {
let messages = [] let messages = []
// 复制一份,消息列表数据 // 复制一份,消息列表数据
let msgs = [...this.msgList] let msgs = JSON.parse(JSON.stringify(this.msgList))
// 带总结的消息 index // 带总结的消息 index
let findIndex = [...msgs].reverse().findIndex(item => item.summarize) let findIndex = [...msgs].reverse().findIndex(item => item.summarize)
// console.log('findIndex', findIndex) // console.log('findIndex', findIndex)
...@@ -417,17 +419,19 @@ ...@@ -417,17 +419,19 @@
.page, .page,
.container { .container {
background-color: #efefef; background-color: #efefef;
/* #ifdef APP-NVUE */ /* #ifdef APP-NVUE */
flex: 1; flex: 1;
/* #endif */ /* #endif */
/* #ifndef APP-NVUE */
height: 100vh;
/* #endif */
/* #ifdef H5 */ /* #ifdef H5 */
height: calc(100vh - 44px); height: calc(100vh - 44px);
/* #endif */ /* #endif */
/* #ifdef MP */
height: 100vh;
/* #endif */
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
...@@ -564,6 +568,23 @@ ...@@ -564,6 +568,23 @@
/* #endif */ /* #endif */
} }
/* #ifndef APP-NVUE */
.content {
display: inline;
}
.content ::v-deep rich-text{
max-width: 550rpx;
overflow: auto;
}
/* #endif */
/* #ifdef H5 */
.content * {
display: inline;
}
/* #endif */
.reverse { .reverse {
flex-direction: row-reverse; flex-direction: row-reverse;
} }
...@@ -635,7 +656,19 @@ ...@@ -635,7 +656,19 @@
.content { .content {
background-color: #f9f9f9; background-color: #f9f9f9;
position: relative;
} }
// .copy {
// color: #888888;
// position: absolute;
// right: 8px;
// top: 8px;
// font-size: 12px;
// cursor:pointer;
// }
// .copy :hover{
// color: #4b9e5f;
// }
.foot-box, .foot-box,
.foot-box-content, .foot-box-content,
...@@ -717,4 +750,5 @@ ...@@ -717,4 +750,5 @@
} }
} }
/* #endif */ /* #endif */
</style> </style>
\ No newline at end of file
...@@ -7334,7 +7334,7 @@ function S(e2) { ...@@ -7334,7 +7334,7 @@ function S(e2) {
function b(e2) { function b(e2) {
return e2 && "string" == typeof e2 ? JSON.parse(e2) : e2; return e2 && "string" == typeof e2 ? JSON.parse(e2) : e2;
} }
const k = true, T = "mp-weixin", P = b([]), A = T, E = b('{\n "address": [\n "127.0.0.1",\n "192.168.31.184"\n ],\n "debugPort": 9000,\n "initialLaunchType": "local",\n "servePort": 7001,\n "skipFiles": [\n "<node_internals>/**",\n "/Applications/HBuilderX-Alpha.app/Contents/HBuilderX/plugins/unicloud/**/*.js"\n ]\n}\n'), O = b('[{"provider":"aliyun","spaceName":"test-ai","spaceId":"mp-eadf9303-2ce8-4270-b1b0-c1100b2a90ec","clientSecret":"xZRfyqUPB4zflkYS5d9UhQ==","endpoint":"https://api.next.bspapp.com"}]') || []; const k = true, T = "mp-weixin", P = b([]), A = T, E = b('{\n "address": [\n "127.0.0.1",\n "192.168.31.184"\n ],\n "debugPort": 9000,\n "initialLaunchType": "remote",\n "servePort": 7001,\n "skipFiles": [\n "<node_internals>/**",\n "/Applications/HBuilderX-Alpha.app/Contents/HBuilderX/plugins/unicloud/**/*.js"\n ]\n}\n'), O = b('[{"provider":"aliyun","spaceName":"test-ai","spaceId":"mp-eadf9303-2ce8-4270-b1b0-c1100b2a90ec","clientSecret":"xZRfyqUPB4zflkYS5d9UhQ==","endpoint":"https://api.next.bspapp.com"}]') || [];
let R = ""; let R = "";
try { try {
R = "__UNI__8F14B14"; R = "__UNI__8F14B14";
...@@ -6,17 +6,22 @@ const md = new common_vendor.MarkdownIt({ ...@@ -6,17 +6,22 @@ const md = new common_vendor.MarkdownIt({
highlight: function(str, lang) { highlight: function(str, lang) {
if (lang && common_vendor.HighlightJS.getLanguage(lang)) { if (lang && common_vendor.HighlightJS.getLanguage(lang)) {
try { try {
return '<pre class="hljs"><code>' + common_vendor.HighlightJS.highlight(lang, str, true).value + "</code></pre>"; return '<pre class="hljs" style="padding: 5px 8px;margin: 5px 0;overflow: auto;"><code>' + common_vendor.HighlightJS.highlight(lang, str, true).value + "</code></pre>";
} catch (__) { } catch (__) {
} }
} }
return '<pre class="hljs"><code>' + md.utils.escapeHtml(str) + "</code></pre>"; return '<pre class="hljs" style="padding: 5px 8px;margin: 5px 0;overflow: auto;"><code>' + md.utils.escapeHtml(str) + "</code></pre>";
} }
}); });
const _sfc_main = { const _sfc_main = {
name: "msg", name: "msg",
data() { data() {
return {}; return {
left: "-100px",
top: "-100px"
};
},
mounted() {
}, },
props: { props: {
md: { md: {
...@@ -34,12 +39,14 @@ const _sfc_main = { ...@@ -34,12 +39,14 @@ const _sfc_main = {
}, },
computed: { computed: {
html() { html() {
return md.render(this.md + '<span class="cursor">|</span>'); let html = md.render(this.md + '<span class="cursor">|</span>');
return html;
}, },
nodes() { nodes() {
return components_uniAiMsg_htmlParser.parseHtml(this.html); return components_uniAiMsg_htmlParser.parseHtml(this.html);
} }
} },
methods: {}
}; };
function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) { function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
return common_vendor.e({ return common_vendor.e({
......
<view class="{{['rich-text-box', c && 'show-cursor']}}"><rich-text wx:if="{{a}}" space="nbsp" nodes="{{b}}"></rich-text></view> <view class="{{['rich-text-box', c && 'show-cursor']}}" ref="rich-text-box"><rich-text wx:if="{{a}}" space="nbsp" nodes="{{b}}"></rich-text></view>
\ No newline at end of file \ No newline at end of file
...@@ -86,10 +86,10 @@ code.hljs{padding:3px 5px} ...@@ -86,10 +86,10 @@ code.hljs{padding:3px 5px}
.hljs-emphasis{font-style:italic} .hljs-emphasis{font-style:italic}
.hljs-strong{font-weight:700} .hljs-strong{font-weight:700}
@media screen and (-ms-high-contrast:active){.hljs-addition,.hljs-attribute,.hljs-built_in,.hljs-bullet,.hljs-comment,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-quote,.hljs-string,.hljs-symbol,.hljs-type{color:highlight}.hljs-keyword,.hljs-selector-tag{font-weight:700}} @media screen and (-ms-high-contrast:active){.hljs-addition,.hljs-attribute,.hljs-built_in,.hljs-bullet,.hljs-comment,.hljs-link,.hljs-literal,.hljs-meta,.hljs-number,.hljs-params,.hljs-quote,.hljs-string,.hljs-symbol,.hljs-type{color:highlight}.hljs-keyword,.hljs-selector-tag{font-weight:700}}
pre.hljs { .rich-text-box pre.hljs {
padding: 5px 8px; padding: 5px 8px;
margin: 5px 0; margin: 5px 0;
overflow: scroll; overflow: auto;
} }
.cursor { .cursor {
display: none; display: none;
......
...@@ -48,11 +48,13 @@ const _sfc_main = { ...@@ -48,11 +48,13 @@ const _sfc_main = {
fail: () => { fail: () => {
this.stream = false; this.stream = false;
common_vendor.index.showModal({ common_vendor.index.showModal({
content: "你暂未开通uni-push。不支持此功能", content: "应用暂未开通uni-push。不支持此功能",
showCancel: false,
confirmText: "查看详情", confirmText: "查看详情",
complete() { complete(e) {
let url = "https://uniapp.dcloud.net.cn/uniCloud/uni-ai-chat.html#%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9"; if (!e.confirm) {
return;
}
let url = "https://uniapp.dcloud.net.cn/uniCloud/uni-ai-chat.html#heed";
common_vendor.index.setClipboardData({ common_vendor.index.setClipboardData({
data: url, data: url,
showToast: false, showToast: false,
...@@ -68,7 +70,8 @@ const _sfc_main = { ...@@ -68,7 +70,8 @@ const _sfc_main = {
}); });
console.log("你暂未开通uni-push。不支持此功能。详情:https://uniapp.dcloud.net.cn/uniCloud/uni-ai-chat.html#%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9"); console.log("你暂未开通uni-push。不支持此功能。详情:https://uniapp.dcloud.net.cn/uniCloud/uni-ai-chat.html#%E6%B3%A8%E6%84%8F%E4%BA%8B%E9%A1%B9");
}, },
success: () => { success: (e) => {
console.log("success", e);
this.changeStream.check = () => { this.changeStream.check = () => {
}; };
} }
...@@ -106,7 +109,7 @@ const _sfc_main = { ...@@ -106,7 +109,7 @@ const _sfc_main = {
}, },
async send() { async send() {
let messages = []; let messages = [];
let msgs = [...this.msgList]; let msgs = JSON.parse(JSON.stringify(this.msgList));
let findIndex = [...msgs].reverse().findIndex((item) => item.summarize); let findIndex = [...msgs].reverse().findIndex((item) => item.summarize);
if (findIndex != -1) { if (findIndex != -1) {
let aiSummaryIndex = msgs.length - findIndex - 1; let aiSummaryIndex = msgs.length - findIndex - 1;
......
...@@ -34,7 +34,6 @@ page, ...@@ -34,7 +34,6 @@ page,
.page, .page,
.container { .container {
background-color: #efefef; background-color: #efefef;
flex: 1;
height: 100vh; height: 100vh;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
...@@ -136,6 +135,13 @@ page, ...@@ -136,6 +135,13 @@ page,
user-select: text; user-select: text;
cursor: text; cursor: text;
} }
.content {
display: inline;
}
.content rich-text {
max-width: 550rpx;
overflow: auto;
}
.reverse { .reverse {
flex-direction: row-reverse; flex-direction: row-reverse;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册