Files
claude-relay-service/web/admin-spa/dist/assets/SettingsView-Dr_Y0aLV.js

4 lines
10 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{aR as F,r as h,aW as O,q as T,x as d,z as t,L as v,u as s,K as S,aq as D,O as p,C as j,P as w,aY as C,y as c}from"./vue-vendor-CKToUHZx.js";import{s as g}from"./toast-BvwA7Mwb.js";import{a as N,_ as E}from"./index-D1PUfDNP.js";import"./element-plus-B8Fs_0jW.js";import"./vendor-BDiMbLwQ.js";const V=F("settings",()=>{const l=h({siteName:"Claude Relay Service",siteIcon:"",siteIconData:"",updatedAt:null}),u=h(!1),f=h(!1),m=async()=>{u.value=!0;try{const i=await N.get("/admin/oem-settings");return i&&i.success&&(l.value={...l.value,...i.data},x()),i}catch(i){throw console.error("Failed to load OEM settings:",i),i}finally{u.value=!1}},a=async i=>{f.value=!0;try{const o=await N.put("/admin/oem-settings",i);return o&&o.success&&(l.value={...l.value,...o.data},x()),o}catch(o){throw console.error("Failed to save OEM settings:",o),o}finally{f.value=!1}},y=async()=>{const i={siteName:"Claude Relay Service",siteIcon:"",siteIconData:"",updatedAt:null};return l.value={...i},await a(i)},x=()=>{if(l.value.siteName&&(document.title=`${l.value.siteName} - 管理后台`),l.value.siteIconData||l.value.siteIcon){const i=document.querySelector('link[rel="icon"]')||document.createElement("link");i.rel="icon",i.href=l.value.siteIconData||l.value.siteIcon,document.querySelector('link[rel="icon"]')||document.head.appendChild(i)}};return{oemSettings:l,loading:u,saving:f,loadOemSettings:m,saveOemSettings:a,resetOemSettings:y,applyOemSettings:x,formatDateTime:i=>i?new Date(i).toLocaleString("zh-CN",{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit"}):"",validateIconFile:i=>{const o=[];return i.size>350*1024&&o.push("图标文件大小不能超过 350KB"),["image/x-icon","image/png","image/jpeg","image/jpg","image/svg+xml"].includes(i.type)||o.push("不支持的文件类型,请选择 .ico, .png, .jpg 或 .svg 文件"),{isValid:o.length===0,errors:o}},fileToBase64:i=>new Promise((o,n)=>{const e=new FileReader;e.onload=r=>o(r.target.result),e.onerror=n,e.readAsDataURL(i)})}}),R={class:"settings-container"},B={class:"card p-4 sm:p-6"},A={key:0,class:"text-center py-12"},M={key:1,class:"hidden sm:block table-container"},U={class:"min-w-full"},$={class:"divide-y divide-gray-200/50"},q={class:"table-row"},z={class:"px-6 py-4"},L={class:"table-row"},P={class:"px-6 py-4"},G={class:"space-y-3"},K={key:0,class:"inline-flex items-center gap-3 p-3 bg-gray-50 rounded-lg"},J=["src"],W={class:"px-6 py-6",colspan:"2"},Y={class:"flex items-center justify-between"},H={class:"flex gap-3"},Q=["disabled"],X={key:0,class:"loading-spinner mr-2"},Z={key:1,class:"fas fa-save mr-2"},tt=["disabled"],et={key:0,class:"text-sm text-gray-500"},st={key:2,class:"sm:hidden space-y-4"},at={class:"bg-gray-50 rounded-lg p-4"},it={class:"space-y-2"},ot={class:"bg-gray-50 rounded-lg p-4"},nt={class:"space-y-3"},lt={key:0,class:"inline-flex items-center gap-3 p-3 bg-white rounded-lg border border-gray-200 w-full"},rt=["src"],dt={class:"flex flex-col gap-2"},ct={class:"space-y-3 pt-2"},ut=["disabled"],mt={key:0,class:"loading-spinner mr-2"},pt={key:1,class:"fas fa-save mr-2"},gt=["disabled"],ft={key:0,class:"text-center text-xs text-gray-500"},xt={__name:"SettingsView",setup(l){const u=V(),{loading:f,saving:m,oemSettings:a}=O(u),y=h();T(async()=>{try{await u.loadOemSettings()}catch{g("加载设置失败","error")}});const x=async()=>{try{const n={siteName:a.value.siteName,siteIcon:a.value.siteIcon,siteIconData:a.value.siteIconData},e=await u.saveOemSettings(n);e&&e.success?g("OEM设置保存成功","success"):g((e==null?void 0:e.message)||"保存失败","error")}catch{g("保存OEM设置失败","error")}},I=async()=>{if(confirm(`确定要重置为默认设置吗?
这将清除所有自定义的网站名称和图标设置。`))try{const n=await u.resetOemSettings();n&&n.success?g("已重置为默认设置","success"):g("重置失败","error")}catch{g("重置失败","error")}},k=async n=>{const e=n.target.files[0];if(!e)return;const r=u.validateIconFile(e);if(!r.isValid){r.errors.forEach(b=>g(b,"error"));return}try{const b=await u.fileToBase64(e);a.value.siteIconData=b}catch{g("文件读取失败","error")}n.target.value=""},_=()=>{a.value.siteIcon="",a.value.siteIconData=""},i=()=>{console.warn("Icon failed to load")},o=u.formatDateTime;return(n,e)=>(c(),d("div",R,[t("div",B,[e[25]||(e[25]=t("div",{class:"mb-4 sm:mb-6"},[t("h3",{class:"text-lg sm:text-xl font-bold text-gray-900 mb-1 sm:mb-2"}," 其他设置 "),t("p",{class:"text-sm sm:text-base text-gray-600"}," 自定义网站名称和图标 ")],-1)),s(f)?(c(),d("div",A,e[5]||(e[5]=[t("div",{class:"loading-spinner mx-auto mb-4"},null,-1),t("p",{class:"text-gray-500"}," 正在加载设置... ",-1)]))):(c(),d("div",M,[t("table",U,[t("tbody",$,[t("tr",q,[e[7]||(e[7]=t("td",{class:"px-6 py-4 whitespace-nowrap w-48"},[t("div",{class:"flex items-center"},[t("div",{class:"w-8 h-8 bg-gradient-to-br from-blue-500 to-blue-600 rounded-lg flex items-center justify-center mr-3"},[t("i",{class:"fas fa-font text-white text-xs"})]),t("div",null,[t("div",{class:"text-sm font-semibold text-gray-900"}," 网站名称 "),t("div",{class:"text-xs text-gray-500"}," 品牌标识 ")])])],-1)),t("td",z,[S(t("input",{"onUpdate:modelValue":e[0]||(e[0]=r=>s(a).siteName=r),type:"text",class:"form-input w-full max-w-md",placeholder:"Claude Relay Service",maxlength:"100"},null,512),[[D,s(a).siteName]]),e[6]||(e[6]=t("p",{class:"text-xs text-gray-500 mt-1"}," 将显示在浏览器标题和页面头部 ",-1))])]),t("tr",L,[e[12]||(e[12]=t("td",{class:"px-6 py-4 whitespace-nowrap w-48"},[t("div",{class:"flex items-center"},[t("div",{class:"w-8 h-8 bg-gradient-to-br from-purple-500 to-purple-600 rounded-lg flex items-center justify-center mr-3"},[t("i",{class:"fas fa-image text-white text-xs"})]),t("div",null,[t("div",{class:"text-sm font-semibold text-gray-900"}," 网站图标 "),t("div",{class:"text-xs text-gray-500"}," Favicon ")])])],-1)),t("td",P,[t("div",G,[s(a).siteIconData||s(a).siteIcon?(c(),d("div",K,[t("img",{src:s(a).siteIconData||s(a).siteIcon,alt:"图标预览",class:"w-8 h-8",onError:i},null,40,J),e[9]||(e[9]=t("span",{class:"text-sm text-gray-600"},"当前图标",-1)),t("button",{class:"text-red-600 hover:text-red-900 font-medium hover:bg-red-50 px-3 py-1 rounded-lg transition-colors",onClick:_},e[8]||(e[8]=[t("i",{class:"fas fa-trash mr-1"},null,-1),p("删除 ",-1)]))])):v("",!0),t("div",null,[t("input",{ref_key:"iconFileInput",ref:y,type:"file",accept:".ico,.png,.jpg,.jpeg,.svg",class:"hidden",onChange:k},null,544),t("button",{class:"btn btn-success px-4 py-2",onClick:e[1]||(e[1]=r=>n.$refs.iconFileInput.click())},e[10]||(e[10]=[t("i",{class:"fas fa-upload mr-2"},null,-1),p(" 上传图标 ",-1)])),e[11]||(e[11]=t("span",{class:"text-xs text-gray-500 ml-3"},"支持 .ico, .png, .jpg, .svg 格式,最大 350KB",-1))])])])]),t("tr",null,[t("td",W,[t("div",Y,[t("div",H,[t("button",{disabled:s(m),class:j(["btn btn-primary px-6 py-3",{"opacity-50 cursor-not-allowed":s(m)}]),onClick:x},[s(m)?(c(),d("div",X)):(c(),d("i",Z)),p(" "+w(s(m)?"保存中...":"保存设置"),1)],10,Q),t("button",{class:"btn bg-gray-100 text-gray-700 hover:bg-gray-200 px-6 py-3",disabled:s(m),onClick:I},e[13]||(e[13]=[t("i",{class:"fas fa-undo mr-2"},null,-1),p(" 重置为默认 ",-1)]),8,tt)]),s(a).updatedAt?(c(),d("div",et,[e[14]||(e[14]=t("i",{class:"fas fa-clock mr-1"},null,-1)),p(" 最后更新:"+w(s(o)(s(a).updatedAt)),1)])):v("",!0)])])])])])])),s(f)?v("",!0):(c(),d("div",st,[t("div",at,[e[16]||(e[16]=C('<div class="flex items-center gap-3 mb-3" data-v-b9afc490><div class="w-10 h-10 bg-gradient-to-br from-blue-500 to-blue-600 rounded-lg flex items-center justify-center flex-shrink-0" data-v-b9afc490><i class="fas fa-font text-white text-sm" data-v-b9afc490></i></div><div data-v-b9afc490><h4 class="text-sm font-semibold text-gray-900" data-v-b9afc490>网站名称</h4><p class="text-xs text-gray-500" data-v-b9afc490>品牌标识</p></div></div>',1)),t("div",it,[S(t("input",{"onUpdate:modelValue":e[2]||(e[2]=r=>s(a).siteName=r),type:"text",class:"form-input w-full text-sm",placeholder:"Claude Relay Service",maxlength:"100"},null,512),[[D,s(a).siteName]]),e[15]||(e[15]=t("p",{class:"text-xs text-gray-500"}," 将显示在浏览器标题和页面头部 ",-1))])]),t("div",ot,[e[22]||(e[22]=C('<div class="flex items-center gap-3 mb-3" data-v-b9afc490><div class="w-10 h-10 bg-gradient-to-br from-purple-500 to-purple-600 rounded-lg flex items-center justify-center flex-shrink-0" data-v-b9afc490><i class="fas fa-image text-white text-sm" data-v-b9afc490></i></div><div data-v-b9afc490><h4 class="text-sm font-semibold text-gray-900" data-v-b9afc490>网站图标</h4><p class="text-xs text-gray-500" data-v-b9afc490>Favicon</p></div></div>',1)),t("div",nt,[s(a).siteIconData||s(a).siteIcon?(c(),d("div",lt,[t("img",{src:s(a).siteIconData||s(a).siteIcon,alt:"图标预览",class:"w-8 h-8",onError:i},null,40,rt),e[18]||(e[18]=t("span",{class:"text-sm text-gray-600 flex-1"},"当前图标",-1)),t("button",{class:"text-red-600 hover:text-red-900 text-sm font-medium hover:bg-red-50 px-3 py-1 rounded-lg transition-colors",onClick:_},e[17]||(e[17]=[t("i",{class:"fas fa-trash mr-1"},null,-1),p("删除 ",-1)]))])):v("",!0),t("input",{ref_key:"iconFileInput",ref:y,type:"file",accept:"image/*",style:{display:"none"},onChange:k},null,544),t("div",dt,[t("button",{class:"w-full px-4 py-2 bg-white border border-gray-200 rounded-lg text-sm text-gray-700 hover:bg-gray-50 transition-colors flex items-center justify-center gap-2",onClick:e[3]||(e[3]=r=>n.$refs.iconFileInput.click())},e[19]||(e[19]=[t("i",{class:"fas fa-upload"},null,-1),p(" 上传图标 ",-1)])),e[20]||(e[20]=t("div",{class:"text-xs text-gray-500"}," 或者输入图标URL ",-1)),S(t("input",{"onUpdate:modelValue":e[4]||(e[4]=r=>s(a).siteIcon=r),type:"url",class:"form-input w-full text-sm",placeholder:"https://example.com/icon.png"},null,512),[[D,s(a).siteIcon]])]),e[21]||(e[21]=t("p",{class:"text-xs text-gray-500"}," 支持 PNG、JPEG、GIF 格式,建议使用正方形图片 ",-1))])]),t("div",ct,[t("button",{class:"btn btn-primary w-full py-3 text-sm font-semibold",disabled:s(m),onClick:x},[s(m)?(c(),d("div",mt)):(c(),d("i",pt)),p(" "+w(s(m)?"保存中...":"保存设置"),1)],8,ut),t("button",{class:"btn bg-gray-100 text-gray-700 hover:bg-gray-200 w-full py-3 text-sm",disabled:s(m),onClick:I},e[23]||(e[23]=[t("i",{class:"fas fa-undo mr-2"},null,-1),p(" 重置为默认 ",-1)]),8,gt),s(a).updatedAt?(c(),d("div",ft,[e[24]||(e[24]=t("i",{class:"fas fa-clock mr-1"},null,-1)),p(" 最后更新:"+w(s(o)(s(a).updatedAt)),1)])):v("",!0)])]))])]))}},It=E(xt,[["__scopeId","data-v-b9afc490"]]);export{It as default};