Files
FreeERP.Applet/miniprogram/miniprogram_npm/tdesign-miniprogram/chat-actionbar/chat-actionbar.js
2026-01-09 16:33:18 +08:00

1 line
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{__decorate}from"tslib";import{SuperComponent,wxComponent}from"../common/src/index";import config from"../common/config";import props from"./props";const{prefix:prefix}=config,name=`${prefix}-chat-actionbar`;let ChatActionbar=class extends SuperComponent{constructor(){super(...arguments),this.options={multipleSlots:!0},this.properties=props,this.data={actions:[],classPrefix:name,pComment:"",iconMap:{good:"thumb-up",bad:"thumb-down",replay:"refresh",copy:"copy",share:"share-1"},iconActiveMap:{good:"thumb-up-filled",bad:"thumb-down-filled"}},this.observers={comment(t){this.setData({pComment:t||""})},"actionBar, pComment"(){this.setActions()}},this.methods={filterSpecialChars(t){let e=t;const a=[];e=e.replace(/^(\s*\|.*\|.*\n\s*\|[-: ]+\|.*\n(\s*\|.*\|.*\n)*)/gm,t=>{const e=t.replace(/\[\d+(?:,\d+)*\]\(@ref\)/g,"").replace(/(\*\*|__)(.*?)\1|(\*|_)(.*?)\3/g,"$2$4").replace(/<br\s*\/?>/gi,"\n");return a.push(e),`%%TABLE${a.length-1}%%`}),e=e.replace(/^(\s*)#{1,6}\s+/gm,"$1"),e=e.replace(/(\*\*|__)(.*?)\1|(\*|_)(.*?)\3/g,"$2$4"),e=e.replace(/!\[.*?\]\(.*?\)/g,""),e=e.replace(/\[\d+(?:,\d+)*\]\(@ref\)/g,"");return e=e.replace(/(\\|`|\{|\}|\[|\]|\(|\)|\|||@ref|\([@#]\w+\))/g,""),e=e.replace(/\[\d+\]/g,""),e=e.replace(/<br\s*\/?>/gi,"\n"),e=e.replace(/%%TABLE(\d+)%%/g,(t,e)=>a[parseInt(e,10)]||""),e.replace(/\n{3,}/g,"\n\n").trim()},handleActionClick(t){const{name:e}=t.currentTarget.dataset;if("copy"===e&&this.data.content)this.data.handleCopy();else if("good"===e){const t="good"===this.data.pComment;this.setData({pComment:t?void 0:"good"}),this.triggerEvent("actions",{name:e,active:!t})}else if("bad"===e){const t="bad"===this.data.pComment;this.setData({pComment:t?void 0:"bad"}),this.triggerEvent("actions",{name:e,active:!t})}else this.triggerEvent("actions",{name:e})},handleCopy(){if(!this.data.content)return;const t="markdown"===this.data.copyMode?this.data.content:this.data.filterSpecialChars(this.data.content);this.triggerEvent("actions",{name:"copy",data:t})},setActions(){const t=[];Array.isArray(this.properties.actionBar)&&this.properties.actionBar.forEach(e=>{"good"===e||"bad"===e?t.push({name:e,isActive:this.data.pComment===e}):t.push({name:e,isActive:!1})}),this.setData({actions:t})}},this.lifetimes={created(){this.data.filterSpecialChars=this.filterSpecialChars.bind(this),this.data.handleActionClick=this.handleActionClick.bind(this),this.data.handleCopy=this.handleCopy.bind(this)},attached(){this.setData({pComment:this.properties.comment||""}),this.setActions()},detached(){}}}};ChatActionbar=__decorate([wxComponent()],ChatActionbar);export default ChatActionbar;