| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- import { formatStaticAssetsUrl } from '../../utils/utils';
- /**
- * 格式化文档引用的数据
- * 将对象转换为字符串
- * @param {object} refference
- * @param {string} field_key - 数据中的相关字段
- */
- export function formatRefferenceString(refference, field_key) {
- if (!refference) {
- return '';
- }
- const doc_aggs = refference.doc_aggs;
- if (!doc_aggs) {
- return '';
- }
- // 仅返回一个容器,模板内容通过组件生成
- return `<div class="client-formated-markdown-element-item client-formated-markdown-doc-refference-container"></div>`;
- // const refs_markdown = [];
- // if (Array.isArray(doc_aggs)) {
- // doc_aggs.forEach((item, index) => {
- // refs_markdown.push(
- // `<li
- // class="client-formated-markdown-element-item client-formated-markdown-doc-refference-item"
- // data-doc-id="${item.doc_id}"
- // data-real-index="${index}"
- // data-ref-key="${field_key}"
- // >
- // <span class="refference-index">${index + 1}</span>
- // <span class="refference-label">${item.doc_name}</span>
- // </li>`
- // );
- // });
- // }
- // const li_str = refs_markdown.join('');
- // const ref_header = `<header class="client-formated-markdown-element-item client-formated-markdown-refference-header">
- // <div>来源</div>
- // <div>查看全部关联</div>
- // </header>`;
- // const ref_list = `<ul class="client-formated-markdown-element-item client-formated-markdown-doc-refference-container" data-ref-key="${field_key}">${li_str}</ul>`;
- // return `${ref_header} ${ref_list}`;
- }
- export function formatRefferenceFlag(answer) {
- if (!answer) {
- return '';
- }
- let cur_text = answer;
- cur_text = cur_text.replace(/##\d\$\$/g, function (match, index, full) {
- // console.log(match, index, full);
- // match示例数据 ##1$$ ##2$$
- // 通过两次替换,字符串只剩下序号
- const match_v1 = match.replace('##', '');
- const match_v2 = match_v1.replace('$$', '');
- const ref_idx = match_v2;
- return `<span class="client-formated-markdown-element-item client-formated-markdown-doc-refference-flag" data-ref-index="${ref_idx}"></span>`;
- });
- return cur_text;
- }
- /**
- * 处理文件下载链接
- * @param {string} file_name
- * @param {string} file_url
- * @param {string} file_id
- */
- export function formatFileDownloadStr(file_name, file_url, file_id) {
- if (!file_name || !file_url) {
- return '';
- }
- let real_url = file_url.replace('//', '/');
- real_url = file_url.replace('/./', '/');
- real_url = file_url.replace('./', '/');
- real_url = formatStaticAssetsUrl(real_url);
- return `<div class="client-formated-markdown-element-item client-formated-download-container">
- <a class="download-link" href="${real_url}" target="_blank">
- <span class="download-icon">
- <svg viewBox="0 0 48 48" fill="none" xmlns="http://www.w3.org/2000/svg" stroke="currentColor" class="arco-icon arco-icon-download" stroke-width="4" stroke-linecap="butt" stroke-linejoin="miter" filter="downl" data-v-2bc6460e="">
- <path d="m33.072 22.071-9.07 9.071-9.072-9.07M24 5v26m16 4v6H8v-6"></path>
- </svg>
- </span>
- <span>${file_name}</span>
- </a>
- </div>`;
- }
|