2 lines
10 KiB
JavaScript
2 lines
10 KiB
JavaScript
import{_ as j}from"./BasicMainCard-f5011b39.js";import{_ as K}from"./BasicModal.vue_vue_type_style_index_0_lang-a547157a.js";import{_ as Q,u as Y}from"./useBaseTable-13b436e1.js";import{_ as Z}from"./button.vue_vue_type_style_index_0_lang-851afdd8.js";import{I as z}from"./Icon-04c02c0b.js";import{t as ee}from"./useDataTime-10f46d84.js";import{I as O,d as te,g as T,A as ae,o as P,c as U,b as m,w as v,a as p,e as H,G as ne,j as A,z as se,t as E,k as F,D as g}from"./index-82b07f49.js";import{_ as le}from"./TextPreview.vue_vue_type_script_setup_true_lang-38b465eb.js";import{M as G}from"./index-5dc3a2fa.js";import{I as oe}from"./index-c6d6dccd.js";import{T as J}from"./shallowequal-17b27246.js";import{U as ie}from"./index-0f0f5d8d.js";import"./_plugin-vue_export-helper-f81f33f1.js";import"./index-ad11eb53.js";import"./index-a4d2dbbb.js";import"./Col-5d52aed9.js";import"./vnode-007df887.js";import"./useState-e0a5bff5.js";import"./useRefs-e9385981.js";import"./isPlainObject-f3a46277.js";import"./index-1f61ecf5.js";import"./index-7e5faec0.js";import"./toArray-e3bbd719.js";import"./FormItemContext-f4f190fd.js";import"./pickAttrs-b9acd388.js";import"./index-d634ff29.js";import"./index-2a5d6560.js";const re=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:r=>r.record.index+1},{title:"نام ارسال کننده",dataIndex:"owner_name",key:"owner_name",customRender:r=>r.record.owner_name||"-"},{title:"متن پیام",dataIndex:"text",key:"text",slot:"text"},{title:"فایل",dataIndex:"file",key:"file",align:"center",width:120,slot:"file"},{title:"وضعیت پین",dataIndex:"pined",key:"pined",align:"center",width:100,customRender:r=>r.record.pined?"پین شده":"-"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:r=>ee(r.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];async function ce(r){const{data:c,error:_}=await O.from("channel_message").insert([r]).select();if(_)throw _;return c}async function W(r,c){const{data:_,error:k}=await O.from("channel_message").update(c).eq("id",r).select();if(k)throw k;return _}async function ue(r){const{error:c}=await O.from("channel_message").delete().eq("id",r);if(c)throw c}async function de(r){const c={...r};!c.sort&&!c.order&&(c.order="-id");const{limit:_,filters:k,page:b,sort:w,order:I,search:C}=c;let e=O.from("channel_message").select("*, users!owner_id(first_name, last_name, phone)",{count:"exact"});if(C&&C.trim()){const t=`%${C}%`;e=e.ilike("text",t)}if(k&&Array.isArray(k)&&k.forEach(t=>{const{field:u,op:S,value:x,hidden:l}=t;if(!l)switch(S){case"eq":e=e.eq(u,x);break;case"neq":e=e.neq(u,x);break;case"gt":e=e.gt(u,x);break;case"lt":e=e.lt(u,x);break;case"gte":e=e.gte(u,x);break;case"lte":e=e.lte(u,x);break;case"has":e=e.ilike(u,`%${x}%`);break;case"like":e=e.like(u,`%${x}%`);break}}),_&&b){const t=(b-1)*_,u=t+_-1;e=e.range(t,u)}if(w&&w.key){const t=w.order==="asc";e=e.order(w.key,{ascending:t})}else if(I){const t=!I.startsWith("-"),u=I.replace(/^[-+]/,"");e=e.order(u,{ascending:t})}const{data:y,error:$,count:h}=await e;if($)return console.error("[getChannelMessagesTable] Supabase query error:",$),{query:{...c,limit:_||10,page:b||1,total:0},rows:[]};try{if(Array.isArray(y)){const t=b||1,u=_||200,S=(t-1)*u,x=y.map((l,N)=>{let D=null;if(l.owner_id){const M=Array.isArray(l.users)?l.users[0]:l.users;M?D=`${M.first_name||""} ${M.last_name||""}`.trim()||M.phone||`کاربر ${l.owner_id}`:D=`کاربر ${l.owner_id}`}return{id:l.id,owner_id:l.owner_id??null,owner_name:D,text:l.text??"",file:l.file??null,pined:l.pined??!1,pined_at:l.pined_at??null,created_at:l.created_at??"",updated_at:l.updated_at??"",index:S+N,...l}});return{query:{...c,limit:_||10,page:b||1,total:h||0},rows:x}}}catch(t){console.log("[getChannelMessagesTable] normalize error:",t)}return{query:{...c,limit:_||10,page:b||1,total:h||0},rows:y||[]}}const fe={class:"flex justify-between items-center mb-4"},me=p("h2",null,"اطلاع رسانی",-1),pe=["href"],_e={key:1},ve={class:"gap-2 flex justify-center"},ge=p("span",null,"پین کردن",-1),he=p("span",null,"حذف",-1),xe=p("span",null,"ویرایش",-1),ye={class:"space-y-4"},ke=p("div",{class:"mb-1 text-sm text-gray-600"},"متن پیام *",-1),we=p("div",{class:"mb-1 text-sm text-gray-600"},"آپلود فایل (اختیاری)",-1),be={key:0,class:"mt-2"},Ie={class:"h-2 rounded bg-gray-200 overflow-hidden"},Ce={class:"text-xs text-gray-700 font-semibold text-center mt-1"},Te={key:1,class:"mt-2"},$e=["href"],tt=te({__name:"index",setup(r){const{TextArea:c}=oe,[_,k]=Y(),b=T({columns:re,api:de,defaultPageLimit:20}),w=T(!1),I=T(!1),C=T(null),e=ae(),y=T([]),$=T(!1),h=T(0),t=T({owner_id:null,text:"",file:null});function u(n){return n.size/1024/1024<50?!0:(g.error("حجم فایل باید کمتر از 50MB باشد"),!1)}async function S(n){const{file:s,onSuccess:o,onError:d,onProgress:B}=n,R=new FormData;R.append("file",s);const f="https://node.macharta.ir/upload/message-file";h.value=0,$.value=!0,await new Promise((V,L)=>{const i=new XMLHttpRequest;i.open("POST",f),i.setRequestHeader("Authorization",`Bearer ${localStorage.getItem("tamin_token")||localStorage.getItem("token")||""}`),i.timeout=15*60*1e3,i.upload.onprogress=a=>{if(a.lengthComputable){const q=Math.round(a.loaded/a.total*100);h.value=q,B==null||B({percent:q})}},i.onload=()=>{if(h.value=100,i.status>=200&&i.status<300)try{const a=JSON.parse(i.responseText||"{}"),q=a.url||a.path||a.file||a.data&&(a.data.url||a.data.path||a.data.file)||"";t.value.file=q,y.value=q?[{uid:`${Date.now()}`,name:s.name,status:"done",url:q}]:[],o==null||o(a,i),g.success("فایل با موفقیت آپلود شد!"),V()}catch(a){d==null||d(a,i),L(a)}else{const a=new Error("خطا در آپلود فایل");g.error("خطا در آپلود فایل"),d==null||d(a,i),L(a)}},i.onerror=()=>{const a=new Error("خطا در آپلود فایل");g.error("خطا در آپلود فایل"),d==null||d(a,i),L(a)},i.ontimeout=()=>{const a=new Error("آپلود timeout شد");g.error("آپلود timeout شد"),d==null||d(a,i),L(a)},i.onloadend=()=>{$.value=!1,h.value=0},i.send(R)})}async function x(){var s;I.value=!1,C.value=null,y.value=[],e.userInfo||await e.getMyInfo();const n=((s=e.userInfo)==null?void 0:s.id)||null;t.value={owner_id:n,text:"",file:null},w.value=!0}function l(){w.value=!1,y.value=[],h.value=0}async function N(n){C.value=n.id,I.value=!0,t.value={owner_id:null,text:n.text||"",file:n.file||null},n.file?y.value=[{uid:"-1",name:n.file.split("/").pop()||"فایل",status:"done",url:n.file}]:y.value=[],w.value=!0}async function D(n){const s=n.pined===!0;G.confirm({title:"آیا مطمئن هستید؟",content:s?"این پیام در حال حاضر پین شده است. آیا میخواهید آن را از حالت پین خارج کنید؟":"آیا میخواهید این پیام را پین کنید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{try{const o=!s,d={pined:o,pined_at:o?new Date().toISOString():null};await W(n.id,d),g.success(o?"پیام با موفقیت پین شد!":"پیام با موفقیت از حالت پین خارج شد!"),k()}catch(o){g.error(o.message||"خطا در تغییر وضعیت پین پیام")}}})}async function M(n){G.confirm({title:"آیا مطمئن هستید؟",content:"آیا میخواهید این پیام را حذف کنید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{try{await ue(n.id),g.success("پیام با موفقیت حذف شد!"),k()}catch(s){g.error(s.message||"خطا در حذف پیام")}}})}async function X(){var n,s;if(!((n=t.value.text)!=null&&n.trim())){g.error("لطفاً متن پیام را وارد کنید");return}if($.value){g.warning("لطفاً تا پایان آپلود صبر کنید");return}try{if(I.value&&C.value){const o={text:t.value.text,file:t.value.file};await W(C.value,o),g.success("پیام با موفقیت بهروزرسانی شد!")}else{e.userInfo||await e.getMyInfo();const o={owner_id:((s=e.userInfo)==null?void 0:s.id)||null,text:t.value.text,file:t.value.file||null};await ce(o),g.success("پیام با موفقیت افزوده شد!")}l(),k()}catch(o){g.error(o.message||"خطا در ذخیره پیام")}}return(n,s)=>{const o=Z,d=Q,B=K,R=j;return P(),U("div",null,[m(R,null,{default:v(()=>[p("div",fe,[me,m(o,{type:"primary",onClick:x},{default:v(()=>[H("افزودن اطلاع رسانی")]),_:1})]),m(d,ne(b.value,{ref:"table",onRegister:A(_)}),{text:v(({record:f})=>[m(le,{text:f.text},null,8,["text"])]),file:v(({record:f})=>[f.file?(P(),U("a",{key:0,href:f.file,target:"_blank",class:"text-blue-500 hover:underline"}," دانلود فایل ",8,pe)):(P(),U("span",_e,"-"))]),action:v(({record:f})=>[p("div",ve,[m(A(J),{class:"cursor-pointer"},{title:v(()=>[ge]),default:v(()=>[m(z,{icon:"vuesax-linear:bookmark",color:"#16A34A",onClick:V=>D(f)},null,8,["onClick"])]),_:2},1024),m(A(J),{class:"cursor-pointer"},{title:v(()=>[he]),default:v(()=>[m(z,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:V=>M(f)},null,8,["onClick"])]),_:2},1024),m(A(J),{class:"cursor-pointer"},{title:v(()=>[xe]),default:v(()=>[m(z,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:V=>N(f)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),m(B,{visible:w.value,"onUpdate:visible":s[2]||(s[2]=f=>w.value=f),title:I.value?"ویرایش اطلاع رسانی":"افزودن اطلاع رسانی",onOk:X,onCancel:l,width:"80%",confirmLoading:$.value},{default:v(()=>[p("div",ye,[p("div",null,[ke,m(A(c),{value:t.value.text,"onUpdate:value":s[0]||(s[0]=f=>t.value.text=f),placeholder:"متن پیام",rows:6},null,8,["value"])]),p("div",null,[we,m(A(ie),{"file-list":y.value,"onUpdate:fileList":s[1]||(s[1]=f=>y.value=f),"before-upload":u,"custom-request":S,"max-count":1},{default:v(()=>[m(o,null,{default:v(()=>[m(z,{icon:"vuesax-linear:document-upload",class:"mr-1"}),H(" انتخاب فایل ")]),_:1})]),_:1},8,["file-list"]),h.value>0&&h.value<100?(P(),U("div",be,[p("div",Ie,[p("div",{class:"h-2 bg-blue-500 transition-all",style:se({width:`${h.value}%`})},null,4)]),p("div",Ce,E(h.value)+"%",1)])):F("",!0),t.value.file?(P(),U("div",Te,[p("a",{href:t.value.file,target:"_blank",class:"text-blue-500 hover:underline text-sm"},[m(z,{icon:"vuesax-linear:document-download",class:"inline-block mr-1"}),H(" فایل فعلی: "+E(t.value.file.split("/").pop()),1)],8,$e)])):F("",!0)])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{tt as default};
|