Files
machartaa_admin_dist/dist/assets/index-3700e94c.js
T
2026-08-18 15:43:27 +03:30

2 lines
7.8 KiB
JavaScript

import{_ as E}from"./BasicMainCard-8da61c91.js";import{_ as R}from"./BasicModal.vue_vue_type_style_index_0_lang-dce46cd2.js";import{_ as O,u as V}from"./useBaseTable-a305524f.js";import{_ as j}from"./button.vue_vue_type_style_index_0_lang-ae7cb173.js";import{I as A}from"./Icon-2a751d73.js";import{t as z}from"./useDataTime-0e280561.js";import{G as $,d as N,g as I,A as U,o as G,c as H,b as m,w as u,a as x,e as J,H as L,j as C,D as w}from"./index-64bb19a3.js";import{_ as W}from"./TextPreview.vue_vue_type_script_setup_true_lang-5d44ac6c.js";import{M as D}from"./index-557a2985.js";import{I as F}from"./index-6f7ee4ee.js";import{T as q}from"./isSymbol-77db9868.js";import"./Grid-d205a4b4.js";import"./index-fe1cc383.js";import"./_plugin-vue_export-helper-47756888.js";import"./shallowequal-a3fa20ee.js";import"./index-95a0af99.js";import"./vnode-a1a3bc0f.js";import"./index-b5f90115.js";import"./useState-45a66864.js";import"./useRefs-10844536.js";import"./_flatRest-6bd9fe69.js";import"./isMobile-e2e89480.js";import"./omit-41b1cee4.js";import"./index-53278d29.js";import"./Col-4cc66d2b.js";import"./styleChecker-44a60ba7.js";import"./isPlainObject-908a4d4b.js";import"./index-d19de556.js";import"./updateLocale-34973999.js";import"./index-7a73a23b.js";import"./index-bc659f42.js";import"./useMemo-fddb4a7a.js";import"./FormItemContext-78515ae9.js";import"./lodash-17ce3880.js";import"./BaseSwitch.vue_vue_type_script_setup_true_lang-6148f843.js";import"./index-304c1b28.js";import"./Badge-6baddd17.js";import"./isNumeric-3f69e2aa.js";import"./index-2a5be533.js";import"./index-a5e6bc16.js";import"./index-4ee722bc.js";import"./DialogWrap-c12b3672.js";import"./pickAttrs-ff8c51c6.js";import"./css-aae66f86.js";import"./index-ff7b0bbe.js";import"./toArray-156bc105.js";import"./SearchOutlined-5a638563.js";import"./index-d5b53aee.js";import"./textUtils-c37780ad.js";const K=[{title:"ردیف",dataIndex:"id",key:"id",filterable:!1,width:70,align:"center",customRender:i=>i.record.index+1},{title:"نام کاربر",dataIndex:"owner_id",key:"owner_id",customRender:i=>i.record.owner_name||i.record.owner_id||"-"},{title:"متن نظر یا ایده",dataIndex:"text",key:"text",slot:"text"},{title:"زمان ایجاد",dataIndex:"created_at",key:"created_at",customRender:i=>z(i.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(i){const{data:r,error:l}=await $.from("comments").insert([i]).select();if(l)throw l;return r}async function M(i,r){const{data:l,error:p}=await $.from("comments").update(r).eq("id",i).select();if(p)throw p;return l}async function X(i){const{error:r}=await $.from("comments").delete().eq("id",i);if(r)throw r}async function Y(i){const r={...i};!r.sort&&!r.order&&(r.order="-id");const{limit:l,filters:p,page:y,sort:f,order:v,search:g}=r;let e=$.from("comments").select("*, users!owner_id(first_name, last_name, phone)",{count:"exact"});if(g&&g.trim()){const a=`%${g}%`;e=e.ilike("text",a)}if(p&&Array.isArray(p)&&p.forEach(a=>{const{field:n,op:b,value:c,hidden:t}=a;if(!t)switch(b){case"eq":e=e.eq(n,c);break;case"neq":e=e.neq(n,c);break;case"gt":e=e.gt(n,c);break;case"lt":e=e.lt(n,c);break;case"gte":e=e.gte(n,c);break;case"lte":e=e.lte(n,c);break;case"has":e=e.ilike(n,`%${c}%`);break;case"like":e=e.like(n,`%${c}%`);break}}),l&&y){const a=(y-1)*l,n=a+l-1;e=e.range(a,n)}if(f&&f.key){const a=f.order==="asc";e=e.order(f.key,{ascending:a})}else if(v){const a=!v.startsWith("-"),n=v.replace(/^[-+]/,"");e=e.order(n,{ascending:a})}const{data:d,error:T,count:h}=await e;if(T)return console.error("[getCommentsTable] Supabase query error:",T),{query:{...r,limit:l||10,page:y||1,total:0},rows:[]};try{if(Array.isArray(d)){const a=y||1,n=l||200,b=(a-1)*n,c=d.map((t,o)=>{let s=null;if(t.owner_id){const k=Array.isArray(t.users)?t.users[0]:t.users;k?s=`${k.first_name||""} ${k.last_name||""}`.trim()||k.phone||`کاربر ${t.owner_id}`:s=`کاربر ${t.owner_id}`}return{id:t.id,owner_id:t.owner_id??null,owner_name:s,text:t.text??"",created_at:t.created_at??"",updated_at:t.updated_at??"",index:b+o,...t}});return{query:{...r,limit:l||10,page:y||1,total:h||0},rows:c}}}catch(a){console.log("[getCommentsTable] normalize error:",a)}return{query:{...r,limit:l||10,page:y||1,total:h||0},rows:d||[]}}const Z={class:"flex justify-between items-center mb-4"},ee=x("h2",null,"ایده و نظرات",-1),te={class:"gap-2 flex justify-center"},oe=x("span",null,"پین کردن",-1),re=x("span",null,"حذف",-1),ae=x("span",null,"ویرایش",-1),ne={class:"space-y-4"},ie=x("div",{class:"mb-1 text-sm text-gray-600"},"متن پیام *",-1),ot=N({__name:"index",setup(i){const{TextArea:r}=F,[l,p]=V(),y=I({columns:K,api:Y,defaultPageLimit:20}),f=I(!1),v=I(!1),g=I(null),e=U(),d=I({owner_id:null,text:""});async function T(){var o;v.value=!1,g.value=null,e.userInfo||await e.getMyInfo();const t=((o=e.userInfo)==null?void 0:o.id)||null;d.value={owner_id:t,text:""},f.value=!0}function h(){f.value=!1}async function a(t){g.value=t.id,v.value=!0,d.value={owner_id:null,text:t.text||""},f.value=!0}async function n(t){const o=t.pined===!0;D.confirm({title:"آیا مطمئن هستید؟",content:o?"این پیام در حال حاضر پین شده است. آیا می‌خواهید آن را از حالت پین خارج کنید؟":"آیا می‌خواهید این پیام را پین کنید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{try{const s=!o,k={pined:s,pined_at:s?new Date().toISOString():null};await M(t.id,k),w.success(s?"پیام با موفقیت پین شد!":"پیام با موفقیت از حالت پین خارج شد!"),p()}catch(s){w.error(s.message||"خطا در تغییر وضعیت پین پیام")}}})}async function b(t){D.confirm({title:"آیا مطمئن هستید؟",content:"آیا می‌خواهید این پیام را حذف کنید؟",okText:"بله",cancelText:"خیر",onOk:async()=>{try{await X(t.id),w.success("پیام با موفقیت حذف شد!"),p()}catch(o){w.error(o.message||"خطا در حذف پیام")}}})}async function c(){var t,o;if(!((t=d.value.text)!=null&&t.trim())){w.error("لطفاً متن نظر یا ایده را وارد کنید");return}try{if(v.value&&g.value)await M(g.value,{text:d.value.text}),w.success("پیام با موفقیت به‌روزرسانی شد!");else{e.userInfo||await e.getMyInfo();const s={owner_id:((o=e.userInfo)==null?void 0:o.id)||null,text:d.value.text};await Q(s),w.success("پیام با موفقیت افزوده شد!")}h(),p()}catch(s){w.error(s.message||"خطا در ذخیره پیام")}}return(t,o)=>{const s=j,k=O,P=R,S=E;return G(),H("div",null,[m(S,null,{default:u(()=>[x("div",Z,[ee,m(s,{type:"primary",onClick:T},{default:u(()=>[J("افزودن نظر یا ایده")]),_:1})]),m(k,L(y.value,{ref:"table",onRegister:C(l)}),{text:u(({record:_})=>[m(W,{text:_.text},null,8,["text"])]),action:u(({record:_})=>[x("div",te,[m(C(q),{class:"cursor-pointer"},{title:u(()=>[oe]),default:u(()=>[m(A,{icon:"vuesax-linear:bookmark",color:"#16A34A",onClick:B=>n(_)},null,8,["onClick"])]),_:2},1024),m(C(q),{class:"cursor-pointer"},{title:u(()=>[re]),default:u(()=>[m(A,{icon:"vuesax-linear:trash",color:"#DC2626",onClick:B=>b(_)},null,8,["onClick"])]),_:2},1024),m(C(q),{class:"cursor-pointer"},{title:u(()=>[ae]),default:u(()=>[m(A,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:B=>a(_)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),m(P,{visible:f.value,"onUpdate:visible":o[1]||(o[1]=_=>f.value=_),title:v.value?"ویرایش پیام":"افزودن پیام",onOk:c,onCancel:h,width:"80%"},{default:u(()=>[x("div",ne,[x("div",null,[ie,m(C(r),{value:d.value.text,"onUpdate:value":o[0]||(o[0]=_=>d.value.text=_),placeholder:"متن پیام",rows:6},null,8,["value"])])])]),_:1},8,["visible","title"])]),_:1})])}}});export{ot as default};