42 lines
3.6 KiB
JavaScript
42 lines
3.6 KiB
JavaScript
// 隔离浏览器验收:挂载真实新增组件,所有 API 由合成内存夹具接管。
|
|
import { createServer } from '../../admin/node_modules/vite/dist/node/index.js'
|
|
import vue from '../../admin/node_modules/@vitejs/plugin-vue/dist/index.mjs'
|
|
import { fileURLToPath } from 'node:url'
|
|
import { readFile } from 'node:fs/promises'
|
|
|
|
const root = fileURLToPath(new URL('../../admin/', import.meta.url)).replaceAll('\\', '/')
|
|
const fixture = await readFile(new URL('./staff-ui-fixture.mjs', import.meta.url), 'utf8')
|
|
const server = await createServer({
|
|
configFile: false,
|
|
root,
|
|
base: '/',
|
|
cacheDir: fileURLToPath(new URL('../../.spool/assistant-service-vite/', import.meta.url)),
|
|
resolve: { alias: { '@': `${root}src` } },
|
|
optimizeDeps: { entries: [], include: ['vue', 'vue-router', 'element-plus', '@element-plus/icons-vue'] },
|
|
plugins: [{
|
|
name: 'assistant-service-isolated-preview',
|
|
enforce: 'pre',
|
|
resolveId(id) {
|
|
if (id === '@/stores/modules/user' || id.endsWith('/src/stores/modules/user')) return '\0assistant-service-user'
|
|
if (id === '@/utils/request' || id.endsWith('/src/utils/request') || id.endsWith('/src/utils/request/index.ts')) return '\0assistant-service-fixture'
|
|
if (id === '/__assistant-service-entry.js') return '\0assistant-service-entry'
|
|
},
|
|
load(id) {
|
|
if (id === '\0assistant-service-user') return `export default function(){return {userInfo:{id:9,admin_id:9,name:'合成主管',root:0},permissions:['*']}}`
|
|
if (id === '\0assistant-service-fixture') return fixture
|
|
if (id === '\0assistant-service-entry') return `import {createApp,h} from 'vue';import {createRouter,createWebHistory,RouterView} from 'vue-router';import ElementPlus from 'element-plus';import 'element-plus/dist/index.css';import Workbench from '/src/views/assistant_service/workbench/index.vue';import Knowledge from '/src/views/assistant_service/knowledge/index.vue';const router=createRouter({history:createWebHistory(),routes:[{path:'/__assistant-service-check',component:Workbench},{path:'/__assistant-service-check/knowledge',component:Knowledge}]});const app=createApp({render:()=>h(RouterView)});app.use(router).use(ElementPlus).mount('#app');`
|
|
},
|
|
configureServer(dev) {
|
|
dev.middlewares.use((req, res, next) => {
|
|
if (!req.url?.startsWith('/__assistant-service-check')) return next()
|
|
res.setHeader('Content-Type', 'text/html;charset=utf-8')
|
|
res.end('<!doctype html><html lang="zh-CN"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>医助服务模块隔离验收</title><style>body{margin:0;background:#f4f6f8;font-family:Arial,"Microsoft YaHei",sans-serif;color:#303133}#fixture-note{padding:10px 20px;background:#fff3d6;font-size:13px}#fixture-note a{margin-left:16px;color:#315f91}#app{padding:20px;max-width:1600px;margin:auto}*{box-sizing:border-box}</style></head><body><nav id="fixture-note">隔离验收:合成资料,不连接业务接口或模型<a href="/__assistant-service-check">服务工作台</a><a href="/__assistant-service-check/knowledge">服务知识</a></nav><div id="app"></div><script type="module" src="/__assistant-service-entry.js"></script></body></html>')
|
|
})
|
|
}
|
|
}, vue()],
|
|
server: { host: '127.0.0.1', port: 5589, strictPort: true, open: false }
|
|
})
|
|
await server.listen()
|
|
console.log('Isolated preview http://127.0.0.1:5589/__assistant-service-check')
|
|
for (const signal of ['SIGINT', 'SIGTERM']) process.on(signal, async () => { await server.close(); process.exit(0) })
|