Feat(云灵AI):界面初始化
This commit is contained in:
@@ -0,0 +1,92 @@
|
||||
// 引入markdown-it库
|
||||
import MarkdownIt from '@/utils/markdown-it.min.js'
|
||||
// hljs是由 Highlight.js 经兼容性修改后的文件,请勿直接升级。否则会造成uni-app-vue3-Android下有兼容问题
|
||||
import hljs from '@/utils/highlight/highlight-uni.min.js'
|
||||
// 引入html-parser.js库
|
||||
// import parseHtml from '@/utils/html-parser.js'
|
||||
|
||||
// 初始化 MarkdownIt库
|
||||
const markdownIt = MarkdownIt({
|
||||
// 在源码中启用 HTML 标签
|
||||
html: true,
|
||||
// 如果结果以 <pre ... 开头,内部包装器则会跳过。
|
||||
highlight: function(str, lang) {
|
||||
// if (lang && hljs.getLanguage(lang)) {
|
||||
// console.error('lang', lang)
|
||||
// try {
|
||||
// return '<pre class="hljs" style="padding: 5px 8px;margin: 5px 0;overflow: auto;display: block;"><code>' +
|
||||
// hljs.highlight('lang', str, true).value +
|
||||
// '</code></pre>';
|
||||
// } catch (__) {}
|
||||
// }
|
||||
// 经过highlight.js处理后的html
|
||||
let preCode = ''
|
||||
try {
|
||||
preCode = hljs.highlightAuto(str).value
|
||||
} catch (err) {
|
||||
preCode = markdownIt.utils.escapeHtml(str)
|
||||
}
|
||||
|
||||
// 以换行进行分割
|
||||
const lines = preCode.split(/\n/).slice(0, -1)
|
||||
// 添加自定义行号
|
||||
let html = lines.map((item, index) => {
|
||||
// 去掉空行
|
||||
if (item === '') {
|
||||
return ''
|
||||
}
|
||||
return '<li><span class="line-num" data-line="' + (index + 1) + '"></span>' + item + '</li>'
|
||||
}).join('')
|
||||
html = '<ol style="padding: 0px 30px;">' + html + '</ol>'
|
||||
let htmlCode = `<div style="background:#0d1117;margin-top: 5px;color: #888;padding:5px 0;border-radius: 5px;">`
|
||||
htmlCode += `<pre class="hljs" style="padding:0 8px;margin-bottom:5px;overflow: auto;display: block;border-radius: 5px;"><code>${html}</code></pre>`
|
||||
htmlCode += '</div>'
|
||||
return htmlCode
|
||||
}
|
||||
})
|
||||
|
||||
export function formatAiMsgContent(val) {
|
||||
if (!val) {
|
||||
return ''
|
||||
}
|
||||
let htmlString = ''
|
||||
// 修改转换结果的htmlString值 用于正确给界面增加鼠标闪烁的效果
|
||||
// 判断markdown中代码块标识符的数量是否为偶数
|
||||
if (val.split('```').length % 2) {
|
||||
let msgContent = val
|
||||
if (msgContent[msgContent.length - 1] !== '\n') {
|
||||
msgContent += '\n'
|
||||
}
|
||||
msgContent += ' <span class="cursor">|</span>'
|
||||
htmlString = markdownIt.render(msgContent)
|
||||
} else {
|
||||
htmlString = markdownIt.render(val)
|
||||
htmlString = markdownIt.render(val) + ' \n <span class="cursor">|</span>'
|
||||
}
|
||||
// console.log(htmlString)
|
||||
return htmlString
|
||||
}
|
||||
|
||||
/**
|
||||
* 简单实现防抖方法
|
||||
*
|
||||
* 防抖(debounce)函数在第一次触发给定的函数时,不立即执行函数,而是给出一个期限值(delay),比如100ms。
|
||||
* 如果100ms内再次执行函数,就重新开始计时,直到计时结束后再真正执行函数。
|
||||
* 这样做的好处是如果短时间内大量触发同一事件,只会执行一次函数。
|
||||
*
|
||||
* @param fn 要防抖的函数
|
||||
* @param delay 防抖的毫秒数
|
||||
* @returns {Function}
|
||||
*/
|
||||
export function simpleDebounce(fn, delay = 100) {
|
||||
let timer = null
|
||||
return function() {
|
||||
const args = arguments
|
||||
if (timer) {
|
||||
clearTimeout(timer)
|
||||
}
|
||||
timer = setTimeout(() => {
|
||||
fn.apply(null, args)
|
||||
}, delay)
|
||||
}
|
||||
}
|
||||
Vendored
+10
@@ -0,0 +1,10 @@
|
||||
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}/*!
|
||||
Theme: GitHub Dark
|
||||
Description: Dark theme as seen on github.com
|
||||
Author: github.com
|
||||
Maintainer: @Hirse
|
||||
Updated: 2021-05-15
|
||||
|
||||
Outdated base version: https://github.com/primer/github-syntax-dark
|
||||
Current colors taken from GitHub's CSS
|
||||
*/.hljs{color:#c9d1d9;background:#0d1117}.hljs-doctag,.hljs-keyword,.hljs-meta .hljs-keyword,.hljs-template-tag,.hljs-template-variable,.hljs-type,.hljs-variable.language_{color:#ff7b72}.hljs-title,.hljs-title.class_,.hljs-title.class_.inherited__,.hljs-title.function_{color:#d2a8ff}.hljs-attr,.hljs-attribute,.hljs-literal,.hljs-meta,.hljs-number,.hljs-operator,.hljs-selector-attr,.hljs-selector-class,.hljs-selector-id,.hljs-variable{color:#79c0ff}.hljs-meta .hljs-string,.hljs-regexp,.hljs-string{color:#a5d6ff}.hljs-built_in,.hljs-symbol{color:#ffa657}.hljs-code,.hljs-comment,.hljs-formula{color:#8b949e}.hljs-name,.hljs-quote,.hljs-selector-pseudo,.hljs-selector-tag{color:#7ee787}.hljs-subst{color:#c9d1d9}.hljs-section{color:#1f6feb;font-weight:700}.hljs-bullet{color:#f2cc60}.hljs-emphasis{color:#c9d1d9;font-style:italic}.hljs-strong{color:#c9d1d9;font-weight:700}.hljs-addition{color:#aff5b4;background-color:#033a16}.hljs-deletion{color:#ffdcd7;background-color:#67060c}
|
||||
Vendored
+5256
File diff suppressed because one or more lines are too long
Vendored
+2
File diff suppressed because one or more lines are too long
@@ -74,9 +74,6 @@ function baseRequest(options) {
|
||||
|
||||
// 结构请求需要的参数
|
||||
const {url, params, data, login, ...option} = options
|
||||
console.log(params, '=====params');
|
||||
console.log(params, '=====data');
|
||||
console.log(option, '=======option');
|
||||
let _params = {}
|
||||
if(['get', 'GET'].includes(options.method)) {
|
||||
_params = {
|
||||
|
||||
+3
-3
@@ -155,7 +155,7 @@ function pushSysBySecondsHandle() {
|
||||
}
|
||||
}
|
||||
if (statsData.length < 1) {
|
||||
console.log('*************没有页面埋点数据则不用上报,节约网络请求')
|
||||
// console.log('*************没有页面埋点数据则不用上报,节约网络请求')
|
||||
return
|
||||
}
|
||||
// 设备类型phone、pad、pc、unknow
|
||||
@@ -169,7 +169,7 @@ function pushSysBySecondsHandle() {
|
||||
deviceType: deviceType === 'phone' ? osName : 'unknown',
|
||||
statsData
|
||||
}
|
||||
console.log('开始上报数据-------------------')
|
||||
// console.log('开始上报数据-------------------')
|
||||
pushSystemStatic(postData).then(res => {
|
||||
const { success } = res
|
||||
if (success) {
|
||||
@@ -177,7 +177,7 @@ function pushSysBySecondsHandle() {
|
||||
for (const key in Vue.prototype.$pageToWatchData) {
|
||||
Vue.prototype.$pageToWatchData[key] = []
|
||||
}
|
||||
console.log('*************清除上次未登录缓存的页面埋点数据')
|
||||
// console.log('*************清除上次未登录缓存的页面埋点数据')
|
||||
uni.removeStorageSync(pageViewDataCacheKey)
|
||||
}
|
||||
}).catch(err => {
|
||||
|
||||
Reference in New Issue
Block a user