bettertend/frontend/dist/assets/FPTable-CWvngIYd.js

2 lines
5.4 KiB
JavaScript

import{_ as A,bg as L,r as m,c as T,a as n,j as r,b as l,p as y,af as b,aR as p,t as c,d as S,w as P,e as z,F as B,g as i,n as v,k as N}from"./index-QAlcqU00.js";const D={class:"fp-table-container"},I={key:0,class:"flex items-center justify-between mb-4"},q={key:0},E={key:1,class:"flex items-center space-x-2"},H={key:1,class:"mb-4"},K={class:"overflow-x-auto shadow ring-1 ring-black ring-opacity-5 rounded"},O={class:"min-w-full divide-y divide-gray-300 bg-white"},G={class:"bg-gray-50"},J=["onClick"],Q={class:"flex items-center space-x-1"},U={key:0,class:"flex flex-col"},W={key:0,class:"px-6 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider"},X={class:"bg-white divide-y divide-gray-200"},Y={key:0},Z=["colspan"],_={key:1},ee=["colspan"],te={class:"flex flex-col items-center"},se={class:"text-sm font-medium"},ae=["onClick"],ne={key:1,class:"text-sm text-gray-900"},ie={key:0,class:"px-6 py-4 whitespace-nowrap text-right text-sm font-medium"},le={key:2,class:"flex items-center justify-between mt-4"},oe={class:"text-sm text-gray-700"},re={class:"flex items-center space-x-2"},de={__name:"FPTable",props:{columns:{type:Array,required:!0},data:{type:Array,default:()=>[]},loading:{type:Boolean,default:!1},emptyMessage:{type:String,default:"No data available"},selectable:{type:Boolean,default:!1},pagination:{type:Object,default:null},rowKey:{type:String,default:"id"}},emits:["sort-change","row-click","page-change"],setup(a,{emit:V}){const x=a,w=V,M=L(),h=m(""),u=m("asc"),g=m([]),f=T(()=>!!M["row-actions"]),k=(e,t)=>e[x.rowKey]||t,$=(e,t)=>t.split(".").reduce((s,o)=>s==null?void 0:s[o],e),j=(e,t)=>t.formatter&&typeof t.formatter=="function"?t.formatter(e):e,F=e=>{h.value===e?u.value=u.value==="asc"?"desc":"asc":(h.value=e,u.value="asc"),w("sort-change",{column:e,direction:u.value})},C=(e,t)=>h.value!==e?"text-gray-300":u.value===t?"text-gray-600":"text-gray-300",R=(e,t)=>{if(x.selectable){const s=k(e,t);g.value.includes(s)?g.value=g.value.filter(o=>o!==s):g.value.push(s)}w("row-click",{row:e,index:t})};return(e,t)=>(i(),n("div",D,[e.$slots.header||e.$slots.actions?(i(),n("div",I,[e.$slots.header?(i(),n("div",q,[y(e.$slots,"header",{},void 0,!0)])):r("",!0),e.$slots.actions?(i(),n("div",E,[y(e.$slots,"actions",{},void 0,!0)])):r("",!0)])):r("",!0),e.$slots.filters?(i(),n("div",H,[y(e.$slots,"filters",{},void 0,!0)])):r("",!0),l("div",K,[l("table",O,[l("thead",G,[l("tr",null,[(i(!0),n(b,null,p(a.columns,s=>(i(),n("th",{key:s.key,class:v(["px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",s.sortable?"cursor-pointer hover:bg-gray-100":"",s.width?`w-${s.width}`:""]),onClick:o=>s.sortable?F(s.key):null},[l("div",Q,[l("span",null,c(s.label),1),s.sortable?(i(),n("div",U,[(i(),n("svg",{class:v(["w-3 h-3",C(s.key,"asc")]),fill:"currentColor",viewBox:"0 0 20 20"},t[2]||(t[2]=[l("path",{d:"M14.707 12.707a1 1 0 01-1.414 0L10 9.414l-3.293 3.293a1 1 0 01-1.414-1.414l4-4a1 1 0 011.414 0l4 4a1 1 0 010 1.414z"},null,-1)]),2)),(i(),n("svg",{class:v(["w-3 h-3 -mt-1",C(s.key,"desc")]),fill:"currentColor",viewBox:"0 0 20 20"},t[3]||(t[3]=[l("path",{d:"M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z"},null,-1)]),2))])):r("",!0)])],10,J))),128)),e.$slots.actions||f.value?(i(),n("th",W," Actions ")):r("",!0)])]),l("tbody",X,[a.loading?(i(),n("tr",Y,[l("td",{colspan:a.columns.length+(f.value?1:0),class:"px-6 py-8 text-center"},t[4]||(t[4]=[l("div",{class:"flex justify-center"},[l("div",{class:"animate-spin rounded-full h-6 w-6 border-b-2 border-primary-600"})],-1)]),8,Z)])):!a.data||a.data.length===0?(i(),n("tr",_,[l("td",{colspan:a.columns.length+(f.value?1:0),class:"px-6 py-8 text-center text-gray-500"},[l("div",te,[t[5]||(t[5]=l("svg",{class:"w-12 h-12 text-gray-300 mb-4",fill:"none",viewBox:"0 0 24 24",stroke:"currentColor"},[l("path",{"stroke-linecap":"round","stroke-linejoin":"round","stroke-width":"1",d:"M9 12h6m-6 4h6m2 5H7a2 2 0 01-2-2V5a2 2 0 012-2h5.586a1 1 0 01.707.293l5.414 5.414a1 1 0 01.293.707V19a2 2 0 01-2 2z"})],-1)),l("p",se,c(a.emptyMessage||"No data available"),1)])],8,ee)])):r("",!0),(i(!0),n(b,null,p(a.data,(s,o)=>(i(),n("tr",{key:k(s,o),class:v(["hover:bg-gray-50",a.selectable?"cursor-pointer":"",g.value.includes(k(s,o))?"bg-primary-50":""]),onClick:d=>a.selectable?R(s,o):null},[(i(!0),n(b,null,p(a.columns,d=>(i(),n("td",{key:d.key,class:"px-6 py-4 whitespace-nowrap"},[e.$slots[`column-${d.key}`]?y(e.$slots,`column-${d.key}`,{key:0,row:s,value:$(s,d.key),index:o},void 0,!0):(i(),n("div",ne,c(j($(s,d.key),d)),1))]))),128)),f.value?(i(),n("td",ie,[y(e.$slots,"row-actions",{row:s,index:o},void 0,!0)])):r("",!0)],10,ae))),128))])])]),a.pagination&&!a.loading?(i(),n("div",le,[l("div",oe," Showing "+c((a.pagination.currentPage-1)*a.pagination.pageSize+1)+" to "+c(Math.min(a.pagination.currentPage*a.pagination.pageSize,a.pagination.total))+" of "+c(a.pagination.total)+" results ",1),l("div",re,[S(z(B),{variant:"outline",size:"sm",disabled:a.pagination.currentPage<=1,onClick:t[0]||(t[0]=s=>e.$emit("page-change",a.pagination.currentPage-1))},{default:P(()=>t[6]||(t[6]=[N(" Previous ",-1)])),_:1,__:[6]},8,["disabled"]),S(z(B),{variant:"outline",size:"sm",disabled:a.pagination.currentPage>=Math.ceil(a.pagination.total/a.pagination.pageSize),onClick:t[1]||(t[1]=s=>e.$emit("page-change",a.pagination.currentPage+1))},{default:P(()=>t[7]||(t[7]=[N(" Next ",-1)])),_:1,__:[7]},8,["disabled"])])])):r("",!0)]))}},ue=A(de,[["__scopeId","data-v-7a4d805f"]]);export{ue as F};