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

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={name:I.name.trim(),tags:I.tags.map(e=>e.trim()).filter(Boolean),venue_ids:[...I.venue_ids],intro_html:I.intro_html||``,sort:I.sort??0,is_active:I.is_active};return j.value?(await y.post(`/study-tours`,t),e.success(`新增线路成功`)):M.value&&(await y.put(`/study-tours/${M.value}`,t),e.success(`更新线路成功`)),A.value=!1,await G(),!0}catch(t){return e.error(t?.response?.data?.message??`保存失败`),!1}finally{k.value=!1}}async function te(t){try{await y.delete(`/study-tours/${t.id}`),e.success(`删除成功`),await G()}catch(t){e.error(t?.response?.data?.message??`删除失败`)}}return n(G),(e,n)=>{let l=r(`a-button`),d=r(`a-space`),f=r(`a-table-column`),_=r(`a-tag`),y=r(`a-popconfirm`),M=r(`a-table`),z=r(`a-card`),B=r(`a-input`),V=r(`a-form-item`),H=r(`a-option`),ne=r(`a-select`),re=r(`a-empty`),ie=r(`a-input-number`),ae=r(`a-switch`),oe=r(`a-form`),se=r(`a-modal`);return t(),p(c,null,[g(z,{title:`研学线路管理 / 线路列表`},{extra:i(()=>[g(d,null,{default:i(()=>[g(l,{onClick:G},{default:i(()=>[...n[6]||=[a(`刷新`,-1)]]),_:1}),g(l,{type:`primary`,onClick:K},{default:i(()=>[...n[7]||=[a(`新增线路`,-1)]]),_:1})]),_:1})]),default:i(()=>[g(M,{class:`list-data-table`,scroll:{x:h(S)},data:N.value,loading:b.value,"row-key":`id`,pagination:{pageSize:10}},{columns:i(()=>[g(f,{title:`ID`,"data-index":`id`,width:80,ellipsis:!0,tooltip:!0}),g(f,{title:`线路名称`,"data-index":`name`,width:200,"min-width":160,ellipsis:!0,tooltip:!0}),g(f,{title:`标签`,width:200,"min-width":140,ellipsis:!0,tooltip:!0},{cell:i(({record:e})=>[a(u(W(e.tags)),1)]),_:1}),g(f,{title:`场馆数量`,width:100},{cell:i(({record:e})=>[a(u((e.venue_ids||[]).length),1)]),_:1}),g(f,{title:`排序`,"data-index":`sort`,width:100,ellipsis:!0,tooltip:!0}),g(f,{title:`状态`,width:100},{cell:i(({record:e})=>[g(_,{color:e.is_active?`green`:`gray`},{default:i(()=>[a(u(e.is_active?`启用`:`禁用`),1)]),_:2},1032,[`color`])]),_:1}),g(f,{title:`操作`,width:160,fixed:`right`,align:`center`},{cell:i(({record:e})=>[g(d,null,{default:i(()=>[g(l,{type:`text`,onClick:t=>q(e)},{default:i(()=>[...n[8]||=[a(`编辑`,-1)]]),_:1},8,[`onClick`]),g(y,{content:`确定删除该线路?`,onOk:t=>te(e)},{default:i(()=>[g(l,{type:`text`,status:`danger`},{default:i(()=>[...n[9]||=[a(`删除`,-1)]]),_:1})]),_:1},8,[`onOk`])]),_:2},1024)]),_:1})]),_:1},8,[`scroll`,`data`,`loading`])]),_:1}),g(se,{visible:A.value,"onUpdate:visible":n[5]||=e=>A.value=e,title:j.value?`新增线路`:`编辑线路`,width:`70%`,"body-style":F,"confirm-loading":k.value,"on-before-ok":ee},{default:i(()=>[g(oe,{model:I,layout:`vertical`},{default:i(()=>[g(V,{label:`线路名称`,required:``},{default:i(()=>[g(B,{modelValue:I.name,"onUpdate:modelValue":n[0]||=e=>I.name=e},null,8,[`modelValue`])]),_:1}),g(V,{label:`标签数组`},{default:i(()=>[g(d,{style:{width:`100%`}},{default:i(()=>[g(B,{modelValue:L.value,"onUpdate:modelValue":n[1]||=e=>L.value=e,placeholder:`请输入标签内容`},null,8,[`modelValue`]),g(l,{type:`primary`,onClick:Q},{default:i(()=>[...n[10]||=[a(`新增标签`,-1)]]),_:1})]),_:1}),m(`div`,C,[(t(!0),p(c,null,v(I.tags,(e,n)=>(t(),o(_,{key:`${e}-${n}`,closable:``,style:{"margin-right":`8px`,"margin-bottom":`0`},onClose:e=>$(n)},{default:i(()=>[a(u(e),1)]),_:2},1032,[`onClose`]))),128)),I.tags.length?s(``,!0):(t(),p(`span`,w,`暂无标签`))])]),_:1}),g(V,{label:`场馆数组(可排序)`,required:``},{default:i(()=>[m(`div`,T,[m(`div`,E,[g(ne,{"model-value":I.venue_ids,multiple:``,"allow-search":``,"allow-clear":``,placeholder:`请选择场馆`,onChange:J},{default:i(()=>[(t(!0),p(c,null,v(P.value,e=>(t(),o(H,{key:e.id,value:e.id},{default:i(()=>[a(u(e.name),1)]),_:2},1032,[`value`]))),128))]),_:1},8,[`model-value`])]),m(`div`,D,[g(d,{direction:`vertical`,fill:``},{default:i(()=>[(t(!0),p(c,null,v(R.value,(e,r)=>(t(),p(`div`,{key:e.id,style:{display:`flex`,"align-items":`center`,"justify-content":`space-between`,border:`1px solid #f2f3f5`,"border-radius":`4px`,padding:`6px 8px`}},[m(`span`,null,u(r+1)+`. `+u(e.name),1),g(d,null,{default:i(()=>[g(l,{size:`mini`,disabled:r===0,onClick:e=>Y(r)},{default:i(()=>[...n[11]||=[a(`上移`,-1)]]),_:1},8,[`disabled`,`onClick`]),g(l,{size:`mini`,disabled:r===R.value.length-1,onClick:e=>X(r)},{default:i(()=>[...n[12]||=[a(`下移`,-1)]]),_:1},8,[`disabled`,`onClick`]),g(l,{size:`mini`,status:`danger`,onClick:t=>Z(e.id)},{default:i(()=>[...n[13]||=[a(`移除`,-1)]]),_:1},8,[`onClick`])]),_:2},1024)]))),128)),R.value.length?s(``,!0):(t(),o(re,{key:0,description:`未选择场馆`}))]),_:1})])])]),_:1}),g(V,{label:`线路简介`},{default:i(()=>[m(`div`,O,[g(h(x),{content:I.intro_html,"onUpdate:content":n[2]||=e=>I.intro_html=e,"content-type":`html`,theme:`snow`,options:U,class:`intro-editor`,style:{height:`300px`}},null,8,[`content`])])]),_:1}),g(V,{label:`排序`},{default:i(()=>[g(ie,{modelValue:I.sort,"onUpdate:modelValue":n[3]||=e=>I.sort=e,min:0},null,8,[`modelValue`])]),_:1}),g(V,{label:`状态`},{default:i(()=>[g(ae,{modelValue:I.is_active,"onUpdate:modelValue":n[4]||=e=>I.is_active=e},null,8,[`modelValue`])]),_:1})]),_:1},8,[`model`])]),_:1},8,[`visible`,`title`,`confirm-loading`])],64)}}}),[[`__scopeId`,`data-v-b59fa1ba`]]);export{k as default};