2 lines
10 KiB
JavaScript
2 lines
10 KiB
JavaScript
import{_ as Y}from"./BasicMainCard-d7ded7d7.js";import{_ as Z}from"./BasicModal.vue_vue_type_style_index_0_lang-d37c1f01.js";import{_ as ee,u as te}from"./useBaseTable-5854ed19.js";import{_ as ae}from"./button.vue_vue_type_style_index_0_lang-110418ce.js";import{I as T}from"./Icon-53c563d2.js";import{t as ne}from"./useDataTime-4b2700c1.js";import{H as C,d as se,g as b,A as le,o as A,c as D,b as c,w as m,a as d,e as P,G as oe,j as S,y as ie,t as N,k as V,D as p}from"./index-b43045cf.js";import{f as F,a as re,b as ue,c as ce,d as de,e as H}from"./supabaseTableQuery-95762ff3.js";import{_ as fe}from"./TextPreview.vue_vue_type_script_setup_true_lang-d28838d9.js";import{e as me,g as pe}from"./convert-67c23be8.js";import{M as O}from"./index-1e0b33f2.js";import{I as _e}from"./index-b94f9b16.js";import{T as R}from"./shallowequal-18e8473a.js";import{U as ve}from"./index-51f8d94b.js";import"./index-e4c6896e.js";import"./index-0d9e50ef.js";import"./_plugin-vue_export-helper-d47eb12d.js";import"./styleChecker-0c8ed500.js";import"./vnode-96240c5a.js";import"./useState-ace49857.js";import"./useRefs-3d56a112.js";import"./Col-8aeddcae.js";import"./index-b2401969.js";import"./isPlainObject-8c91e78f.js";import"./index-6f54d687.js";import"./fa_IR-2461e941.js";import"./toArray-8f75a9bb.js";import"./FormItemContext-a080d4f0.js";import"./pickAttrs-5ae7ff2e.js";import"./lodash-7fcfac04.js";import"./index-6e92857b.js";import"./index-671f1170.js";const he=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:e=>e.record.index+1},{title:"نام ارسال کننده",dataIndex:"owner_name",key:"owner_name",filterField:"owner_name",customRender:e=>e.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:e=>e.record.pined?"پین شده":"-"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:e=>ne(e.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}],xe=new Set(["text","file","pined","pined_at","created_at","updated_at","owner_id"]),ge=["text"];async function ye(e){const{data:s,error:_}=await C.from("channel_message").insert([e]).select();if(_)throw _;return s}async function z(e,s){const{data:_,error:w}=await C.from("channel_message").update(s).eq("id",e).select();if(w)throw w;return _}async function we(e){const{error:s}=await C.from("channel_message").delete().eq("id",e);if(s)throw s}function be(e){let s=null;if(e.owner_id){const _=Array.isArray(e.users)?e.users[0]:e.users;_?s=`${_.first_name||""} ${_.last_name||""}`.trim()||_.phone||`کاربر ${e.owner_id}`:s=`کاربر ${e.owner_id}`}return{...e,owner_name:s,text:e.text??"",file:e.file??null,pined:e.pined??!1,pined_at:e.pined_at??null,created_at:e.created_at??"",updated_at:e.updated_at??""}}async function ke(e){const s={...e};!s.sort&&!s.order&&(s.order="-id");const{limit:_=20,page:w=1,search:k,filters:x}=s;let l=C.from("channel_message").select("*, users!owner_id(first_name, last_name, phone)",{count:"exact"});if(k!=null&&k.trim()){const f=await F(C,k);l=re(l,k,ge,f,"owner_id")}if(x!=null&&x.length){for(const f of x)if(!(f.hidden||!f.field)){if(f.field==="owner_name"){if(["eq","has","like"].includes(f.op)){const h=await F(C,String(f.value));h.length?l=l.in("owner_id",h):l=l.eq("owner_id","00000000-0000-0000-0000-000000000000")}continue}xe.has(f.field)&&(l=ue(l,f))}}l=ce(l,s,"-id",["id","created_at","updated_at","pined","text"]),l=de(l,w,_);const{data:I,error:g,count:y}=await l;return g?(console.error("[getChannelMessagesTable] Supabase query error:",g),H([],0,s)):H(I,y,s,be)}const Ie={class:"flex justify-between items-center mb-4"},Se=d("h2",null,"اطلاع رسانی",-1),Ce=["href"],Me={key:1},Te={class:"gap-2 flex justify-center"},Ae=d("span",null,"پین کردن",-1),De=d("span",null,"حذف",-1),$e=d("span",null,"ویرایش",-1),Be={class:"space-y-4"},Ue=d("div",{class:"mb-1 text-sm text-gray-600"},"متن پیام *",-1),Ee=d("div",{class:"mb-1 text-sm text-gray-600"},"آپلود فایل (اختیاری)",-1),Le={key:0,class:"mt-2"},Pe={class:"h-2 rounded bg-gray-200 overflow-hidden"},Re={class:"text-xs text-gray-700 font-semibold text-center mt-1"},qe={key:1,class:"mt-2"},Ne=["href"],xt=se({__name:"index",setup(e){const{TextArea:s}=_e,[_,w]=te(),k=b({columns:he,api:ke,defaultPageLimit:20}),x=b(!1),l=b(!1),I=b(null),g=le(),y=b([]),f=b(!1),h=b(0),v=b({owner_id:null,text:"",file:null});function G(a){return a.size/1024/1024<50?!0:(p.error("حجم فایل باید کمتر از 50MB باشد"),!1)}async function J(a){const{file:n,onSuccess:o,onError:r,onProgress:M}=a,$=new FormData;$.append("file",n);const u="https://node.macharta.ir/upload/message-file";h.value=0,f.value=!0,await new Promise((B,U)=>{const i=new XMLHttpRequest;i.open("POST",u),i.setRequestHeader("Authorization",`Bearer ${localStorage.getItem("tamin_token")||localStorage.getItem("token")||""}`),i.timeout=15*60*1e3,i.upload.onprogress=t=>{if(t.lengthComputable){const E=Math.round(t.loaded/t.total*100);h.value=E,M==null||M({percent:E})}},i.onload=()=>{if(h.value=100,i.status>=200&&i.status<300)try{const t=JSON.parse(i.responseText||"{}"),E=t.url||t.path||t.file||t.data&&(t.data.url||t.data.path||t.data.file)||"",L=me(E);v.value.file=L,y.value=L?[{uid:`${Date.now()}`,name:n.name,status:"done",url:pe(L)}]:[],o==null||o(t,i),p.success("فایل با موفقیت آپلود شد!"),B()}catch(t){r==null||r(t,i),U(t)}else{const t=new Error("خطا در آپلود فایل");p.error("خطا در آپلود فایل"),r==null||r(t,i),U(t)}},i.onerror=()=>{const t=new Error("خطا در آپلود فایل");p.error("خطا در آپلود فایل"),r==null||r(t,i),U(t)},i.ontimeout=()=>{const t=new Error("آپلود timeout شد");p.error("آپلود timeout شد"),r==null||r(t,i),U(t)},i.onloadend=()=>{f.value=!1,h.value=0},i.send($)})}async function X(){var n;l.value=!1,I.value=null,y.value=[],g.userInfo||await g.getMyInfo();const a=((n=g.userInfo)==null?void 0:n.id)||null;v.value={owner_id:a,text:"",file:null},x.value=!0}function q(){x.value=!1,y.value=[],h.value=0}async function j(a){I.value=a.id,l.value=!0,v.value={owner_id:null,text:a.text||"",file:a.file||null},a.file?y.value=[{uid:"-1",name:a.file.split("/").pop()||"فایل",status:"done",url:a.file}]:y.value=[],x.value=!0}async function K(a){const n=a.pined===!0;O.confirm({title:"آیا مطمئن هستید؟",content:n?"این پیام در حال حاضر پین شده است. آیا میخواهید آن را از حالت پین خارج کنید؟":"آیا میخواهید این پیام را پین کنید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{try{const o=!n,r={pined:o,pined_at:o?new Date().toISOString():null};await z(a.id,r),p.success(o?"پیام با موفقیت پین شد!":"پیام با موفقیت از حالت پین خارج شد!"),w()}catch(o){p.error(o.message||"خطا در تغییر وضعیت پین پیام")}}})}async function Q(a){O.confirm({title:"آیا مطمئن هستید؟",content:"آیا میخواهید این پیام را حذف کنید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{try{await we(a.id),p.success("پیام با موفقیت حذف شد!"),w()}catch(n){p.error(n.message||"خطا در حذف پیام")}}})}async function W(){var a,n;if(!((a=v.value.text)!=null&&a.trim())){p.error("لطفاً متن پیام را وارد کنید");return}if(f.value){p.warning("لطفاً تا پایان آپلود صبر کنید");return}try{if(l.value&&I.value){const o={text:v.value.text,file:v.value.file};await z(I.value,o),p.success("پیام با موفقیت بهروزرسانی شد!")}else{g.userInfo||await g.getMyInfo();const o={owner_id:((n=g.userInfo)==null?void 0:n.id)||null,text:v.value.text,file:v.value.file||null};await ye(o),p.success("پیام با موفقیت افزوده شد!")}q(),w()}catch(o){p.error(o.message||"خطا در ذخیره پیام")}}return(a,n)=>{const o=ae,r=ee,M=Z,$=Y;return A(),D("div",null,[c($,null,{default:m(()=>[d("div",Ie,[Se,c(o,{type:"primary",onClick:X},{default:m(()=>[P("افزودن اطلاع رسانی")]),_:1})]),c(r,oe(k.value,{ref:"table",onRegister:S(_)}),{text:m(({record:u})=>[c(fe,{text:u.text},null,8,["text"])]),file:m(({record:u})=>[u.file?(A(),D("a",{key:0,href:u.file,target:"_blank",class:"text-blue-500 hover:underline"}," دانلود فایل ",8,Ce)):(A(),D("span",Me,"-"))]),action:m(({record:u})=>[d("div",Te,[c(S(R),{class:"cursor-pointer"},{title:m(()=>[Ae]),default:m(()=>[c(T,{icon:"vuesax-linear:bookmark",color:"#16A34A",onClick:B=>K(u)},null,8,["onClick"])]),_:2},1024),c(S(R),{class:"cursor-pointer"},{title:m(()=>[De]),default:m(()=>[c(T,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:B=>Q(u)},null,8,["onClick"])]),_:2},1024),c(S(R),{class:"cursor-pointer"},{title:m(()=>[$e]),default:m(()=>[c(T,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:B=>j(u)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),c(M,{visible:x.value,"onUpdate:visible":n[2]||(n[2]=u=>x.value=u),title:l.value?"ویرایش اطلاع رسانی":"افزودن اطلاع رسانی",onOk:W,onCancel:q,width:"80%",confirmLoading:f.value},{default:m(()=>[d("div",Be,[d("div",null,[Ue,c(S(s),{value:v.value.text,"onUpdate:value":n[0]||(n[0]=u=>v.value.text=u),placeholder:"متن پیام",rows:6},null,8,["value"])]),d("div",null,[Ee,c(S(ve),{"file-list":y.value,"onUpdate:fileList":n[1]||(n[1]=u=>y.value=u),"before-upload":G,"custom-request":J,"max-count":1},{default:m(()=>[c(o,null,{default:m(()=>[c(T,{icon:"vuesax-linear:document-upload",class:"mr-1"}),P(" انتخاب فایل ")]),_:1})]),_:1},8,["file-list"]),h.value>0&&h.value<100?(A(),D("div",Le,[d("div",Pe,[d("div",{class:"h-2 bg-blue-500 transition-all",style:ie({width:`${h.value}%`})},null,4)]),d("div",Re,N(h.value)+"%",1)])):V("",!0),v.value.file?(A(),D("div",qe,[d("a",{href:v.value.file,target:"_blank",class:"text-blue-500 hover:underline text-sm"},[c(T,{icon:"vuesax-linear:document-download",class:"inline-block mr-1"}),P(" فایل فعلی: "+N(v.value.file.split("/").pop()),1)],8,Ne)])):V("",!0)])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{xt as default};
|