Files
tehran_tala/apps/admin-panel/dist/assets/model-B5c8wFLh.js
T
2026-09-15 17:06:27 +03:30

2 lines
7.7 KiB
JavaScript

import{d as ne,q as re,o as r,i as S,h as D,f as _,j as k,g as u,l as v,c as d,F as P,k as R,Q as ue,m,r as F,v as de,s as ce,e as c,t as he}from"./index-Q3FR3cGM.js";import{_ as pe}from"./_plugin-vue_export-helper-DlAUqK2U.js";const fe={class:"x-table"},_e={class:"x-table__toolbar"},ve={class:"x-table__actions"},me={key:0,class:"x-table__filters"},ye={class:"x-table__filter-actions"},ge=ne({__name:"XTable",props:{model:{},hasSelection:{type:Boolean,default:!1},modelValue:{default:()=>[]}},emits:["query","update:modelValue"],setup(b,{expose:i,emit:w}){const f=b,V=w,Y=m(()=>f.hasSelection?{selectedRowKeys:f.modelValue.map(e=>e.id),onChange:(e,t)=>{V("update:modelValue",t)}}:void 0),$=F([]),C=F(!1),y=F(!1),T=F(void 0),M=F("asc"),l=de({search:void 0,filters:[],total:0,limit:10,page:1}),O={emptyText:"هیج رکوردی یافت نشد."},j=[{value:"=",label:"برابر"},{value:"!=",label:"نامساوی"},{value:"like",label:"شامل"},{value:">",label:"بزرگتر"},{value:">=",label:"بزرگتر مساوی"},{value:"<",label:"کوچکتر"},{value:"<=",label:"کوچکتر مساوی"},{value:"between",label:"بین"}],U=m(()=>{var e;return((e=f.model)==null?void 0:e.cols)??[]}),I=m(()=>U.value.filter(e=>e.show)),E=m(()=>U.value.filter(e=>e.filtered).map(e=>({value:e.__fkey??e.key,label:e.title}))),Q=m(()=>T.value?`${M.value==="asc"?"+":"-"}${T.value}`:void 0),A=m(()=>I.value.map(e=>{var t;return{key:e.key,title:e.title,dataIndex:e.dataIndex.includes(".")?e.dataIndex.split("."):e.dataIndex,sorter:e.__sorter,width:e.width,__slot:(t=e.scopedSlots)==null?void 0:t.customRender}}));function N(e){return e.__slot}function B(e){if(e)return U.value.find(t=>(t.__fkey??t.key)===e)}function X(e){const t=B(e);if(!((t==null?void 0:t.filterType)!=="select"||!t.filterItems))return Object.entries(t.filterItems).map(([s,h])=>({value:s,label:h}))}function L(e){var t;return((t=B(e))==null?void 0:t.filterType)==="date"}const W=m(()=>{var e;return(e=f.model)!=null&&e._hidePagination?!1:{current:l.page,pageSize:l.limit,total:l.total,showSizeChanger:!0}});function G(e){var o;const t={};I.value.forEach(p=>{t[p.key]=p.title});const s=I.value.map(p=>p.key),h={search:l.search,filters:l.filters.filter(p=>p.field&&p.op),total:l.total,limit:l.limit,page:l.page,order:Q.value,select:s,titles:t,report_title:(o=f.model)==null?void 0:o.title};return e?{...h,op:e}:h}async function g(e){var t,s,h;if(f.model)try{C.value=!0;const{data:o}=await ce.post(f.model.url,G(e));$.value=o.rows,l.total=((t=o.query)==null?void 0:t.total)??0,l.page=((s=o.query)==null?void 0:s.page)??l.page,l.limit=((h=o.query)==null?void 0:h.limit)??l.limit,V("query",o.query)}catch(o){throw console.log(o),o}finally{C.value=!1}}function H(e){l.search=e,l.page=1,g()}function J(){y.value=!y.value,y.value&&l.filters.length===0&&z()}function z(){l.filters.push({id:parseFloat(`${l.filters.length}.${Math.floor(Math.random()*1e3)}`)})}function Z(e){l.filters.splice(e,1)}function ee(){y.value=!1,l.page=1,g()}function te(e,t,s){l.page=e.current??1,l.limit=e.pageSize??l.limit,s!=null&&s.columnKey&&s.order?(T.value=String(s.columnKey),M.value=s.order==="ascend"?"asc":"desc"):T.value=void 0,g()}return re(()=>{var e;for(const t of((e=f.model)==null?void 0:e.defaultFilters)??[])l.filters.push({id:Math.random(),...t});g()}),i({fetch:g}),(e,t)=>{const s=c("a-input-search"),h=c("a-badge"),o=c("a-button"),p=c("a-checkbox"),le=c("a-menu-item"),ae=c("a-menu"),ie=c("a-dropdown"),q=c("a-select"),oe=c("a-date-picker"),K=c("a-input"),se=c("a-table");return r(),S("div",fe,[D("div",_e,[b.model._hideSearch?k("",!0):(r(),_(s,{key:0,value:l.search,"onUpdate:value":t[0]||(t[0]=a=>l.search=a),placeholder:"جستجو","allow-clear":"",style:{"max-width":"260px"},onSearch:H},null,8,["value"])),D("div",ve,[b.model._noFilters?k("",!0):(r(),_(o,{key:0,type:y.value?"primary":"default",onClick:J},{default:u(()=>[t[2]||(t[2]=v(" فیلتر ",-1)),l.filters.length?(r(),_(h,{key:0,count:l.filters.length},null,8,["count"])):k("",!0)]),_:1},8,["type"])),d(ie,{trigger:["click"]},{overlay:u(()=>[d(ae,null,{default:u(()=>[(r(!0),S(P,null,R(U.value,a=>(r(),_(le,{key:a.key},{default:u(()=>[d(p,{checked:a.show,"onUpdate:checked":x=>a.show=x},{default:u(()=>[v(he(a.title),1)]),_:2},1032,["checked","onUpdate:checked"])]),_:2},1024))),128))]),_:1})]),default:u(()=>[d(o,null,{default:u(()=>[...t[3]||(t[3]=[v("ستون‌ها",-1)])]),_:1})]),_:1}),d(o,{class:"refresh-btn",loading:C.value,onClick:t[1]||(t[1]=a=>g())},{default:u(()=>[...t[4]||(t[4]=[v("بارگذاری مجدد",-1)])]),_:1},8,["loading"])])]),y.value?(r(),S("div",me,[(r(!0),S(P,null,R(l.filters,(a,x)=>(r(),S("div",{key:a.id,class:"x-table__filter-row"},[d(q,{value:a.field,"onUpdate:value":n=>a.field=n,placeholder:"ستون",style:{width:"180px"},options:E.value},null,8,["value","onUpdate:value","options"]),d(q,{value:a.op,"onUpdate:value":n=>a.op=n,placeholder:"شرط",style:{width:"130px"},options:j},null,8,["value","onUpdate:value"]),X(a.field)?(r(),_(q,{key:0,value:a.value,"onUpdate:value":n=>a.value=n,placeholder:"مقدار",style:{width:"200px"},options:X(a.field)},null,8,["value","onUpdate:value","options"])):L(a.field)?(r(),_(oe,{key:1,value:a.value,"onUpdate:value":n=>a.value=n,placeholder:"مقدار",style:{width:"200px"},"value-format":"YYYY-MM-DD"},null,8,["value","onUpdate:value"])):(r(),_(K,{key:2,value:a.value,"onUpdate:value":n=>a.value=n,placeholder:"مقدار",style:{width:"200px"}},null,8,["value","onUpdate:value"])),a.op==="between"?(r(),_(K,{key:3,value:a.value2,"onUpdate:value":n=>a.value2=n,placeholder:"تا",style:{width:"200px"}},null,8,["value","onUpdate:value"])):k("",!0),d(o,{danger:"",onClick:n=>Z(x)},{default:u(()=>[...t[5]||(t[5]=[v("حذف",-1)])]),_:1},8,["onClick"])]))),128)),D("div",ye,[d(o,{onClick:z},{default:u(()=>[...t[6]||(t[6]=[v("افزودن فیلتر",-1)])]),_:1}),d(o,{type:"primary",onClick:ee},{default:u(()=>[...t[7]||(t[7]=[v("اعمال",-1)])]),_:1})])])):k("",!0),d(se,{columns:A.value,"data-source":$.value,loading:C.value,pagination:W.value,locale:O,"row-selection":Y.value,"row-key":"id",size:"middle",bordered:"",onChange:te},{bodyCell:u(({column:a,record:x,text:n})=>[N(a)?ue(e.$slots,N(a),{text:n,record:x},void 0,!0,0):k("",!0)]),_:3},8,["columns","data-source","loading","pagination","row-selection"])])}}}),we=pe(ge,[["__scopeId","data-v-80e65b68"]]);class xe{constructor(i,w){this.show=!0,this.__sorter=!0,this.filtered=!1,this.key=i,this.title=w,this.dataIndex=i}__filter(){this.filtered=!0,this.scopedSlots||(this.scopedSlots={}),this.scopedSlots.filterDropdown=`${this.key}_filterDropdown`,this.scopedSlots.filterIcon=`${this.key}_filterIcon`}filterKey(i){return this.__fkey=i,this}renderSlot(i){return this.scopedSlots||(this.scopedSlots={}),this.scopedSlots.customRender=i,this}filterText(){return this.__filter(),this.filterType="default",this}filterSwitch(){return this.__filter(),this.filterType="switch",this}filterQuery(i){return this.__filter(),this.filterType="query",this.filterAction=i,this}filterDate(){return this.__filter(),this.filterType="date",this}filterNumber(){return this.__filter(),this.filterType="number",this}filterSelect(i){return this.__filter(),this.filterType="select",this.filterItems=i,this}noSort(){return this.__sorter=!1,this}hidden(){return this.show=!1,this}setWidth(i){return this.width=i,this}}class Se{constructor(i,w){this.cols=[],this._hidePagination=!1,this._hideSearch=!1,this._noFilters=!1,this.url=i,this.title=w}add(i){return this.cols.push(i),this}addDefaultFilter(i){return this.defaultFilters||(this.defaultFilters=[]),this.defaultFilters.push(i),this}hidePagination(){return this._hidePagination=!0,this}hideSearch(){return this._hideSearch=!0,this}noFilters(){return this._noFilters=!0,this}getSortFields(){return this.cols.filter(i=>i.__sorter)}}export{we as X,Se as a,xe as b};