You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1 line
9.1 KiB

3 days ago
import{n as e}from"./axios-CiYFffbI.js";import{I as t,N as n,V as r,Y as i,_ as a,d as o,f as s,i as c,it as l,kt as u,l as d,nt as f,p,u as m,ut as h,v as g,y as _,z as v}from"./runtime-core.esm-bundler-CnFWH3R5.js";import{n as y,o as b}from"./index-DscUIWPJ.js";import{t as x}from"./vue-quill.snow-BT2oa_xL.js";import{t as S}from"./listTable-Djel28e5.js";var C={style:{"margin-top":`8px`,width:`100%`,"overflow-x":`auto`,"white-space":`nowrap`}},w={key:0,style:{color:`#86909c`}},T={style:{width:`100%`,display:`flex`,"flex-direction":`column`,"align-items":`stretch`}},E={style:{width:`100%`,"margin-bottom":`8px`}},D={style:{width:`100%`,border:`1px solid #e5e6eb`,"border-radius":`6px`,padding:`8px`}},O={class:`intro-editor-wrap`},k=b(_({__name:`StudyTourList`,setup(_){let b=l(!1),k=l(!1),A=l(!1),j=l(!0),M=l(null),N=l([]),P=l([]),F={maxHeight:`70vh`,overflow:`auto`},I=f({name:``,tags:[],venue_ids:[],intro_html:``,sort:0,is_active:!0}),L=l(``),R=d(()=>{let e=new Map(P.value.map(e=>[e.id,e]));return I.venue_ids.map(t=>e.get(t)).filter(Boolean)});function z(e,t){let n=String(e||``).trim();if(n)return/^https?:\/\//i.test(n)?n:n.startsWith(`/`)?`${window.location.origin}${n}`:`${window.location.origin}/${n}`;let r=String(t||``).trim();if(!r)return``;let i=r.replace(/^\/+/,``);return`${window.location.origin}/storage/${i}`}async function B(e){let t=new FormData;t.append(`file`,e);let{data:n}=await y.post(`/upload`,t,{headers:{"Content-Type":`multipart/form-data`}}),r=z(n?.url,n?.path);if(!r)throw Error(`上传成功但未返回可用地址`);return r}function V(){let t=this.quill,n=document.createElement(`input`);n.type=`file`,n.accept=`image/*`,n.onchange=async()=>{let r=n.files?.[0];if(r)try{let n=await B(r),i=t.getSelection(!0)?.index??Math.max(0,t.getLength()-1);t.insertEmbed(i,`image`,n,`user`),t.setSelection(i+1,0),e.success(`图片已上传并插入`)}catch(t){e.error(t?.response?.data?.message??t?.message??`图片上传失败`)}},n.click()}function H(){let t=this.quill,n=document.createElement(`input`);n.type=`file`,n.accept=`video/*`,n.onchange=async()=>{let r=n.files?.[0];if(r)try{let n=await B(r),i=t.getSelection(!0)?.index??Math.max(0,t.getLength()-1);t.insertEmbed(i,`video`,n,`user`),t.setSelection(i+1,0),e.success(`视频已上传并插入`)}catch(t){e.error(t?.response?.data?.message??t?.message??`视频上传失败`)}},n.click()}let U={modules:{toolbar:{container:[[{header:[1,2,3,!1]}],[`bold`,`italic`,`underline`,`strike`],[{color:[]},{background:[]}],[{list:`ordered`},{list:`bullet`}],[{align:[]}],[`link`,`image`,`video`],[`clean`]],handlers:{image:V,video:H}}},placeholder:`请输入线路简介`};function W(e){return(e||[]).length?(e||[]).join(``):`-`}async function G(){b.value=!0;try{let[e,t]=await Promise.all([y.get(`/study-tours`),y.get(`/venues`)]);N.value=e.data,P.value=t.data}catch(t){e.error(t?.response?.data?.message??`加载研学线路失败`)}finally{b.value=!1}}function K(){j.value=!0,M.value=null,I.name=``,I.tags=[],I.venue_ids=[],I.intro_html=``,I.sort=0,I.is_active=!0,A.value=!0}function q(e){j.value=!1,M.value=e.id,I.name=e.name,I.tags=Array.isArray(e.tags)?[...e.tags]:[],I.venue_ids=Array.isArray(e.venue_ids)?[...e.venue_ids]:[],I.intro_html=e.intro_html||``,I.sort=e.sort??0,I.is_active=!!e.is_active,A.value=!0}function J(e){let t=new Set(e),n=I.venue_ids.filter(e=>t.has(e)),r=new Set(n);for(let t of e)r.has(t)||n.push(t);I.venue_ids=n}function Y(e){if(e<=0)return;let t=[...I.venue_ids],n=t[e-1];t[e-1]=t[e],t[e]=n,I.venue_ids=t}function X(e){if(e>=I.venue_ids.length-1)return;let t=[...I.venue_ids],n=t[e+1];t[e+1]=t[e],t[e]=n,I.venue_ids=t}function Z(e){I.venue_ids=I.venue_ids.filter(t=>t!==e)}function Q(){let t=L.value.trim();if(!t){e.warning(`请输入标签内容`);return}if(I.tags.includes(t)){e.warning(`标签已存在`);return}I.tags=[...I.tags,t],L.value=``}function $(e){let t=[...I.tags];t.splice(e,1),I.tags=t}async function ee(){if(!I.name.trim())return e.warning(`请填写线路名称`),!1;if(!I.venue_ids.length)return e.warning(`请至少选择一个场馆`),!1;k.value=!0;try{let t