2 lines
7.0 KiB
JavaScript
2 lines
7.0 KiB
JavaScript
import{_ as E}from"./BasicMainCard-06dad464.js";import{_ as R}from"./BasicModal.vue_vue_type_style_index_0_lang-c07380a4.js";import{_ as O,u as V}from"./useBaseTable-89e367b0.js";import{_ as j}from"./button.vue_vue_type_style_index_0_lang-80cf0b72.js";import{I as A}from"./Icon-e9a9d64e.js";import{t as z}from"./useDataTime-60875705.js";import{I as $,d as N,g as I,A as U,o as G,c as J,b as d,w as m,a as x,e as L,G as W,j as C,D as w}from"./index-10f45eca.js";import{_ as F}from"./TextPreview.vue_vue_type_script_setup_true_lang-42c9e2e4.js";import{M as D}from"./index-5bc6b40d.js";import{I as H}from"./index-cca2d62a.js";import{T as q}from"./index-ceff8631.js";import"./_plugin-vue_export-helper-2f157ef4.js";import"./index-ecb339ad.js";import"./index-1b352863.js";import"./Col-c6f28462.js";import"./vnode-b14d5532.js";import"./useState-4f4a8c99.js";import"./isPlainObject-75024cd7.js";import"./index-00f73089.js";import"./index-db46c961.js";import"./pickAttrs-2c86ae65.js";import"./index-9601d570.js";import"./toArray-45e57117.js";import"./FormItemContext-a11ae724.js";const K=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:s=>s.record.index+1},{title:"نام کاربر",dataIndex:"owner_id",key:"owner_id",customRender:s=>s.record.owner_name||s.record.owner_id||"-"},{title:"متن نظر یا ایده",dataIndex:"text",key:"text",slot:"text"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:s=>z(s.record.created_at)},{title:"عملیات",dataIndex:"action",key:"action",slot:"action",filterable:!1,align:"center"},{title:"پین شده",dataIndex:"pined",key:"pined",type:"Boolean",filterable:!0,show:!1}];async function Q(s){const{data:n,error:l}=await $.from("comments").insert([s]).select();if(l)throw l;return n}async function M(s,n){const{data:l,error:f}=await $.from("comments").update(n).eq("id",s).select();if(f)throw f;return l}async function X(s){const{error:n}=await $.from("comments").delete().eq("id",s);if(n)throw n}async function Y(s){const n={...s};!n.sort&&!n.order&&(n.order="-id");const{limit:l,filters:f,page:y,sort:p,order:v,search:g}=n;let e=$.from("comments").select("*, users!owner_id(first_name, last_name, phone)",{count:"exact"});if(g&&g.trim()){const o=`%${g}%`;e=e.ilike("text",o)}if(f&&Array.isArray(f)&&f.forEach(o=>{const{field:r,op:b,value:c,hidden:t}=o;if(!t)switch(b){case"eq":e=e.eq(r,c);break;case"neq":e=e.neq(r,c);break;case"gt":e=e.gt(r,c);break;case"lt":e=e.lt(r,c);break;case"gte":e=e.gte(r,c);break;case"lte":e=e.lte(r,c);break;case"has":e=e.ilike(r,`%${c}%`);break;case"like":e=e.like(r,`%${c}%`);break}}),l&&y){const o=(y-1)*l,r=o+l-1;e=e.range(o,r)}if(p&&p.key){const o=p.order==="asc";e=e.order(p.key,{ascending:o})}else if(v){const o=!v.startsWith("-"),r=v.replace(/^[-+]/,"");e=e.order(r,{ascending:o})}const{data:u,error:T,count:h}=await e;if(T)return console.error("[getCommentsTable] Supabase query error:",T),{query:{...n,limit:l||10,page:y||1,total:0},rows:[]};try{if(Array.isArray(u)){const o=y||1,r=l||200,b=(o-1)*r,c=u.map((t,a)=>{let i=null;if(t.owner_id){const k=Array.isArray(t.users)?t.users[0]:t.users;k?i=`${k.first_name||""} ${k.last_name||""}`.trim()||k.phone||`کاربر ${t.owner_id}`:i=`کاربر ${t.owner_id}`}return{id:t.id,owner_id:t.owner_id??null,owner_name:i,text:t.text??"",created_at:t.created_at??"",updated_at:t.updated_at??"",index:b+a,...t}});return{query:{...n,limit:l||10,page:y||1,total:h||0},rows:c}}}catch(o){console.log("[getCommentsTable] normalize error:",o)}return{query:{...n,limit:l||10,page:y||1,total:h||0},rows:u||[]}}const Z={class:"flex justify-between items-center mb-4"},ee=x("h2",null,"ایده و نظرات",-1),te={class:"gap-2 flex justify-center"},ae=x("span",null,"پین کردن",-1),ne=x("span",null,"حذف",-1),oe=x("span",null,"ویرایش",-1),re={class:"space-y-4"},se=x("div",{class:"mb-1 text-sm text-gray-600"},"متن پیام *",-1),De=N({__name:"index",setup(s){const{TextArea:n}=H,[l,f]=V(),y=I({columns:K,api:Y,defaultPageLimit:20}),p=I(!1),v=I(!1),g=I(null),e=U(),u=I({owner_id:null,text:""});async function T(){var a;v.value=!1,g.value=null,e.userInfo||await e.getMyInfo();const t=((a=e.userInfo)==null?void 0:a.id)||null;u.value={owner_id:t,text:""},p.value=!0}function h(){p.value=!1}async function o(t){g.value=t.id,v.value=!0,u.value={owner_id:null,text:t.text||""},p.value=!0}async function r(t){const a=t.pined===!0;D.confirm({title:"آیا مطمئن هستید؟",content:a?"این پیام در حال حاضر پین شده است. آیا میخواهید آن را از حالت پین خارج کنید؟":"آیا میخواهید این پیام را پین کنید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{try{const i=!a,k={pined:i,pined_at:i?new Date().toISOString():null};await M(t.id,k),w.success(i?"پیام با موفقیت پین شد!":"پیام با موفقیت از حالت پین خارج شد!"),f()}catch(i){w.error(i.message||"خطا در تغییر وضعیت پین پیام")}}})}async function b(t){D.confirm({title:"آیا مطمئن هستید؟",content:"آیا میخواهید این پیام را حذف کنید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{try{await X(t.id),w.success("پیام با موفقیت حذف شد!"),f()}catch(a){w.error(a.message||"خطا در حذف پیام")}}})}async function c(){var t,a;if(!((t=u.value.text)!=null&&t.trim())){w.error("لطفاً متن نظر یا ایده را وارد کنید");return}try{if(v.value&&g.value)await M(g.value,{text:u.value.text}),w.success("پیام با موفقیت بهروزرسانی شد!");else{e.userInfo||await e.getMyInfo();const i={owner_id:((a=e.userInfo)==null?void 0:a.id)||null,text:u.value.text};await Q(i),w.success("پیام با موفقیت افزوده شد!")}h(),f()}catch(i){w.error(i.message||"خطا در ذخیره پیام")}}return(t,a)=>{const i=j,k=O,P=R,S=E;return G(),J("div",null,[d(S,null,{default:m(()=>[x("div",Z,[ee,d(i,{type:"primary",onClick:T},{default:m(()=>[L("افزودن نظر یا ایده")]),_:1})]),d(k,W(y.value,{ref:"table",onRegister:C(l)}),{text:m(({record:_})=>[d(F,{text:_.text},null,8,["text"])]),action:m(({record:_})=>[x("div",te,[d(C(q),{class:"cursor-pointer"},{title:m(()=>[ae]),default:m(()=>[d(A,{icon:"vuesax-linear:bookmark",color:"#16A34A",onClick:B=>r(_)},null,8,["onClick"])]),_:2},1024),d(C(q),{class:"cursor-pointer"},{title:m(()=>[ne]),default:m(()=>[d(A,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:B=>b(_)},null,8,["onClick"])]),_:2},1024),d(C(q),{class:"cursor-pointer"},{title:m(()=>[oe]),default:m(()=>[d(A,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:B=>o(_)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),d(P,{visible:p.value,"onUpdate:visible":a[1]||(a[1]=_=>p.value=_),title:v.value?"ویرایش پیام":"افزودن پیام",onOk:c,onCancel:h,width:"80%"},{default:m(()=>[x("div",re,[x("div",null,[se,d(C(n),{value:u.value.text,"onUpdate:value":a[0]||(a[0]=_=>u.value.text=_),placeholder:"متن پیام",rows:6},null,8,["value"])])])]),_:1},8,["visible","title"])]),_:1})])}}});export{De as default};
|