2 lines
5.5 KiB
JavaScript
2 lines
5.5 KiB
JavaScript
import{_ as D}from"./BasicMainCard-4e5b70c4.js";import{M as P,_ as L}from"./BasicModal.vue_vue_type_style_index_0_lang-7fe5902c.js";import{_ as V}from"./BaseTable.vue_vue_type_style_index_0_lang-1772e74f.js";import{_ as N}from"./button.vue_vue_type_style_index_0_lang-720928c4.js";import{I as C}from"./Icon-d8714ef2.js";import{u as O}from"./useBaseTable-3aeb2499.js";import{t as S}from"./useDataTime-a9e84b2b.js";import{a3 as k,a5 as b,d as U,r as g,Y as q,o as z,c as j,b as l,w as d,a as p,e as J,a2 as X,L as h,a0 as w}from"./index-860fa59f.js";import{_ as Y}from"./TextPreview.vue_vue_type_script_setup_true_lang-6f2e38d1.js";import{I as F}from"./index-6052676c.js";import{T}from"./styleChecker-d72667fe.js";import"./_plugin-vue_export-helper-483988fe.js";import"./index-f2ed3e06.js";import"./useState-5bd6c786.js";import"./vnode-1c666eb2.js";import"./Col-3da990c2.js";import"./index-26e2d4f8.js";const G=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:t=>t.record.index+1},{title:"نام کاربر",dataIndex:"owner_id",key:"owner_id",customRender:t=>t.record.owner_name||t.record.owner_id||"-"},{title:"متن نظر یا ایده",dataIndex:"text",key:"text",slot:"text"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:t=>S(t.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"}];async function H(t){const{data:r,error:u}=await b.from("comments").insert([t]).select();if(u)throw u;return r}async function K(t,r){const{data:u,error:a}=await b.from("comments").update(r).eq("id",t).select();if(a)throw a;return u}async function Q(t){const{error:r}=await b.from("comments").delete().eq("id",t);if(r)throw r}async function W(t){const{TableEngineRequest:r}=await k(()=>import("./buildSupabaseQuery-c53aff88.js"),["assets/buildSupabaseQuery-c53aff88.js","assets/index-860fa59f.js","assets/index-90aca5a6.css"]),{getUsersList:u}=await k(()=>import("./index-860fa59f.js").then(n=>n.cX),["assets/index-860fa59f.js","assets/index-90aca5a6.css"]),a={...t};!a.sort&&!a.order&&(a.order="-id");const m=await r(a,"comments");try{if(Array.isArray(m==null?void 0:m.rows)){let n=new Map;try{const e=await u();Array.isArray(e)&&e.forEach(s=>{if(s.id){const I=`${s.first_name||""} ${s.last_name||""}`.trim()||s.phone||`کاربر ${s.id}`;n.set(s.id,I)}})}catch(e){console.log("[getCommentsTable] Error fetching users:",e)}const x=a.page||1,v=a.limit||200,_=(x-1)*v,c=m.rows.map((e,s)=>({id:e.id,owner_id:e.owner_id??null,owner_name:e.owner_id?n.get(e.owner_id)||`کاربر ${e.owner_id}`:null,text:e.text??"",created_at:e.created_at??"",updated_at:e.updated_at??"",index:_+s,...e}));return{...m,rows:c}}}catch(n){console.log("[getCommentsTable] normalize error:",n)}return m}const Z={class:"flex justify-between items-center mb-4"},ee=p("h2",null,"ایده و نظرات",-1),te={class:"gap-2 flex justify-center"},ae=p("span",null,"حذف",-1),ne=p("span",null,"ویرایش",-1),oe={class:"space-y-4"},se=p("div",{class:"mb-1 text-sm text-gray-600"},"متن نظر یا ایده *",-1),be=U({__name:"index",setup(t){const{TextArea:r}=F,[u,a]=O(),m=g({columns:G,api:W,defaultPageLimit:20}),n=g(!1),x=g(!1),v=g(null),_=q(),c=g({owner_id:null,text:""});async function e(){var o;x.value=!1,v.value=null,_.userInfo||await _.getMyInfo();const i=((o=_.userInfo)==null?void 0:o.id)||null;c.value={owner_id:i,text:""},n.value=!0}function s(){n.value=!1}async function I(i){v.value=i.id,x.value=!0,c.value={owner_id:null,text:i.text||""},n.value=!0}async function E(i){P.confirm({title:"آیا مطمئن هستید؟",content:"آیا میخواهید این نظر/ایده را حذف کنید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{try{await Q(i.id),w.success("نظر/ایده با موفقیت حذف شد!"),a()}catch(o){w.error(o.message||"خطا در حذف نظر/ایده")}}})}async function $(){var i,o;if(!((i=c.value.text)!=null&&i.trim())){w.error("لطفاً متن نظر یا ایده را وارد کنید");return}try{if(x.value&&v.value)await K(v.value,{text:c.value.text}),w.success("نظر/ایده با موفقیت بهروزرسانی شد!");else{_.userInfo||await _.getMyInfo();const y={owner_id:((o=_.userInfo)==null?void 0:o.id)||null,text:c.value.text};await H(y),w.success("نظر/ایده با موفقیت افزوده شد!")}s(),a()}catch(y){w.error(y.message||"خطا در ذخیره نظر/ایده")}}return(i,o)=>{const y=N,B=V,M=L,A=D;return z(),j("div",null,[l(A,null,{default:d(()=>[p("div",Z,[ee,l(y,{type:"primary",onClick:e},{default:d(()=>[J("افزودن نظر یا ایده")]),_:1})]),l(B,X(m.value,{ref:"table",onRegister:h(u)}),{text:d(({record:f})=>[l(Y,{text:f.text},null,8,["text"])]),action:d(({record:f})=>[p("div",te,[l(h(T),{class:"cursor-pointer"},{title:d(()=>[ae]),default:d(()=>[l(C,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:R=>E(f)},null,8,["onClick"])]),_:2},1024),l(h(T),{class:"cursor-pointer"},{title:d(()=>[ne]),default:d(()=>[l(C,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:R=>I(f)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),l(M,{visible:n.value,"onUpdate:visible":o[1]||(o[1]=f=>n.value=f),title:x.value?"ویرایش نظر/ایده":"افزودن نظر/ایده",onOk:$,onCancel:s,width:"80%"},{default:d(()=>[p("div",oe,[p("div",null,[se,l(h(r),{value:c.value.text,"onUpdate:value":o[0]||(o[0]=f=>c.value.text=f),placeholder:"متن نظر یا ایده",rows:6},null,8,["value"])])])]),_:1},8,["visible","title"])]),_:1})])}}});export{be as default};
|