- 新 api/module/anon.ts:两把探针走原生 fetch(alova 的 302 拦截对全部 /api/* 生效且没有
per-request 豁免位,用它问"有没有会话"会当场整页跳 CAS,C15 的代码事实);带 yschapirequest
头让墙内未登录回 JSON 的 code=302 信封而不是 HTML 跳转。提交回落 alova(/anon 面无 302 语义)。
- Fill.vue 引导改双探针:probeSession → 有会话走登录通道并取"我的提交"段;无会话再 probeAnonForm
→ 命中即匿名渲染(匿名人无任何查询能力,编辑/删除段整条不出现);两跳都落空才 guideToLogin。
- F1 顺修(取"改判通道"那一支,不动全局 errorHandle):旧判据 e?.code===4 是死分支——alova 抛的是
不带 code 的 Error,embed 的 needLogin 从来没发出去过;现在未登录引导只由探针结论触发。
- F2 顺修:slot desc → #desc 两处(Vue 3 下旧写法静默不进 Alert 描述插槽,报名号那行从未渲染)。
- App.vue:/f/ 前缀路由先以原生探针判会话,无会话则裸渲染且一个鉴权请求都不发(P124——否则无会话者
还没走到填报页的探针就被带去 CAS,"匿名表单 page=直接可填"根本兑现不了);探到会话时结果直接复用,
登录面不多发一次请求。其余路由引导一字未动。
- upload/image 两个附件控件的上传端点改 inject("fcUploadUrl", 默认 /api/form/upload),由 Fill.vue
按通道 provide;设计器预览等调用点行为不变。vite.config.ts 代理加 /anon → 8086。
门禁:npx vue-tsc --noEmit exit 0;npm run build ✓ built in 11.61s。
154 lines
6.6 KiB
TypeScript
154 lines
6.6 KiB
TypeScript
import { ConfigEnv, UserConfig, defineConfig } from "vite";
|
||
import { createHtmlPlugin } from "vite-plugin-html";
|
||
import vue from "@vitejs/plugin-vue";
|
||
import path, { resolve } from "path";
|
||
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
|
||
import { viteMockServe } from "vite-plugin-mock";
|
||
import ViteAutoImport from "unplugin-auto-import/vite";
|
||
|
||
import UnoCSS from "@unocss/vite";
|
||
import presetUno from "@unocss/preset-uno";
|
||
import presetRemToPx from "@unocss/preset-rem-to-px";
|
||
|
||
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||
// 构建产物直出 dist/(notice / flow-center 同口径):projman 前端发布要求 zip 根含 index.html,
|
||
// 不得再套 dist/base 中间层;dev(serve) 不写产物,两者共用该值无冲突
|
||
const outDir = "dist";
|
||
|
||
return {
|
||
plugins: [
|
||
vue(),
|
||
createSvgIconsPlugin({
|
||
iconDirs: [resolve(process.cwd(), "src/assets/icons")],
|
||
symbolId: "icon-[dir]-[name]",
|
||
inject: "body-last",
|
||
customDomId: "__svg__icons__dom__",
|
||
}),
|
||
viteMockServe({
|
||
mockPath: "./src/assets/mock",
|
||
// 仅 --mode mock 时启用 mock 中间件;dev/联调/正式均走真实后端
|
||
localEnabled: mode === "mock",
|
||
}),
|
||
ViteAutoImport({
|
||
imports: [
|
||
"vue",
|
||
"vue-router",
|
||
{
|
||
"view-ui-plus": ["Button", "Table", "Modal", "Message", "Form", "FormItem", "Input", "Select"],
|
||
},
|
||
{
|
||
from: "alova/client",
|
||
imports: ["usePagination", "useRequest", "useWatcher", "useForm"],
|
||
},
|
||
],
|
||
dts: "./src/auto-imports.d.ts",
|
||
dirs: ["src/api"], // 自动导入 api hooks
|
||
}),
|
||
createHtmlPlugin({
|
||
minify: true,
|
||
pages: [
|
||
{
|
||
entry: "src/main.ts",
|
||
template: "index.html",
|
||
filename: "index.html",
|
||
injectOptions: {
|
||
data: {
|
||
title: "表单中心",
|
||
injectScript: ``,
|
||
},
|
||
},
|
||
},
|
||
],
|
||
}),
|
||
UnoCSS({
|
||
presets: [presetUno(), presetRemToPx({ baseFontSize: 4 })],
|
||
shortcuts: {
|
||
"flex-center": "flex items-center justify-center",
|
||
btn: "px-16px py-8px rounded-4px cursor-pointer transition-all duration-200",
|
||
card: "bg-white rounded-8px shadow-md p-16px",
|
||
"text-ellipsis": "truncate",
|
||
"text-multi-ellipsis": "line-clamp-2",
|
||
},
|
||
theme: {
|
||
fontSize: {
|
||
xs: "12px",
|
||
sm: "14px",
|
||
base: "16px",
|
||
lg: "18px",
|
||
xl: "20px",
|
||
"2xl": "24px",
|
||
},
|
||
},
|
||
}),
|
||
// 主题接入已免插件化(A 类,规范 §2.1):唯一接入点 = index.html 的 loader;
|
||
// 下面的 /static 代理只是 dev 联调便利(prod 同源用不到),删除不影响线上主题
|
||
],
|
||
resolve: {
|
||
alias: {
|
||
"@": path.resolve(__dirname, "./src"),
|
||
},
|
||
},
|
||
server: {
|
||
host: "localhost",
|
||
// 本地 dev 端口(执行手册 §5 P6:service=8086 / front=8089)
|
||
port: 8089,
|
||
proxy: {
|
||
// dev 正式模式:serviceHost 为空(同源相对路径 /api/...),经此代理转发到本地后端
|
||
// (后端 CAS 过滤器对 /api/* 不回 CORS 头,浏览器直连 8086 会被拦,必须同源代理)
|
||
"/api": {
|
||
target: "http://localhost:8086",
|
||
changeOrigin: true,
|
||
},
|
||
// 匿名面(契约 v2 C6/T15):后端把 /anon/** 整族放在 CAS 墙外(yh.sso.url-pattern 仍只 /api/*),
|
||
// dev 同样要同源代理过去,否则填报页的匿名探针与提交在浏览器里是 404(生产由 Caddy 反代
|
||
// /form-center/anon/*,T15 部署前置的轻运维项)
|
||
"/anon": {
|
||
target: "http://localhost:8086",
|
||
changeOrigin: true,
|
||
},
|
||
// 附件/图片回显同源代理(P93:URL={serviceHost}/upload/{key},dev 下 serviceHost 空)
|
||
"/upload": {
|
||
target: "http://localhost:8086",
|
||
changeOrigin: true,
|
||
},
|
||
// 主题通道本地联调:dev 下 loader 走同源相对,manifest/CSS 经此代理到中央通道。
|
||
// 联调本地通道源:YschTheme 侧 npm run serve:static(默认 9527),再用
|
||
// YH_THEME_PROXY_TARGET=http://localhost:9527 覆盖本 target
|
||
"/static": {
|
||
target: process.env.YH_THEME_PROXY_TARGET || "http://base.yunhaixingtong.com",
|
||
changeOrigin: true,
|
||
},
|
||
},
|
||
},
|
||
base: "./",
|
||
build: {
|
||
target: "modules",
|
||
outDir,
|
||
assetsDir: "assets",
|
||
sourcemap: false,
|
||
minify: "esbuild",
|
||
chunkSizeWarningLimit: 1000,
|
||
cssTarget: "chrome61", // 安卓微信 webview 不支持 #RGBA 十六进制颜色
|
||
rollupOptions: {
|
||
input: {
|
||
main: resolve("index.html"),
|
||
},
|
||
output: {
|
||
chunkFileNames: "static/js/[name]-[hash].js",
|
||
entryFileNames: "static/js/[name]-[hash].js",
|
||
assetFileNames: (assetInfo: any) => {
|
||
if (assetInfo.type === "asset" && /\.(jpe?g|png|gif|svg)$/i.test(assetInfo.name)) {
|
||
return "static/img/[name].[hash][ext]";
|
||
}
|
||
if (assetInfo.type === "asset" && /\.(ttf|woff|woff2|eot)$/i.test(assetInfo.name)) {
|
||
return "static/fonts/[name].[hash][ext]";
|
||
}
|
||
return "static/[ext]/[name]-[hash].[ext]";
|
||
},
|
||
},
|
||
manualEntrypoint: "index.html",
|
||
},
|
||
},
|
||
};
|
||
});
|