54 lines
2.9 KiB
JavaScript
54 lines
2.9 KiB
JavaScript
import { createServer } from '../../admin/node_modules/vite/dist/node/index.js'
|
|
import vue from '../../admin/node_modules/@vitejs/plugin-vue/dist/index.mjs'
|
|
|
|
const root = 'D:/web/zyt/admin'
|
|
const entry = `
|
|
import { createApp, h, onMounted, reactive, ref } from 'vue';
|
|
import ElementPlus from 'element-plus';
|
|
import zhCn from 'element-plus/es/locale/lang/zh-cn';
|
|
import 'element-plus/dist/index.css';
|
|
import Dialog from '/src/views/consumer/prescription/components/PrescriptionOrderTimeDialog.vue';
|
|
import { state } from 'time-fixture-state';
|
|
createApp({setup() {
|
|
const dialog = ref(null);
|
|
const row = {id: 42, order_no: '测试订单-42', create_time: '2026-09-09 11:12:37'};
|
|
onMounted(() => dialog.value.open(row));
|
|
return () => h('main', {style:'font-family:system-ui;padding:20px'}, [
|
|
h('h2', '订单时间隔离验证(虚构数据)'),
|
|
h('button', {onClick:() => dialog.value.open(row)}, '打开弹窗'),
|
|
h('pre', {id:'fixture-state'}, JSON.stringify(state, null, 2)),
|
|
h(Dialog, {ref:dialog, onSaved:id => state.saved.push(id)})
|
|
]);
|
|
}}).use(ElementPlus, {locale:zhCn}).mount('#app');`
|
|
|
|
const server = await createServer({
|
|
configFile: false, root, base: '/',
|
|
cacheDir: 'D:/web/zyt/artifacts/prescription-enhancements/vite-cache',
|
|
optimizeDeps: { entries: [], include: ['vue', 'element-plus'] },
|
|
resolve: { alias: { '@': `${root}/src` } },
|
|
plugins: [{
|
|
name: 'time-dialog-isolated-fixture', enforce: 'pre',
|
|
resolveId(id) {
|
|
if (id === 'time-fixture-state') return '\0time-state'
|
|
if (id === '@/api/tcm' || id.endsWith('/src/api/tcm')) return '\0time-api'
|
|
if (id === '/__time-entry.js') return '\0time-entry'
|
|
},
|
|
load(id) {
|
|
if (id === '\0time-state') return `import {reactive} from 'vue'; export const state = reactive({requests:[],saved:[]});`
|
|
if (id === '\0time-api') return `import {state} from 'time-fixture-state'; export async function prescriptionOrderEditTime(params){state.requests.push(params);return {...params};}`
|
|
if (id === '\0time-entry') return entry
|
|
},
|
|
configureServer(dev) {
|
|
dev.middlewares.use((req, res, next) => {
|
|
if (!req.url?.startsWith('/__time-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></head><body><div id="app"></div><script type="module" src="/__time-entry.js"></script></body></html>')
|
|
})
|
|
}
|
|
}, vue()],
|
|
server: { host: '127.0.0.1', port: 5586, strictPort: true, open: false }
|
|
})
|
|
await server.listen()
|
|
console.log('Isolated fixture: http://127.0.0.1:5586/__time-check')
|
|
for (const event of ['SIGINT', 'SIGTERM']) process.on(event, async () => { await server.close(); process.exit(0) })
|