Files
machartaa_admin_dist/dist/assets/index-4689043a.js
T

2 lines
10 KiB
JavaScript

import{_ as K}from"./BasicMainCard-6a209b66.js";import{_ as Q}from"./BasicModal.vue_vue_type_style_index_0_lang-5906452a.js";import{_ as Y,u as Z}from"./useBaseTable-36a578d2.js";import{_ as ee}from"./button.vue_vue_type_style_index_0_lang-8d279d3c.js";import{I as D}from"./Icon-66e4762f.js";import{t as te}from"./useDataTime-9d6aa2eb.js";import{H as O,d as ae,g as T,z as ne,o as P,c as U,b as m,w as v,a as p,e as E,E as se,j as q,y as le,t as J,k as W,C as g}from"./index-23e11ebb.js";import{_ as oe}from"./TextPreview.vue_vue_type_script_setup_true_lang-11b99d5e.js";import{e as ie,g as re}from"./convert-67c23be8.js";import{M as X}from"./index-9227ec88.js";import{I as ce}from"./index-956ab9e6.js";import{T as F}from"./shallowequal-c0c30dbc.js";import{U as ue}from"./index-46cbdc62.js";import"./_plugin-vue_export-helper-80f83411.js";import"./index-1da12123.js";import"./index-edb526a6.js";import"./Col-2dd17677.js";import"./vnode-c21a367b.js";import"./useState-9bab46e8.js";import"./useRefs-c7f510f3.js";import"./isPlainObject-b53c2fec.js";import"./index-1e67613f.js";import"./fa_IR-7046f8f0.js";import"./toArray-b4b91f87.js";import"./FormItemContext-28dcc8c8.js";import"./pickAttrs-deed8a82.js";import"./lodash-94e4bf0b.js";import"./index-464e86be.js";import"./index-a973200c.js";const de=[{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=>te(r.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];async function fe(r){const{data:c,error:_}=await O.from("channel_message").insert([r]).select();if(_)throw _;return c}async function j(r,c){const{data:_,error:k}=await O.from("channel_message").update(c).eq("id",r).select();if(k)throw k;return _}async function me(r){const{error:c}=await O.from("channel_message").delete().eq("id",r);if(c)throw c}async function pe(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 A=null;if(l.owner_id){const M=Array.isArray(l.users)?l.users[0]:l.users;M?A=`${M.first_name||""} ${M.last_name||""}`.trim()||M.phone||`کاربر ${l.owner_id}`:A=`کاربر ${l.owner_id}`}return{id:l.id,owner_id:l.owner_id??null,owner_name:A,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 _e={class:"flex justify-between items-center mb-4"},ve=p("h2",null,"اطلاع رسانی",-1),ge=["href"],he={key:1},xe={class:"gap-2 flex justify-center"},ye=p("span",null,"پین کردن",-1),ke=p("span",null,"حذف",-1),we=p("span",null,"ویرایش",-1),be={class:"space-y-4"},Ie=p("div",{class:"mb-1 text-sm text-gray-600"},"متن پیام *",-1),Ce=p("div",{class:"mb-1 text-sm text-gray-600"},"آپلود فایل (اختیاری)",-1),Te={key:0,class:"mt-2"},$e={class:"h-2 rounded bg-gray-200 overflow-hidden"},Me={class:"text-xs text-gray-700 font-semibold text-center mt-1"},qe={key:1,class:"mt-2"},Se=["href"],ot=ae({__name:"index",setup(r){const{TextArea:c}=ce,[_,k]=Z(),b=T({columns:de,api:pe,defaultPageLimit:20}),w=T(!1),I=T(!1),C=T(null),e=ne(),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,z=new FormData;z.append("file",s);const f="https://node.macharta.ir/upload/message-file";h.value=0,$.value=!0,await new Promise((R,V)=>{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 L=Math.round(a.loaded/a.total*100);h.value=L,B==null||B({percent:L})}},i.onload=()=>{if(h.value=100,i.status>=200&&i.status<300)try{const a=JSON.parse(i.responseText||"{}"),L=a.url||a.path||a.file||a.data&&(a.data.url||a.data.path||a.data.file)||"",H=ie(L);t.value.file=H,y.value=H?[{uid:`${Date.now()}`,name:s.name,status:"done",url:re(H)}]:[],o==null||o(a,i),g.success("فایل با موفقیت آپلود شد!"),R()}catch(a){d==null||d(a,i),V(a)}else{const a=new Error("خطا در آپلود فایل");g.error("خطا در آپلود فایل"),d==null||d(a,i),V(a)}},i.onerror=()=>{const a=new Error("خطا در آپلود فایل");g.error("خطا در آپلود فایل"),d==null||d(a,i),V(a)},i.ontimeout=()=>{const a=new Error("آپلود timeout شد");g.error("آپلود timeout شد"),d==null||d(a,i),V(a)},i.onloadend=()=>{$.value=!1,h.value=0},i.send(z)})}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 A(n){const s=n.pined===!0;X.confirm({title:"آیا مطمئن هستید؟",content:s?"این پیام در حال حاضر پین شده است. آیا می‌خواهید آن را از حالت پین خارج کنید؟":"آیا می‌خواهید این پیام را پین کنید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{try{const o=!s,d={pined:o,pined_at:o?new Date().toISOString():null};await j(n.id,d),g.success(o?"پیام با موفقیت پین شد!":"پیام با موفقیت از حالت پین خارج شد!"),k()}catch(o){g.error(o.message||"خطا در تغییر وضعیت پین پیام")}}})}async function M(n){X.confirm({title:"آیا مطمئن هستید؟",content:"آیا می‌خواهید این پیام را حذف کنید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{try{await me(n.id),g.success("پیام با موفقیت حذف شد!"),k()}catch(s){g.error(s.message||"خطا در حذف پیام")}}})}async function G(){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 j(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 fe(o),g.success("پیام با موفقیت افزوده شد!")}l(),k()}catch(o){g.error(o.message||"خطا در ذخیره پیام")}}return(n,s)=>{const o=ee,d=Y,B=Q,z=K;return P(),U("div",null,[m(z,null,{default:v(()=>[p("div",_e,[ve,m(o,{type:"primary",onClick:x},{default:v(()=>[E("افزودن اطلاع رسانی")]),_:1})]),m(d,se(b.value,{ref:"table",onRegister:q(_)}),{text:v(({record:f})=>[m(oe,{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,ge)):(P(),U("span",he,"-"))]),action:v(({record:f})=>[p("div",xe,[m(q(F),{class:"cursor-pointer"},{title:v(()=>[ye]),default:v(()=>[m(D,{icon:"vuesax-linear:bookmark",color:"#16A34A",onClick:R=>A(f)},null,8,["onClick"])]),_:2},1024),m(q(F),{class:"cursor-pointer"},{title:v(()=>[ke]),default:v(()=>[m(D,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:R=>M(f)},null,8,["onClick"])]),_:2},1024),m(q(F),{class:"cursor-pointer"},{title:v(()=>[we]),default:v(()=>[m(D,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:R=>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:G,onCancel:l,width:"80%",confirmLoading:$.value},{default:v(()=>[p("div",be,[p("div",null,[Ie,m(q(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,[Ce,m(q(ue),{"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(D,{icon:"vuesax-linear:document-upload",class:"mr-1"}),E(" انتخاب فایل ")]),_:1})]),_:1},8,["file-list"]),h.value>0&&h.value<100?(P(),U("div",Te,[p("div",$e,[p("div",{class:"h-2 bg-blue-500 transition-all",style:le({width:`${h.value}%`})},null,4)]),p("div",Me,J(h.value)+"%",1)])):W("",!0),t.value.file?(P(),U("div",qe,[p("a",{href:t.value.file,target:"_blank",class:"text-blue-500 hover:underline text-sm"},[m(D,{icon:"vuesax-linear:document-download",class:"inline-block mr-1"}),E(" فایل فعلی: "+J(t.value.file.split("/").pop()),1)],8,Se)])):W("",!0)])])]),_:1},8,["visible","title","confirmLoading"])]),_:1})])}}});export{ot as default};