Files
YG_FT/frontend/dist/assets/DatasetPreviewView-Dbmt-5C2.js

7 lines
39 KiB
JavaScript
Raw Normal View History

import{E as Tn}from"./el-alert-BG9zdCSg.js";import{O as Rn,E as Re}from"./el-popper-CH-5nvKD.js";import{f as He,E as le,e as Sn}from"./index-CvV3lMhj.js";import{E as Se}from"./index-CnkeFGDp.js";import{v as On}from"./directive-DpNCSVjv.js";import{d as j,h as z,B as Y,G as Ye,f as U,H as We,y as _,F as ae,b as Nn,R as ke,V as _e,bf as W,D as qe,aS as Fn,a9 as ce,j as E,bg as Dn,P as Bn,ai as J,o as c,e as D,w as v,s as k,bh as Pn,bi as An,W as ve,S as Ln,E as Qe,a as Oe,aW as Mn,am as Kn,N as Xe,c as O,a$ as Ze,Y as ye,n as fe,g as K,q as l,r as Jn,aL as Te,M as ne,bj as Je,al as jn,l as zn,ab as xe,ad as he,x as P,aa as N,aQ as Gn,K as je,ac as Un,A as oe,b1 as Hn,b2 as Yn}from"./index-BYkWxQIk.js";import{E as $e}from"./index-Tl9aG0c-.js";import"./el-tooltip-l0sNRNKZ.js";/* empty css */import{A as Wn}from"./AppConfirmDialog-BlKhh74f.js";import{P as qn}from"./PageCard-CpmwMuco.js";import{b as Qn,f as Xn,h as Ve,i as Zn,j as xn,k as et,l as nt}from"./dataset-DnxZfPFl.js";import{E as tt,a as ot}from"./el-select-BxbHSoSW.js";import{_ as X}from"./index-B-vAs-FR.js";import{E as at}from"./el-scrollbar-Dc6NVUlJ.js";import{d as lt,a as en,b as rt}from"./dropdown-CkygC_Yn.js";import{c as st}from"./castArray-j4qYoqmg.js";import{c as nn,E as it}from"./el-dialog-DKnNOV_q.js";import{_ as pe}from"./_plugin-vue_export-helper-DlAUqK2U.js";import{E as tn}from"./index-DIc4JAau.js";import{E as ut}from"./el-pagination-CUoX_U1O.js";import{E as dt,a as ct}from"./el-table-C8aUqsXR.js";import"./el-checkbox-tNAtI3nS.js";import{E as vt,a as ft}from"./el-form-item-BCGHWWEr.js";import"./vnode-p1CrQgfy.js";import"./index-BdMmiJIJ.js";import"./validator-FKO6GsbV.js";import"./index-BOLx8smi.js";import"./clamp-z56vzo_d.js";import"./toNumber-C_8Vj9e5.js";import"./index-DDfJVSKy.js";import"./scroll-omk9EOhU.js";import"./raf-DvNAB6YI.js";import"./el-card-Bdh7v7FQ.js";import"./index-CD1DSa6s.js";import"./index-CMHvcH47.js";import"./_baseIteratee-BBbQXU-s.js";import"./use-dialog-Dw2htIqg.js";import"./_baseClone-BHCmlOrP.js";import"./debounce-DwoMwtvP.js";import"./omit-DIEVeOei.js";const Ee=Symbol("elDropdown"),on="elDropdown";var pt=j({inheritAttrs:!1});function mt(e,a,r,n,p,s){return z(e.$slots,"default")}var gt=X(pt,[["render",mt]]),wt=j({name:"ElCollectionItem",inheritAttrs:!1});function bt(e,a,r,n,p,s){return z(e.$slots,"default")}var yt=X(wt,[["render",bt]]);const an="data-el-collection-item",_t=e=>{const a=`El${e}Collection`,r=`${a}Item`,n=Symbol(a),p=Symbol(r);return{COLLECTION_INJECTION_KEY:n,COLLECTION_ITEM_INJECTION_KEY:p,ElCollection:Object.assign({},gt,{name:a,setup(){const s=_(),t=new Map;ae(n,{itemMap:t,getItems:(()=>{const w=U(s);if(!w)return[];const f=Array.from(w.querySelectorAll(`[${an}]`));return[...t.values()].sort((b,y)=>f.indexOf(b.ref)-f.indexOf(y.ref))}),collectionRef:s})}}),ElCollectionItem:Object.assign({},yt,{name:r,setup(s,{attrs:t}){const m=_(),w=Y(n,void 0);ae(p,{collectionItemRef:m}),Ye(()=>{const f=U(m);f&&w.itemMap.set(f,{ref:f,...t})}),We(()=>{const f=U(m);w.itemMap.delete(f)})}})}},ht=Nn({style:{type:ke([String,Array,Object,Boolean]),default:void 0},currentTabId:{type:ke(String)},defaultCurrentTabId:String,loop:Boolean,dir:{type:String,values:["ltr","rtl"],default:"ltr"},orientation:{type:ke(String)},onBlur:Function,onFocus:Function,onMousedown:Function}),{ElCollection:Et,ElCollectionItem:Ct,COLLECTION_INJECTION_KEY:ln,COLLECTION_ITEM_INJECTION_KEY:It}=_t("RovingFocusGroup"),Ne=Symbol("elRovingFocusGroup"),rn=Symbol("elRovingFocusGroupItem"),kt={ArrowLeft:"prev",ArrowUp:"prev",ArrowRight:"next",ArrowDown:"next",PageUp:"first",Home:"first",PageDown:"last",End:"last"},$t=(e,a)=>e,Vt=(e,a,r)=>{const n=$t(_e(e));return kt[n]},Tt=(e,a)=>e.map((r,n)=>e[(n+a)%e.length]),ze=e=>{const{activeElement:a}=document;for(const r of e)if(r===a||(r.focus(),a!==document.activeElement))return},Ge="currentTabIdChange",Ue="rovingFocusGroup.entryFocus",Rt={bubbles:!1,cancelable:!0};var St=j({name:"ElRovingFocusGroupImpl",inheritAttrs:!1,props:ht,emits:[Ge,"entryFocus"],setup(e,{emit:a}){const r=_((e.currentTabId||e.defaultCurrentTa
`).forEach((p,s)=>{p.trim()&&n.push(to(p,s,n.length+1))}),{supported:!0,records:n}}if(r.endsWith(".json"))try{const n=JSON.parse(e);return{supported:!0,records:(Array.isArray(n)?n:[n]).map((s,t)=>({sourceIndex:t,displayIndex:t+1,raw:JSON.stringify(s),kind:cn(s)?"object":"primitive",value:s}))}}catch(n){return{supported:!0,records:[{sourceIndex:0,displayIndex:1,raw:e,kind:"invalid",value:e,error:n instanceof Error?n.message:"JSON 格式不正确"}]}}return{supported:!1,records:[]}}function ao(e,a,r,n){const p=a.toLowerCase();if(p.endsWith(".jsonl")){const s=e.split(`
`);if(r<0||r>=s.length)throw new Error("目标样本不存在");return s[r]=JSON.stringify(n),s.join(`
`)}if(p.endsWith(".json")){let s;try{s=JSON.parse(e)}catch{if(r!==0)throw new Error("目标样本不存在");return JSON.stringify(n,null,2)}if(Array.isArray(s)){if(r<0||r>=s.length)throw new Error("目标样本不存在");return s[r]=n,JSON.stringify(s,null,2)}if(r!==0)throw new Error("目标样本不存在");return JSON.stringify(n,null,2)}throw new Error("当前文件不支持逐条编辑")}const lo={class:"version-control-bar","aria-label":"数据集版本控制"},ro={class:"version-selector-group"},so={class:"version-status",role:"status","aria-live":"polite"},io={key:0,class:"fa fa-ellipsis-h","aria-hidden":"true"},uo=j({__name:"DatasetVersionBar",props:{modelValue:{},versions:{},viewedVersion:{},activeVersionId:{},isViewingActiveVersion:{type:Boolean},hasPendingVersionChanges:{type:Boolean},versionLoading:{type:Boolean},savingRecord:{type:Boolean},activatingVersion:{type:Boolean},deletingVersion:{type:Boolean}},emits:["update:modelValue","change","activate","delete"],setup(e,{emit:a}){const r=e,n=a,p=E(()=>r.versionLoading||r.savingRecord||r.activatingVersion||r.deletingVersion),s=E(()=>{var y;return((y=r.viewedVersion)==null?void 0:y.version)===1?"初始版本不可删除":r.versions.length<=1?"至少需要保留一个版本":""}),t=E(()=>p.value||!!s.value);function m(y){return new Date(y).toLocaleString("zh-CN",{hour12:!1})}function w(y){const u=y.id===r.activeVersionId?"当前版本":"历史版本";return`V${y.version} · ${u} · ${m(y.create_time)}`}function f(y){n("update:modelValue",y),n("change",y)}function b(y){if(!p.value){if(y==="activate"){n("activate");return}t.value||n("delete")}}return(y,u)=>{const R=ot,F=tt,T=Se,S=le,g=eo,d=no,$=xt;return c(),O("section",lo,[l("div",ro,[u[0]||(u[0]=l("label",{for:"dataset-version-select"},"数据版本",-1)),k(F,{id:"dataset-version-select","model-value":e.modelValue,class:"version-select",loading:e.versionLoading,disabled:e.versionLoading||e.savingRecord,"aria-label":"选择要查看的数据集版本",onChange:f},{default:v(()=>[(c(!0),O(ne,null,he(e.versions,C=>(c(),D(R,{key:C.id,label:w(C),value:C.id},null,8,["label","value"]))),128))]),_:1},8,["model-value","loading","disabled"])]),l("div",so,[e.viewedVersion?(c(),O(ne,{key:0},[e.isViewingActiveVersion?(c(),D(T,{key:0,type:"success"},{default:v(()=>[P(" V"+N(e.viewedVersion.version)+" · 当前版本 ",1)]),_:1})):(c(),D(T,{key:1,type:"info"},{default:v(()=>[P("V"+N(e.viewedVersion.version)+" · 历史版本(只读)",1)]),_:1})),e.hasPendingVersionChanges?(c(),D(T,{key:2,type:"warning"},{default:v(()=>[...u[1]||(u[1]=[P("有待保存修改",-1)])]),_:1})):K("",!0),l("span",null,N(e.viewedVersion.description||"无版本说明")+" · "+N(m(e.viewedVersion.create_time)),1)],64)):K("",!0)]),e.viewedVersion&&!e.isViewingActiveVersion?(c(),D($,{key:0,class:"version-actions",trigger:"click",placement:"bottom-end","popper-class":"version-actions-popper",disabled:p.value,onCommand:b},{dropdown:v(()=>[k(d,null,{default:v(()=>[k(g,{command:"activate",class:"version-action-primary",disabled:p.value},{default:v(()=>[...u[2]||(u[2]=[l("i",{class:"fa fa-check-circle","aria-hidden":"true"},null,-1),P(" 设为当前版本 ",-1)])]),_:1},8,["disabled"]),k(g,{command:"delete",class:"version-action-danger",disabled:t.value,title:s.value||void 0,divided:""},{default:v(()=>[...u[3]||(u[3]=[l("i",{class:"fa fa-trash-o","aria-hidden":"true"},null,-1),P(" 删除版本 ",-1)])]),_:1},8,["disabled","title"])]),_:1})]),default:v(()=>[k(S,{class:"version-actions-button",loading:e.activatingVersion||e.deletingVersion,disabled:p.value,"aria-label":"打开历史版本操作菜单"},{default:v(()=>[!e.activatingVersion&&!e.deletingVersion?(c(),O("i",io)):K("",!0)]),_:1},8,["loading","disabled"])]),_:1},8,["disabled"])):K("",!0)])}}}),co=pe(uo,[["__scopeId","data-v-e51d9b4f"]]),vo={class:"records-viewer"},fo={class:"records-toolbar"},po={key:0,class:"viewer-state record-empty-state"},mo={key:1,class:"record-table-shell","aria-label":"数据样本表格"},go={class:"table-index"},wo={class:"table-cell-text"},bo={class:"table-cell-text"},yo
`).slice(0,100));return(n,p)=>(c(),O("div",{class:"code-viewer",tabindex:"0","aria-label":`${e.fileName||""} 文件内容`},[(c(!0),O(ne,null,he(r.value,(s,t)=>(c(),O("div",{key:t,class:"code-line"},[l("span",So,N(t+1),1),l("code",null,N(s||" "),1)]))),128))],8,Ro))}}),No=pe(Oo,[["__scopeId","data-v-6d3466ce"]]),Fo={class:"page-header"},Do={class:"page-heading"},Bo={class:"heading-row"},Po={class:"dataset-overview","aria-label":"数据集概览"},Ao={class:"overview-item"},Lo={class:"overview-item"},Mo={class:"overview-item overview-item-wide"},Ko={key:1,class:"preview-workspace","aria-label":"数据集文件详情"},Jo={class:"content-pane"},jo={class:"content-toolbar"},zo={class:"content-title"},Go={class:"toolbar-actions"},Uo=["aria-busy"],Ho={key:0,class:"viewer-state"},Yo={key:1,class:"viewer-state viewer-state-error",role:"alert"},Wo={key:2,class:"viewer-state"},qo={class:"viewer-footer"},Qo={key:0},Xo={key:1},Zo={key:2,class:"empty-files","aria-label":"空文件列表"},xo=j({__name:"DatasetPreviewView",setup(e){const r=Un().params.id,n=_(),p=_(!1),s=_(!1),t=_(null),m=_(""),w=_(""),f=_(""),b=_(""),y=_(!1),u=_(null),R=_([]),F=_(""),T=_(""),S=_(!1),g=_(!1),d=_([]),$=_(""),C=_(""),I=_(""),L=_(!1),G=_(!1),Z=_(!1),x=_(1);let V=0;const Q=E(()=>{var o;return((o=t.value)==null?void 0:o.files)||[]}),A=E(()=>Q.value.find(o=>q(o)===m.value)),B=E(()=>w.value?w.value.split(`
`).length:0),re=E(()=>{var o;return oo(w.value,((o=A.value)==null?void 0:o.name)||"")}),Ce=E(()=>re.value.supported),Fe=E(()=>re.value.records),te=E(()=>d.value.find(o=>o.id===I.value)),ee=E(()=>!!I.value&&I.value===C.value),vn=E(()=>{var o;return((o=u.value)==null?void 0:o.kind)==="object"?JSON.stringify(R.value):F.value}),Ie=E(()=>y.value&&vn.value!==T.value),me=E(()=>w.value!==f.value),De=E(()=>Ie.value||me.value),fn=E(()=>{var i,h;const o=String(((i=t.value)==null?void 0:i.type)||"").toLowerCase();return Hn[o]||((h=t.value)==null?void 0:h.type)||"-"}),pn=E(()=>{var i;const o=((i=t.value)==null?void 0:i.storage_type)||"";return Yn[o]||o||"-"}),mn=E(()=>{var o;return(o=t.value)!=null&&o.create_time?new Date(t.value.create_time).toLocaleString("zh-CN"):"-"});function q(o){return String(o.id||o.name)}async function gn(){p.value=!0;try{t.value=await Qn(r);const o=Q.value[0];o&&(m.value=q(o),await Be(o))}finally{p.value=!1}}async function Be(o){s.value=!0,b.value="";const i=++V;try{const h=await Xn(q(o)),H=await Ve(q(o),h.active_version_id);if(i!==V)return;d.value=h.versions,x.value=h.next_version_number??Math.max(0,...h.versions.map(M=>M.version))+1,C.value=h.active_version_id,$.value=h.active_version_id,I.value=h.active_version_id,w.value=H.content,f.value=H.content,se()}catch{i===V&&(b.value="版本内容加载失败,请稍后重试")}finally{i===V&&(s.value=!1)}}async function wn(o){if(!A.value||o===I.value)return;const i=I.value;if(!await Pe("切换版本后,当前样本的未保存修改将丢失。")){$.value=i;return}L.value=!0;const h=++V;try{const H=await Ve(q(A.value),o);if(h!==V)return;w.value=H.content,f.value=H.content,I.value=H.version.id,se()}catch{h===V&&($.value=i)}finally{h===V&&(L.value=!1)}}async function bn(){if(!(!A.value||!te.value||ee.value)){try{await $e.confirm(`确定将 V${te.value.version} 设为当前版本吗后续任务将使用该版本`,"切换当前版本",{type:"warning",confirmButtonText:"设为当前版本",cancelButtonText:"取消"})}catch{return}G.value=!0;try{const o=await et(q(A.value),te.value.id,C.value);C.value=o.version.id,w.value=o.content,f.value=o.content,oe.success(`已将 V${o.version.version} 设为当前版本`)}finally{G.value=!1}}}async function yn(){var h,H;if(!A.value||!te.value||ee.value||Z.value)return;const o=te.value;if(await((H=n.value)==null?void 0:H.open({title:`删除 V${o.version} 版本`,message:`删除后无法恢复当前版本 V${((h=d.value.find(M=>M.id===C.value))==null?void 0:h.version)||"-"} 不受影响`,confirmText:"删除版本",cancelText:"取消",tone:"danger"}))){Z.value=!0,L.value=!0;try{const M=await nt(q(A.value),o.id,C.value),ge=await Ve(q(A.value),M.active_version_id);d.value=M.versions,x.value=M.next_version_number??Math.max(0,...M.versions.map(we=>we.version))+1,C.value=M.active_version_id,$.value=M.active_version_id,I.value=M.active_version_id,w.value=ge.content,f.value=ge.content,se(),oe.success(`V${o.version} 版本已删除`)}finally{L.value=!1,Z.value=!1}}}function _n(o){if(!ee.value){oe.warning("历史版本为只读,请先设为当前版本");return}u.value=o,o.kind==="object"?(R.value=Object.entries(o.value).map(([i,h])=>({key:i,value:typeof h=="string"?h:JSON.stringify(h,null,2),isJson:typeof h!="string"})),F.value=""):(R.value=[],F.value=o.raw),y.value=!0,T.value=o.kind==="object"?JSON.stringify(R.value):F.value}function se(){y.value=!1,u.value=null,R.value=[],F.value="",T.value=""}function hn(o,i){const h=R.value[o];h&&(h.value=i)}async function Pe(o="当前存在尚未保存为版本的修改,放弃后将无法恢复。"){if(!De.value)return!0;try{return await $e.confirm(o,"确认放弃修改?",{type:"warning",confirmButtonText:"放弃修改",cancelButtonText:"继续编辑"}),!0}catch{return!1}}async function En(){if(!Ie.value)return!0;try{return await $e.confirm("当前样本存在未暂存修改,放弃后将无法恢复。","确认放弃修改?",{type:"warning",confirmButtonText:"放弃修改",cancelButtonText:"继续编辑"}),!0}catch{return!1}}async function Cn(o){S.value||await En()&&(se(),