Commit b361337f by Lin

feat:mono-repo框架源码

1 parent 26d0d13d
Showing 49 changed files with 1543 additions and 27 deletions
# Changesets
Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works
with multi-package repos, or single-package repos to help you version and publish your code. You can
find the full documentation for it [in our repository](https://github.com/changesets/changesets)
We have a quick list of common questions to get you started engaging with this project in
[our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md)
{
"$schema": "https://unpkg.com/@changesets/config@3.1.1/schema.json",
"changelog": "@changesets/cli/changelog",
"commit": false,
"fixed": [],
"linked": [],
"access": "restricted",
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": []
}
---
"@venus/charts": major
---
1.0.0
root = true
[*]
charset=utf-8
end_of_line=lf
insert_final_newline=true
indent_style=space
indent_size=2
max_line_length = 100
trim_trailing_whitespace = true
quote_type = single
[*.{yml,yaml,json}]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>scrm-app-vue</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
\ No newline at end of file
{
"name": "scrm-app-vue",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite --port 5174",
"build": "vue-tsc -b && vite build",
"preview": "vite preview --port 5174"
},
"dependencies": {
"vue": "catalog:"
},
"devDependencies": {
"@types/node": "catalog:",
"@vitejs/plugin-vue": "catalog:",
"@vue/tsconfig": "catalog:",
"typescript": "catalog:",
"vite": "catalog:",
"vue-tsc": "catalog:",
"vite-plugin-qiankun": "^1.0.15"
}
}
\ No newline at end of file
<script setup lang="ts">
import { ref, onMounted } from 'vue'
const global = ref<any>(null)
const msg = ref('')
onMounted(() => {
const actions = (window as any).__QIANKUN_ACTIONS__
actions?.onGlobalStateChange?.((s: any) => {
global.value = s
}, true)
})
function broadcast() {
const actions = (window as any).__QIANKUN_ACTIONS__
actions?.setGlobalState?.({ ...(global.value || {}), msg: msg.value })
}
</script>
<template>
<div style="padding: 24px">
<h2 style="margin-bottom: 12px;">SCRM 子应用(Vue)</h2>
<div style="display:flex; gap:12px; align-items:center; margin-bottom: 12px;">
<input
v-model="msg"
placeholder="向基座广播消息"
style="padding:6px; border:1px solid #ccc; border-radius:4px;"
/>
<button @click="broadcast" style="padding:6px 10px;">广播</button>
</div>
<div>当前全局消息:{{ global?.msg }}</div>
</div>
</template>
<style scoped></style>
\ No newline at end of file
/*
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @Date: 2025-11-11 15:39:04
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @LastEditTime: 2025-11-11 19:17:19
* @FilePath: \venus\apps\frontend\micro-vue\scrm-app-vue\src\main.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { createApp } from 'vue'
import App from './App.vue'
let app: ReturnType<typeof createApp> | null = null
let mountEl: Element | null = null
function ensureContainerEl(container?: Element | null) {
if (!container) return document.getElementById('app')
const id = 'app'
let el = container.querySelector('#' + id)
if (!el) {
el = document.createElement('div')
el.id = id
container.appendChild(el)
}
return el
}
function render(props: any = {}) {
const { container } = props
mountEl = ensureContainerEl(container)
if (!mountEl) throw new Error('Micro app mount element not found')
// 若已存在旧实例(可能由 HMR 或重复挂载造成),先安全卸载并清空容器
if (app) {
try {
app.unmount()
} catch {}
;(mountEl as HTMLElement).innerHTML = ''
app = null
}
app = createApp(App)
app.mount(mountEl)
}
export async function bootstrap() {
// 可在此进行应用初始化逻辑
console.log("bootstrap");
}
export async function mount(props: any) {
console.log("mount",props);
return new Promise((resolve, reject) => {
// Always reject with an Error.
reject(new Error('hi'));
});
// render(props)
}
export async function unmount(_props: any) {
try {
app?.unmount()
} finally {
if (mountEl) {
// 清空容器,确保二次挂载不会触发 HMR 卸载异常
;(mountEl as HTMLElement).innerHTML = ''
}
app = null
mountEl = null
}
}
// 独立运行(本地开发直接访问)
if (!(window as any).__POWERED_BY_QIANKUN__) {
render()
}
\ No newline at end of file
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"types": ["vite/client"],
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
}
\ No newline at end of file
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import qiankun from 'vite-plugin-qiankun'
// 子应用名称需与基座 registerMicroApps 中保持一致
const appName = 'scrm-app-vue'
export default defineConfig({
base: './',
plugins: [
vue(),
qiankun(appName, { useDevMode: true }),
],
server: {
port: 5174,
cors: true,
origin: 'http://localhost:5174',
},
})
\ No newline at end of file
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
# Vue 3 + TypeScript + Vite
This template should help get you started developing with Vue 3 and TypeScript in Vite. The template uses Vue 3 `<script setup>` SFCs, check out the [script setup docs](https://v3.vuejs.org/api/sfc-script-setup.html#sfc-script-setup) to learn more.
Learn more about the recommended Project Setup and IDE Support in the [Vue Docs TypeScript Guide](https://vuejs.org/guide/typescript/overview.html#project-setup).
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>scrm-base</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
{
"name": "scrm-base",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "vue-tsc -b && vite build",
"preview": "vite preview"
},
"dependencies": {
"qiankun": "catalog:",
"vue": "catalog:",
"vue-router": "catalog:",
"@venus/common-ui": "workspace:*",
"pinia": "catalog:",
"pinia-plugin-persistedstate": "catalog:"
},
"devDependencies": {
"@types/node": "catalog:",
"@vitejs/plugin-vue": "catalog:",
"@vue/tsconfig": "catalog:",
"typescript": "catalog:",
"vite": "catalog:",
"vue-tsc": "catalog:"
}
}
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
\ No newline at end of file
<script setup lang="ts"></script>
<template>
<router-view />
</template>
<style scoped></style>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="37.07" height="36" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 198"><path fill="#41B883" d="M204.8 0H256L128 220.8L0 0h97.92L128 51.2L157.44 0h47.36Z"></path><path fill="#41B883" d="m0 0l128 220.8L256 0h-51.2L128 132.48L50.56 0H0Z"></path><path fill="#35495E" d="M50.56 0L128 133.12L204.8 0h-47.36L128 51.2L97.92 0H50.56Z"></path></svg>
\ No newline at end of file
<script setup lang="ts">
import { ref } from 'vue'
defineProps<{ msg: string }>()
const count = ref(0)
</script>
<template>
<h1>{{ msg }}</h1>
<div class="card">
<button type="button" @click="count++">count is {{ count }}</button>
<p>
Edit
<code>components/HelloWorld.vue</code> to test HMR
</p>
</div>
<p>
Check out
<a href="https://vuejs.org/guide/quick-start.html#local" target="_blank"
>create-vue</a
>, the official Vue + Vite starter
</p>
<p>
Learn more about IDE Support for Vue in the
<a
href="https://vuejs.org/guide/scaling-up/tooling.html#ide-support"
target="_blank"
>Vue Docs Scaling up Guide</a
>.
</p>
<p class="read-the-docs">Click on the Vite and Vue logos to learn more</p>
</template>
<style scoped>
.read-the-docs {
color: #888;
}
</style>
<script setup lang="ts">
import { ref } from 'vue'
import Topbar from './components/Topbar.vue'
import Sidebar from './components/Sidebar.vue'
import appsManifest from '../mfe/apps.json'
const collapsed = ref(false)
const keepAliveNames = appsManifest.apps.map(m => `Micro_${m.dir}`)
</script>
<template>
<div class="base-layout">
<Topbar @toggleSidebar="collapsed = !collapsed" />
<div class="layout-body">
<Sidebar :collapsed="collapsed" />
<main class="content">
<router-view v-slot="{ Component }">
<KeepAlive :include="keepAliveNames">
<component :is="Component" />
</KeepAlive>
</router-view>
</main>
</div>
</div>
</template>
<style scoped>
.base-layout {
height: 100vh;
display: flex;
flex-direction: column;
background: #f3f4f6;
}
.layout-body {
display: flex;
flex: 1;
min-height: 0;
}
.content {
flex: 1;
min-width: 0;
overflow: auto;
padding: 16px;
}
</style>
\ No newline at end of file
<script setup lang="ts">
import appsManifest from '../../mfe/apps.json'
const props = defineProps<{ collapsed: boolean }>()
</script>
<template>
<aside :class="['sidebar', { collapsed: props.collapsed }]">
<div class="brand" title="SCRM">S</div>
<nav class="menu">
<router-link to="/">首页</router-link>
<div style="margin-top:8px;">
<div style="opacity:.8; font-size:12px; margin-bottom:6px;">子应用</div>
<div style="display:flex; flex-direction:column; gap:6px;">
<router-link
v-for="m in appsManifest.apps"
:key="m.dir"
:to="m.route"
>{{ m.displayName }}</router-link>
</div>
</div>
</nav>
</aside>
</template>
<style scoped>
.sidebar {
width: 240px;
min-width: 240px;
background: #111827;
color: #fff;
height: calc(100vh - 56px);
display: flex;
flex-direction: column;
}
.collapsed {
width: 64px;
min-width: 64px;
}
.brand {
height: 56px;
display: flex;
align-items: center;
justify-content: center;
font-weight: 700;
border-bottom: 1px solid #1f2937;
}
.menu {
padding: 8px 0;
}
.menu a {
display: block;
padding: 10px 16px;
color: #cbd5e1;
text-decoration: none;
}
.menu a.router-link-active {
background: #1f2937;
color: #fff;
}
</style>
\ No newline at end of file
<script setup lang="ts">
import { useRouter } from 'vue-router'
const emit = defineEmits<{ (e: 'toggleSidebar'): void }>()
const router = useRouter()
function logout() {
localStorage.removeItem('token')
router.push('/login')
}
</script>
<template>
<header class="topbar">
<button class="icon-btn" @click="emit('toggleSidebar')">☰</button>
<div class="title">SCRM Base</div>
<div class="spacer" />
<div class="actions">
<button class="text-btn" @click="logout">退出</button>
</div>
</header>
</template>
<style scoped>
.topbar {
height: 56px;
display: flex;
align-items: center;
padding: 0 12px;
background: #ffffff;
border-bottom: 1px solid #e5e7eb;
}
.title {
font-weight: 600;
margin-left: 8px;
}
.spacer {
flex: 1;
}
.actions {
display: flex;
align-items: center;
gap: 8px;
}
.icon-btn {
width: 32px;
height: 32px;
border: 1px solid #e5e7eb;
background: #fff;
border-radius: 6px;
cursor: pointer;
}
.text-btn {
border: 1px solid #e5e7eb;
background: #fff;
border-radius: 6px;
padding: 6px 10px;
cursor: pointer;
}
.icon-btn:hover, .text-btn:hover { background: #f9fafb; }
</style>
\ No newline at end of file
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router/index.ts'
// import { setupCommonUI } from '@venus/common-ui'
import { registerMicroApps, start, initGlobalState } from 'qiankun'
import appsManifest from './mfe/apps.json'
import pinia from './stores'
import { useAuthStore } from './stores/auth'
// import { usePermissionStore } from './stores/permission'
const app = createApp(App)
app.use(pinia)
app.use(router)
// setupCommonUI(app)
app.mount('#app')
// ------- qiankun 集成与全局状态通信 -------
const actions = initGlobalState({
user: { name: 'BaseUser' },
msg: '',
})
;(window as any).__QIANKUN_ACTIONS__ = actions
// 同步全局状态到 Pinia(在组件外使用 store,需要显式传入 pinia 实例)
const auth = useAuthStore(pinia)
// const perm = usePermissionStore(pinia)
actions.onGlobalStateChange((s: any) => {
auth.setFromGlobal(s.user, s.token)
// perm.setupByRoles(s.user?.roles || [])
}, true)
registerMicroApps(
appsManifest.apps.map((m) => ({
name: m.name,
entry: m.entry,
container: m.container,
// 按路由匹配激活,容器将在路由页面渲染后可用
activeRule: (location) => location.pathname.startsWith(m.route),
// 注入渲染所需的全局 actions
props: { actions: (window as any).__QIANKUN_ACTIONS__ },
}))
)
router.isReady().then(() => {
// 开发阶段关闭 sandbox,但开启资源预取以加快首次进入
start({
sandbox: false,
prefetch: true,
})
})
{
"apps": [
{
"name": "scrm-app-vue",
"dir": "scrm-app-vue",
"route": "/mfe/scrm-app-vue",
"container": "#mfe-scrm-app-vue",
"entry": "http://localhost:5174/",
"displayName": "scrm-app-vue"
}
]
}
\ No newline at end of file
<!--
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @Date: 2025-11-10 17:56:50
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @LastEditTime: 2025-11-11 16:19:06
* @FilePath: \venus\apps\frontend\micro-vue\scrm-base\src\pages\Home.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue'
import appsManifest from '../mfe/apps.json'
const text = ref('')
function handleClick() {
alert(`当前输入:${text.value || '(空)'}`)
}
// ------- 主应用 -> 子应用:通过 qiankun 全局状态广播 -------
const hostMsg = ref('')
const globalState = ref<any>(null)
onMounted(() => {
const actions = (window as any).__QIANKUN_ACTIONS__
actions?.onGlobalStateChange?.((s: any) => {
globalState.value = s
}, true)
})
// ------- 监听子应用挂载完成事件 -------
const lastMountedApp = ref('')
function handleMounted(e: any) {
const detail = e?.detail || {}
lastMountedApp.value = detail.appName || ''
}
onMounted(() => {
window.addEventListener('mfe:mounted', handleMounted as EventListener)
})
onBeforeUnmount(() => {
window.removeEventListener('mfe:mounted', handleMounted as EventListener)
})
function broadcastToMicro() {
const actions = (window as any).__QIANKUN_ACTIONS__
actions?.setGlobalState?.({ ...(globalState.value || {}), msg: hostMsg.value })
}
function syncUserToMicro() {
const actions = (window as any).__QIANKUN_ACTIONS__
actions?.setGlobalState?.({
...(globalState.value || {}),
user: { name: 'HostUser', roles: ['admin'] },
})
}
</script>
<template>
<div style="padding: 24px">
<h2 style="margin-bottom: 12px;">示例:公共基础样式组件</h2>
<div style="display:flex; gap:12px; align-items:center;">
<VInput v-model="text" placeholder="请输入内容" style="max-width: 240px;" />
<VButton type="primary" @click="handleClick">提交</VButton>
</div>
<h2 style="margin: 24px 0 12px;">主应用向子应用广播示例</h2>
<div style="display:flex; gap:12px; align-items:center;">
<input
v-model="hostMsg"
placeholder="向子应用广播消息"
style="padding:6px; border:1px solid #ccc; border-radius:4px; max-width: 240px;"
/>
<button @click="broadcastToMicro" style="padding:6px 10px;">广播到子应用</button>
<button @click="syncUserToMicro" style="padding:6px 10px;">同步用户信息</button>
<span>当前全局消息:{{ globalState?.msg }}</span>
<span style="margin-left:8px;">子应用列表:</span>
<router-link
v-for="m in appsManifest.apps"
:key="m.dir"
:to="m.route"
style="margin-right:8px;"
>打开 {{ m.displayName }}</router-link>
<span v-if="lastMountedApp" style="margin-left:8px; color:#059669;">最近挂载:{{ lastMountedApp }}</span>
</div>
</div>
</template>
<style scoped></style>
\ No newline at end of file
<!--
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @Date: 2025-11-10 17:56:58
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @LastEditTime: 2025-11-11 14:40:21
* @FilePath: \venus\apps\frontend\micro-vue\scrm-base\src\pages\Login.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="ts">
import { ref } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const username = ref('')
const password = ref('')
function handleLogin() {
// 占位登录逻辑:设置一个 token 即视为登录成功
if (username.value && password.value) {
localStorage.setItem('token', 'mock-token')
router.push('/')
}
}
</script>
<template>
<div style="display:flex; align-items:center; justify-content:center; height:100vh;">
<div style="width:320px; padding:24px; border:1px solid #e5e7eb; border-radius:8px; background:#fff;">
<h2 style="margin:0 0 16px;">登录</h2>
<div style="display:flex; flex-direction:column; gap:12px;">
<input v-model="username" placeholder="用户名" style="padding:8px; border:1px solid #ccc; border-radius:4px;" />
<input v-model="password" type="password" placeholder="密码" style="padding:8px; border:1px solid #ccc; border-radius:4px;" />
<button @click="handleLogin" style="padding:10px; border:none; border-radius:4px; background:#646cff; color:#fff; cursor:pointer;">登录</button>
</div>
</div>
</div>
</template>
<style scoped></style>
\ No newline at end of file
<!--
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @Date: 2025-11-11 17:12:31
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @LastEditTime: 2025-11-11 18:14:05
* @FilePath: \venus\apps\frontend\micro-vue\scrm-base\src\pages\MicroHost.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="ts">
import { computed, ref, onMounted, onBeforeUnmount } from 'vue'
import { useRoute } from 'vue-router'
import appsManifest from '../mfe/apps.json'
const route = useRoute()
const meta = computed(() => {
return appsManifest.apps.find((a) => route.path.startsWith(a.route))
})
const containerId = computed(() => {
const c = meta.value?.container || ''
return c.startsWith('#') ? c.slice(1) : c || `mfe-${(route.path.split('/').pop() || '').trim()}`
})
const loading = ref(true)
let observer: MutationObserver | null = null
function checkReady(el: Element | null) {
if (!el) return
const appRoot = el.querySelector('#app')
if (appRoot && appRoot.childNodes.length > 0) {
loading.value = false
observer?.disconnect()
observer = null
}
}
onMounted(() => {
const el = document.getElementById(containerId.value)
if (!el) return
// 初次检查
checkReady(el)
// 监听容器变化以检测子应用挂载完成
observer = new MutationObserver(() => checkReady(el))
observer.observe(el, { childList: true, subtree: true })
// 自动注册模式下,qiankun 将根据 activeRule 与容器自动挂载
})
onBeforeUnmount(() => {
observer?.disconnect()
observer = null
// 自动注册模式下无需手动卸载
})
</script>
<template>
<div style="padding: 12px;">
<div style="margin-bottom: 8px; font-size: 12px; color: #6b7280;">
<span>当前子应用:</span>
<strong>{{ meta?.displayName || '未知' }}</strong>
<span style="margin-left:8px;">入口:</span>
<code>{{ meta?.entry || '-' }}</code>
<span style="margin-left:8px;">容器:</span>
<code>#{{ containerId }}</code>
</div>
<div v-if="loading" class="mfe-loading">子应用加载中…</div>
<div :id="containerId"></div>
</div>
</template>
<style scoped>
.mfe-loading {
padding: 8px 12px;
margin-bottom: 8px;
font-size: 13px;
color: #374151;
background: #f9fafb;
border: 1px solid #e5e7eb;
border-radius: 4px;
}
</style>
\ No newline at end of file
<!--
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @Date: 2025-11-11 11:52:02
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @LastEditTime: 2025-11-11 19:30:18
* @FilePath: \venus\apps\frontend\micro-vue\scrm-base\src\pages\ScrmApp.vue
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<script setup lang="ts">
import { ref, onMounted } from 'vue'
const hostMsg = ref('')
const global = ref<any>(null)
onMounted(() => {
const actions = (window as any).__QIANKUN_ACTIONS__
actions?.onGlobalStateChange?.((s: any) => {
global.value = s
}, true)
})
function broadcast() {
const actions = (window as any).__QIANKUN_ACTIONS__
actions?.setGlobalState?.({ ...(global.value || {}), msg: hostMsg.value })
}
</script>
<template>
<div>
<div style="margin-bottom:12px; display:flex; gap:8px; align-items:center;">
<input
v-model="hostMsg"
placeholder="向子应用广播消息"
style="padding:6px; border:1px solid #ccc; border-radius:4px;"
/>
<button @click="broadcast" style="padding:6px 10px;">广播</button>
<span>当前全局消息:{{ global?.msg }}</span>
</div>
<div id="mfe-scrm-app"></div>
</div>
</template>
<style scoped></style>
\ No newline at end of file
/*
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @Date: 2025-11-10 17:56:22
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @LastEditTime: 2025-11-11 19:22:32
* @FilePath: \venus\apps\frontend\micro-vue\scrm-base\src\router\index.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { createRouter, createWebHistory } from 'vue-router'
import type { RouteRecordRaw } from 'vue-router'
import appsManifest from '../mfe/apps.json'
const routes: RouteRecordRaw[] = [
{
path: '/login',
name: 'Login',
component: () => import('../pages/Login.vue'),
},
{
path: '/',
component: () => import('../layout/BaseLayout.vue'),
meta: { requiresAuth: true },
children: [
{
path: '',
name: 'Home',
meta: { requiresAuth: true },
component: () => import('../pages/Home.vue'),
},
...appsManifest.apps.map((m) => ({
path: m.route,
name: `Micro_${m.dir}`,
meta: { requiresAuth: true },
component: () => import('../pages/MicroHost.vue'),
})),
],
},
]
const router = createRouter({
history: createWebHistory(),
routes,
})
router.beforeEach((to, _from, next) => {
const token = localStorage.getItem('token')
if (to.path === '/login') {
if (token) return next('/')
return next()
}
if (to.meta && (to.meta as any).requiresAuth && !token) {
return next('/login')
}
next()
})
export default router
\ No newline at end of file
import { defineStore } from 'pinia'
export interface UserInfo {
id: string
name: string
roles: string[]
}
interface AuthState {
token: string | null
user: UserInfo | null
}
export const useAuthStore = defineStore('auth', {
state: (): AuthState => ({
token: null,
user: null,
}),
getters: {
isAuthenticated: (s) => !!s.token,
roleSet: (s) => new Set(s.user?.roles || []),
},
actions: {
async login(username: string, password: string) {
if (!username || !password) return false
// Mock: 基于用户名设定角色
const roles = username === 'admin' ? ['admin'] : ['user']
this.token = 'mock-token'
this.user = { id: 'u-' + username, name: username, roles }
// 同步到 qiankun 全局态(如存在)
const actions = (window as any).__QIANKUN_ACTIONS__
actions?.setGlobalState?.({ user: { name: username, roles }, token: this.token })
return true
},
logout() {
this.token = null
this.user = null
const actions = (window as any).__QIANKUN_ACTIONS__
actions?.setGlobalState?.({ user: null, token: null })
},
setFromGlobal(user?: any, token?: string | null) {
if (typeof token !== 'undefined') this.token = token || null
if (user) {
const roles = Array.isArray(user.roles) ? user.roles : []
this.user = { id: 'global', name: user.name || 'User', roles }
}
},
},
persist: {
paths: ['token', 'user'],
},
})
\ No newline at end of file
/*
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @Date: 2025-11-11 14:38:18
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @LastEditTime: 2025-11-11 15:22:33
* @FilePath: \venus\apps\frontend\micro-vue\scrm-base\src\stores\index.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import { createPinia } from 'pinia'
import createPersistedState from 'pinia-plugin-persistedstate'
const pinia = createPinia()
pinia.use(createPersistedState)
export default pinia
\ No newline at end of file
:root {
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
.card {
padding: 2em;
}
#app {
height: 100vh;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}
{
"extends": "@vue/tsconfig/tsconfig.dom.json",
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"types": ["vite/client"],
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["src/**/*.ts", "src/**/*.tsx", "src/**/*.vue"]
}
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": ["node"],
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"verbatimModuleSyntax": true,
"moduleDetection": "force",
"noEmit": true,
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"erasableSyntaxOnly": true,
"noFallthroughCasesInSwitch": true,
"noUncheckedSideEffectImports": true
},
"include": ["vite.config.ts"]
}
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
// https://vite.dev/config/
export default defineConfig({
plugins: [vue()],
})
......@@ -5,6 +5,7 @@
"main": "index.js",
"type": "module",
"scripts": {
"changeset": "pnpm exec changeset",
"test": "echo \"Error: no test specified\" && exit 1",
"lint:prettier": "prettier --write \"**/*.{js,ts,mjs,cjs,json,tsx,css,less,scss,vue,html,md}\"",
"lint:eslint": "eslint --fix \"**/*.{js,ts,mjs,cjs,json,tsx,css,less,scss,vue,html,md}\"",
......@@ -13,8 +14,17 @@
"prepare": "husky",
"precommit": "lint-staged",
"build": "venus build",
"build:ws": "pnpm -r --if-present build",
"lint:ws": "pnpm -r --if-present lint",
"test:ws": "pnpm -r --if-present test",
"dev:playground": "pnpm -r --parallel --filter ./playground/** --filter !./playground/mfe/** dev",
"dev:playground:host": "pnpm -C playground/qiankun-host dev",
"dev:playground:micro": "pnpm -C playground/micro-vue dev",
"release": "pnpm changeset version && pnpm -r --if-present build && pnpm changeset publish",
"postinstall": "node scripts/build.js && pnpm -C packages/cli link --global && node scripts/createShims.cjs",
"venus": "venus"
"venus": "venus",
"clean:vue": "node scripts/cleanApp.js vue",
"clean:react": "node scripts/cleanApp.js react"
},
"config": {
"commitizen": {
......@@ -32,35 +42,37 @@
},
"devDependencies": {
"@venus/cli": "workspace:*",
"@commitlint/cli": "^20.0.0",
"@commitlint/config-conventional": "^20.0.0",
"@cspell/dict-lorem-ipsum": "^4.0.5",
"@eslint/js": "^9.36.0",
"@changesets/changelog-github": "catalog:",
"@changesets/cli": "catalog:",
"@commitlint/cli": "catalog:",
"@commitlint/config-conventional": "catalog:",
"@cspell/dict-lorem-ipsum": "catalog:",
"@eslint/js": "catalog:",
"@rollup/plugin-commonjs": "^28.0.6",
"@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-terser": "^0.4.4",
"@types/node": "^24.5.2",
"@vitejs/plugin-vue": "^6.0.1",
"commitizen": "^4.3.1",
"cspell": "^9.2.1",
"cz-git": "^1.12.0",
"eslint": "^9.36.0",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-prettier": "^5.5.4",
"eslint-plugin-vue": "^10.5.0",
"globals": "^16.4.0",
"husky": "^9.1.7",
"lint-staged": "^16.2.6",
"prettier": "^3.6.2",
"rollup": "^4.52.3",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-typescript2": "^0.36.0",
"rollup-plugin-vue": "^6.0.0",
"typescript": "^5.9.2",
"typescript-eslint": "^8.44.1",
"vue-eslint-parser": "^10.2.0"
"@types/node": "catalog:",
"@vitejs/plugin-vue": "catalog:",
"commitizen": "catalog:",
"cspell": "catalog:",
"cz-git": "catalog:",
"eslint": "catalog:",
"eslint-config-prettier": "catalog:",
"eslint-plugin-prettier": "catalog:",
"eslint-plugin-vue": "catalog:",
"globals":"catalog:",
"husky": "catalog:",
"lint-staged": "catalog:",
"prettier": "catalog:",
"rollup": "catalog:",
"rollup-plugin-postcss": "catalog:",
"rollup-plugin-typescript2": "catalog:",
"rollup-plugin-vue": "catalog:",
"typescript": "catalog:",
"typescript-eslint": "catalog:",
"vue-eslint-parser": "catalog:"
},
"dependencies": {
"vue": "^3.5.22"
"vue": "catalog:"
}
}
......@@ -9,12 +9,14 @@
"preview": "vite preview"
},
"dependencies": {
"vue": "^3.4.27"
"vue": "^3.4.27",
"element-plus": "catalog:"
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.4",
"typescript": "^5.4.5",
"vite": "^5.2.10",
"vue-tsc": "^2.0.21"
}
}
{
"name": "@venus/common-ui",
"version": "0.1.0",
"description": "Common UI wrappers for Vue, based on element-plus",
"type": "module",
"main": "./dist/index.cjs.js",
"module": "./dist/index.esm.js",
"types": "./dist/index.d.ts",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.esm.js",
"require": "./dist/index.cjs.js"
},
"./dist/*": "./dist/*"
},
"files": [
"dist",
"src",
"vue-ui"
],
"scripts": {
"clean": "rimraf dist",
"type-check": "vue-tsc --noEmit",
"build": "node ../../scripts/buildSingle.js common-ui"
},
"author": "liimin",
"license": "ISC",
"dependencies": {
"element-plus": "catalog:"
},
"peerDependencies": {
"vue": "^3.0.0"
},
"devDependencies": {
"@types/node": "catalog:",
"@vue/typescript-plugin": "^3.1.0",
"sass": "catalog:",
"rimraf": "catalog:",
"typescript": "catalog:",
"vue": "catalog:",
"vue-tsc": "catalog:"
},
"buildOptions": {
"name": "VenusCommonUI",
"formats": [
"esm",
"cjs",
"iife"
]
}
}
<script setup lang="ts">
import { ElButton } from "element-plus";
defineProps<{
type?: "primary" | "success" | "warning" | "danger" | "info" | "default";
size?: "large" | "default" | "small";
disabled?: boolean;
loading?: boolean;
plain?: boolean;
round?: boolean;
circle?: boolean;
block?: boolean;
}>();
const emit = defineEmits(["click"]);
function handleClick(e: MouseEvent) {
emit("click", e);
}
</script>
<template>
<!--
二次封装:
- 默认类型设为 primary
- 支持 block(全宽)
- 统一样式类 v-btn
-->
<ElButton
class="v-btn"
:class="[{ 'v-btn--block': !!$props.block }]"
:type="$props.type ?? 'primary'"
v-bind="$attrs"
@click="handleClick"
>
<slot />
</ElButton>
</template>
<style scoped>
.v-btn {
--v-primary: #3b82f6;
}
.v-btn--block {
display: block;
width: 100%;
}
</style>
\ No newline at end of file
<script setup lang="ts">
import { ElInput } from "element-plus";
const props = defineProps<{
modelValue?: string | number;
placeholder?: string;
type?: string;
clearable?: boolean;
disabled?: boolean;
block?: boolean;
}>();
const emit = defineEmits(["update:modelValue"]);
</script>
<template>
<!--
二次封装:
- 统一样式类 v-input
- 支持 block(全宽)
-->
<ElInput
class="v-input"
:class="[{ 'v-input--block': !!props.block }]"
:model-value="props.modelValue"
:placeholder="props.placeholder"
:type="props.type"
:clearable="props.clearable"
:disabled="props.disabled"
v-bind="$attrs"
@update:model-value="emit('update:modelValue', $event)"
>
<template #prepend>
<slot name="prepend" />
</template>
<template #append>
<slot name="append" />
</template>
<template #prefix>
<slot name="prefix" />
</template>
<template #suffix>
<slot name="suffix" />
</template>
</ElInput>
</template>
<style scoped>
.v-input {
/* 可以在此定制输入框的默认样式 */
}
.v-input--block {
display: block;
}
</style>
\ No newline at end of file
export { default as VButton } from "./VButton.vue";
export { default as VInput } from "./VInput.vue";
\ No newline at end of file
/*
* @Author: linlei
* @Date: 2025-11-11 14:03:41
* @LastEditors:
* @LastEditTime: 2025-11-11 14:03:48
* @FilePath: \venus\packages\common-ui\vue-ui\src\index.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
export * from './components';
\ No newline at end of file
/*
* @Author: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @Date: 2025-10-29 14:52:18
* @LastEditors: error: error: git config user.name & please set dead value or install git && error: git config user.email & please set dead value or install git & please set dead value or install git
* @LastEditTime: 2025-11-11 09:38:11
* @FilePath: \venus\packages\components\vue\src\index.ts
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
// 组件导出
export { default as VButton } from "./VButton";
......
......@@ -2,3 +2,197 @@ packages:
- "packages/*"
- "apps/frontend/*"
- "apps/backend/*"
- "playground/*"
- "playground/mfe/*"
- "playground/common-ui/*"
catalog:
'@cspell/dict-lorem-ipsum': ^4.0.5
'@ast-grep/napi': ^0.37.0
'@changesets/changelog-github': ^0.5.1
'@changesets/cli': ^2.29.5
'@changesets/git': ^3.0.4
'@clack/prompts': ^0.10.1
'@commitlint/cli': ^20.0.0
'@commitlint/config-conventional': ^20.0.0
'@ctrl/tinycolor': ^4.1.0
'@eslint/js': ^9.36.0
'@faker-js/faker': ^9.9.0
'@iconify/json': ^2.2.354
'@iconify/tailwind': ^1.2.0
'@iconify/vue': ^5.0.0
'@intlify/core-base': ^11.1.7
'@intlify/unplugin-vue-i18n': ^6.0.8
'@jspm/generator': ^2.6.2
'@manypkg/get-packages': ^3.0.0
'@nolebase/vitepress-plugin-git-changelog': ^2.18.0
'@playwright/test': ^1.53.2
'@pnpm/workspace.read-manifest': ^1000.2.0
'@stylistic/stylelint-plugin': ^3.1.3
'@tailwindcss/nesting': 0.0.0-insiders.565cd3e
'@tailwindcss/typography': ^0.5.16
'@tanstack/vue-query': ^5.81.5
'@tanstack/vue-store': ^0.7.1
'@types/archiver': ^6.0.3
'@types/eslint': ^9.6.1
'@types/html-minifier-terser': ^7.0.2
'@types/json-bigint': ^1.0.4
'@types/jsonwebtoken': ^9.0.10
'@types/lodash.clonedeep': ^4.5.9
'@types/lodash.get': ^4.4.9
'@types/lodash.isequal': ^4.5.8
'@types/lodash.set': ^4.3.9
'@types/node': ^24.5.2
'@types/nprogress': ^0.2.3
'@types/postcss-import': ^14.0.3
'@types/qrcode': ^1.5.5
'@types/qs': ^6.14.0
'@types/sortablejs': ^1.15.8
typescript-eslint: ^8.44.1
'@typescript-eslint/eslint-plugin': ^8.35.1
'@typescript-eslint/parser': ^8.35.1
'@vee-validate/zod': ^4.15.1
'@vite-pwa/vitepress': ^1.0.0
'@vitejs/plugin-vue': ^6.0.1
'@vitejs/plugin-vue-jsx': ^5.0.1
'@vue/tsconfig': ^0.8.1
'@vue/reactivity': ^3.5.17
'@vue/shared': ^3.5.17
'@vue/test-utils': ^2.4.6
'@vueuse/core': ^13.4.0
'@vueuse/integrations': ^13.4.0
'@vueuse/motion': ^3.0.3
ant-design-vue: ^4.2.6
archiver: ^7.0.1
autoprefixer: ^10.4.21
axios: ^1.10.0
commitizen: ^4.3.1
axios-mock-adapter: ^2.1.0
cac: ^6.7.14
chalk: ^5.4.1
cheerio: ^1.1.0
circular-dependency-scanner: ^2.3.0
class-variance-authority: ^0.7.1
clsx: ^2.1.1
commitlint-plugin-function-rules: ^4.0.2
consola: ^3.4.2
cross-env: ^7.0.3
cspell: ^9.2.1
cssnano: ^7.0.7
cz-git: ^1.11.2
czg: ^1.11.1
dayjs: ^1.11.13
defu: ^6.1.4
depcheck: ^1.4.7
dotenv: ^16.6.1
echarts: ^5.6.0
element-plus: ^2.10.2
eslint: ^9.36.0
eslint-config-prettier: ^10.1.8
eslint-plugin-prettier: ^5.5.1
eslint-config-turbo: ^2.5.4
eslint-plugin-command: ^3.3.1
eslint-plugin-eslint-comments: ^3.2.0
eslint-plugin-import-x: ^4.16.1
eslint-plugin-jsdoc: ^50.8.0
eslint-plugin-jsonc: ^2.20.1
eslint-plugin-n: ^17.20.0
eslint-plugin-no-only-tests: ^3.3.0
eslint-plugin-perfectionist: ^4.15.0
eslint-plugin-regexp: ^2.9.0
eslint-plugin-unicorn: ^59.0.1
eslint-plugin-unused-imports: ^4.1.4
eslint-plugin-vitest: ^0.5.4
eslint-plugin-vue: ^10.5.0
execa: ^9.6.0
find-up: ^7.0.0
get-port: ^7.1.0
globals: ^16.3.0
h3: ^1.15.3
husky: ^9.1.7
happy-dom: ^17.6.3
html-minifier-terser: ^7.2.0
is-ci: ^4.1.0
json-bigint: ^1.0.0
jsonc-eslint-parser: ^2.4.0
jsonwebtoken: ^9.0.2
lefthook: ^1.11.14
lodash: ^4.17.21
lint-staged: ^16.2.6
lodash.clonedeep: ^4.5.0
lodash.get: ^4.4.2
lodash.isequal: ^4.5.0
lodash.set: ^4.3.2
lucide-vue-next: ^0.507.0
medium-zoom: ^1.1.0
nitropack: ^2.11.13
nprogress: ^0.2.0
ora: ^8.2.0
pinia: ^3.0.3
pinia-plugin-persistedstate: ^4.4.1
pkg-types: ^2.2.0
playwright: ^1.53.2
postcss: ^8.5.6
postcss-antd-fixes: ^0.2.0
postcss-html: ^1.8.0
postcss-import: ^16.1.1
postcss-preset-env: ^10.2.4
postcss-scss: ^4.0.9
prettier: ^3.6.2
prettier-plugin-tailwindcss: ^0.6.13
publint: ^0.3.12
qrcode: ^1.5.4
qs: ^6.14.0
radix-vue: ^1.9.17
resolve.exports: ^2.0.3
rimraf: ^6.0.1
rollup: ^4.52.3
rollup-plugin-visualizer: ^5.14.0
rollup-plugin-postcss: ^4.0.2
rollup-plugin-vue: ^6.0.0
rollup-plugin-typescript2: ^0.36.0
sass: ^1.89.2
secure-ls: ^2.0.0
sortablejs: ^1.15.6
stylelint: ^16.21.0
stylelint-config-recess-order: ^6.1.0
stylelint-config-recommended: ^16.0.0
stylelint-config-recommended-scss: ^14.1.0
stylelint-config-recommended-vue: ^1.6.1
stylelint-config-standard: ^38.0.0
stylelint-order: ^7.0.0
stylelint-prettier: ^5.0.3
stylelint-scss: ^6.12.1
tailwind-merge: ^2.6.0
tailwindcss: ^3.4.17
tailwindcss-animate: ^1.0.7
theme-colors: ^0.1.0
tippy.js: ^6.3.7
turbo: ^2.5.4
typescript: ^5.9.2
unbuild: ^3.6.1
unplugin-element-plus: ^0.10.0
vee-validate: ^4.15.1
vite: ^7.1.2
vite-plugin-compression: ^0.5.1
vite-plugin-dts: ^4.5.4
vite-plugin-html: ^3.2.2
vite-plugin-lazy-import: ^1.0.7
vite-plugin-pwa: ^1.0.1
vite-plugin-vue-devtools: ^7.7.7
vitepress: ^1.6.3
vitepress-plugin-group-icons: ^1.6.1
vitest: ^3.2.4
qiankun: ^2.10.13
vue: ^3.5.17
vue-eslint-parser: ^10.2.0
vue-i18n: ^11.1.7
vue-json-viewer: ^3.0.4
vue-router: ^4.5.1
vue-tippy: ^6.7.1
vue-tsc: 2.2.10
vxe-pc-ui: ^4.9.29
vxe-table: ^4.16.11
watermark-js-plus: ^1.6.2
zod: ^3.25.67
zod-defaults: ^0.1.3
......@@ -28,6 +28,11 @@ function discoverPackages() {
if (fs.existsSync(path.resolve(cliPath, "package.json"))) {
result.push("cli");
}
// common-ui
const commonUIPath = path.resolve(base, "common-ui");
if (fs.existsSync(path.resolve(commonUIPath, "package.json"))) {
result.push("common-ui");
}
// components/*
const componentsPath = path.resolve(base, "components");
if (fs.existsSync(componentsPath)) {
......
import fs from "node:fs";
import path from "node:path";
// Usage:
// node scripts/cleanApp.js vue <name> [--dir=apps/frontend/vue] [--subdir=playground]
// node scripts/cleanApp.js react <name> [--dir=apps/frontend/react] [--subdir=playground]
// node scripts/cleanApp.js path --path=apps/frontend/vue/my-app-vue
// node scripts/cleanApp.js <template> <name> [--dir=<relative base>] [--subdir=<sub path>]
const args = process.argv.slice(2);
const template = (args[0] || "vue").toLowerCase();
const flags = args.filter(a => typeof a === "string" && a.startsWith("--"));
const positionals = args.filter(a => typeof a === "string" && !a.startsWith("--")).slice(1); // drop template
const dirArg = flags.find(a => a.startsWith("--dir="));
const subdirArg = flags.find(a => a.startsWith("--subdir="));
const pathArg = flags.find(a => a.startsWith("--path="));
const defaultBase = template === "react"
? "apps/frontend/react"
: "apps/frontend/vue";
let target;
if (pathArg) {
const rel = pathArg.slice("--path=".length);
target = path.resolve(process.cwd(), rel);
} else {
const name = positionals[0];
if (!name) {
console.error("请提供要清理的项目名。例如: pnpm run clean:vue my-app-vue");
process.exit(1);
}
let base = dirArg ? dirArg.slice("--dir=".length) : defaultBase;
if (subdirArg) {
base = path.join(base, subdirArg.slice("--subdir=".length));
}
target = path.resolve(process.cwd(), base, name);
}
try {
if (!fs.existsSync(target)) {
console.log(`目标目录不存在,已跳过: ${target}`);
process.exit(0);
}
fs.rmSync(target, { recursive: true, force: true });
console.log(`已清理: ${target}`);
process.exit(0);
} catch (err) {
console.error(`清理失败: ${err?.message || err}`);
process.exit(1);
}
\ No newline at end of file
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!