Volcanos(chat.ONIMPORT, { _init: function(can, msg) { can.require(["https://unpkg.com/showdown/dist/showdown.min.js"]) can.ui = can.onappend.layout(can), can.ui.responseList = [], can.onmotion.toggle(can, can.ui.display, true) msg.Table(function(value) { can.onimport.item(can, { name: value.NAME, nick: value.NAME+" ("+value.SIZE+")", }, function(event, item, show, target) { can.onimport.tabsCache(can, item, target, function() { can.onimport.content(can, target) }) can.onappend._status(can, msg), can.onimport.layout(can) }) }) }, content: function(can, target) { can.page.Append(can, can.ui.content, [ {view: chat.RESPONSE, list: [ {text: can.user.trans(can, "Please Ask Anything!", "有什么问题尽管问吧!")}, ]}, ]) can.page.Append(can, can.ui.display, [ {type: html.TEXTAREA, placeholder: can.user.trans(can, "Please Input Your Question!", "请输入的您的问题!"), onkeydown: function(event) { if (event.key == code.ENTER) { can.onaction.request(event, can, event.target.value), event.target.value = "", can.onkeymap.prevent(event) } }}, ]) }, _grow: function(can, msg, which, text) { var target = can.ui.responseList[parseInt(which)-1], data = JSON.parse(text) if (window.showdown) { target._text = (target._text||"")+data.message.content var converter = new showdown.Converter(); target.innerHTML = converter.makeHtml(target._text) } else { can.page.Append(can, target, [{text: data.message.content}]) } can.ui.content.scrollBy(0, 1000) }, }) Volcanos(chat.ONACTION, { request: function(event, can, text) { can.page.Append(can, can.ui.content, [{view: chat.REQUEST, list: [{text: text}]}]) var response = can.page.Append(can, can.ui.content, [{view: chat.RESPONSE}])._target; can.ui.responseList.push(response) can.request(event, {model: can.db.value.name, role: "user", content: text, which: ""+can.ui.responseList.length}) can.runAction(event, chat.REQUEST, [], function(msg) {}) }, })