优化openai 样式
This commit is contained in:
parent
26188255ad
commit
077cf6c099
|
|
@ -34,10 +34,13 @@
|
||||||
let last_page = 0;
|
let last_page = 0;
|
||||||
let current_page = 1;
|
let current_page = 1;
|
||||||
|
|
||||||
// hljs.initHighlightingOnLoad();
|
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
highlight: function(code, lang) {
|
highlight: function(code, lang) {
|
||||||
return hljs.highlight(lang, code).value;
|
if (lang && hljs.getLanguage(lang)) {
|
||||||
|
return hljs.highlight(lang, code, true).value;
|
||||||
|
} else {
|
||||||
|
return hljs.highlightAuto(code).value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -69,7 +72,19 @@
|
||||||
$('#answer').height($(window).height() - 260);
|
$('#answer').height($(window).height() - 260);
|
||||||
$(document).ready(function() {
|
$(document).ready(function() {
|
||||||
loadQuantities();
|
loadQuantities();
|
||||||
loadHistories();
|
loadHistories(1 , function() {
|
||||||
|
// 获取 answer .answer-list 内容高度
|
||||||
|
let height = 0;
|
||||||
|
$('.answer-list').each(function() {
|
||||||
|
height += $(this).height();
|
||||||
|
})
|
||||||
|
|
||||||
|
let answerHeight = $('#answer').height();
|
||||||
|
|
||||||
|
if (height < answerHeight) {
|
||||||
|
loadHistories(current_page + 1);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$('#ai-input').keydown(function(e) {
|
$('#ai-input').keydown(function(e) {
|
||||||
if (e.keyCode == 13) {
|
if (e.keyCode == 13) {
|
||||||
|
|
@ -147,7 +162,7 @@
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadHistories(page = 1) {
|
function loadHistories(page = 1, callback = null) {
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: `${config.api_url}/api/openai/histories?domain=${config.app_url}&page=${page}`,
|
url: `${config.api_url}/api/openai/histories?domain=${config.app_url}&page=${page}`,
|
||||||
headers: {
|
headers: {
|
||||||
|
|
@ -155,12 +170,16 @@
|
||||||
},
|
},
|
||||||
success: function(data) {
|
success: function(data) {
|
||||||
$('.text-loading').remove();
|
$('.text-loading').remove();
|
||||||
|
|
||||||
last_page = data.last_page;
|
last_page = data.last_page;
|
||||||
current_page = data.current_page;
|
current_page = data.current_page;
|
||||||
|
|
||||||
if (data.data.length) {
|
if (data.data && data.data.length) {
|
||||||
$('.not-answer').remove();
|
$('.not-answer').remove();
|
||||||
|
|
||||||
|
// data.data 倒叙
|
||||||
|
data.data.reverse();
|
||||||
|
|
||||||
let html = '';
|
let html = '';
|
||||||
data.data.forEach(function(item, index) {
|
data.data.forEach(function(item, index) {
|
||||||
html += '<div class="answer-list ' + (!index ? 'first' : '') + '">',
|
html += '<div class="answer-list ' + (!index ? 'first' : '') + '">',
|
||||||
|
|
@ -174,12 +193,17 @@
|
||||||
})
|
})
|
||||||
|
|
||||||
$('#answer').prepend(html);
|
$('#answer').prepend(html);
|
||||||
|
|
||||||
if (page == 1) {
|
if (page == 1) {
|
||||||
$('#answer').scrollTop($('#answer')[0].scrollHeight);
|
$('#answer').scrollTop($('#answer')[0].scrollHeight);
|
||||||
} else {
|
} else {
|
||||||
$('#answer').scrollTop($('#answer .answer-list.first:eq(1)').offset().top - 100 - $('#answer')
|
$('#answer').scrollTop($('#answer .answer-list.first:eq(1)').offset().top - 100 - $('#answer')
|
||||||
.offset().top);
|
.offset().top);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (callback) {
|
||||||
|
callback();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
@ -194,7 +218,6 @@
|
||||||
#answer {
|
#answer {
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
border-radius: 0.25rem;
|
border-radius: 0.25rem;
|
||||||
white-space: pre-wrap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.not-answer {
|
.not-answer {
|
||||||
|
|
@ -211,6 +234,7 @@
|
||||||
.answer-list {
|
.answer-list {
|
||||||
padding-bottom: 20px;
|
padding-bottom: 20px;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
|
white-space: pre-wrap;
|
||||||
border-bottom: 1px solid #eee;
|
border-bottom: 1px solid #eee;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue