Files
machartaa_admin_dist/dist/assets/index-821b5b28.js
T
2026-08-15 13:12:23 +03:30

2 lines
7.7 KiB
JavaScript

import{_ as E}from"./BasicMainCard-f046b61e.js";import{_ as R}from"./BasicModal.vue_vue_type_style_index_0_lang-83760d3e.js";import{_ as O,u as V}from"./useBaseTable-55ad5e52.js";import{_ as j}from"./button.vue_vue_type_style_index_0_lang-bd596a6a.js";import{I as A}from"./Icon-d887a0f8.js";import{t as z}from"./useDataTime-7241b1ee.js";import{G as $,d as N,g as I,A as U,o as G,c as H,b as d,w as m,a as x,e as J,H as L,j as C,D as w}from"./index-885a0812.js";import{_ as W}from"./TextPreview.vue_vue_type_script_setup_true_lang-60928929.js";import{M as D}from"./index-9b411a61.js";import{I as F}from"./index-2ed626d8.js";import{T as q}from"./isSymbol-7a58081d.js";import"./Grid-a6ca9fb5.js";import"./index-667a03eb.js";import"./_plugin-vue_export-helper-b63d6b5b.js";import"./index-49e4db02.js";import"./vnode-70560f26.js";import"./index-7b5ec00b.js";import"./useState-90bb98a8.js";import"./useRefs-d4aed6f9.js";import"./_flatRest-0a2f05bf.js";import"./isMobile-e2e89480.js";import"./index-11c04e4f.js";import"./Col-46619619.js";import"./styleChecker-d1351987.js";import"./isPlainObject-6f4a3c75.js";import"./index-d4e74b97.js";import"./updateLocale-d7121807.js";import"./index-675e28c4.js";import"./useMemo-565770c1.js";import"./FormItemContext-9dda29cf.js";import"./lodash-3b12211b.js";import"./BaseSwitch.vue_vue_type_script_setup_true_lang-a6c897ab.js";import"./index-32515dee.js";import"./Badge-1926c75c.js";import"./isNumeric-3f69e2aa.js";import"./index-572a9242.js";import"./index-22f9b99f.js";import"./index-2c072252.js";import"./DialogWrap-bea4ac16.js";import"./pickAttrs-bb97af78.js";import"./css-aae66f86.js";import"./index-89e03fc4.js";import"./toArray-64a01f73.js";import"./SearchOutlined-c7e22afc.js";import"./index-6c7f8dff.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:a,error:l}=await $.from("comments").insert([i]).select();if(l)throw l;return a}async function M(i,a){const{data:l,error:p}=await $.from("comments").update(a).eq("id",i).select();if(p)throw p;return l}async function X(i){const{error:a}=await $.from("comments").delete().eq("id",i);if(a)throw a}async function Y(i){const a={...i};!a.sort&&!a.order&&(a.order="-id");const{limit:l,filters:p,page:y,sort:f,order:v,search:g}=a;let e=$.from("comments").select("*, users!owner_id(first_name, last_name, phone)",{count:"exact"});if(g&&g.trim()){const n=`%${g}%`;e=e.ilike("text",n)}if(p&&Array.isArray(p)&&p.forEach(n=>{const{field:r,op:b,value:c,hidden:t}=n;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 n=(y-1)*l,r=n+l-1;e=e.range(n,r)}if(f&&f.key){const n=f.order==="asc";e=e.order(f.key,{ascending:n})}else if(v){const n=!v.startsWith("-"),r=v.replace(/^[-+]/,"");e=e.order(r,{ascending:n})}const{data:u,error:T,count:h}=await e;if(T)return console.error("[getCommentsTable] Supabase query error:",T),{query:{...a,limit:l||10,page:y||1,total:0},rows:[]};try{if(Array.isArray(u)){const n=y||1,r=l||200,b=(n-1)*r,c=u.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:{...a,limit:l||10,page:y||1,total:h||0},rows:c}}}catch(n){console.log("[getCommentsTable] normalize error:",n)}return{query:{...a,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"},oe=x("span",null,"پین کردن",-1),ae=x("span",null,"حذف",-1),ne=x("span",null,"ویرایش",-1),re={class:"space-y-4"},ie=x("div",{class:"mb-1 text-sm text-gray-600"},"متن پیام *",-1),Ze=N({__name:"index",setup(i){const{TextArea:a}=F,[l,p]=V(),y=I({columns:K,api:Y,defaultPageLimit:20}),f=I(!1),v=I(!1),g=I(null),e=U(),u=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;u.value={owner_id:t,text:""},f.value=!0}function h(){f.value=!1}async function n(t){g.value=t.id,v.value=!0,u.value={owner_id:null,text:t.text||""},f.value=!0}async function r(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=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 s={owner_id:((o=e.userInfo)==null?void 0:o.id)||null,text:u.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,[d(S,null,{default:m(()=>[x("div",Z,[ee,d(s,{type:"primary",onClick:T},{default:m(()=>[J("افزودن نظر یا ایده")]),_:1})]),d(k,L(y.value,{ref:"table",onRegister:C(l)}),{text:m(({record:_})=>[d(W,{text:_.text},null,8,["text"])]),action:m(({record:_})=>[x("div",te,[d(C(q),{class:"cursor-pointer"},{title:m(()=>[oe]),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(()=>[ae]),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(()=>[ne]),default:m(()=>[d(A,{icon:"vuesax-linear:edit",color:"#1D4ED8",onClick:B=>n(_)},null,8,["onClick"])]),_:2},1024)])]),_:1},16,["onRegister"]),d(P,{visible:f.value,"onUpdate:visible":o[1]||(o[1]=_=>f.value=_),title:v.value?"ویرایش پیام":"افزودن پیام",onOk:c,onCancel:h,width:"80%"},{default:m(()=>[x("div",re,[x("div",null,[ie,d(C(a),{value:u.value.text,"onUpdate:value":o[0]||(o[0]=_=>u.value.text=_),placeholder:"متن پیام",rows:6},null,8,["value"])])])]),_:1},8,["visible","title"])]),_:1})])}}});export{Ze as default};