/** 公共站点配置:全应用共享成功结果和在途请求,失败可重试,页面错误文案各自维护。 */ import { ref } from "vue"; import { computed } from "vue"; import { useState } from "#app"; import { useApi } from "~/lib/auth.js"; var i = null; function a() { let a = useState(`site-config`, () => null), o = ref(``); // /common 控制验证码、充值、资料锁定等前端入口;这些开关不替代后端权限校验。 async function s() { if (((o.value = ``), a.value)) return a.value; i ||= useApi() .get(`/common`, void 0, !1, { timeoutMs: 1e4, }) .then((e) => ((a.value = e), e)) .catch((e) => { throw ((i = null), e); }); try { return await i; } catch (e) { return ( (o.value = e instanceof Error ? e.message : `加载站点配置失败`), null ); } } // 后端开关可能是布尔、数字或字符串,仅把明确的 1/true 当成开启。 let c = (e) => e === 1 || e === `1` || e === !0; return { config: a, error: o, load: s, on: c, maintenance: computed(() => c(a.value?.maintenance_mode)), rechargeClosed: computed( () => a.value != null && !c(a.value.recharge_open), ), lockedFields: computed( () => a.value?.prohibit_user_information_changes ?? [], ), siteName: computed(() => a.value?.website_name || `破碎工坊云`), scanLoginEnabled: computed(() => c(a.value?.plugin_configuration?.mp_weixin_notice?.scan_login), ), }; } export { a as t };