Commit 064099dd by Jaxon

style: monorepo 根项目配置文件格式化

1 parent 91142695
Showing 143 changed files with 1439 additions and 1132 deletions
export default { export default {
"*.{js,ts,tsx,jsx,vue}": ["prettier --write", "eslint --fix"], "*.{js,ts,tsx,jsx,vue}": [ "prettier --write", "eslint --fix" ],
"*.{md,json,css,less,scss}": ["prettier --write"], "*.{md,json,css,less,scss}": [ "prettier --write" ],
}; };
...@@ -2,7 +2,6 @@ dist ...@@ -2,7 +2,6 @@ dist
dev-dist dev-dist
.local .local
.output.js .output.js
node_modules
.nvmrc .nvmrc
coverage coverage
CODEOWNERS CODEOWNERS
...@@ -14,6 +13,7 @@ CODEOWNERS ...@@ -14,6 +13,7 @@ CODEOWNERS
**/*.ts **/*.ts
**/*.jsx **/*.jsx
**/*.tsx **/*.tsx
**/*.json
**/*.wxs **/*.wxs
**/*.svg **/*.svg
**/*.sh **/*.sh
...@@ -22,8 +22,10 @@ public ...@@ -22,8 +22,10 @@ public
.npmrc .npmrc
*-lock.yaml *-lock.yaml
node_modules
miniprogram_npm miniprogram_npm
uni_modules uni_modules
wxcomponents
# 只格式化 wxml # 只格式化 wxml
!*.wxml !*.wxml
......
...@@ -4,3 +4,4 @@ __tests__ ...@@ -4,3 +4,4 @@ __tests__
coverage coverage
miniprogram_npm miniprogram_npm
uni_modules uni_modules
wxcomponents
{
"servers": {
"ESLint": {
"type": "stdio",
"command": "npx",
"args": [
"@eslint/mcp@latest"
]
}
},
"inputs": []
}
<script setup lang="ts">
import { onMounted } from "vue";
onMounted(() => {
console.log("Vue3 微应用已挂载");
});
</script>
<template> <template>
<div id="micro-app" class="micro-app-container"> <div id="micro-app" class="micro-app-container">
<header class="app-header"> <header class="app-header">
<h1>🚀 Vue3 微前端子应用</h1> <h1>🚀 Vue3 微前端子应用</h1>
<nav class="nav-menu"> <nav class="nav-menu">
<router-link to="/" class="nav-link">首页</router-link> <router-link class="nav-link" to="/">
<router-link to="/about" class="nav-link">关于</router-link> 首页
<router-link to="/communication" class="nav-link">通信示例</router-link> </router-link>
<router-link to="/user" class="nav-link">用户管理</router-link> <router-link class="nav-link" to="/about">
<router-link to="/settings" class="nav-link">系统设置</router-link> 关于
</router-link>
<router-link class="nav-link" to="/communication">
通信示例
</router-link>
<router-link class="nav-link" to="/user">
用户管理
</router-link>
<router-link class="nav-link" to="/settings">
系统设置
</router-link>
</nav> </nav>
</header> </header>
<main class="app-main"> <main class="app-main">
<router-view v-slot="{ Component }"> <router-view v-slot="{ Component }">
<transition name="fade" mode="out-in"> <transition mode="out-in" name="fade">
<component :is="Component" /> <component :is="Component" />
</transition> </transition>
</router-view> </router-view>
...@@ -33,6 +35,14 @@ onMounted(() => { ...@@ -33,6 +35,14 @@ onMounted(() => {
</div> </div>
</template> </template>
<script setup lang="ts">
import { onMounted } from "vue";
onMounted(() => {
console.log("Vue3 微应用已挂载");
});
</script>
<style scoped> <style scoped>
.micro-app-container { .micro-app-container {
display: flex; display: flex;
......
...@@ -164,7 +164,7 @@ class SubAppCommunicationManager { ...@@ -164,7 +164,7 @@ class SubAppCommunicationManager {
// 注意:这里需要基座的 communication manager 来处理通知添加逻辑 // 注意:这里需要基座的 communication manager 来处理通知添加逻辑
// 所以我们实际上是触发一个状态变化,让基座来处理 // 所以我们实际上是触发一个状态变化,让基座来处理
this.setGlobalState({ this.setGlobalState({
notifications: [newNotification] as any, // 基座会合并到现有通知列表 notifications: [ newNotification ] as any, // 基座会合并到现有通知列表
}); });
} }
......
<script setup lang="ts">
// About 页面
</script>
<template> <template>
<div class="about-view"> <div class="about-view">
<div class="content-card"> <div class="content-card">
...@@ -52,20 +48,28 @@ ...@@ -52,20 +48,28 @@
<section class="section"> <section class="section">
<h2>快速开始</h2> <h2>快速开始</h2>
<div class="code-block"> <div class="code-block">
<pre><code># 安装依赖 <pre>
<code>
# 安装依赖
pnpm install pnpm install
# 启动开发服务器 # 启动开发服务器
pnpm dev pnpm dev
# 构建生产版本 # 构建生产版本
pnpm build</code></pre> pnpm build
</code>
</pre>
</div> </div>
</section> </section>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts">
// About 页面
</script>
<style scoped> <style scoped>
.about-view { .about-view {
max-width: 900px; max-width: 900px;
......
<script setup lang="ts">
import type { GlobalState } from "@/utils/communication";
import { computed, ref } from "vue";
import { useRoute } from "vue-router";
import { notify, useGlobalState } from "@/utils/communication";
import { qiankunWindow } from "vite-plugin-qiankun/dist/helper";
const route = useRoute();
const counter = ref(0);
const globalState = ref<GlobalState | null>(null);
const runMode = computed(() => {
return qiankunWindow.__POWERED_BY_QIANKUN__ ? "🔗 基座模式" : "🏠 独立模式";
});
const currentRoute = computed(() => route.fullPath);
const increment = () => {
counter.value++;
};
const decrement = () => {
counter.value--;
};
// 监听主应用传递的全局状态
if (qiankunWindow.__POWERED_BY_QIANKUN__) {
useGlobalState((state, prev) => {
console.log("📥 接收到主应用数据:", state);
console.log("📝 之前的数据:", prev);
globalState.value = state;
});
}
// 发送测试通知到主应用
const sendTestNotification = () => {
notify("success", "来自微应用的通知", `这是一条测试通知,发送时间: ${new Date().toLocaleTimeString()}`);
};
</script>
<template> <template>
<div class="home-view"> <div class="home-view">
<div class="hero-section"> <div class="hero-section">
<h1 class="hero-title">🎉 欢迎使用 Vue3 微前端子应用AAA</h1> <h1 class="hero-title">
<p class="hero-subtitle">基于 qiankun + Vue3 + Vite + TypeScript 构建</p> 🎉 欢迎使用 Vue3 微前端子应用AAA
</h1>
<p class="hero-subtitle">
基于 qiankun + Vue3 + Vite + TypeScript 构建
</p>
</div> </div>
<div class="cards-grid"> <div class="cards-grid">
<div class="card"> <div class="card">
<div class="card-icon">🚀</div> <div class="card-icon">
🚀
</div>
<h3>快速启动</h3> <h3>快速启动</h3>
<p>使用 Vite 构建,开发体验极速</p> <p>使用 Vite 构建,开发体验极速</p>
</div> </div>
<div class="card"> <div class="card">
<div class="card-icon">🎯</div> <div class="card-icon">
🎯
</div>
<h3>独立运行</h3> <h3>独立运行</h3>
<p>支持独立开发和集成运行两种模式</p> <p>支持独立开发和集成运行两种模式</p>
</div> </div>
<div class="card"> <div class="card">
<div class="card-icon">🔧</div> <div class="card-icon">
🔧
</div>
<h3>开箱即用</h3> <h3>开箱即用</h3>
<p>集成路由、状态管理等常用功能</p> <p>集成路由、状态管理等常用功能</p>
</div> </div>
<div class="card"> <div class="card">
<div class="card-icon">💡</div> <div class="card-icon">
💡
</div>
<h3>TypeScript</h3> <h3>TypeScript</h3>
<p>完整的类型支持,开发更安全</p> <p>完整的类型支持,开发更安全</p>
</div> </div>
<div class="card"> <div class="card">
<div class="card-icon">💡</div> <div class="card-icon">
💡
</div>
<p>{{ globalState }}</p> <p>{{ globalState }}</p>
</div> </div>
</div> </div>
...@@ -92,8 +64,12 @@ const sendTestNotification = () => { ...@@ -92,8 +64,12 @@ const sendTestNotification = () => {
<div class="info-item"> <div class="info-item">
<span class="info-label">计数器:</span> <span class="info-label">计数器:</span>
<span class="info-value">{{ counter }}</span> <span class="info-value">{{ counter }}</span>
<button @click="increment" class="btn-primary">+1</button> <button class="btn-primary" @click="increment">
<button @click="decrement" class="btn-secondary">-1</button> +1
</button>
<button class="btn-secondary" @click="decrement">
-1
</button>
</div> </div>
</div> </div>
</div> </div>
...@@ -104,7 +80,9 @@ const sendTestNotification = () => { ...@@ -104,7 +80,9 @@ const sendTestNotification = () => {
<div class="info-content"> <div class="info-content">
<!-- 用户信息 --> <!-- 用户信息 -->
<div v-if="globalState?.user" class="data-group"> <div v-if="globalState?.user" class="data-group">
<h3 class="data-group-title">👤 用户信息</h3> <h3 class="data-group-title">
👤 用户信息
</h3>
<div class="info-item"> <div class="info-item">
<span class="info-label">用户ID:</span> <span class="info-label">用户ID:</span>
<span class="info-value">{{ globalState.user.id }}</span> <span class="info-value">{{ globalState.user.id }}</span>
...@@ -125,7 +103,9 @@ const sendTestNotification = () => { ...@@ -125,7 +103,9 @@ const sendTestNotification = () => {
<!-- 主题配置 --> <!-- 主题配置 -->
<div v-if="globalState?.theme" class="data-group"> <div v-if="globalState?.theme" class="data-group">
<h3 class="data-group-title">🎨 主题配置</h3> <h3 class="data-group-title">
🎨 主题配置
</h3>
<div class="info-item"> <div class="info-item">
<span class="info-label">主题模式:</span> <span class="info-label">主题模式:</span>
<span class="info-value">{{ globalState.theme.mode }}</span> <span class="info-value">{{ globalState.theme.mode }}</span>
...@@ -142,7 +122,9 @@ const sendTestNotification = () => { ...@@ -142,7 +122,9 @@ const sendTestNotification = () => {
<!-- 配置信息 --> <!-- 配置信息 -->
<div v-if="globalState?.config" class="data-group"> <div v-if="globalState?.config" class="data-group">
<h3 class="data-group-title">⚙️ 配置信息</h3> <h3 class="data-group-title">
⚙️ 配置信息
</h3>
<div class="info-item"> <div class="info-item">
<span class="info-label">API地址:</span> <span class="info-label">API地址:</span>
<span class="info-value">{{ globalState.config.apiBaseUrl }}</span> <span class="info-value">{{ globalState.config.apiBaseUrl }}</span>
...@@ -155,14 +137,15 @@ const sendTestNotification = () => { ...@@ -155,14 +137,15 @@ const sendTestNotification = () => {
<!-- 通知消息 --> <!-- 通知消息 -->
<div v-if="globalState?.notifications && globalState.notifications.length > 0" class="data-group"> <div v-if="globalState?.notifications && globalState.notifications.length > 0" class="data-group">
<h3 class="data-group-title">📢 通知消息 ({{ globalState.notifications.length }})</h3> <h3 class="data-group-title">
<div 📢 通知消息 ({{ globalState.notifications.length }})
v-for="notification in globalState.notifications.slice(0, 3)" </h3>
<div v-for="notification in globalState.notifications.slice(0, 3)"
:key="notification.id" :key="notification.id"
class="notification-item"> class="notification-item">
<span class="notification-type" :class="[notification.type]">{{ notification.type }}</span> <span class="notification-type" :class="[notification.type]">{{ notification.type }}</span>
<span class="notification-title">{{ notification.title }}</span> <span class="notification-title">{{ notification.title }}</span>
<span class="notification-from" v-if="notification.from">来自: {{ notification.from }}</span> <span v-if="notification.from" class="notification-from">来自: {{ notification.from }}</span>
</div> </div>
</div> </div>
...@@ -174,12 +157,56 @@ const sendTestNotification = () => { ...@@ -174,12 +157,56 @@ const sendTestNotification = () => {
<!-- 操作按钮 --> <!-- 操作按钮 -->
<div class="actions"> <div class="actions">
<button @click="sendTestNotification" class="btn-action">📤 发送测试通知到主应用</button> <button class="btn-action" @click="sendTestNotification">
📤 发送测试通知到主应用
</button>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts">
import type { GlobalState } from "@/utils/communication";
import { computed, ref } from "vue";
import { useRoute } from "vue-router";
import { notify, useGlobalState } from "@/utils/communication";
import { qiankunWindow } from "vite-plugin-qiankun/dist/helper";
const route = useRoute();
const counter = ref(0);
const globalState = ref<GlobalState | null>(null);
const runMode = computed(() => {
return qiankunWindow.__POWERED_BY_QIANKUN__ ? "🔗 基座模式" : "🏠 独立模式";
});
const currentRoute = computed(() => route.fullPath);
const increment = () => {
counter.value++;
};
const decrement = () => {
counter.value--;
};
// 监听主应用传递的全局状态
if (qiankunWindow.__POWERED_BY_QIANKUN__) {
useGlobalState((state, prev) => {
console.log("📥 接收到主应用数据:", state);
console.log("📝 之前的数据:", prev);
globalState.value = state;
});
}
// 发送测试通知到主应用
const sendTestNotification = () => {
notify("success", "来自微应用的通知", `这是一条测试通知,发送时间: ${new Date().toLocaleTimeString()}`);
};
</script>
<style scoped> <style scoped>
.home-view { .home-view {
max-width: 1200px; max-width: 1200px;
......
<template>
<div class="notfound-view">
<div class="content-card">
<div class="error-code">
404
</div>
<h1>页面未找到</h1>
<p>抱歉,您访问的页面不存在或已被删除</p>
<button class="btn-home" @click="goHome">
🏠 返回首页
</button>
</div>
</div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
...@@ -8,17 +23,6 @@ const goHome = () => { ...@@ -8,17 +23,6 @@ const goHome = () => {
}; };
</script> </script>
<template>
<div class="notfound-view">
<div class="content-card">
<div class="error-code">404</div>
<h1>页面未找到</h1>
<p>抱歉,您访问的页面不存在或已被删除</p>
<button @click="goHome" class="btn-home">🏠 返回首页</button>
</div>
</div>
</template>
<style scoped> <style scoped>
.notfound-view { .notfound-view {
display: flex; display: flex;
......
<script setup lang="ts">
import { reactive } from "vue";
interface Settings {
darkMode: boolean;
language: string;
notifications: {
desktop: boolean;
email: boolean;
sms: boolean;
};
security: {
sessionTimeout: number;
twoFactor: boolean;
};
theme: string;
timezone: string;
}
const defaultSettings: Settings = {
theme: "purple",
darkMode: false,
notifications: {
desktop: true,
email: true,
sms: false,
},
language: "zh-CN",
timezone: "Asia/Shanghai",
security: {
twoFactor: false,
sessionTimeout: 30,
},
};
const settings = reactive<Settings>({ ...defaultSettings });
const saveSettings = () => {
console.log("保存设置:", settings);
alert("设置已保存!");
};
const resetSettings = () => {
if (confirm("确定要重置为默认设置吗?")) {
Object.assign(settings, defaultSettings);
alert("已重置为默认设置!");
}
};
</script>
<template> <template>
<div class="settings-view"> <div class="settings-view">
<div class="content-card"> <div class="content-card">
...@@ -59,15 +9,25 @@ const resetSettings = () => { ...@@ -59,15 +9,25 @@ const resetSettings = () => {
<div class="setting-item"> <div class="setting-item">
<label>主题色:</label> <label>主题色:</label>
<select v-model="settings.theme" class="select-input"> <select v-model="settings.theme" class="select-input">
<option value="purple">紫色</option> <option value="purple">
<option value="blue">蓝色</option> 紫色
<option value="green">绿色</option> </option>
<option value="orange">橙色</option> <option value="blue">
蓝色
</option>
<option value="green">
绿色
</option>
<option value="orange">
橙色
</option>
</select> </select>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>暗黑模式:</label> <label>暗黑模式:</label>
<input type="checkbox" v-model="settings.darkMode" class="checkbox-input" /> <input v-model="settings.darkMode"
class="checkbox-input"
type="checkbox" />
</div> </div>
</div> </div>
...@@ -75,15 +35,21 @@ const resetSettings = () => { ...@@ -75,15 +35,21 @@ const resetSettings = () => {
<h2>🔔 通知设置</h2> <h2>🔔 通知设置</h2>
<div class="setting-item"> <div class="setting-item">
<label>桌面通知:</label> <label>桌面通知:</label>
<input type="checkbox" v-model="settings.notifications.desktop" class="checkbox-input" /> <input v-model="settings.notifications.desktop"
class="checkbox-input"
type="checkbox" />
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>邮件通知:</label> <label>邮件通知:</label>
<input type="checkbox" v-model="settings.notifications.email" class="checkbox-input" /> <input v-model="settings.notifications.email"
class="checkbox-input"
type="checkbox" />
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>短信通知:</label> <label>短信通知:</label>
<input type="checkbox" v-model="settings.notifications.sms" class="checkbox-input" /> <input v-model="settings.notifications.sms"
class="checkbox-input"
type="checkbox" />
</div> </div>
</div> </div>
...@@ -92,17 +58,29 @@ const resetSettings = () => { ...@@ -92,17 +58,29 @@ const resetSettings = () => {
<div class="setting-item"> <div class="setting-item">
<label>界面语言:</label> <label>界面语言:</label>
<select v-model="settings.language" class="select-input"> <select v-model="settings.language" class="select-input">
<option value="zh-CN">简体中文</option> <option value="zh-CN">
<option value="en-US">English</option> 简体中文
<option value="ja-JP">日本語</option> </option>
<option value="en-US">
English
</option>
<option value="ja-JP">
日本語
</option>
</select> </select>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>时区:</label> <label>时区:</label>
<select v-model="settings.timezone" class="select-input"> <select v-model="settings.timezone" class="select-input">
<option value="Asia/Shanghai">北京时间 (UTC+8)</option> <option value="Asia/Shanghai">
<option value="America/New_York">纽约时间 (UTC-5)</option> 北京时间 (UTC+8)
<option value="Europe/London">伦敦时间 (UTC+0)</option> </option>
<option value="America/New_York">
纽约时间 (UTC-5)
</option>
<option value="Europe/London">
伦敦时间 (UTC+0)
</option>
</select> </select>
</div> </div>
</div> </div>
...@@ -111,23 +89,28 @@ const resetSettings = () => { ...@@ -111,23 +89,28 @@ const resetSettings = () => {
<h2>🔒 安全设置</h2> <h2>🔒 安全设置</h2>
<div class="setting-item"> <div class="setting-item">
<label>双因素认证:</label> <label>双因素认证:</label>
<input type="checkbox" v-model="settings.security.twoFactor" class="checkbox-input" /> <input v-model="settings.security.twoFactor"
class="checkbox-input"
type="checkbox" />
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>会话超时 (分钟):</label> <label>会话超时 (分钟):</label>
<input <input v-model="settings.security.sessionTimeout"
type="number"
v-model="settings.security.sessionTimeout"
class="number-input" class="number-input"
max="120"
min="5" min="5"
max="120" /> type="number" />
</div> </div>
</div> </div>
</div> </div>
<div class="actions"> <div class="actions">
<button @click="saveSettings" class="btn-save">💾 保存设置</button> <button class="btn-save" @click="saveSettings">
<button @click="resetSettings" class="btn-reset">🔄 重置默认</button> 💾 保存设置
</button>
<button class="btn-reset" @click="resetSettings">
🔄 重置默认
</button>
</div> </div>
<div class="current-settings"> <div class="current-settings">
...@@ -138,6 +121,57 @@ const resetSettings = () => { ...@@ -138,6 +121,57 @@ const resetSettings = () => {
</div> </div>
</template> </template>
<script setup lang="ts">
import { reactive } from "vue";
interface Settings {
darkMode: boolean;
language: string;
notifications: {
desktop: boolean;
email: boolean;
sms: boolean;
};
security: {
sessionTimeout: number;
twoFactor: boolean;
};
theme: string;
timezone: string;
}
const defaultSettings: Settings = {
theme: "purple",
darkMode: false,
notifications: {
desktop: true,
email: true,
sms: false,
},
language: "zh-CN",
timezone: "Asia/Shanghai",
security: {
twoFactor: false,
sessionTimeout: 30,
},
};
const settings = reactive<Settings>({ ...defaultSettings });
const saveSettings = () => {
console.log("保存设置:", settings);
/* eslint-disable no-alert */
alert("设置已保存!");
};
const resetSettings = () => {
if (confirm("确定要重置为默认设置吗?")) {
Object.assign(settings, defaultSettings);
alert("已重置为默认设置!");
}
};
</script>
<style scoped> <style scoped>
.settings-view { .settings-view {
max-width: 1200px; max-width: 1200px;
......
<template>
<div class="user-view">
<div class="content-card">
<h1>👥 用户管理</h1>
<div class="toolbar">
<button class="btn-add" @click="addUser">
➕ 新增用户
</button>
</div>
<div class="table-container">
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>邮箱</th>
<th>角色</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users" :key="user.id">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
<td>{{ user.email }}</td>
<td>
<span class="badge" :class="`badge-${user.role}`">
{{ user.role }}
</span>
</td>
<td>
<span class="status" :class="user.active ? 'status-active' : 'status-inactive'">
{{ user.active ? "在线" : "离线" }}
</span>
</td>
<td>
<button class="btn-edit" @click="editUser(user)">
编辑
</button>
<button class="btn-delete" @click="deleteUser(user.id)">
删除
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { ref } from "vue";
...@@ -53,65 +107,17 @@ const addUser = () => { ...@@ -53,65 +107,17 @@ const addUser = () => {
const editUser = (user: User) => { const editUser = (user: User) => {
console.log("编辑用户:", user); console.log("编辑用户:", user);
alert(`编辑用户: ${user.name}`);
}; };
const deleteUser = (id: number) => { const deleteUser = (id: number) => {
const index = users.value.findIndex((u) => u.id === id); const index = users.value.findIndex((u) => u.id === id);
// eslint-disable-next-line
if (index !== -1 && confirm(`确定要删除用户 ${users.value[index].name} 吗?`)) { if (index !== -1 && confirm(`确定要删除用户 ${users.value[index].name} 吗?`)) {
users.value.splice(index, 1); users.value.splice(index, 1);
} }
}; };
</script> </script>
<template>
<div class="user-view">
<div class="content-card">
<h1>👥 用户管理</h1>
<div class="toolbar">
<button @click="addUser" class="btn-add">➕ 新增用户</button>
</div>
<div class="table-container">
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>邮箱</th>
<th>角色</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users" :key="user.id">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
<td>{{ user.email }}</td>
<td>
<span class="badge" :class="`badge-${user.role}`">
{{ user.role }}
</span>
</td>
<td>
<span class="status" :class="user.active ? 'status-active' : 'status-inactive'">
{{ user.active ? "在线" : "离线" }}
</span>
</td>
<td>
<button @click="editUser(user)" class="btn-edit">编辑</button>
<button @click="deleteUser(user.id)" class="btn-delete">删除</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<style scoped> <style scoped>
.user-view { .user-view {
max-width: 1200px; max-width: 1200px;
......
...@@ -21,7 +21,7 @@ export default defineConfig(({ mode, command }) => { ...@@ -21,7 +21,7 @@ export default defineConfig(({ mode, command }) => {
vueJsx(), vueJsx(),
// 自动导入 Vue 相关函数 // 自动导入 Vue 相关函数
AutoImport({ AutoImport({
imports: ["vue", "vue-router", "pinia"], imports: [ "vue", "vue-router", "pinia" ],
dts: "src/auto-imports.d.ts", dts: "src/auto-imports.d.ts",
eslintrc: { eslintrc: {
enabled: false, enabled: false,
...@@ -38,7 +38,7 @@ export default defineConfig(({ mode, command }) => { ...@@ -38,7 +38,7 @@ export default defineConfig(({ mode, command }) => {
], ],
resolve: { resolve: {
alias: { alias: {
"@": resolve(__dirname, "src"), "@": resolve(import.meta.dirname, "src"),
}, },
}, },
server: { server: {
......
...@@ -26,8 +26,8 @@ const mockUsers = [ ...@@ -26,8 +26,8 @@ const mockUsers = [
avatar: "👤", avatar: "👤",
email: "admin@scrm.com", email: "admin@scrm.com",
phone: "13800138000", phone: "13800138000",
roles: ["admin", "user"], roles: [ "admin", "user" ],
permissions: ["*:*:*"], permissions: [ "*:*:*" ],
department: "技术部", department: "技术部",
position: "系统管理员", position: "系统管理员",
status: 1, status: 1,
...@@ -43,8 +43,8 @@ const mockUsers = [ ...@@ -43,8 +43,8 @@ const mockUsers = [
avatar: "👨", avatar: "👨",
email: "user@scrm.com", email: "user@scrm.com",
phone: "13800138001", phone: "13800138001",
roles: ["user"], roles: [ "user" ],
permissions: ["user:read", "user:write"], permissions: [ "user:read", "user:write" ],
department: "销售部", department: "销售部",
position: "销售专员", position: "销售专员",
status: 1, status: 1,
...@@ -60,8 +60,8 @@ const mockUsers = [ ...@@ -60,8 +60,8 @@ const mockUsers = [
avatar: "🧑", avatar: "🧑",
email: "guest@scrm.com", email: "guest@scrm.com",
phone: "13800138002", phone: "13800138002",
roles: ["guest"], roles: [ "guest" ],
permissions: ["user:read"], permissions: [ "user:read" ],
department: "访客", department: "访客",
position: "访客", position: "访客",
status: 1, status: 1,
......
...@@ -15,7 +15,7 @@ export const config = { ...@@ -15,7 +15,7 @@ export const config = {
baseURL: "https://dj.glsx.com.cn/rop-dj-smartcarlife/router", baseURL: "https://dj.glsx.com.cn/rop-dj-smartcarlife/router",
appkey: "d7ffc3346fc9a45bccaaa35300d59022", appkey: "d7ffc3346fc9a45bccaaa35300d59022",
secret: "4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353", secret: "4bc07f8868374c49a4661d603377e3106fc9a45bccaaa353",
timeout: 50000, timeout: 50_000,
result: { result: {
data_key: "data", data_key: "data",
message_key: "message", message_key: "message",
...@@ -28,7 +28,7 @@ export const config = { ...@@ -28,7 +28,7 @@ export const config = {
baseURL: "https://scrm.glsx.com.cn/rop-scrm-shopmall/router", baseURL: "https://scrm.glsx.com.cn/rop-scrm-shopmall/router",
appkey: "48e5e13229b82c1b4e6e8c96151f0637", appkey: "48e5e13229b82c1b4e6e8c96151f0637",
secret: "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b", secret: "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b",
timeout: 50000, timeout: 50_000,
result: { result: {
data_key: "data", data_key: "data",
message_key: "message", message_key: "message",
...@@ -41,7 +41,7 @@ export const config = { ...@@ -41,7 +41,7 @@ export const config = {
baseURL: "http://didicb.glsx.com.cn/router?method=glsx.accounts.biz.common.pictureUpload", baseURL: "http://didicb.glsx.com.cn/router?method=glsx.accounts.biz.common.pictureUpload",
appkey: "48e5e13229b82c1b4e6e8c96151f0637", appkey: "48e5e13229b82c1b4e6e8c96151f0637",
secret: "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b", secret: "c24619ed7fef02a0ae16328146bca5f97cc6493957a2137b",
timeout: 50000, timeout: 50_000,
result: { result: {
data_key: "data", data_key: "data",
message_key: "message", message_key: "message",
......
<template>
<div class="notification-center">
<!-- 通知图标按钮 -->
<div class="notification-badge" @click="togglePanel">
<span class="icon">🔔</span>
<span v-if="unreadCount > 0" class="badge">{{ unreadCount }}</span>
</div>
<!-- 通知面板 -->
<transition name="slide">
<div v-if="showPanel" class="notification-panel">
<div class="panel-header">
<h3>通知中心</h3>
<button v-if="notifications.length > 0"
class="clear-btn"
@click="clearAll">
清空
</button>
</div>
<div class="notification-list">
<div v-for="notification in notifications"
:key="notification.id"
class="notification-item"
:class="[`type-${notification.type}`]">
<div class="notification-icon">
{{ getIcon(notification.type) }}
</div>
<div class="notification-content">
<div class="notification-title">
{{ notification.title }}
</div>
<div class="notification-message">
{{ notification.message }}
</div>
<div class="notification-meta">
<span v-if="notification.from" class="from">来自: {{ notification.from }}</span>
<span class="time">{{ formatTime(notification.timestamp) }}</span>
</div>
</div>
<button class="close-btn" @click="removeNotification(notification.id)">
✕
</button>
</div>
<div v-if="notifications.length === 0" class="empty-state">
<div class="empty-icon">
📭
</div>
<div class="empty-text">
暂无通知
</div>
</div>
</div>
</div>
</transition>
</div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import type { GlobalState } from "../qiankun"; import type { GlobalState } from "../qiankun";
...@@ -78,52 +137,6 @@ onUnmounted(() => { ...@@ -78,52 +137,6 @@ onUnmounted(() => {
}); });
</script> </script>
<template>
<div class="notification-center">
<!-- 通知图标按钮 -->
<div class="notification-badge" @click="togglePanel">
<span class="icon">🔔</span>
<span v-if="unreadCount > 0" class="badge">{{ unreadCount }}</span>
</div>
<!-- 通知面板 -->
<transition name="slide">
<div v-if="showPanel" class="notification-panel">
<div class="panel-header">
<h3>通知中心</h3>
<button v-if="notifications.length > 0" @click="clearAll" class="clear-btn">清空</button>
</div>
<div class="notification-list">
<div
v-for="notification in notifications"
:key="notification.id"
class="notification-item"
:class="[`type-${notification.type}`]">
<div class="notification-icon">
{{ getIcon(notification.type) }}
</div>
<div class="notification-content">
<div class="notification-title">{{ notification.title }}</div>
<div class="notification-message">{{ notification.message }}</div>
<div class="notification-meta">
<span v-if="notification.from" class="from">来自: {{ notification.from }}</span>
<span class="time">{{ formatTime(notification.timestamp) }}</span>
</div>
</div>
<button @click="removeNotification(notification.id)" class="close-btn">✕</button>
</div>
<div v-if="notifications.length === 0" class="empty-state">
<div class="empty-icon">📭</div>
<div class="empty-text">暂无通知</div>
</div>
</div>
</div>
</transition>
</div>
</template>
<style scoped> <style scoped>
.notification-center { .notification-center {
position: relative; position: relative;
......
<template>
<div class="sidebar-menu-item">
<!-- 菜单项本身 -->
<div class="menu-item-content"
:class="{
active: isActive,
'has-children': hasChildren,
[`level-${menu.level || 1}`]: true,
}"
@click="handleClick">
<!-- 展开/收起图标 -->
<span v-if="hasChildren"
class="expand-icon"
@click.stop="handleToggle">
{{ isExpanded ? "▼" : "▶" }}
</span>
<!-- 菜单图标 -->
<span v-if="menu.icon" class="menu-icon">{{ menu.icon }}</span>
<!-- 菜单标题 -->
<span class="menu-title">{{ menu.title }}</span>
<!-- 徽章 -->
<span v-if="menu.meta?.badge" class="menu-badge">
{{ menu.meta.badge }}
</span>
</div>
<!-- 子菜单 -->
<transition name="submenu-expand">
<div v-if="hasChildren && isExpanded" class="submenu">
<SidebarMenuItem v-for="child in menu.children"
:key="child.id"
:active-path="activePath"
:expanded-keys="expandedKeys"
:menu="child"
@click="$emit('click', $event)"
@toggle="$emit('toggle', $event)" />
</div>
</transition>
</div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import type { MenuItem } from "@/types/menu"; import type { MenuItem } from "@/types/menu";
import { computed } from "vue"; import { computed } from "vue";
// eslint-disable-next-line
import SidebarMenuItem from "./SidebarMenuItem.vue"; import SidebarMenuItem from "./SidebarMenuItem.vue";
interface Props { interface Props {
...@@ -47,50 +92,6 @@ const handleToggle = () => { ...@@ -47,50 +92,6 @@ const handleToggle = () => {
}; };
</script> </script>
<template>
<div class="sidebar-menu-item">
<!-- 菜单项本身 -->
<div
class="menu-item-content"
:class="{
active: isActive,
'has-children': hasChildren,
[`level-${menu.level || 1}`]: true,
}"
@click="handleClick">
<!-- 展开/收起图标 -->
<span v-if="hasChildren" class="expand-icon" @click.stop="handleToggle">
{{ isExpanded ? "▼" : "▶" }}
</span>
<!-- 菜单图标 -->
<span v-if="menu.icon" class="menu-icon">{{ menu.icon }}</span>
<!-- 菜单标题 -->
<span class="menu-title">{{ menu.title }}</span>
<!-- 徽章 -->
<span v-if="menu.meta?.badge" class="menu-badge">
{{ menu.meta.badge }}
</span>
</div>
<!-- 子菜单 -->
<transition name="submenu-expand">
<div v-if="hasChildren && isExpanded" class="submenu">
<SidebarMenuItem
v-for="child in menu.children"
:key="child.id"
:menu="child"
:active-path="activePath"
:expanded-keys="expandedKeys"
@click="$emit('click', $event)"
@toggle="$emit('toggle', $event)" />
</div>
</transition>
</div>
</template>
<style scoped> <style scoped>
.sidebar-menu-item { .sidebar-menu-item {
width: 100%; width: 100%;
......
<template>
<div class="user-info">
<!-- 已登录状态 -->
<div v-if="userStore.isLoggedIn"
class="user-card"
@click="toggleDropdown">
<div class="user-avatar">
{{ userStore.userAvatar || "👤" }}
</div>
<div class="user-details">
<div class="user-name">
{{ userStore.userName }}
</div>
<div class="user-role">
{{ getRoleText() }}
</div>
</div>
<div class="dropdown-icon">
▼
</div>
<!-- 下拉菜单 -->
<div v-if="showDropdown"
class="user-dropdown"
@click.stop>
<div class="dropdown-header">
<div class="dropdown-avatar">
{{ userStore.userAvatar || "👤" }}
</div>
<div class="dropdown-info">
<div class="dropdown-name">
{{ userStore.userName }}
</div>
<div class="dropdown-id">
ID: {{ userStore.userId }}
</div>
</div>
</div>
<div class="dropdown-divider"></div>
<div class="dropdown-menu">
<div class="menu-item" @click="handleProfile">
<span class="menu-icon">👤</span>
<span>个人中心</span>
</div>
<div class="menu-item" @click="handleSettings">
<span class="menu-icon">⚙️</span>
<span>设置</span>
</div>
</div>
<div class="dropdown-divider"></div>
<div class="dropdown-footer">
<button class="logout-btn" @click="handleLogout">
<span class="logout-icon">🚪</span>
<span>退出登录</span>
</button>
</div>
</div>
</div>
<!-- 未登录状态 -->
<div v-else class="user-empty">
<router-link class="login-link" to="/login">
登录
</router-link>
</div>
<!-- 确认对话框 -->
<div v-if="showConfirmDialog"
class="confirm-dialog-overlay"
@click="showConfirmDialog = false">
<div class="confirm-dialog" @click.stop>
<div class="dialog-header">
<span class="dialog-icon">❓</span>
<h3 class="dialog-title">
确认退出
</h3>
</div>
<div class="dialog-content">
<p>确定要退出登录吗?</p>
</div>
<div class="dialog-footer">
<button class="dialog-btn cancel-btn" @click="showConfirmDialog = false">
取消
</button>
<button class="dialog-btn confirm-btn" @click="confirmLogout">
确认退出
</button>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, onUnmounted, ref } from "vue"; import { onMounted, onUnmounted, ref } from "vue";
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
...@@ -92,75 +189,6 @@ onUnmounted(() => { ...@@ -92,75 +189,6 @@ onUnmounted(() => {
}); });
</script> </script>
<template>
<div class="user-info">
<!-- 已登录状态 -->
<div v-if="userStore.isLoggedIn" class="user-card" @click="toggleDropdown">
<div class="user-avatar">{{ userStore.userAvatar || "👤" }}</div>
<div class="user-details">
<div class="user-name">{{ userStore.userName }}</div>
<div class="user-role">{{ getRoleText() }}</div>
</div>
<div class="dropdown-icon">▼</div>
<!-- 下拉菜单 -->
<div v-if="showDropdown" class="user-dropdown" @click.stop>
<div class="dropdown-header">
<div class="dropdown-avatar">{{ userStore.userAvatar || "👤" }}</div>
<div class="dropdown-info">
<div class="dropdown-name">{{ userStore.userName }}</div>
<div class="dropdown-id">ID: {{ userStore.userId }}</div>
</div>
</div>
<div class="dropdown-divider"></div>
<div class="dropdown-menu">
<div class="menu-item" @click="handleProfile">
<span class="menu-icon">👤</span>
<span>个人中心</span>
</div>
<div class="menu-item" @click="handleSettings">
<span class="menu-icon">⚙️</span>
<span>设置</span>
</div>
</div>
<div class="dropdown-divider"></div>
<div class="dropdown-footer">
<button class="logout-btn" @click="handleLogout">
<span class="logout-icon">🚪</span>
<span>退出登录</span>
</button>
</div>
</div>
</div>
<!-- 未登录状态 -->
<div v-else class="user-empty">
<router-link to="/login" class="login-link">登录</router-link>
</div>
<!-- 确认对话框 -->
<div v-if="showConfirmDialog" class="confirm-dialog-overlay" @click="showConfirmDialog = false">
<div class="confirm-dialog" @click.stop>
<div class="dialog-header">
<span class="dialog-icon">❓</span>
<h3 class="dialog-title">确认退出</h3>
</div>
<div class="dialog-content">
<p>确定要退出登录吗?</p>
</div>
<div class="dialog-footer">
<button class="dialog-btn cancel-btn" @click="showConfirmDialog = false">取消</button>
<button class="dialog-btn confirm-btn" @click="confirmLogout">确认退出</button>
</div>
</div>
</div>
</div>
</template>
<style scoped> <style scoped>
@keyframes dropdown-slide-in { @keyframes dropdown-slide-in {
from { from {
......
...@@ -193,7 +193,7 @@ export function getMenuParentPaths(menus: MenuItem[], targetPath: string): strin ...@@ -193,7 +193,7 @@ export function getMenuParentPaths(menus: MenuItem[], targetPath: string): strin
function findPath(items: MenuItem[], target: string, currentPaths: string[]): boolean { function findPath(items: MenuItem[], target: string, currentPaths: string[]): boolean {
for (const item of items) { for (const item of items) {
const newPaths = [...currentPaths, item.path]; const newPaths = [ ...currentPaths, item.path ];
if (item.path === target) { if (item.path === target) {
paths.push(...newPaths); paths.push(...newPaths);
......
...@@ -21,8 +21,7 @@ ...@@ -21,8 +21,7 @@
<!-- 按顶部菜单分组显示所有菜单 --> <!-- 按顶部菜单分组显示所有菜单 -->
<template v-for="topMenu in topMenus" :key="topMenu.id"> <template v-for="topMenu in topMenus" :key="topMenu.id">
<div v-if="topMenu.sidebarMenus && topMenu.sidebarMenus.length > 0" class="menu-group"> <div v-if="topMenu.sidebarMenus && topMenu.sidebarMenus.length > 0" class="menu-group">
<div <div class="menu-group-title"
class="menu-group-title"
:class="{ active: isTopMenuActive(topMenu.id) }" :class="{ active: isTopMenuActive(topMenu.id) }"
@click="handleTopMenuClick(topMenu.id, topMenu.path)"> @click="handleTopMenuClick(topMenu.id, topMenu.path)">
<span v-if="topMenu.icon" class="group-icon"> <span v-if="topMenu.icon" class="group-icon">
...@@ -31,8 +30,7 @@ ...@@ -31,8 +30,7 @@
<span>{{ topMenu.title }}</span> <span>{{ topMenu.title }}</span>
</div> </div>
<template v-for="item in topMenu.sidebarMenus" :key="item.id"> <template v-for="item in topMenu.sidebarMenus" :key="item.id">
<SidebarMenuItem <SidebarMenuItem :active-path="route.path"
:active-path="route.path"
:expanded-keys="expandedKeys" :expanded-keys="expandedKeys"
:menu="item" :menu="item"
@click="handleMenuClick" @click="handleMenuClick"
...@@ -48,8 +46,7 @@ ...@@ -48,8 +46,7 @@
<!-- 面包屑导航 --> <!-- 面包屑导航 -->
<div v-if="breadcrumbs.length > 0" class="breadcrumb"> <div v-if="breadcrumbs.length > 0" class="breadcrumb">
<template v-for="(crumb, index) in breadcrumbs" :key="index"> <template v-for="(crumb, index) in breadcrumbs" :key="index">
<span <span class="breadcrumb-item"
class="breadcrumb-item"
:class="{ :class="{
clickable: crumb.path && index < breadcrumbs.length - 1, clickable: crumb.path && index < breadcrumbs.length - 1,
}" }"
...@@ -64,7 +61,9 @@ ...@@ -64,7 +61,9 @@
<div class="content-wrapper"> <div class="content-wrapper">
<router-view v-slot="{ Component, route: viewRoute }"> <router-view v-slot="{ Component, route: viewRoute }">
<!-- 微应用路由不使用过渡动画,避免延迟容器挂载 --> <!-- 微应用路由不使用过渡动画,避免延迟容器挂载 -->
<transition v-if="!isMicroAppRoute(viewRoute.path)" mode="out-in" name="fade"> <transition v-if="!isMicroAppRoute(viewRoute.path)"
mode="out-in"
name="fade">
<component :is="Component" /> <component :is="Component" />
</transition> </transition>
<!-- 微应用路由直接渲染,无过渡 --> <!-- 微应用路由直接渲染,无过渡 -->
...@@ -133,7 +132,7 @@ const isTopMenuActive = (topMenuId: string): boolean => { ...@@ -133,7 +132,7 @@ const isTopMenuActive = (topMenuId: string): boolean => {
// 面包屑导航 // 面包屑导航
const breadcrumbs = computed<BreadcrumbItem[]>(() => { const breadcrumbs = computed<BreadcrumbItem[]>(() => {
const crumbs: BreadcrumbItem[] = [{ title: "首页", path: "/home" }]; const crumbs: BreadcrumbItem[] = [ { title: "首页", path: "/home" } ];
// 如果不在首页,添加当前路由的面包屑 // 如果不在首页,添加当前路由的面包屑
if (route.path !== "/home" && route.path !== "/") { if (route.path !== "/home" && route.path !== "/") {
......
...@@ -61,7 +61,7 @@ const initialState: GlobalState = { ...@@ -61,7 +61,7 @@ const initialState: GlobalState = {
name: "张三仨", name: "张三仨",
avatar: "👨‍💼", avatar: "👨‍💼",
role: "admin", role: "admin",
permissions: ["read", "write", "delete", "admin"], permissions: [ "read", "write", "delete", "admin" ],
}, },
theme: { theme: {
mode: "light", mode: "light",
...@@ -101,7 +101,7 @@ class CommunicationManager { ...@@ -101,7 +101,7 @@ class CommunicationManager {
}; };
this.setGlobalState({ this.setGlobalState({
notifications: [...this.currentState.notifications, newNotification], notifications: [ ...this.currentState.notifications, newNotification ],
}); });
} }
......
<template>
<div class="micro-app-container">
<!-- 微应用加载状态显示 -->
<!-- <div v-if="loading" class="loading-container">
<div class="loading-spinner"></div>
<p class="loading-text">正在加载微应用...</p>
</div>
-->
<!-- 微应用加载失败提示 -->
<div v-if="error" class="error-container">
<div class="error-icon">
⚠️
</div>
<p class="error-text">
{{ error }}
</p>
<button class="retry-button" @click="handleRetry">
重试
</button>
</div>
</div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, onUnmounted, ref } from "vue"; import { onMounted, onUnmounted, ref } from "vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
...@@ -55,23 +78,6 @@ const handleRetry = () => { ...@@ -55,23 +78,6 @@ const handleRetry = () => {
}; };
</script> </script>
<template>
<div class="micro-app-container">
<!-- 微应用加载状态显示 -->
<!-- <div v-if="loading" class="loading-container">
<div class="loading-spinner"></div>
<p class="loading-text">正在加载微应用...</p>
</div>
-->
<!-- 微应用加载失败提示 -->
<div v-if="error" class="error-container">
<div class="error-icon">⚠️</div>
<p class="error-text">{{ error }}</p>
<button class="retry-button" @click="handleRetry">重试</button>
</div>
</div>
</template>
<style scoped> <style scoped>
@keyframes spin { @keyframes spin {
0% { 0% {
......
...@@ -112,7 +112,7 @@ const router = createRouter({ ...@@ -112,7 +112,7 @@ const router = createRouter({
}); });
// 白名单:不需要登录的路由 // 白名单:不需要登录的路由
const whiteList = new Set(["/forgot-password", "/login", "/register"]); const whiteList = new Set([ "/forgot-password", "/login", "/register" ]);
/** /**
* 全局前置守卫 * 全局前置守卫
......
<template>
<!-- qiankun 微应用容器 - 作为唯一的微应用挂载点 -->
<div id="subapp-container" class="micro-app-container"></div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import { onMounted, onUnmounted } from "vue"; import { onMounted, onUnmounted } from "vue";
import { useRoute } from "vue-router"; import { useRoute } from "vue-router";
...@@ -13,11 +18,6 @@ onUnmounted(() => { ...@@ -13,11 +18,6 @@ onUnmounted(() => {
}); });
</script> </script>
<template>
<!-- qiankun 微应用容器 - 作为唯一的微应用挂载点 -->
<div id="subapp-container" class="micro-app-container"></div>
</template>
<style scoped> <style scoped>
.micro-app-container { .micro-app-container {
width: 100%; width: 100%;
......
<template>
<div class="not-found-page">
<div class="not-found-content">
<div class="error-code">
404
</div>
<h2 class="error-title">
页面未找到
</h2>
<p class="error-desc">
抱歉,您访问的页面不存在
</p>
<button class="back-button" @click="goHome">
返回首页
</button>
</div>
</div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
...@@ -8,17 +27,6 @@ const goHome = () => { ...@@ -8,17 +27,6 @@ const goHome = () => {
}; };
</script> </script>
<template>
<div class="not-found-page">
<div class="not-found-content">
<div class="error-code">404</div>
<h2 class="error-title">页面未找到</h2>
<p class="error-desc">抱歉,您访问的页面不存在</p>
<button class="back-button" @click="goHome">返回首页</button>
</div>
</div>
</template>
<style scoped> <style scoped>
.not-found-page { .not-found-page {
display: flex; display: flex;
......
/// <reference types="vite/client" /> // / <reference types="vite/client" />
interface ImportMetaEnv { interface ImportMetaEnv {
readonly VITE_API_BASE_URL: string; readonly VITE_API_BASE_URL: string;
......
...@@ -12,20 +12,20 @@ export default defineConfig({ ...@@ -12,20 +12,20 @@ export default defineConfig({
vue(), vue(),
vueJsx(), vueJsx(),
AutoImport({ AutoImport({
imports: ["vue", "vue-router", "pinia"], imports: [ "vue", "vue-router", "pinia" ],
resolvers: [ElementPlusResolver()], resolvers: [ ElementPlusResolver() ],
dts: "src/auto-imports.d.ts", dts: "src/auto-imports.d.ts",
}), }),
Components({ Components({
resolvers: [ElementPlusResolver()], resolvers: [ ElementPlusResolver() ],
dts: "src/components.d.ts", dts: "src/components.d.ts",
}), }),
], ],
resolve: { resolve: {
alias: { alias: {
"@": resolve(__dirname, "src"), "@": resolve(import.meta.dirname, "src"),
// 开发环境和构建时都直接使用源代码,避免 stub 模式的 jiti 问题 // 开发环境和构建时都直接使用源代码,避免 stub 模式的 jiti 问题
"@venus/common-ui-vue": resolve(__dirname, "../../../packages/common-ui/vue-ui/src/index.ts"), "@venus/common-ui-vue": resolve(import.meta.dirname, "../../../packages/common-ui/vue-ui/src/index.ts"),
}, },
}, },
server: { server: {
......
<script setup lang="ts">
import { ref } from "vue";
import { qiankunWindow } from "vite-plugin-qiankun/dist/helper";
// 判断是否在 qiankun 环境中
const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__);
</script>
<template> <template>
<div id="micro-app" class="micro-app-container"> <div id="micro-app" class="micro-app-container">
<header class="app-header"> <header class="app-header">
...@@ -19,17 +10,27 @@ const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__); ...@@ -19,17 +10,27 @@ const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__);
</div> </div>
</div> </div>
<nav class="nav-menu"> <nav class="nav-menu">
<router-link to="/" class="nav-link">首页</router-link> <router-link class="nav-link" to="/">
<router-link to="/about" class="nav-link">关于</router-link> 首页
<router-link to="/communication" class="nav-link">通信示例</router-link> </router-link>
<router-link to="/user" class="nav-link">用户管理</router-link> <router-link class="nav-link" to="/about">
<router-link to="/settings" class="nav-link">系统设置</router-link> 关于
</router-link>
<router-link class="nav-link" to="/communication">
通信示例
</router-link>
<router-link class="nav-link" to="/user">
用户管理
</router-link>
<router-link class="nav-link" to="/settings">
系统设置
</router-link>
</nav> </nav>
</header> </header>
<main class="app-main"> <main class="app-main">
<router-view v-slot="{ Component }"> <router-view v-slot="{ Component }">
<transition name="fade" mode="out-in"> <transition mode="out-in" name="fade">
<component :is="Component" /> <component :is="Component" />
</transition> </transition>
</router-view> </router-view>
...@@ -41,6 +42,15 @@ const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__); ...@@ -41,6 +42,15 @@ const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__);
</div> </div>
</template> </template>
<script setup lang="ts">
import { ref } from "vue";
import { qiankunWindow } from "vite-plugin-qiankun/dist/helper";
// 判断是否在 qiankun 环境中
const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__);
</script>
<style scoped> <style scoped>
/* 响应式设计 */ /* 响应式设计 */
@media (max-width: 768px) { @media (max-width: 768px) {
......
...@@ -174,7 +174,7 @@ class SubAppCommunicationManager { ...@@ -174,7 +174,7 @@ class SubAppCommunicationManager {
// 注意:这里需要基座的 communication manager 来处理通知添加逻辑 // 注意:这里需要基座的 communication manager 来处理通知添加逻辑
// 所以我们实际上是触发一个状态变化,让基座来处理 // 所以我们实际上是触发一个状态变化,让基座来处理
this.setGlobalState({ this.setGlobalState({
notifications: [newNotification] as any, // 基座会合并到现有通知列表 notifications: [ newNotification ] as any, // 基座会合并到现有通知列表
}); });
} }
......
<script setup lang="ts">
import { ref } from "vue";
import { qiankunWindow } from "vite-plugin-qiankun/dist/helper";
// 判断是否在 qiankun 环境中
const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__);
</script>
<template> <template>
<div class="communication-page"> <div class="communication-page">
<div class="page-header"> <div class="page-header">
<h1>📱 子应用通信示例</h1> <h1>📱 子应用通信示例</h1>
<p class="subtitle">演示子应用如何与基座进行数据通信</p> <p class="subtitle">
演示子应用如何与基座进行数据通信
</p>
<div class="mode-badge"> <div class="mode-badge">
<span v-if="isQiankunMode" class="badge qiankun">🔗 基座模式</span> <span v-if="isQiankunMode" class="badge qiankun">🔗 基座模式</span>
<span v-else class="badge standalone">🏠 独立模式</span> <span v-else class="badge standalone">🏠 独立模式</span>
...@@ -20,7 +13,9 @@ const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__); ...@@ -20,7 +13,9 @@ const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__);
<!-- 独立模式提示 --> <!-- 独立模式提示 -->
<div v-if="!isQiankunMode" class="alert alert-warning"> <div v-if="!isQiankunMode" class="alert alert-warning">
<div class="alert-icon">⚠️</div> <div class="alert-icon">
⚠️
</div>
<div class="alert-content"> <div class="alert-content">
<h3>独立模式运行</h3> <h3>独立模式运行</h3>
<p>当前子应用运行在独立模式下,通信功能不可用。</p> <p>当前子应用运行在独立模式下,通信功能不可用。</p>
...@@ -49,6 +44,15 @@ const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__); ...@@ -49,6 +44,15 @@ const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__);
</div> </div>
</template> </template>
<script setup lang="ts">
import { ref } from "vue";
import { qiankunWindow } from "vite-plugin-qiankun/dist/helper";
// 判断是否在 qiankun 环境中
const isQiankunMode = ref(qiankunWindow.__POWERED_BY_QIANKUN__);
</script>
<style scoped> <style scoped>
.communication-page { .communication-page {
max-width: 1400px; max-width: 1400px;
......
<template>
<div class="notfound-view">
<div class="content-card">
<div class="error-code">
404
</div>
<h1>页面未找到</h1>
<p>抱歉,您访问的页面不存在或已被删除</p>
<button class="btn-home" @click="goHome">
🏠 返回首页
</button>
</div>
</div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
...@@ -8,17 +23,6 @@ const goHome = () => { ...@@ -8,17 +23,6 @@ const goHome = () => {
}; };
</script> </script>
<template>
<div class="notfound-view">
<div class="content-card">
<div class="error-code">404</div>
<h1>页面未找到</h1>
<p>抱歉,您访问的页面不存在或已被删除</p>
<button @click="goHome" class="btn-home">🏠 返回首页</button>
</div>
</div>
</template>
<style scoped> <style scoped>
.notfound-view { .notfound-view {
display: flex; display: flex;
......
<script setup lang="ts">
import { reactive } from "vue";
interface Settings {
theme: string;
darkMode: boolean;
notifications: {
desktop: boolean;
email: boolean;
sms: boolean;
};
language: string;
timezone: string;
security: {
sessionTimeout: number;
twoFactor: boolean;
};
}
const defaultSettings: Settings = {
theme: "purple",
darkMode: false,
notifications: {
desktop: true,
email: true,
sms: false,
},
language: "zh-CN",
timezone: "Asia/Shanghai",
security: {
twoFactor: false,
sessionTimeout: 30,
},
};
const settings = reactive<Settings>({ ...defaultSettings });
const saveSettings = () => {
console.log("保存设置:", settings);
alert("设置已保存!");
};
const resetSettings = () => {
if (confirm("确定要重置为默认设置吗?")) {
Object.assign(settings, defaultSettings);
alert("已重置为默认设置!");
}
};
</script>
<template> <template>
<div class="settings-view"> <div class="settings-view">
<div class="content-card"> <div class="content-card">
...@@ -59,15 +9,25 @@ const resetSettings = () => { ...@@ -59,15 +9,25 @@ const resetSettings = () => {
<div class="setting-item"> <div class="setting-item">
<label>主题色:</label> <label>主题色:</label>
<select v-model="settings.theme" class="select-input"> <select v-model="settings.theme" class="select-input">
<option value="purple">紫色</option> <option value="purple">
<option value="blue">蓝色</option> 紫色
<option value="green">绿色</option> </option>
<option value="orange">橙色</option> <option value="blue">
蓝色
</option>
<option value="green">
绿色
</option>
<option value="orange">
橙色
</option>
</select> </select>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>暗黑模式:</label> <label>暗黑模式:</label>
<input type="checkbox" v-model="settings.darkMode" class="checkbox-input" /> <input v-model="settings.darkMode"
class="checkbox-input"
type="checkbox" />
</div> </div>
</div> </div>
...@@ -75,15 +35,21 @@ const resetSettings = () => { ...@@ -75,15 +35,21 @@ const resetSettings = () => {
<h2>🔔 通知设置</h2> <h2>🔔 通知设置</h2>
<div class="setting-item"> <div class="setting-item">
<label>桌面通知:</label> <label>桌面通知:</label>
<input type="checkbox" v-model="settings.notifications.desktop" class="checkbox-input" /> <input v-model="settings.notifications.desktop"
class="checkbox-input"
type="checkbox" />
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>邮件通知:</label> <label>邮件通知:</label>
<input type="checkbox" v-model="settings.notifications.email" class="checkbox-input" /> <input v-model="settings.notifications.email"
class="checkbox-input"
type="checkbox" />
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>短信通知:</label> <label>短信通知:</label>
<input type="checkbox" v-model="settings.notifications.sms" class="checkbox-input" /> <input v-model="settings.notifications.sms"
class="checkbox-input"
type="checkbox" />
</div> </div>
</div> </div>
...@@ -92,17 +58,29 @@ const resetSettings = () => { ...@@ -92,17 +58,29 @@ const resetSettings = () => {
<div class="setting-item"> <div class="setting-item">
<label>界面语言:</label> <label>界面语言:</label>
<select v-model="settings.language" class="select-input"> <select v-model="settings.language" class="select-input">
<option value="zh-CN">简体中文</option> <option value="zh-CN">
<option value="en-US">English</option> 简体中文
<option value="ja-JP">日本語</option> </option>
<option value="en-US">
English
</option>
<option value="ja-JP">
日本語
</option>
</select> </select>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>时区:</label> <label>时区:</label>
<select v-model="settings.timezone" class="select-input"> <select v-model="settings.timezone" class="select-input">
<option value="Asia/Shanghai">北京时间 (UTC+8)</option> <option value="Asia/Shanghai">
<option value="America/New_York">纽约时间 (UTC-5)</option> 北京时间 (UTC+8)
<option value="Europe/London">伦敦时间 (UTC+0)</option> </option>
<option value="America/New_York">
纽约时间 (UTC-5)
</option>
<option value="Europe/London">
伦敦时间 (UTC+0)
</option>
</select> </select>
</div> </div>
</div> </div>
...@@ -111,23 +89,28 @@ const resetSettings = () => { ...@@ -111,23 +89,28 @@ const resetSettings = () => {
<h2>🔒 安全设置</h2> <h2>🔒 安全设置</h2>
<div class="setting-item"> <div class="setting-item">
<label>双因素认证:</label> <label>双因素认证:</label>
<input type="checkbox" v-model="settings.security.twoFactor" class="checkbox-input" /> <input v-model="settings.security.twoFactor"
class="checkbox-input"
type="checkbox" />
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>会话超时 (分钟):</label> <label>会话超时 (分钟):</label>
<input <input v-model="settings.security.sessionTimeout"
type="number"
v-model="settings.security.sessionTimeout"
class="number-input" class="number-input"
max="120"
min="5" min="5"
max="120" /> type="number" />
</div> </div>
</div> </div>
</div> </div>
<div class="actions"> <div class="actions">
<button @click="saveSettings" class="btn-save">💾 保存设置</button> <button class="btn-save" @click="saveSettings">
<button @click="resetSettings" class="btn-reset">🔄 重置默认</button> 💾 保存设置
</button>
<button class="btn-reset" @click="resetSettings">
🔄 重置默认
</button>
</div> </div>
<div class="current-settings"> <div class="current-settings">
...@@ -138,6 +121,59 @@ const resetSettings = () => { ...@@ -138,6 +121,59 @@ const resetSettings = () => {
</div> </div>
</template> </template>
<script setup lang="ts">
import { reactive } from "vue";
interface Settings {
theme: string;
darkMode: boolean;
notifications: {
desktop: boolean;
email: boolean;
sms: boolean;
};
language: string;
timezone: string;
security: {
sessionTimeout: number;
twoFactor: boolean;
};
}
const defaultSettings: Settings = {
theme: "purple",
darkMode: false,
notifications: {
desktop: true,
email: true,
sms: false,
},
language: "zh-CN",
timezone: "Asia/Shanghai",
security: {
twoFactor: false,
sessionTimeout: 30,
},
};
const settings = reactive<Settings>({ ...defaultSettings });
const saveSettings = () => {
console.log("保存设置:", settings);
// eslint-disable-next-line
alert("设置已保存!");
};
const resetSettings = () => {
// eslint-disable-next-line
if (confirm("确定要重置为默认设置吗?")) {
Object.assign(settings, defaultSettings);
// eslint-disable-next-line
alert("已重置为默认设置!");
}
};
</script>
<style scoped> <style scoped>
.settings-view { .settings-view {
max-width: 1200px; max-width: 1200px;
......
<template>
<div class="user-view">
<div class="content-card">
<h1>👥 用户管理</h1>
<div class="toolbar">
<button class="btn-add" @click="addUser">
➕ 新增用户
</button>
</div>
<div class="table-container">
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>邮箱</th>
<th>角色</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users" :key="user.id">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
<td>{{ user.email }}</td>
<td>
<span class="badge" :class="`badge-${user.role}`">
{{ user.role }}
</span>
</td>
<td>
<span class="status" :class="user.active ? 'status-active' : 'status-inactive'">
{{ user.active ? "在线" : "离线" }}
</span>
</td>
<td>
<button class="btn-edit" @click="editUser(user)">
编辑
</button>
<button class="btn-delete" @click="deleteUser(user.id)">
删除
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { ref } from "vue";
...@@ -53,65 +107,19 @@ const addUser = () => { ...@@ -53,65 +107,19 @@ const addUser = () => {
const editUser = (user: User) => { const editUser = (user: User) => {
console.log("编辑用户:", user); console.log("编辑用户:", user);
// eslint-disable-next-line
alert(`编辑用户: ${user.name}`); alert(`编辑用户: ${user.name}`);
}; };
const deleteUser = (id: number) => { const deleteUser = (id: number) => {
const index = users.value.findIndex((u) => u.id === id); const index = users.value.findIndex((u) => u.id === id);
// eslint-disable-next-line
if (index !== -1 && confirm(`确定要删除用户 ${users.value[index].name} 吗?`)) { if (index !== -1 && confirm(`确定要删除用户 ${users.value[index].name} 吗?`)) {
users.value.splice(index, 1); users.value.splice(index, 1);
} }
}; };
</script> </script>
<template>
<div class="user-view">
<div class="content-card">
<h1>👥 用户管理</h1>
<div class="toolbar">
<button @click="addUser" class="btn-add">➕ 新增用户</button>
</div>
<div class="table-container">
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>邮箱</th>
<th>角色</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users" :key="user.id">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
<td>{{ user.email }}</td>
<td>
<span class="badge" :class="`badge-${user.role}`">
{{ user.role }}
</span>
</td>
<td>
<span class="status" :class="user.active ? 'status-active' : 'status-inactive'">
{{ user.active ? "在线" : "离线" }}
</span>
</td>
<td>
<button @click="editUser(user)" class="btn-edit">编辑</button>
<button @click="deleteUser(user.id)" class="btn-delete">删除</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<style scoped> <style scoped>
.user-view { .user-view {
max-width: 1200px; max-width: 1200px;
......
{ {
"compilerOptions": { "compilerOptions": {
"target": "ES2020", "target": "ES2021",
"jsx": "preserve", "jsx": "preserve",
"lib": ["ES2020", "DOM", "DOM.Iterable"], "lib": ["ES2021", "DOM", "DOM.Iterable"],
"useDefineForClassFields": true, "useDefineForClassFields": true,
/* Path Alias */ /* Path Alias */
......
...@@ -21,7 +21,7 @@ export default defineConfig(({ mode, command }) => { ...@@ -21,7 +21,7 @@ export default defineConfig(({ mode, command }) => {
vueJsx(), vueJsx(),
// 自动导入 Vue 相关函数 // 自动导入 Vue 相关函数
AutoImport({ AutoImport({
imports: ["vue", "vue-router", "pinia"], imports: [ "vue", "vue-router", "pinia" ],
dts: "src/auto-imports.d.ts", dts: "src/auto-imports.d.ts",
eslintrc: { eslintrc: {
enabled: false, enabled: false,
...@@ -38,7 +38,7 @@ export default defineConfig(({ mode, command }) => { ...@@ -38,7 +38,7 @@ export default defineConfig(({ mode, command }) => {
], ],
resolve: { resolve: {
alias: { alias: {
"@": resolve(__dirname, "src"), "@": resolve(import.meta.dirname, "src"),
}, },
}, },
server: { server: {
......
...@@ -81,7 +81,7 @@ export default defineConfig({ ...@@ -81,7 +81,7 @@ export default defineConfig({
], ],
}, },
socialLinks: [{ icon: "github", link: "https://github.com/venusjs/vue-venus-admin" }], socialLinks: [ { icon: "github", link: "https://github.com/venusjs/vue-venus-admin" } ],
// 搜索配置 // 搜索配置
search: { search: {
...@@ -122,7 +122,7 @@ export default defineConfig({ ...@@ -122,7 +122,7 @@ export default defineConfig({
// 大纲配置 // 大纲配置
outline: { outline: {
level: [2, 3], level: [ 2, 3 ],
label: "页面导航", label: "页面导航",
}, },
...@@ -165,9 +165,9 @@ export default defineConfig({ ...@@ -165,9 +165,9 @@ export default defineConfig({
// 自定义元信息 // 自定义元信息
head: [ head: [
["link", { rel: "icon", href: "/favicon.ico" }], [ "link", { rel: "icon", href: "/favicon.ico" } ],
["meta", { name: "theme-color", content: "#646cff" }], [ "meta", { name: "theme-color", content: "#646cff" } ],
["meta", { name: "og:type", content: "website" }], [ "meta", { name: "og:type", content: "website" } ],
["meta", { name: "og:locale", content: "zh-CN" }], [ "meta", { name: "og:locale", content: "zh-CN" } ],
], ],
}); });
...@@ -3,5 +3,5 @@ import { defineBuildConfig } from "unbuild"; ...@@ -3,5 +3,5 @@ import { defineBuildConfig } from "unbuild";
export default defineBuildConfig({ export default defineBuildConfig({
clean: true, clean: true,
declaration: true, declaration: true,
entries: ["src/index"], entries: [ "src/index" ],
}); });
...@@ -13,7 +13,7 @@ import type { Linter } from "eslint"; ...@@ -13,7 +13,7 @@ import type { Linter } from "eslint";
import { interopDefault } from "../util"; import { interopDefault } from "../util";
export async function comments(): Promise<Linter.Config[]> { export async function comments(): Promise<Linter.Config[]> {
const [pluginComments] = await Promise.all([ const [ pluginComments ] = await Promise.all([
// @ts-expect-error - no types // @ts-expect-error - no types
interopDefault(import("eslint-plugin-eslint-comments")), interopDefault(import("eslint-plugin-eslint-comments")),
] as const); ] as const);
...@@ -26,7 +26,7 @@ export async function comments(): Promise<Linter.Config[]> { ...@@ -26,7 +26,7 @@ export async function comments(): Promise<Linter.Config[]> {
rules: { rules: {
"eslint-comments/no-aggregating-enable": "error", "eslint-comments/no-aggregating-enable": "error",
"eslint-comments/no-duplicate-disable": "error", "eslint-comments/no-duplicate-disable": "error",
"eslint-comments/no-unlimited-disable": "error", "eslint-comments/no-unlimited-disable": "warn",
"eslint-comments/no-unused-enable": "error", "eslint-comments/no-unused-enable": "error",
}, },
}, },
......
...@@ -13,7 +13,7 @@ import type { Linter } from "eslint"; ...@@ -13,7 +13,7 @@ import type { Linter } from "eslint";
export async function disableds(): Promise<Linter.Config[]> { export async function disableds(): Promise<Linter.Config[]> {
return [ return [
{ {
files: ["**/__tests__/**/*.?([cm])[jt]s?(x)"], files: [ "**/__tests__/**/*.?([cm])[jt]s?(x)" ],
name: "disables/test", name: "disables/test",
rules: { rules: {
"@typescript-eslint/ban-ts-comment": "off", "@typescript-eslint/ban-ts-comment": "off",
...@@ -21,14 +21,14 @@ export async function disableds(): Promise<Linter.Config[]> { ...@@ -21,14 +21,14 @@ export async function disableds(): Promise<Linter.Config[]> {
}, },
}, },
{ {
files: ["**/*.d.ts"], files: [ "**/*.d.ts" ],
name: "disables/dts", name: "disables/dts",
rules: { rules: {
"@typescript-eslint/triple-slash-reference": "off", "@typescript-eslint/triple-slash-reference": "off",
}, },
}, },
{ {
files: ["**/*.js", "**/*.mjs", "**/*.cjs"], files: [ "**/*.js", "**/*.mjs", "**/*.cjs" ],
name: "disables/js", name: "disables/js",
rules: { rules: {
"@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/explicit-module-boundary-types": "off",
......
...@@ -20,7 +20,7 @@ export async function importPluginConfig(): Promise<Linter.Config[]> { ...@@ -20,7 +20,7 @@ export async function importPluginConfig(): Promise<Linter.Config[]> {
}, },
rules: { rules: {
// 优先在顶层位置声明类型导出,减少嵌套导致的类型混淆 // 优先在顶层位置声明类型导出,减少嵌套导致的类型混淆
"import/consistent-type-specifier-style": ["error", "prefer-top-level"], "import/consistent-type-specifier-style": [ "error", "prefer-top-level" ],
// 导入应集中在文件顶部 // 导入应集中在文件顶部
"import/first": "error", "import/first": "error",
// 导入后需换行以增强可读性 // 导入后需换行以增强可读性
......
...@@ -39,15 +39,15 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -39,15 +39,15 @@ export async function javascript(): Promise<Linter.Config[]> {
linterOptions: { linterOptions: {
reportUnusedDisableDirectives: true, reportUnusedDisableDirectives: true,
}, },
ignores: ["**/*.wxml"], ignores: [ "**/*.wxml" ],
plugins: { plugins: {
"unused-imports": pluginUnusedImports, "unused-imports": pluginUnusedImports,
}, },
rules: { rules: {
...js.configs.recommended.rules, ...js.configs.recommended.rules,
"object-curly-spacing": ["error", "always"], "object-curly-spacing": [ "error", "always" ],
semi: ["error", "always"], semi: [ "error", "always" ],
"array-bracket-spacing": ["error", "always"], "array-bracket-spacing": [ "error", "always" ],
indent: [ indent: [
"error", "error",
"tab", "tab",
...@@ -66,7 +66,7 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -66,7 +66,7 @@ export async function javascript(): Promise<Linter.Config[]> {
flatTernaryExpressions: false, flatTernaryExpressions: false,
}, },
], ],
"comma-spacing": ["error", { before: false, after: true }], "comma-spacing": [ "error", { before: false, after: true } ],
// 允许使用 tab(必须关掉 no-tabs) // 允许使用 tab(必须关掉 no-tabs)
"no-tabs": "off", "no-tabs": "off",
...@@ -78,16 +78,16 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -78,16 +78,16 @@ export async function javascript(): Promise<Linter.Config[]> {
allowTemplateLiterals: true, allowTemplateLiterals: true,
}, },
], ],
"keyword-spacing": ["error", { before: true, after: true }], "keyword-spacing": [ "error", { before: true, after: true } ],
"accessor-pairs": ["error", { enforceForClassMembers: true, setWithoutGet: true }], "accessor-pairs": [ "error", { enforceForClassMembers: true, setWithoutGet: true } ],
"array-callback-return": "error", "array-callback-return": "error",
"block-scoped-var": "error", "block-scoped-var": "error",
"constructor-super": "error", "constructor-super": "error",
"default-case-last": "error", "default-case-last": "error",
"dot-notation": ["error", { allowKeywords: true }], "dot-notation": [ "error", { allowKeywords: true } ],
eqeqeq: ["error", "always"], eqeqeq: [ "error", "always" ],
"new-cap": ["error", { capIsNew: false, newIsCap: true, properties: true }], "new-cap": [ "error", { capIsNew: false, newIsCap: true, properties: true } ],
"no-alert": "error", "no-alert": "error",
"no-array-constructor": "error", "no-array-constructor": "error",
"no-async-promise-executor": "error", "no-async-promise-executor": "error",
...@@ -95,7 +95,7 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -95,7 +95,7 @@ export async function javascript(): Promise<Linter.Config[]> {
"no-case-declarations": "error", "no-case-declarations": "error",
"no-class-assign": "error", "no-class-assign": "error",
"no-compare-neg-zero": "error", "no-compare-neg-zero": "error",
"no-cond-assign": ["error", "always"], "no-cond-assign": [ "error", "always" ],
"no-console": "off", "no-console": "off",
"no-const-assign": "error", "no-const-assign": "error",
"no-control-regex": "error", "no-control-regex": "error",
...@@ -105,7 +105,7 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -105,7 +105,7 @@ export async function javascript(): Promise<Linter.Config[]> {
"no-dupe-class-members": "error", "no-dupe-class-members": "error",
"no-dupe-keys": "error", "no-dupe-keys": "error",
"no-duplicate-case": "error", "no-duplicate-case": "error",
"no-empty": ["error", { allowEmptyCatch: true }], "no-empty": [ "error", { allowEmptyCatch: true } ],
"no-empty-character-class": "error", "no-empty-character-class": "error",
"no-empty-function": "off", "no-empty-function": "off",
"no-empty-pattern": "error", "no-empty-pattern": "error",
...@@ -122,7 +122,7 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -122,7 +122,7 @@ export async function javascript(): Promise<Linter.Config[]> {
"no-invalid-regexp": "error", "no-invalid-regexp": "error",
"no-irregular-whitespace": "error", "no-irregular-whitespace": "error",
"no-iterator": "error", "no-iterator": "error",
"no-labels": ["error", { allowLoop: false, allowSwitch: false }], "no-labels": [ "error", { allowLoop: false, allowSwitch: false } ],
"no-lone-blocks": "error", "no-lone-blocks": "error",
"no-loss-of-precision": "error", "no-loss-of-precision": "error",
"no-misleading-character-class": "error", "no-misleading-character-class": "error",
...@@ -137,7 +137,7 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -137,7 +137,7 @@ export async function javascript(): Promise<Linter.Config[]> {
"no-octal-escape": "error", "no-octal-escape": "error",
"no-proto": "error", "no-proto": "error",
"no-prototype-builtins": "error", "no-prototype-builtins": "error",
"no-redeclare": ["error", { builtinGlobals: false }], "no-redeclare": [ "error", { builtinGlobals: false } ],
"no-regex-spaces": "error", "no-regex-spaces": "error",
"no-restricted-globals": [ "no-restricted-globals": [
"error", "error",
...@@ -175,7 +175,7 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -175,7 +175,7 @@ export async function javascript(): Promise<Linter.Config[]> {
"TSEnumDeclaration[const=true]", "TSEnumDeclaration[const=true]",
"TSExportAssignment", "TSExportAssignment",
], ],
"no-self-assign": ["error", { props: true }], "no-self-assign": [ "error", { props: true } ],
"no-self-compare": "error", "no-self-compare": "error",
"no-sequences": "error", "no-sequences": "error",
"no-shadow-restricted-names": "error", "no-shadow-restricted-names": "error",
...@@ -187,7 +187,7 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -187,7 +187,7 @@ export async function javascript(): Promise<Linter.Config[]> {
"no-undef-init": "error", "no-undef-init": "error",
"no-unexpected-multiline": "error", "no-unexpected-multiline": "error",
"no-unmodified-loop-condition": "error", "no-unmodified-loop-condition": "error",
"no-unneeded-ternary": ["error", { defaultAssignment: false }], "no-unneeded-ternary": [ "error", { defaultAssignment: false } ],
"no-unreachable": "error", "no-unreachable": "error",
"no-unreachable-loop": "error", "no-unreachable-loop": "error",
"no-unsafe-finally": "error", "no-unsafe-finally": "error",
...@@ -209,7 +209,7 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -209,7 +209,7 @@ export async function javascript(): Promise<Linter.Config[]> {
vars: "all", vars: "all",
}, },
], ],
"no-use-before-define": ["error", { classes: false, functions: false, variables: false }], "no-use-before-define": [ "error", { classes: false, functions: false, variables: false } ],
"no-useless-backreference": "error", "no-useless-backreference": "error",
"no-useless-call": "error", "no-useless-call": "error",
"no-useless-catch": "error", "no-useless-catch": "error",
...@@ -219,8 +219,8 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -219,8 +219,8 @@ export async function javascript(): Promise<Linter.Config[]> {
"no-useless-return": "error", "no-useless-return": "error",
"no-var": "error", "no-var": "error",
"no-with": "error", "no-with": "error",
"object-shorthand": ["error", "always", { avoidQuotes: true, ignoreConstructors: false }], "object-shorthand": [ "error", "always", { avoidQuotes: true, ignoreConstructors: false } ],
"one-var": ["error", { initialized: "never" }], "one-var": [ "error", { initialized: "never" } ],
"prefer-arrow-callback": [ "prefer-arrow-callback": [
"error", "error",
{ {
...@@ -238,14 +238,14 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -238,14 +238,14 @@ export async function javascript(): Promise<Linter.Config[]> {
"prefer-exponentiation-operator": "error", "prefer-exponentiation-operator": "error",
"prefer-promise-reject-errors": "error", "prefer-promise-reject-errors": "error",
"prefer-regex-literals": ["error", { disallowRedundantWrapping: true }], "prefer-regex-literals": [ "error", { disallowRedundantWrapping: true } ],
"prefer-rest-params": "warn", "prefer-rest-params": "warn",
"prefer-spread": "error", "prefer-spread": "error",
"prefer-template": "error", "prefer-template": "error",
"space-before-function-paren": "off", "space-before-function-paren": "off",
"spaced-comment": "error", "spaced-comment": "error",
"symbol-description": "error", "symbol-description": "error",
"unicode-bom": ["error", "never"], "unicode-bom": [ "error", "never" ],
"unused-imports/no-unused-imports": "error", "unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": [ "unused-imports/no-unused-vars": [
...@@ -257,11 +257,11 @@ export async function javascript(): Promise<Linter.Config[]> { ...@@ -257,11 +257,11 @@ export async function javascript(): Promise<Linter.Config[]> {
varsIgnorePattern: "^_", varsIgnorePattern: "^_",
}, },
], ],
"use-isnan": ["error", { enforceForIndexOf: true, enforceForSwitchCase: true }], "use-isnan": [ "error", { enforceForIndexOf: true, enforceForSwitchCase: true } ],
"valid-typeof": ["error", { requireStringLiterals: true }], "valid-typeof": [ "error", { requireStringLiterals: true } ],
"vars-on-top": "error", "vars-on-top": "error",
yoda: ["error", "never"], yoda: [ "error", "never" ],
}, },
}, },
]; ];
......
...@@ -12,7 +12,7 @@ import type { Linter } from "eslint"; ...@@ -12,7 +12,7 @@ import type { Linter } from "eslint";
import { interopDefault } from "../util"; import { interopDefault } from "../util";
export async function jsdoc(): Promise<Linter.Config[]> { export async function jsdoc(): Promise<Linter.Config[]> {
const [pluginJsdoc] = await Promise.all([interopDefault(import("eslint-plugin-jsdoc"))] as const); const [ pluginJsdoc ] = await Promise.all([ interopDefault(import("eslint-plugin-jsdoc")) ] as const);
return [ return [
{ {
......
...@@ -21,7 +21,7 @@ export async function node(): Promise<Linter.Config[]> { ...@@ -21,7 +21,7 @@ export async function node(): Promise<Linter.Config[]> {
n: pluginNode, n: pluginNode,
}, },
rules: { rules: {
"n/handle-callback-err": ["error", "^(err|error)$"], "n/handle-callback-err": [ "error", "^(err|error)$" ],
"n/no-deprecated-api": "error", "n/no-deprecated-api": "error",
"n/no-exports-assign": "error", "n/no-exports-assign": "error",
"n/no-extraneous-import": [ "n/no-extraneous-import": [
...@@ -48,14 +48,14 @@ export async function node(): Promise<Linter.Config[]> { ...@@ -48,14 +48,14 @@ export async function node(): Promise<Linter.Config[]> {
version: ">=20.12.0", version: ">=20.12.0",
}, },
], ],
"n/prefer-global/buffer": ["error", "never"], "n/prefer-global/buffer": [ "error", "never" ],
// 'n/no-missing-import': 'off', // 'n/no-missing-import': 'off',
"n/prefer-global/process": ["error", "never"], "n/prefer-global/process": [ "error", "never" ],
"n/process-exit-as-throw": "error", "n/process-exit-as-throw": "error",
}, },
}, },
{ {
files: ["scripts/**/*.?([cm])[jt]s?(x)", "internal/**/*.?([cm])[jt]s?(x)"], files: [ "scripts/**/*.?([cm])[jt]s?(x)", "internal/**/*.?([cm])[jt]s?(x)" ],
rules: { rules: {
"n/prefer-global/process": "off", "n/prefer-global/process": "off",
}, },
......
...@@ -31,38 +31,38 @@ export async function perfectionist(): Promise<Linter.Config[]> { ...@@ -31,38 +31,38 @@ export async function perfectionist(): Promise<Linter.Config[]> {
{ {
customGroups: { customGroups: {
type: { type: {
"vben-core-type": ["^@vben-core/.+"], "vben-core-type": [ "^@vben-core/.+" ],
"vben-type": ["^@venus/.+"], "vben-type": [ "^@venus/.+" ],
"vue-type": ["^vue$", "^vue-.+", "^@vue/.+"], "vue-type": [ "^vue$", "^vue-.+", "^@vue/.+" ],
}, },
value: { value: {
vben: ["^@venus/.+"], vben: [ "^@venus/.+" ],
"vben-core": ["^@vben-core/.+"], "vben-core": [ "^@vben-core/.+" ],
vue: ["^vue$", "^vue-.+", "^@vue/.+"], vue: [ "^vue$", "^vue-.+", "^@vue/.+" ],
}, },
}, },
environment: "node", environment: "node",
groups: [ groups: [
["external-type", "builtin-type", "type"], [ "external-type", "builtin-type", "type" ],
"vue-type", "vue-type",
"vben-type", "vben-type",
"vben-core-type", "vben-core-type",
["parent-type", "sibling-type", "index-type"], [ "parent-type", "sibling-type", "index-type" ],
["internal-type"], [ "internal-type" ],
"builtin", "builtin",
"vue", "vue",
"vben", "vben",
"vben-core", "vben-core",
"external", "external",
"internal", "internal",
["parent", "sibling", "index"], [ "parent", "sibling", "index" ],
"side-effect", "side-effect",
"side-effect-style", "side-effect-style",
"style", "style",
"object", "object",
"unknown", "unknown",
], ],
internalPattern: ["^#/.+"], internalPattern: [ "^#/.+" ],
newlinesBetween: "always", newlinesBetween: "always",
order: "asc", order: "asc",
type: "natural", type: "natural",
...@@ -84,8 +84,8 @@ export async function perfectionist(): Promise<Linter.Config[]> { ...@@ -84,8 +84,8 @@ export async function perfectionist(): Promise<Linter.Config[]> {
list: "list", list: "list",
children: "children", children: "children",
}, },
groups: ["unknown", "items", "list", "children"], groups: [ "unknown", "items", "list", "children" ],
ignorePattern: ["children"], ignorePattern: [ "children" ],
order: "asc", order: "asc",
type: "natural", type: "natural",
}, },
......
...@@ -12,7 +12,7 @@ import type { Linter } from "eslint"; ...@@ -12,7 +12,7 @@ import type { Linter } from "eslint";
import { interopDefault } from "../util"; import { interopDefault } from "../util";
export async function regexp(): Promise<Linter.Config[]> { export async function regexp(): Promise<Linter.Config[]> {
const [pluginRegexp] = await Promise.all([interopDefault(import("eslint-plugin-regexp"))] as const); const [ pluginRegexp ] = await Promise.all([ interopDefault(import("eslint-plugin-regexp")) ] as const);
return [ return [
{ {
......
...@@ -13,7 +13,7 @@ import type { Linter } from "eslint"; ...@@ -13,7 +13,7 @@ import type { Linter } from "eslint";
import { interopDefault } from "../util"; import { interopDefault } from "../util";
export async function test(): Promise<Linter.Config[]> { export async function test(): Promise<Linter.Config[]> {
const [pluginTest, pluginNoOnlyTests] = await Promise.all([ const [ pluginTest, pluginNoOnlyTests ] = await Promise.all([
interopDefault(import("eslint-plugin-vitest")), interopDefault(import("eslint-plugin-vitest")),
// @ts-expect-error - no types // @ts-expect-error - no types
interopDefault(import("eslint-plugin-no-only-tests")), interopDefault(import("eslint-plugin-no-only-tests")),
...@@ -40,7 +40,7 @@ export async function test(): Promise<Linter.Config[]> { ...@@ -40,7 +40,7 @@ export async function test(): Promise<Linter.Config[]> {
rules: { rules: {
"no-console": "off", "no-console": "off",
"node/prefer-global/process": "off", "node/prefer-global/process": "off",
"test/consistent-test-it": ["error", { fn: "it", withinDescribe: "it" }], "test/consistent-test-it": [ "error", { fn: "it", withinDescribe: "it" } ],
"test/no-identical-title": "error", "test/no-identical-title": "error",
"test/no-import-node-test": "error", "test/no-import-node-test": "error",
"test/no-only-tests": "error", "test/no-only-tests": "error",
......
...@@ -11,7 +11,7 @@ import type { Linter } from "eslint"; ...@@ -11,7 +11,7 @@ import type { Linter } from "eslint";
import { interopDefault } from "../util"; import { interopDefault } from "../util";
export async function turbo(): Promise<Linter.Config[]> { export async function turbo(): Promise<Linter.Config[]> {
const [pluginTurbo] = await Promise.all([interopDefault(import("eslint-config-turbo"))] as const); const [ pluginTurbo ] = await Promise.all([ interopDefault(import("eslint-config-turbo")) ] as const);
return [ return [
{ {
......
...@@ -12,14 +12,14 @@ import type { Linter } from "eslint"; ...@@ -12,14 +12,14 @@ import type { Linter } from "eslint";
import { interopDefault } from "../util"; import { interopDefault } from "../util";
export async function typescript(): Promise<Linter.Config[]> { export async function typescript(): Promise<Linter.Config[]> {
const [pluginTs, parserTs] = await Promise.all([ const [ pluginTs, parserTs ] = await Promise.all([
interopDefault(import("@typescript-eslint/eslint-plugin")), interopDefault(import("@typescript-eslint/eslint-plugin")),
interopDefault(import("@typescript-eslint/parser")), interopDefault(import("@typescript-eslint/parser")),
] as const); ] as const);
return [ return [
{ {
files: ["**/*.?([cm])[jt]s?(x)"], files: [ "**/*.?([cm])[jt]s?(x)" ],
languageOptions: { languageOptions: {
parser: parserTs, parser: parserTs,
parserOptions: { parserOptions: {
...@@ -29,7 +29,7 @@ export async function typescript(): Promise<Linter.Config[]> { ...@@ -29,7 +29,7 @@ export async function typescript(): Promise<Linter.Config[]> {
jsx: true, jsx: true,
}, },
ecmaVersion: "latest", ecmaVersion: "latest",
extraFileExtensions: [".vue"], extraFileExtensions: [ ".vue" ],
jsxPragma: "React", jsxPragma: "React",
project: "./tsconfig.*.json", project: "./tsconfig.*.json",
sourceType: "module", sourceType: "module",
...@@ -61,7 +61,7 @@ export async function typescript(): Promise<Linter.Config[]> { ...@@ -61,7 +61,7 @@ export async function typescript(): Promise<Linter.Config[]> {
"@typescript-eslint/no-empty-function": [ "@typescript-eslint/no-empty-function": [
"error", "error",
{ {
allow: ["arrowFunctions", "functions", "methods"], allow: [ "arrowFunctions", "functions", "methods" ],
}, },
], ],
"@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-explicit-any": "off",
...@@ -90,7 +90,7 @@ export async function typescript(): Promise<Linter.Config[]> { ...@@ -90,7 +90,7 @@ export async function typescript(): Promise<Linter.Config[]> {
function ignoresMiniprogram(pluginTs: any, parserTs: any): Linter.Config { function ignoresMiniprogram(pluginTs: any, parserTs: any): Linter.Config {
return { return {
files: ["apps/miniprogram/**/*.?([cm])[jt]s?(x)"], files: [ "apps/miniprogram/**/*.?([cm])[jt]s?(x)" ],
languageOptions: { languageOptions: {
parser: parserTs, parser: parserTs,
parserOptions: { parserOptions: {
...@@ -99,7 +99,7 @@ function ignoresMiniprogram(pluginTs: any, parserTs: any): Linter.Config { ...@@ -99,7 +99,7 @@ function ignoresMiniprogram(pluginTs: any, parserTs: any): Linter.Config {
jsx: true, jsx: true,
}, },
ecmaVersion: "latest", ecmaVersion: "latest",
extraFileExtensions: [".vue"], extraFileExtensions: [ ".vue" ],
jsxPragma: "React", jsxPragma: "React",
project: "./tsconfig.*.json", project: "./tsconfig.*.json",
sourceType: "module", sourceType: "module",
...@@ -121,7 +121,7 @@ function ignoresMiniprogram(pluginTs: any, parserTs: any): Linter.Config { ...@@ -121,7 +121,7 @@ function ignoresMiniprogram(pluginTs: any, parserTs: any): Linter.Config {
function ignoresScript(pluginTs: any, parserTs: any): Linter.Config { function ignoresScript(pluginTs: any, parserTs: any): Linter.Config {
return { return {
files: ["scripts/**/*.?([cm])[jt]s?(x)"], files: [ "scripts/**/*.?([cm])[jt]s?(x)" ],
languageOptions: { languageOptions: {
parser: parserTs, parser: parserTs,
parserOptions: { parserOptions: {
...@@ -130,7 +130,7 @@ function ignoresScript(pluginTs: any, parserTs: any): Linter.Config { ...@@ -130,7 +130,7 @@ function ignoresScript(pluginTs: any, parserTs: any): Linter.Config {
jsx: true, jsx: true,
}, },
ecmaVersion: "latest", ecmaVersion: "latest",
extraFileExtensions: [".vue"], extraFileExtensions: [ ".vue" ],
jsxPragma: "React", jsxPragma: "React",
project: "./tsconfig.*.json", project: "./tsconfig.*.json",
sourceType: "module", sourceType: "module",
......
...@@ -13,14 +13,14 @@ import type { Linter } from "eslint"; ...@@ -13,14 +13,14 @@ import type { Linter } from "eslint";
import { interopDefault } from "../util"; import { interopDefault } from "../util";
export async function unicorn(): Promise<Linter.Config[]> { export async function unicorn(): Promise<Linter.Config[]> {
const [pluginUnicorn] = await Promise.all([interopDefault(import("eslint-plugin-unicorn"))] as const); const [ pluginUnicorn ] = await Promise.all([ interopDefault(import("eslint-plugin-unicorn")) ] as const);
return [ return [
{ {
plugins: { plugins: {
unicorn: pluginUnicorn, unicorn: pluginUnicorn,
}, },
ignores: ["**/*.wxml"], ignores: [ "**/*.wxml" ],
rules: { rules: {
...pluginUnicorn.configs.recommended.rules, ...pluginUnicorn.configs.recommended.rules,
"unicorn/no-abusive-eslint-disable": "off", "unicorn/no-abusive-eslint-disable": "off",
...@@ -40,14 +40,14 @@ export async function unicorn(): Promise<Linter.Config[]> { ...@@ -40,14 +40,14 @@ export async function unicorn(): Promise<Linter.Config[]> {
"unicorn/no-useless-undefined": "off", "unicorn/no-useless-undefined": "off",
"unicorn/prefer-at": "off", "unicorn/prefer-at": "off",
"unicorn/prefer-dom-node-text-content": "off", "unicorn/prefer-dom-node-text-content": "off",
"unicorn/prefer-export-from": ["error", { ignoreUsedVariables: true }], "unicorn/prefer-export-from": [ "error", { ignoreUsedVariables: true } ],
"unicorn/prefer-global-this": "off", "unicorn/prefer-global-this": "off",
"unicorn/prefer-top-level-await": "off", "unicorn/prefer-top-level-await": "off",
"unicorn/prevent-abbreviations": "off", "unicorn/prevent-abbreviations": "off",
}, },
}, },
{ {
files: ["scripts/**/*.?([cm])[jt]s?(x)", "internal/**/*.?([cm])[jt]s?(x)"], files: [ "scripts/**/*.?([cm])[jt]s?(x)", "internal/**/*.?([cm])[jt]s?(x)" ],
rules: { rules: {
"unicorn/no-process-exit": "off", "unicorn/no-process-exit": "off",
}, },
......
...@@ -12,7 +12,7 @@ import type { Linter } from "eslint"; ...@@ -12,7 +12,7 @@ import type { Linter } from "eslint";
import { interopDefault } from "../util"; import { interopDefault } from "../util";
export async function vue(): Promise<Linter.Config[]> { export async function vue(): Promise<Linter.Config[]> {
const [pluginVue, parserVue, parserTs] = await Promise.all([ const [ pluginVue, parserVue, parserTs ] = await Promise.all([
interopDefault(import("eslint-plugin-vue")), interopDefault(import("eslint-plugin-vue")),
interopDefault(import("vue-eslint-parser")), interopDefault(import("vue-eslint-parser")),
interopDefault(import("@typescript-eslint/parser")), interopDefault(import("@typescript-eslint/parser")),
...@@ -28,7 +28,7 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -28,7 +28,7 @@ export async function vue(): Promise<Linter.Config[]> {
...flatRecommended, ...flatRecommended,
{ {
// 针对 .vue 文件的专属规则 // 针对 .vue 文件的专属规则
files: ["**/*.vue"], files: [ "**/*.vue" ],
languageOptions: { languageOptions: {
// globals: { // globals: {
// computed: 'readonly', // computed: 'readonly',
...@@ -51,7 +51,7 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -51,7 +51,7 @@ export async function vue(): Promise<Linter.Config[]> {
ecmaFeatures: { ecmaFeatures: {
jsx: true, jsx: true,
}, },
extraFileExtensions: [".vue"], extraFileExtensions: [ ".vue" ],
parser: parserTs, parser: parserTs,
sourceType: "module", sourceType: "module",
}, },
...@@ -64,7 +64,7 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -64,7 +64,7 @@ export async function vue(): Promise<Linter.Config[]> {
// 继承插件基础规则 // 继承插件基础规则
...pluginVue.configs?.base?.rules, ...pluginVue.configs?.base?.rules,
"array-bracket-spacing": ["error", "always"], "array-bracket-spacing": [ "error", "always" ],
/** /**
* vue/attribute-hyphenation: 要求模板属性使用连字符风格 * vue/attribute-hyphenation: 要求模板属性使用连字符风格
* 设置原因: HTML 属性习惯上使用连字符(kebab-case),与 HTML 标准一致,便于代码审阅和 HTML 直接识别 * 设置原因: HTML 属性习惯上使用连字符(kebab-case),与 HTML 标准一致,便于代码审阅和 HTML 直接识别
...@@ -84,7 +84,7 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -84,7 +84,7 @@ export async function vue(): Promise<Linter.Config[]> {
"vue/block-order": [ "vue/block-order": [
"error", "error",
{ {
order: ["template", "script", "style"], order: [ [ "template", "script" ], "style" ],
}, },
], ],
...@@ -113,19 +113,19 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -113,19 +113,19 @@ export async function vue(): Promise<Linter.Config[]> {
* vue/component-name-in-template-casing: 要求模板中的组件使用 PascalCase 命名 * vue/component-name-in-template-casing: 要求模板中的组件使用 PascalCase 命名
* 设置原因: PascalCase 使组件易于识别,与 JavaScript 类的命名约定一致,提高代码可读性 * 设置原因: PascalCase 使组件易于识别,与 JavaScript 类的命名约定一致,提高代码可读性
*/ */
"vue/component-name-in-template-casing": ["error", "PascalCase"], "vue/component-name-in-template-casing": [ "error", "PascalCase" ],
/** /**
* vue/component-options-name-casing: 要求组件选项名使用 PascalCase * vue/component-options-name-casing: 要求组件选项名使用 PascalCase
* 设置原因: 组件选项如 MyComponent 使用 PascalCase,与类和构造函数的命名约定一致 * 设置原因: 组件选项如 MyComponent 使用 PascalCase,与类和构造函数的命名约定一致
*/ */
"vue/component-options-name-casing": ["error", "PascalCase"], "vue/component-options-name-casing": [ "error", "PascalCase" ],
/** /**
* vue/custom-event-name-casing: 要求自定义事件名使用 camelCase * vue/custom-event-name-casing: 要求自定义事件名使用 camelCase
* 设置原因: camelCase 是 JavaScript 事件的标准命名约定(如 onClick、onChange),保持一致性 * 设置原因: camelCase 是 JavaScript 事件的标准命名约定(如 onClick、onChange),保持一致性
*/ */
"vue/custom-event-name-casing": ["error", "camelCase"], "vue/custom-event-name-casing": [ "error", "camelCase" ],
/** /**
* vue/define-macros-order: 强制 defineXxx 宏的执行顺序 * vue/define-macros-order: 强制 defineXxx 宏的执行顺序
...@@ -134,7 +134,7 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -134,7 +134,7 @@ export async function vue(): Promise<Linter.Config[]> {
"vue/define-macros-order": [ "vue/define-macros-order": [
"error", "error",
{ {
order: ["defineOptions", "defineProps", "defineEmits", "defineSlots"], order: [ "defineOptions", "defineProps", "defineEmits", "defineSlots" ],
}, },
], ],
...@@ -142,19 +142,19 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -142,19 +142,19 @@ export async function vue(): Promise<Linter.Config[]> {
* vue/dot-location: 强制点号位置在属性上 * vue/dot-location: 强制点号位置在属性上
* 设置原因: 点号位于属性左侧(property)时,更符合代码链式调用的视觉习惯 * 设置原因: 点号位于属性左侧(property)时,更符合代码链式调用的视觉习惯
*/ */
"vue/dot-location": ["error", "property"], "vue/dot-location": [ "error", "property" ],
/** /**
* vue/dot-notation: 要求使用点号记法而不是括号记法访问属性 * vue/dot-notation: 要求使用点号记法而不是括号记法访问属性
* 设置原因: 点号记法(obj.prop)比括号记法(obj['prop'])更简洁易读,allowKeywords 允许使用保留字作属性 * 设置原因: 点号记法(obj.prop)比括号记法(obj['prop'])更简洁易读,allowKeywords 允许使用保留字作属性
*/ */
"vue/dot-notation": ["error", { allowKeywords: true }], "vue/dot-notation": [ "error", { allowKeywords: true } ],
/** /**
* vue/eqeqeq: 要求使用 === 和 !== 而不是 == 和 != * vue/eqeqeq: 要求使用 === 和 !== 而不是 == 和 !=
* 设置原因: smart 模式允许与 null 比较时使用 ==,避免隐式类型转换导致的 bug,同时保持常见情况的简洁 * 设置原因: smart 模式允许与 null 比较时使用 ==,避免隐式类型转换导致的 bug,同时保持常见情况的简洁
*/ */
"vue/eqeqeq": ["error", "smart"], "vue/eqeqeq": [ "error", "smart" ],
// 控制 Vue 模板中 HTML 标签的缩进 // 控制 Vue 模板中 HTML 标签的缩进
"vue/html-indent": [ "vue/html-indent": [
"error", "error",
...@@ -172,7 +172,7 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -172,7 +172,7 @@ export async function vue(): Promise<Linter.Config[]> {
* vue/html-quotes: 要求 HTML 属性值使用双引号 * vue/html-quotes: 要求 HTML 属性值使用双引号
* 设置原因: 双引号是 HTML 的标准写法,与代码规范一致,提高统一性 * 设置原因: 双引号是 HTML 的标准写法,与代码规范一致,提高统一性
*/ */
"vue/html-quotes": ["error", "double"], "vue/html-quotes": [ "error", "double" ],
/** /**
* vue/max-attributes-per-line: 强制:Vue 元素属性每行最多数量限制 * vue/max-attributes-per-line: 强制:Vue 元素属性每行最多数量限制
...@@ -198,7 +198,7 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -198,7 +198,7 @@ export async function vue(): Promise<Linter.Config[]> {
"vue/singleline-html-element-content-newline": [ "vue/singleline-html-element-content-newline": [
"error", "error",
{ {
externalIgnores: ["text"], // 忽略 <text> 标签(单行 <text> 内容无需换行,适用于 Vue 小程序等场景) externalIgnores: [ "text" ], // 忽略 <text> 标签(单行 <text> 内容无需换行,适用于 Vue 小程序等场景)
}, },
], ],
// 强制:Vue 元素首属性的换行格式 // 强制:Vue 元素首属性的换行格式
...@@ -240,13 +240,13 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -240,13 +240,13 @@ export async function vue(): Promise<Linter.Config[]> {
* vue/no-empty-pattern: 禁止空的解构模式 * vue/no-empty-pattern: 禁止空的解构模式
* 设置原因: 空模式 {} 或 [] 表示的意图不明确,通常是代码错误,应该避免 * 设置原因: 空模式 {} 或 [] 表示的意图不明确,通常是代码错误,应该避免
*/ */
"vue/no-empty-pattern": ["error", { allowObjectPatternsAsParameters: false }], "vue/no-empty-pattern": [ "error", { "allowObjectPatternsAsParameters": false } ],
/** /**
* vue/no-extra-parens: 禁止不必要的括号 * vue/no-extra-parens: 禁止不必要的括号
* 设置原因: 仅禁止函数表达式的多余括号,保持代码简洁,避免视觉混乱 * 设置原因: 仅禁止函数表达式的多余括号,保持代码简洁,避免视觉混乱
*/ */
"vue/no-extra-parens": ["error", "functions"], "vue/no-extra-parens": [ "error", "functions" ],
/** /**
* vue/no-irregular-whitespace: 禁止不规则的空白符 * vue/no-irregular-whitespace: 禁止不规则的空白符
...@@ -270,13 +270,13 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -270,13 +270,13 @@ export async function vue(): Promise<Linter.Config[]> {
* vue/no-restricted-syntax: 禁止某些语法结构 * vue/no-restricted-syntax: 禁止某些语法结构
* 设置原因: 禁止 debugger(生产遗留)、标记语句(不推荐)和 with 语句(易出错),提高代码质量 * 设置原因: 禁止 debugger(生产遗留)、标记语句(不推荐)和 with 语句(易出错),提高代码质量
*/ */
"vue/no-restricted-syntax": ["error", "DebuggerStatement", "LabeledStatement", "WithStatement"], "vue/no-restricted-syntax": [ "error", "DebuggerStatement", "LabeledStatement", "WithStatement" ],
/** /**
* vue/no-restricted-v-bind: 禁止 v-bind 绑定以 'v-' 开头的属性 * vue/no-restricted-v-bind: 禁止 v-bind 绑定以 'v-' 开头的属性
* 设置原因: 以 'v-' 开头的属性是 Vue 指令前缀,不应通过 v-bind 动态绑定,避免混淆 * 设置原因: 以 'v-' 开头的属性是 Vue 指令前缀,不应通过 v-bind 动态绑定,避免混淆
*/ */
"vue/no-restricted-v-bind": ["error", "/^v-/"], "vue/no-restricted-v-bind": [ "error", "/^v-/" ],
/** /**
* vue/no-sparse-arrays: 禁止稀疏数组(数组中有空槽) * vue/no-sparse-arrays: 禁止稀疏数组(数组中有空槽)
...@@ -337,7 +337,7 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -337,7 +337,7 @@ export async function vue(): Promise<Linter.Config[]> {
* vue/prop-name-casing: 要求 prop 名使用 camelCase * vue/prop-name-casing: 要求 prop 名使用 camelCase
* 设置原因: JavaScript 对象属性使用 camelCase,props 作为 JavaScript 对象属性应保持一致 * 设置原因: JavaScript 对象属性使用 camelCase,props 作为 JavaScript 对象属性应保持一致
*/ */
"vue/prop-name-casing": ["error", "camelCase"], "vue/prop-name-casing": [ "error", "camelCase" ],
/** /**
* vue/require-default-prop: 要求所有 prop 有默认值 * vue/require-default-prop: 要求所有 prop 有默认值
...@@ -367,7 +367,7 @@ export async function vue(): Promise<Linter.Config[]> { ...@@ -367,7 +367,7 @@ export async function vue(): Promise<Linter.Config[]> {
* vue/space-unary-ops: 要求一元操作符前后有空格 * vue/space-unary-ops: 要求一元操作符前后有空格
* 设置原因: typeof x 比 typeosx 清晰,words 为 true 使 typeof、delete 等词类操作符前后加空格,nonwords 为 false 不要求 ++、-- 前后空格 * 设置原因: typeof x 比 typeosx 清晰,words 为 true 使 typeof、delete 等词类操作符前后加空格,nonwords 为 false 不要求 ++、-- 前后空格
*/ */
"vue/space-unary-ops": ["error", { nonwords: false, words: true }], "vue/space-unary-ops": [ "error", { nonwords: false, words: true } ],
/** /**
* vue/v-on-event-hyphenation: 要求 v-on 事件名使用连字符风格 * vue/v-on-event-hyphenation: 要求 v-on 事件名使用连字符风格
......
...@@ -21,7 +21,7 @@ export function wxmlConfig(): Linter.Config[] { ...@@ -21,7 +21,7 @@ export function wxmlConfig(): Linter.Config[] {
return [ return [
{ {
files: ["**/*.wxml", "**/*.wxs"], files: [ "**/*.wxml", "**/*.wxs" ],
languageOptions: { languageOptions: {
parser: wxmlParserWithMeta, parser: wxmlParserWithMeta,
}, },
...@@ -211,7 +211,7 @@ export function wxmlConfig(): Linter.Config[] { ...@@ -211,7 +211,7 @@ export function wxmlConfig(): Linter.Config[] {
* ✅ 正确: <view wx:if="{{show}}">{{title}}</view> * ✅ 正确: <view wx:if="{{show}}">{{title}}</view>
* ❌ 错误: <component attr='{{data}}' /> * ❌ 错误: <component attr='{{data}}' />
*/ */
"wxml/quotes": ["error", "double"], "wxml/quotes": [ "error", "double" ],
// =========================== // ===========================
// 事件绑定相关规则 // 事件绑定相关规则
...@@ -224,7 +224,7 @@ export function wxmlConfig(): Linter.Config[] { ...@@ -224,7 +224,7 @@ export function wxmlConfig(): Linter.Config[] {
* ✅ 正确 (colon style): <view bind:tap="clickhandler" />, <view mut-bind:tap="clickhandler" />, <view catch:tap="clickhandler" /> * ✅ 正确 (colon style): <view bind:tap="clickhandler" />, <view mut-bind:tap="clickhandler" />, <view catch:tap="clickhandler" />
* ❌ 错误 (no-colon style): <view bindtap="clickhandler" /> * ❌ 错误 (no-colon style): <view bindtap="clickhandler" />
*/ */
"wxml/event-binding-style": ["error", "colon"], "wxml/event-binding-style": [ "error", "colon" ],
// =========================== // ===========================
// wx:for 和 wx:key 相关规则 // wx:for 和 wx:key 相关规则
...@@ -305,7 +305,7 @@ export function wxmlConfig(): Linter.Config[] { ...@@ -305,7 +305,7 @@ export function wxmlConfig(): Linter.Config[] {
* ✅ 正确: <view depth="1"><view depth="2"><view depth="3"></view></view><view depth="2"></view></view> * ✅ 正确: <view depth="1"><view depth="2"><view depth="3"></view></view><view depth="2"></view></view>
* ❌ 错误: 超过配置的最大深度 * ❌ 错误: 超过配置的最大深度
*/ */
"wxml/max-depth": ["warn", 10], "wxml/max-depth": [ "warn", 10 ],
/** /**
* 强制文件的最大行数 * 强制文件的最大行数
...@@ -314,7 +314,7 @@ export function wxmlConfig(): Linter.Config[] { ...@@ -314,7 +314,7 @@ export function wxmlConfig(): Linter.Config[] {
* ✅ 正确: 文件行数不超过指定数量 * ✅ 正确: 文件行数不超过指定数量
* ❌ 错误: 超过最大行数的文件 * ❌ 错误: 超过最大行数的文件
*/ */
"wxml/max-lines": ["warn", { max: 500 }], "wxml/max-lines": [ "warn", { max: 500 } ],
// =========================== // ===========================
// 其他规则 // 其他规则
......
...@@ -14,6 +14,6 @@ import { customConfigMiniprogram } from "./miniprogram"; ...@@ -14,6 +14,6 @@ import { customConfigMiniprogram } from "./miniprogram";
import { customConfigUniapp } from "./uniapp"; import { customConfigUniapp } from "./uniapp";
import { customConfigVben } from "./vben"; import { customConfigVben } from "./vben";
const customConfig: Linter.Config[] = [...customConfigVben(), ...customConfigMiniprogram(), ...customConfigUniapp()]; const customConfig: Linter.Config[] = [ ...customConfigVben(), ...customConfigMiniprogram(), ...customConfigUniapp() ];
export { customConfig }; export { customConfig };
...@@ -5,7 +5,7 @@ import type { Linter } from "eslint"; ...@@ -5,7 +5,7 @@ import type { Linter } from "eslint";
export function customConfigMiniprogram(): Linter.Config[] { export function customConfigMiniprogram(): Linter.Config[] {
return [ return [
{ {
files: ["apps/**/miniprogram/**/*.?([cm])[jt]s?(x)"], files: [ "apps/**/miniprogram/**/*.?([cm])[jt]s?(x)" ],
rules: { rules: {
// ==================== CommonJS 相关 ==================== // ==================== CommonJS 相关 ====================
// 小程序强制使用 CommonJS,不支持 ES Modules 语法 // 小程序强制使用 CommonJS,不支持 ES Modules 语法
......
...@@ -3,11 +3,12 @@ import type { Linter } from "eslint"; ...@@ -3,11 +3,12 @@ import type { Linter } from "eslint";
export function customConfigUniapp(): Linter.Config[] { export function customConfigUniapp(): Linter.Config[] {
return [ return [
{ {
files: ["apps/**/uniapp/**/**"], files: [ "apps/**/uniapp/**/**" ],
rules: { rules: {
"eslint-comments/no-unlimited-disable": "off", "eslint-comments/no-unlimited-disable": "off",
"unicorn/prefer-module": "warn", "unicorn/prefer-module": "warn",
}, },
}, },
]; ];
} }
import type { Linter } from "eslint"; import type { Linter } from "eslint";
const restrictedImportIgnores = ["**/vite.config.mts", "**/tailwind.config.mjs", "**/postcss.config.mjs"]; const restrictedImportIgnores = [ "**/vite.config.mts", "**/tailwind.config.mjs", "**/postcss.config.mjs" ];
export function customConfigVben(): Linter.Config[] { export function customConfigVben(): Linter.Config[] {
return [ return [
{ {
files: ["**/**/playwright.config.ts"], files: [ "**/**/playwright.config.ts" ],
rules: { rules: {
"n/prefer-global/buffer": "off", "n/prefer-global/buffer": "off",
"n/prefer-global/process": "off", "n/prefer-global/process": "off",
...@@ -12,14 +12,14 @@ export function customConfigVben(): Linter.Config[] { ...@@ -12,14 +12,14 @@ export function customConfigVben(): Linter.Config[] {
}, },
}, },
{ {
files: ["internal/**/**", "scripts/**/**"], files: [ "internal/**/**", "scripts/**/**" ],
rules: { rules: {
"no-console": "off", "no-console": "off",
}, },
}, },
// shadcn-ui 内部组件是自动生成的,不做太多限制 // shadcn-ui 内部组件是自动生成的,不做太多限制
{ {
files: ["packages/@core/ui-kit/shadcn-ui/**/**"], files: [ "packages/@core/ui-kit/shadcn-ui/**/**" ],
rules: { rules: {
"vue/require-default-prop": "off", "vue/require-default-prop": "off",
}, },
...@@ -39,114 +39,114 @@ export function customConfigVben(): Linter.Config[] { ...@@ -39,114 +39,114 @@ export function customConfigVben(): Linter.Config[] {
}, },
}, },
{ {
files: ["**/**.vue"], files: [ "**/**.vue" ],
ignores: restrictedImportIgnores, ignores: restrictedImportIgnores,
rules: { rules: {
"perfectionist/sort-objects": "off", "perfectionist/sort-objects": "off",
}, },
}, },
{ // {
// apps内部的一些基础规则 // // apps内部的一些基础规则
files: ["apps/**/**"], // files: [ "apps/**/**" ],
ignores: restrictedImportIgnores, // ignores: restrictedImportIgnores,
rules: { // rules: {
"no-restricted-imports": [ // "no-restricted-imports": [
"error", // "error",
{ // {
patterns: [ // patterns: [
{ // {
group: ["#/api/*"], // group: [ "#/api/*" ],
message: "The #/api package cannot be imported, please use the @core package itself", // message: "The #/api package cannot be imported, please use the @core package itself",
}, // },
{ // {
group: ["#/layouts/*"], // group: [ "#/layouts/*" ],
message: // message:
"The #/layouts package cannot be imported, please use the @core package itself", // "The #/layouts package cannot be imported, please use the @core package itself",
}, // },
{ // {
group: ["#/locales/*"], // group: [ "#/locales/*" ],
message: // message:
"The #/locales package cannot be imported, please use the @core package itself", // "The #/locales package cannot be imported, please use the @core package itself",
}, // },
{ // {
group: ["#/stores/*"], // group: [ "#/stores/*" ],
message: "The #/stores package cannot be imported, please use the @core package itself", // message: "The #/stores package cannot be imported, please use the @core package itself",
}, // },
], // ],
}, // },
], // ],
"perfectionist/sort-interfaces": "off", // "perfectionist/sort-interfaces": "off",
}, // },
}, // },
{ // {
// @core内部组件,不能引入@venus/* 里面的包 // // @core内部组件,不能引入@venus/* 里面的包
files: ["packages/@core/**/**"], // files: [ "packages/@core/**/**" ],
ignores: restrictedImportIgnores, // ignores: restrictedImportIgnores,
rules: { // rules: {
"no-restricted-imports": [ // "no-restricted-imports": [
"error", // "error",
{ // {
patterns: [ // patterns: [
{ // {
group: ["@venus/*"], // group: [ "@venus/*" ],
message: // message:
"The @core package cannot import the @vben package, please use the @core package itself", // "The @core package cannot import the @vben package, please use the @core package itself",
}, // },
], // ],
}, // },
], // ],
}, // },
}, // },
{ // {
// @core/shared内部组件,不能引入@venus/* 或者 @vben-core/* 里面的包 // // @core/shared内部组件,不能引入@venus/* 或者 @vben-core/* 里面的包
files: ["packages/@core/base/**/**"], // files: [ "packages/@core/base/**/**" ],
ignores: restrictedImportIgnores, // ignores: restrictedImportIgnores,
rules: { // rules: {
"no-restricted-imports": [ // "no-restricted-imports": [
"error", // "error",
{ // {
patterns: [ // patterns: [
{ // {
group: ["@venus/*", "@vben-core/*"], // group: [ "@venus/*", "@vben-core/*" ],
message: // message:
"The @vben-core/shared package cannot import the @vben package, please use the @core/shared package itself", // "The @vben-core/shared package cannot import the @vben package, please use the @core/shared package itself",
}, // },
], // ],
}, // },
], // ],
}, // },
}, // },
{ // {
// 不能引入@venus/*里面的包 // // 不能引入@venus/*里面的包
files: [ // files: [
"packages/types/**/**", // "packages/types/**/**",
"packages/utils/**/**", // "packages/utils/**/**",
"packages/icons/**/**", // "packages/icons/**/**",
"packages/constants/**/**", // "packages/constants/**/**",
"packages/styles/**/**", // "packages/styles/**/**",
"packages/stores/**/**", // "packages/stores/**/**",
"packages/preferences/**/**", // "packages/preferences/**/**",
"packages/locales/**/**", // "packages/locales/**/**",
], // ],
ignores: restrictedImportIgnores, // ignores: restrictedImportIgnores,
rules: { // rules: {
"no-restricted-imports": [ // "no-restricted-imports": [
"error", // "error",
{ // {
patterns: [ // patterns: [
{ // {
group: ["@venus/*"], // group: [ "@venus/*" ],
message: "The @vben package cannot be imported, please use the @core package itself", // message: "The @vben package cannot be imported, please use the @core package itself",
}, // },
], // ],
}, // },
], // ],
}, // },
}, // },
// 后端模拟代码,不需要太多规则 // 后端模拟代码,不需要太多规则
{ {
files: ["apps/backend-mock/**/**", "docs/**/**"], files: [ "apps/backend-mock/**/**", "docs/**/**" ],
rules: { rules: {
"@typescript-eslint/no-extraneous-class": "off", "@typescript-eslint/no-extraneous-class": "off",
"n/no-extraneous-import": "off", "n/no-extraneous-import": "off",
......
...@@ -7,17 +7,17 @@ export default { ...@@ -7,17 +7,17 @@ export default {
htmlWhitespaceSensitivity: "ignore", htmlWhitespaceSensitivity: "ignore",
bracketSameLine: true, bracketSameLine: true,
plugins: ["prettier-plugin-tailwindcss", "@venus/prettier-plugin-wxml"], plugins: [ "prettier-plugin-tailwindcss", "@venus/prettier-plugin-wxml" ],
overrides: [ overrides: [
{ {
files: ["*.json5"], files: [ "*.json5" ],
options: { options: {
quoteProps: "preserve", quoteProps: "preserve",
singleQuote: false, singleQuote: false,
}, },
}, },
{ {
files: ["*.wxml"], files: [ "*.wxml" ],
options: { options: {
parser: "wxml", parser: "wxml",
}, },
......
...@@ -156,11 +156,11 @@ function buildMultiLineMustacheDocFromPrinted(printedText) { ...@@ -156,11 +156,11 @@ function buildMultiLineMustacheDocFromPrinted(printedText) {
if (simple) { if (simple) {
// Simple identifier like "title": content aligns with '{{', '}}' at parent indent // Simple identifier like "title": content aligns with '{{', '}}' at parent indent
return [indent([hardline, "{{", ...contentDoc]), hardline, "}}", hardline]; return [ indent([ hardline, "{{", ...contentDoc ]), hardline, "}}", hardline ];
} }
// Complex expression: indent inner content, align '}}' with '{{' // Complex expression: indent inner content, align '}}' with '{{'
return [indent([hardline, "{{", indent(contentDoc), hardline, "}}"]), hardline]; return [ indent([ hardline, "{{", indent(contentDoc), hardline, "}}" ]), hardline ];
} }
function printElement(path, opts, print) { function printElement(path, opts, print) {
...@@ -244,7 +244,7 @@ function printElement(path, opts, print) { ...@@ -244,7 +244,7 @@ function printElement(path, opts, print) {
const content = allParts.slice(0, -1); // 前面的是内容 const content = allParts.slice(0, -1); // 前面的是内容
return group([ return group([
parts[0], // <text ...> parts[0], // <text ...>
indent([hardline, ...content]), indent([ hardline, ...content ]),
hardline, hardline,
endTag, endTag,
]); ]);
...@@ -321,7 +321,7 @@ function printElement(path, opts, print) { ...@@ -321,7 +321,7 @@ function printElement(path, opts, print) {
parts.push(...childrenParts); parts.push(...childrenParts);
} else { } else {
const childrenWithBreaks = []; const childrenWithBreaks = [];
for (const [i, printed] of childrenParts.entries()) { for (const [ i, printed ] of childrenParts.entries()) {
if (i > 0) childrenWithBreaks.push(hardline); if (i > 0) childrenWithBreaks.push(hardline);
const entry = childEntries[i]; const entry = childEntries[i];
// Don't split multi-line text to avoid instability; trust the printed output // Don't split multi-line text to avoid instability; trust the printed output
...@@ -346,7 +346,7 @@ function printElement(path, opts, print) { ...@@ -346,7 +346,7 @@ function printElement(path, opts, print) {
} }
// Normal path // Normal path
if (!didSpecial) { if (!didSpecial) {
parts.push(indent([hardline, ...childrenWithBreaks]), hardline); parts.push(indent([ hardline, ...childrenWithBreaks ]), hardline);
} }
} }
} }
...@@ -439,7 +439,7 @@ function printStartTag(path, opts, print) { ...@@ -439,7 +439,7 @@ function printStartTag(path, opts, print) {
// 从路径中获取当前节点 // 从路径中获取当前节点
const node = path.getValue(); const node = path.getValue();
// 初始化部分数组,包含开始标签的 "<" 和标签名称 // 初始化部分数组,包含开始标签的 "<" 和标签名称
const parts = ["<", node.name]; const parts = [ "<", node.name ];
// 检查是否存在属性且属性列表不为空 // 检查是否存在属性且属性列表不为空
if (node.attributes && node.attributes.length > 0) { if (node.attributes && node.attributes.length > 0) {
// 将每个属性映射为格式化的属性文档字符串 // 将每个属性映射为格式化的属性文档字符串
...@@ -482,7 +482,7 @@ function printStartTag(path, opts, print) { ...@@ -482,7 +482,7 @@ function printStartTag(path, opts, print) {
parts.push(" ", firstAttr); parts.push(" ", firstAttr);
// 计算与第一个属性对齐的缩进 // 计算与第一个属性对齐的缩进
const firstAttrIndent = " ".repeat(node.name.length + 2); // "<" + tagName + space const firstAttrIndent = " ".repeat(node.name.length + 2); // "<" + tagName + space
const indentedAttributes = [hardline, firstAttrIndent, join([hardline, firstAttrIndent], restAttrs)]; const indentedAttributes = [ hardline, firstAttrIndent, join([ hardline, firstAttrIndent ], restAttrs) ];
parts.push(...indentedAttributes); parts.push(...indentedAttributes);
} else { } else {
// 只有一个属性,保留在同一行 // 只有一个属性,保留在同一行
......
...@@ -3,5 +3,5 @@ import { defineBuildConfig } from "unbuild"; ...@@ -3,5 +3,5 @@ import { defineBuildConfig } from "unbuild";
export default defineBuildConfig({ export default defineBuildConfig({
clean: true, clean: true,
declaration: true, declaration: true,
entries: ["src/index"], entries: [ "src/index" ],
}); });
...@@ -8,15 +8,15 @@ export function configMiniprogram(): ConfigOverride[] { ...@@ -8,15 +8,15 @@ export function configMiniprogram(): ConfigOverride[] {
return [ return [
// WXSS 文件的配置(纯样式文件) // WXSS 文件的配置(纯样式文件)
{ {
files: ["**/apps/miniprogram/**/*.{css,less,scss,sass,wxss}", "**/apps/uniapp/**/*.{css,less,scss,sass}"], files: [ "**/apps/miniprogram/**/*.{css,less,scss,sass,wxss}", "**/apps/uniapp/**/*.{css,less,scss,sass}" ],
customSyntax: "postcss", customSyntax: "postcss",
extends: ["stylelint-config-recess-order"], extends: [ "stylelint-config-recess-order" ],
rules: { rules: {
// 允许 rpx 单位(uni-app 响应式单位) // 允许 rpx 单位(uni-app 响应式单位)
"unit-no-unknown": [ "unit-no-unknown": [
true, true,
{ {
ignoreUnits: ["rpx", "upx"], ignoreUnits: [ "rpx", "upx" ],
}, },
], ],
// 允许未知的属性值(uni-app 特有值) // 允许未知的属性值(uni-app 特有值)
...@@ -27,23 +27,23 @@ export function configMiniprogram(): ConfigOverride[] { ...@@ -27,23 +27,23 @@ export function configMiniprogram(): ConfigOverride[] {
"selector-type-no-unknown": [ "selector-type-no-unknown": [
true, true,
{ {
ignore: ["custom-elements"], ignore: [ "custom-elements" ],
ignoreTypes: ["/^(page|view|text|image|button|input|scroll-view|swiper|navigator)/"], ignoreTypes: [ "/^(page|view|text|image|button|input|scroll-view|swiper|navigator)/" ],
}, },
], ],
}, },
}, },
// Vue 和 HTML 中的样式块 // Vue 和 HTML 中的样式块
{ {
files: ["**/apps/miniprogram/**/*.{vue,html}", "**/apps/uniapp/**/*.{vue,html}"], files: [ "**/apps/miniprogram/**/*.{vue,html}", "**/apps/uniapp/**/*.{vue,html}" ],
customSyntax: "postcss-html", customSyntax: "postcss-html",
extends: ["stylelint-config-recess-order"], extends: [ "stylelint-config-recess-order" ],
rules: { rules: {
// 允许 rpx 单位 // 允许 rpx 单位
"unit-no-unknown": [ "unit-no-unknown": [
true, true,
{ {
ignoreUnits: ["rpx"], ignoreUnits: [ "rpx" ],
}, },
], ],
// 允许未知的属性值 // 允许未知的属性值
...@@ -54,22 +54,22 @@ export function configMiniprogram(): ConfigOverride[] { ...@@ -54,22 +54,22 @@ export function configMiniprogram(): ConfigOverride[] {
"selector-type-no-unknown": [ "selector-type-no-unknown": [
true, true,
{ {
ignore: ["custom-elements"], ignore: [ "custom-elements" ],
ignoreTypes: ["/^(page|view|text|image|button|input|scroll-view|swiper|navigator)/"], ignoreTypes: [ "/^(page|view|text|image|button|input|scroll-view|swiper|navigator)/" ],
}, },
], ],
// Vue 的伪类选择器(如 :global, :deep) // Vue 的伪类选择器(如 :global, :deep)
"selector-pseudo-class-no-unknown": [ "selector-pseudo-class-no-unknown": [
true, true,
{ {
ignorePseudoClasses: ["global", "deep"], ignorePseudoClasses: [ "global", "deep" ],
}, },
], ],
// Vue 的伪元素选择器(如 v-deep, v-global) // Vue 的伪元素选择器(如 v-deep, v-global)
"selector-pseudo-element-no-unknown": [ "selector-pseudo-element-no-unknown": [
true, true,
{ {
ignorePseudoElements: ["v-deep", "v-global", "v-slotted"], ignorePseudoElements: [ "v-deep", "v-global", "v-slotted" ],
}, },
], ],
}, },
......
...@@ -15,10 +15,10 @@ export default { ...@@ -15,10 +15,10 @@ export default {
// 继承的预设配置 // 继承的预设配置
// stylelint-config-standard: 标准的 CSS 规则 // stylelint-config-standard: 标准的 CSS 规则
// stylelint-config-recess-order: 声明属性顺序规则 // stylelint-config-recess-order: 声明属性顺序规则
extends: ["stylelint-config-standard", "stylelint-config-recess-order"], extends: [ "stylelint-config-standard", "stylelint-config-recess-order" ],
// 忽略的文件类型(非样式文件) // 忽略的文件类型(非样式文件)
ignoreFiles: ["**/*.js", "**/*.jsx", "**/*.tsx", "**/*.ts", "**/*.json", "**/*.md"], ignoreFiles: [ "**/*.js", "**/*.jsx", "**/*.tsx", "**/*.ts", "**/*.json", "**/*.md" ],
// 针对不同文件类型的特殊配置覆盖 // 针对不同文件类型的特殊配置覆盖
overrides: [ overrides: [
...@@ -27,20 +27,20 @@ export default { ...@@ -27,20 +27,20 @@ export default {
{ {
// 使用 postcss-html 解析器处理 HTML/Vue 中的样式块 // 使用 postcss-html 解析器处理 HTML/Vue 中的样式块
customSyntax: "postcss-html", customSyntax: "postcss-html",
files: ["*.(html|vue)", "**/*.(html|vue)"], files: [ "*.(html|vue)", "**/*.(html|vue)" ],
rules: { rules: {
// Vue 的伪类选择器(如 :global, :deep) // Vue 的伪类选择器(如 :global, :deep)
"selector-pseudo-class-no-unknown": [ "selector-pseudo-class-no-unknown": [
true, true,
{ {
ignorePseudoClasses: ["global", "deep"], ignorePseudoClasses: [ "global", "deep" ],
}, },
], ],
// Vue 的伪元素选择器(如 v-deep, v-global) // Vue 的伪元素选择器(如 v-deep, v-global)
"selector-pseudo-element-no-unknown": [ "selector-pseudo-element-no-unknown": [
true, true,
{ {
ignorePseudoElements: ["v-deep", "v-global", "v-slotted"], ignorePseudoElements: [ "v-deep", "v-global", "v-slotted" ],
}, },
], ],
}, },
...@@ -49,8 +49,8 @@ export default { ...@@ -49,8 +49,8 @@ export default {
{ {
// 使用 postcss-scss 解析器处理 SCSS 语法 // 使用 postcss-scss 解析器处理 SCSS 语法
customSyntax: "postcss-scss", customSyntax: "postcss-scss",
extends: ["stylelint-config-recommended-scss", "stylelint-config-recommended-vue/scss"], extends: [ "stylelint-config-recommended-scss", "stylelint-config-recommended-vue/scss" ],
files: ["*.scss", "**/*.scss"], files: [ "*.scss", "**/*.scss" ],
}, },
], ],
...@@ -139,7 +139,7 @@ export default { ...@@ -139,7 +139,7 @@ export default {
"rule-empty-line-before": [ "rule-empty-line-before": [
"always", "always",
{ {
ignore: ["after-comment", "first-nested"], ignore: [ "after-comment", "first-nested" ],
}, },
], ],
......
...@@ -3,5 +3,5 @@ import { defineBuildConfig } from "unbuild"; ...@@ -3,5 +3,5 @@ import { defineBuildConfig } from "unbuild";
export default defineBuildConfig({ export default defineBuildConfig({
clean: true, clean: true,
declaration: true, declaration: true,
entries: ["src/index"], entries: [ "src/index" ],
}); });
...@@ -24,7 +24,7 @@ async function getStagedFiles(): Promise<string[]> { ...@@ -24,7 +24,7 @@ async function getStagedFiles(): Promise<string[]> {
changedList = changedList.map((item) => path.resolve(process.cwd(), item)); changedList = changedList.map((item) => path.resolve(process.cwd(), item));
const changedSet = new Set(changedList); const changedSet = new Set(changedList);
changedSet.delete(""); changedSet.delete("");
return [...changedSet]; return [ ...changedSet ];
} catch (error) { } catch (error) {
console.error("Failed to get staged files:", error); console.error("Failed to get staged files:", error);
return []; return [];
......
...@@ -3,7 +3,7 @@ import { defineBuildConfig } from "unbuild"; ...@@ -3,7 +3,7 @@ import { defineBuildConfig } from "unbuild";
export default defineBuildConfig({ export default defineBuildConfig({
clean: true, clean: true,
declaration: true, declaration: true,
entries: ["src/index", "./src/postcss.config"], entries: [ "src/index", "./src/postcss.config" ],
rollup: { rollup: {
emitCJS: true, emitCJS: true,
}, },
......
...@@ -121,7 +121,7 @@ export default { ...@@ -121,7 +121,7 @@ export default {
...tailwindPackages.map((item) => path.join(item, "src/**/*.{vue,js,ts,jsx,tsx,svelte,astro,html}")), ...tailwindPackages.map((item) => path.join(item, "src/**/*.{vue,js,ts,jsx,tsx,svelte,astro,html}")),
], ],
darkMode: "selector", darkMode: "selector",
plugins: [animate, typographyPlugin, addDynamicIconSelectors(), enterAnimationPlugin], plugins: [ animate, typographyPlugin, addDynamicIconSelectors(), enterAnimationPlugin ],
prefix: "", prefix: "",
theme: { theme: {
container: { container: {
...@@ -194,7 +194,7 @@ export default { ...@@ -194,7 +194,7 @@ export default {
}, },
}, },
}, },
safelist: ["dark"], safelist: [ "dark" ],
} as Config; } as Config;
function createColorsPalette(name: string) { function createColorsPalette(name: string) {
......
...@@ -6,7 +6,7 @@ export default { ...@@ -6,7 +6,7 @@ export default {
// Specifying the config is not necessary in most cases, but it is included // Specifying the config is not necessary in most cases, but it is included
autoprefixer: {}, autoprefixer: {},
// 修复 element-plus 和 ant-design-vue 的样式和tailwindcss冲突问题 // 修复 element-plus 和 ant-design-vue 的样式和tailwindcss冲突问题
"postcss-antd-fixes": { prefixes: ["ant", "el"] }, "postcss-antd-fixes": { prefixes: [ "ant", "el" ] },
"postcss-import": {}, "postcss-import": {},
"postcss-preset-env": {}, "postcss-preset-env": {},
tailwindcss: { config }, tailwindcss: { config },
......
...@@ -3,5 +3,5 @@ import { defineBuildConfig } from "unbuild"; ...@@ -3,5 +3,5 @@ import { defineBuildConfig } from "unbuild";
export default defineBuildConfig({ export default defineBuildConfig({
clean: true, clean: true,
declaration: true, declaration: true,
entries: ["src/index"], entries: [ "src/index" ],
}); });
...@@ -28,7 +28,7 @@ function defineApplicationConfig(userConfigPromise?: DefineApplicationOptions) { ...@@ -28,7 +28,7 @@ function defineApplicationConfig(userConfigPromise?: DefineApplicationOptions) {
archiver: true, archiver: true,
archiverPluginOptions: {}, archiverPluginOptions: {},
compress: false, compress: false,
compressTypes: ["brotli", "gzip"], compressTypes: [ "brotli", "gzip" ],
devtools: true, devtools: true,
env, env,
extraAppConfig: true, extraAppConfig: true,
...@@ -112,7 +112,7 @@ function createCssOptions(injectGlobalScss = true): CSSOptions { ...@@ -112,7 +112,7 @@ function createCssOptions(injectGlobalScss = true): CSSOptions {
return content; return content;
}, },
// api: 'modern', // api: 'modern',
importers: [new NodePackageImporter()], importers: [ new NodePackageImporter() ],
}, },
} }
: {}, : {},
......
...@@ -27,14 +27,14 @@ function defineLibraryConfig(userConfigPromise?: DefineLibraryOptions) { ...@@ -27,14 +27,14 @@ function defineLibraryConfig(userConfigPromise?: DefineLibraryOptions) {
const { dependencies = {}, peerDependencies = {} } = await readPackageJSON(root); const { dependencies = {}, peerDependencies = {} } = await readPackageJSON(root);
const externalPackages = [...Object.keys(dependencies), ...Object.keys(peerDependencies)]; const externalPackages = [ ...Object.keys(dependencies), ...Object.keys(peerDependencies) ];
const packageConfig: UserConfig = { const packageConfig: UserConfig = {
build: { build: {
lib: { lib: {
entry: "src/index.ts", entry: "src/index.ts",
fileName: () => "index.mjs", fileName: () => "index.mjs",
formats: ["es"], formats: [ "es" ],
}, },
rollupOptions: { rollupOptions: {
external: (id) => { external: (id) => {
......
...@@ -53,7 +53,7 @@ async function viteExtraAppConfigPlugin({ isBuild, root }: PluginOptions): Promi ...@@ -53,7 +53,7 @@ async function viteExtraAppConfigPlugin({ isBuild, root }: PluginOptions): Promi
return { return {
html, html,
tags: [{ attrs: { src: appConfigSrc }, tag: "script" }], tags: [ { attrs: { src: appConfigSrc }, tag: "script" } ],
}; };
}, },
}; };
......
...@@ -54,7 +54,7 @@ async function viteImportMapPlugin(pluginOptions?: pluginOptions): Promise<Plugi ...@@ -54,7 +54,7 @@ async function viteImportMapPlugin(pluginOptions?: pluginOptions): Promise<Plugi
{ {
debug: false, debug: false,
defaultProvider: "jspm.io", defaultProvider: "jspm.io",
env: ["production", "browser", "module"], env: [ "production", "browser", "module" ],
importmap: [], importmap: [],
}, },
pluginOptions, pluginOptions,
......
...@@ -58,19 +58,19 @@ async function loadCommonPlugins(options: CommonPluginOptions): Promise<Conditio ...@@ -58,19 +58,19 @@ async function loadCommonPlugins(options: CommonPluginOptions): Promise<Conditio
{ {
condition: !isBuild && devtools, condition: !isBuild && devtools,
plugins: () => [viteVueDevTools()], plugins: () => [ viteVueDevTools() ],
}, },
{ {
condition: injectMetadata, condition: injectMetadata,
plugins: async () => [await viteMetadataPlugin()], plugins: async () => [ await viteMetadataPlugin() ],
}, },
{ {
condition: isBuild && !!visualizer, condition: isBuild && !!visualizer,
plugins: () => [<PluginOption>viteVisualizerPlugin({ plugins: () => [ <PluginOption>viteVisualizerPlugin({
filename: "./node_modules/.cache/visualizer/stats.html", filename: "./node_modules/.cache/visualizer/stats.html",
gzipSize: true, gzipSize: true,
open: true, open: true,
})], }) ],
}, },
]; ];
} }
...@@ -124,29 +124,29 @@ async function loadApplicationPlugins(options: ApplicationPluginOptions): Promis ...@@ -124,29 +124,29 @@ async function loadApplicationPlugins(options: ApplicationPluginOptions): Promis
{ {
condition: print, condition: print,
plugins: async () => { plugins: async () => {
return [await vitePrintPlugin({ infoMap: printInfoMap })]; return [ await vitePrintPlugin({ infoMap: printInfoMap }) ];
}, },
}, },
{ {
condition: vxeTableLazyImport, condition: vxeTableLazyImport,
plugins: async () => { plugins: async () => {
return [await viteVxeTableImportsPlugin()]; return [ await viteVxeTableImportsPlugin() ];
}, },
}, },
{ {
condition: nitroMock, condition: nitroMock,
plugins: async () => { plugins: async () => {
return [await viteNitroMockPlugin(nitroMockOptions)]; return [ await viteNitroMockPlugin(nitroMockOptions) ];
}, },
}, },
{ {
condition: injectAppLoading, condition: injectAppLoading,
plugins: async () => [await viteInjectAppLoadingPlugin(!!isBuild, env)], plugins: async () => [ await viteInjectAppLoadingPlugin(!!isBuild, env) ],
}, },
{ {
condition: license, condition: license,
plugins: async () => [await viteLicensePlugin()], plugins: async () => [ await viteLicensePlugin() ],
}, },
{ {
condition: pwa, condition: pwa,
...@@ -180,22 +180,22 @@ async function loadApplicationPlugins(options: ApplicationPluginOptions): Promis ...@@ -180,22 +180,22 @@ async function loadApplicationPlugins(options: ApplicationPluginOptions): Promis
}, },
{ {
condition: !!html, condition: !!html,
plugins: () => [viteHtmlPlugin({ minify: true })], plugins: () => [ viteHtmlPlugin({ minify: true }) ],
}, },
{ {
condition: isBuild && importmap, condition: isBuild && importmap,
plugins: () => { plugins: () => {
return [viteImportMapPlugin(importmapOptions)]; return [ viteImportMapPlugin(importmapOptions) ];
}, },
}, },
{ {
condition: isBuild && extraAppConfig, condition: isBuild && extraAppConfig,
plugins: async () => [await viteExtraAppConfigPlugin({ isBuild: true, root: process.cwd() })], plugins: async () => [ await viteExtraAppConfigPlugin({ isBuild: true, root: process.cwd() }) ],
}, },
{ {
condition: archiver, condition: archiver,
plugins: async () => { plugins: async () => {
return [await viteArchiverPlugin(archiverPluginOptions)]; return [ await viteArchiverPlugin(archiverPluginOptions) ];
}, },
}, },
]); ]);
...@@ -213,7 +213,7 @@ async function loadLibraryPlugins(options: LibraryPluginOptions): Promise<Plugin ...@@ -213,7 +213,7 @@ async function loadLibraryPlugins(options: LibraryPluginOptions): Promise<Plugin
...commonPlugins, ...commonPlugins,
{ {
condition: isBuild && !!dts, condition: isBuild && !!dts,
plugins: () => [viteDtsPlugin({ logLevel: "error" })], plugins: () => [ viteDtsPlugin({ logLevel: "error" }) ],
}, },
]); ]);
} }
......
...@@ -36,10 +36,10 @@ async function resolveMonorepoDependencies() { ...@@ -36,10 +36,10 @@ async function resolveMonorepoDependencies() {
for (const { packageJson } of packages) { for (const { packageJson } of packages) {
const { dependencies = {}, devDependencies = {} } = packageJson; const { dependencies = {}, devDependencies = {} } = packageJson;
for (const [key, value] of Object.entries(dependencies)) { for (const [ key, value ] of Object.entries(dependencies)) {
resultDependencies[key] = resolvePackageVersion(pkgsMeta, key, value, catalog); resultDependencies[key] = resolvePackageVersion(pkgsMeta, key, value, catalog);
} }
for (const [key, value] of Object.entries(devDependencies)) { for (const [ key, value ] of Object.entries(devDependencies)) {
resultDevDependencies[key] = resolvePackageVersion(pkgsMeta, key, value, catalog); resultDevDependencies[key] = resolvePackageVersion(pkgsMeta, key, value, catalog);
} }
} }
......
...@@ -32,7 +32,7 @@ async function viteLicensePlugin(root = process.cwd()): Promise<PluginOption | u ...@@ -32,7 +32,7 @@ async function viteLicensePlugin(root = process.cwd()): Promise<PluginOption | u
*/ */
`.trim(); `.trim();
for (const [, fileContent] of Object.entries(bundle)) { for (const [ , fileContent ] of Object.entries(bundle)) {
if (fileContent.type === "chunk" && fileContent.isEntry) { if (fileContent.type === "chunk" && fileContent.isEntry) {
const chunkContent = fileContent as OutputChunk; const chunkContent = fileContent as OutputChunk;
// 插入版权信息 // 插入版权信息
......
...@@ -13,7 +13,7 @@ export const vitePrintPlugin = (options: PrintPluginOptions = {}): PluginOption ...@@ -13,7 +13,7 @@ export const vitePrintPlugin = (options: PrintPluginOptions = {}): PluginOption
server.printUrls = () => { server.printUrls = () => {
_printUrls(); _printUrls();
for (const [key, value] of Object.entries(infoMap)) { for (const [ key, value ] of Object.entries(infoMap)) {
console.log(` ${colors.green("➜")} ${colors.bold(key)}: ${colors.cyan(value)}`); console.log(` ${colors.green("➜")} ${colors.bold(key)}: ${colors.cyan(value)}`);
} }
}; };
......
...@@ -24,7 +24,7 @@ function getConfFiles() { ...@@ -24,7 +24,7 @@ function getConfFiles() {
if (result) { if (result) {
mode = result[1] as string; mode = result[1] as string;
} }
return [".env", ".env.local", `.env.${mode}`, `.env.${mode}.local`]; return [ ".env", ".env.local", `.env.${mode}`, `.env.${mode}.local` ];
} }
/** /**
......
...@@ -51,12 +51,12 @@ pre-commit: ...@@ -51,12 +51,12 @@ pre-commit:
glob: "*.md" glob: "*.md"
lint-vue: lint-vue:
glob: "*.vue" glob: "*.vue"
run: sh -c "NODE_OPTIONS=--max-old-space-size=8192 pnpm eslint --cache --fix {staged_files} && NODE_OPTIONS=--max-old-space-size=8192 pnpm stylelint --fix --allow-empty-input {staged_files}" run: pnpm eslint --cache --fix {staged_files}
lint-js: lint-js:
run: sh -c "NODE_OPTIONS=--max-old-space-size=8192 pnpm eslint --cache --fix --no-warn-ignored . --ext .js,.jsx,.ts,.tsx" run: pnpm eslint --cache --fix {staged_files}
glob: "*.{js,jsx,ts,tsx}" glob: "*.{js,jsx,ts,tsx}"
lint-style: lint-style:
run: sh -c "NODE_OPTIONS=--max-old-space-size=8192 pnpm stylelint --fix --allow-empty-input {staged_files}" run: pnpm stylelint --fix --allow-empty-input {staged_files}
glob: "*.{scss,less,styl,html,vue,css,wxss}" glob: "*.{scss,less,styl,html,vue,css,wxss}"
lint-package: lint-package:
run: pnpm eslint --cache --fix {staged_files} run: pnpm eslint --cache --fix {staged_files}
......
{ {
"extends": "../../tsconfig.json", "extends": "@venus/tsconfig/web.json",
"compilerOptions": { "compilerOptions": {
"composite": true, "composite": true,
"lib": ["ES2020"], "lib": ["ES2020"],
......
...@@ -2,6 +2,7 @@ import child_process from "node:child_process"; ...@@ -2,6 +2,7 @@ import child_process from "node:child_process";
import fs from "node:fs"; import fs from "node:fs";
import fsp from "node:fs/promises"; import fsp from "node:fs/promises";
import path from "node:path"; import path from "node:path";
import process from "node:process";
import { fileURLToPath } from "node:url"; import { fileURLToPath } from "node:url";
import { cancel, confirm, isCancel, select, text } from "@clack/prompts"; import { cancel, confirm, isCancel, select, text } from "@clack/prompts";
...@@ -17,7 +18,7 @@ function parseArgs(argv: string[]): Flags { ...@@ -17,7 +18,7 @@ function parseArgs(argv: string[]): Flags {
if (!token || !token.startsWith("--")) continue; if (!token || !token.startsWith("--")) continue;
const withoutDashes = token.slice(2); const withoutDashes = token.slice(2);
if (withoutDashes.includes("=")) { if (withoutDashes.includes("=")) {
const [rawKey, rawVal] = withoutDashes.split("="); const [ rawKey, rawVal ] = withoutDashes.split("=");
if (rawKey) { if (rawKey) {
out[rawKey.trim()] = (rawVal ?? "").trim() || true; out[rawKey.trim()] = (rawVal ?? "").trim() || true;
} }
...@@ -66,7 +67,7 @@ function printHelp() { ...@@ -66,7 +67,7 @@ function printHelp() {
function isTextFile(file: string) { function isTextFile(file: string) {
const ext = path.extname(file).toLowerCase(); const ext = path.extname(file).toLowerCase();
return [".css", ".html", ".js", ".json", ".jsx", ".less", ".md", ".scss", ".ts", ".tsx", ".vue"].includes(ext); return [ ".css", ".html", ".js", ".json", ".jsx", ".less", ".md", ".scss", ".ts", ".tsx", ".vue" ].includes(ext);
} }
async function ensureDir(dir: string) { async function ensureDir(dir: string) {
...@@ -100,7 +101,7 @@ async function mergeJson(targetPath: string, mergeObj: Record<string, JsonValue> ...@@ -100,7 +101,7 @@ async function mergeJson(targetPath: string, mergeObj: Record<string, JsonValue>
function deepMerge(a: JsonValue, b: JsonValue | undefined): JsonValue { function deepMerge(a: JsonValue, b: JsonValue | undefined): JsonValue {
if (b === undefined) return a; if (b === undefined) return a;
if (Array.isArray(a) && Array.isArray(b)) { if (Array.isArray(a) && Array.isArray(b)) {
return [...new Set([...a, ...b])]; return [ ...new Set([ ...a, ...b ]) ];
} }
if (isPlainObject(a) && isPlainObject(b)) { if (isPlainObject(a) && isPlainObject(b)) {
const aObj = a as Record<string, JsonValue>; const aObj = a as Record<string, JsonValue>;
...@@ -130,7 +131,7 @@ async function replacePlaceholders(destRoot: string, replacements: Record<string ...@@ -130,7 +131,7 @@ async function replacePlaceholders(destRoot: string, replacements: Record<string
if (entry.isDirectory()) await walk(full); if (entry.isDirectory()) await walk(full);
else if (entry.isFile() && isTextFile(full)) { else if (entry.isFile() && isTextFile(full)) {
let content = await fsp.readFile(full, "utf8"); let content = await fsp.readFile(full, "utf8");
for (const [from, to] of Object.entries(replacements)) { for (const [ from, to ] of Object.entries(replacements)) {
content = content.split(from).join(to); content = content.split(from).join(to);
} }
await fsp.writeFile(full, content); await fsp.writeFile(full, content);
...@@ -191,12 +192,11 @@ async function executeCreate(options: CreateOptions) { ...@@ -191,12 +192,11 @@ async function executeCreate(options: CreateOptions) {
const dirPrefix = dir || defaultDirPrefix; const dirPrefix = dir || defaultDirPrefix;
const destRoot = path.resolve(rootDir, dirPrefix ? path.join(dirPrefix, name) : name); const destRoot = path.resolve(rootDir, dirPrefix ? path.join(dirPrefix, name) : name);
const runtimeDir = typeof __dirname === "undefined" ? path.dirname(fileURLToPath(import.meta.url)) : __dirname; const runtimeDir = path.dirname(fileURLToPath(import.meta.url));
const tplRoot = path.resolve(runtimeDir, "../templates", template); const tplRoot = path.resolve(runtimeDir, "../templates", template);
if (!fs.existsSync(tplRoot)) { if (!fs.existsSync(tplRoot)) {
console.error(`模板不存在: ${template},路径: ${tplRoot}`); throw new Error(`模板不存在: ${template},路径: ${tplRoot}`);
process.exit(1);
} }
// 非空目录保护 // 非空目录保护
...@@ -205,12 +205,10 @@ async function executeCreate(options: CreateOptions) { ...@@ -205,12 +205,10 @@ async function executeCreate(options: CreateOptions) {
if (stat.isDirectory()) { if (stat.isDirectory()) {
const files = await fsp.readdir(destRoot); const files = await fsp.readdir(destRoot);
if (files.length > 0 && !force) { if (files.length > 0 && !force) {
console.error(`目标目录已存在且非空: ${destRoot}。如需覆盖请添加 --force`); throw new Error(`目标目录已存在且非空: ${destRoot}。如需覆盖请添加 --force`);
process.exit(1);
} }
} else { } else {
console.error(`目标路径已存在且不是目录: ${destRoot}`); throw new Error(`目标路径已存在且不是目录: ${destRoot}`);
process.exit(1);
} }
} }
await ensureDir(destRoot); await ensureDir(destRoot);
...@@ -264,12 +262,12 @@ async function executeCreate(options: CreateOptions) { ...@@ -264,12 +262,12 @@ async function executeCreate(options: CreateOptions) {
} }
async function runCreate(argv: string[]) { async function runCreate(argv: string[]) {
const [, , , name, ...rest] = argv; const name = argv[3];
const rest = argv.slice(4);
const flags = parseArgs(rest); const flags = parseArgs(rest);
if (!name) { if (!name) {
console.error("请输入项目名称,例如: venus create my-app --template react");
printHelp(); printHelp();
process.exit(1); throw new Error("请输入项目名称,例如: venus create my-app --template react");
} }
const options: CreateOptions = { const options: CreateOptions = {
...@@ -304,11 +302,11 @@ async function runCreateInteractive() { ...@@ -304,11 +302,11 @@ async function runCreateInteractive() {
}); });
if (!projectName) { if (!projectName) {
cancel("项目名称不能为空"); cancel("项目名称不能为空");
process.exit(0); throw new Error("项目名称不能为空");
} }
if (isCancel(projectName)) { if (isCancel(projectName)) {
cancel("操作已取消"); cancel("操作已取消");
process.exit(0); throw new Error("操作已取消");
} }
// 步骤2: 选择模板类型 // 步骤2: 选择模板类型
...@@ -322,7 +320,7 @@ async function runCreateInteractive() { ...@@ -322,7 +320,7 @@ async function runCreateInteractive() {
if (isCancel(template) || typeof template !== "string") { if (isCancel(template) || typeof template !== "string") {
cancel("操作已取消"); cancel("操作已取消");
process.exit(0); throw new Error("操作已取消");
} }
// 步骤3: 输入构建目录 // 步骤3: 输入构建目录
...@@ -336,7 +334,7 @@ async function runCreateInteractive() { ...@@ -336,7 +334,7 @@ async function runCreateInteractive() {
if (isCancel(dirInput)) { if (isCancel(dirInput)) {
cancel("操作已取消"); cancel("操作已取消");
process.exit(0); throw new Error("操作已取消");
} }
// 步骤4: 选择是否安装依赖 // 步骤4: 选择是否安装依赖
...@@ -347,7 +345,7 @@ async function runCreateInteractive() { ...@@ -347,7 +345,7 @@ async function runCreateInteractive() {
if (isCancel(shouldInstall)) { if (isCancel(shouldInstall)) {
cancel("操作已取消"); cancel("操作已取消");
process.exit(0); throw new Error("操作已取消");
} }
// 步骤5: 选择可选功能 - Router // 步骤5: 选择可选功能 - Router
...@@ -358,7 +356,7 @@ async function runCreateInteractive() { ...@@ -358,7 +356,7 @@ async function runCreateInteractive() {
if (isCancel(hasRouter)) { if (isCancel(hasRouter)) {
cancel("操作已取消"); cancel("操作已取消");
process.exit(0); throw new Error("操作已取消");
} }
// 步骤6: 选择可选功能 - Store // 步骤6: 选择可选功能 - Store
...@@ -369,11 +367,11 @@ async function runCreateInteractive() { ...@@ -369,11 +367,11 @@ async function runCreateInteractive() {
if (isCancel(hasStore)) { if (isCancel(hasStore)) {
cancel("操作已取消"); cancel("操作已取消");
process.exit(0); throw new Error("操作已取消");
} }
// 步骤7: 选择 UI 库 // 步骤7: 选择 UI 库
const runtimeDir = typeof __dirname === "undefined" ? path.dirname(fileURLToPath(import.meta.url)) : __dirname; const runtimeDir = path.dirname(fileURLToPath(import.meta.url));
const tplRoot = path.resolve(runtimeDir, "../templates", template); const tplRoot = path.resolve(runtimeDir, "../templates", template);
const uiDir = path.join(tplRoot, "optional", "ui"); const uiDir = path.join(tplRoot, "optional", "ui");
let selectedUi: string | undefined; let selectedUi: string | undefined;
...@@ -385,12 +383,12 @@ async function runCreateInteractive() { ...@@ -385,12 +383,12 @@ async function runCreateInteractive() {
if (availableUis.length > 0) { if (availableUis.length > 0) {
const uiChoice = await select<string>({ const uiChoice = await select<string>({
message: "请选择 UI 库 (可选):", message: "请选择 UI 库 (可选):",
options: [{ value: "", label: "不使用 UI 库" }, ...availableUis], options: [ { value: "", label: "不使用 UI 库" }, ...availableUis ],
}); });
if (isCancel(uiChoice) || typeof uiChoice !== "string") { if (isCancel(uiChoice) || typeof uiChoice !== "string") {
cancel("操作已取消"); cancel("操作已取消");
process.exit(0); throw new Error("操作已取消");
} }
selectedUi = uiChoice === "" ? undefined : uiChoice; selectedUi = uiChoice === "" ? undefined : uiChoice;
...@@ -405,7 +403,7 @@ async function runCreateInteractive() { ...@@ -405,7 +403,7 @@ async function runCreateInteractive() {
if (isCancel(hasEslint)) { if (isCancel(hasEslint)) {
cancel("操作已取消"); cancel("操作已取消");
process.exit(0); throw new Error("操作已取消");
} }
// 执行创建 // 执行创建
...@@ -426,8 +424,7 @@ async function runCreateInteractive() { ...@@ -426,8 +424,7 @@ async function runCreateInteractive() {
async function runBuild() { async function runBuild() {
const buildScript = path.resolve(process.cwd(), "scripts/build.js"); const buildScript = path.resolve(process.cwd(), "scripts/build.js");
if (!fs.existsSync(buildScript)) { if (!fs.existsSync(buildScript)) {
console.error("未找到 scripts/build.js,请在 Venus 仓库根目录执行该命令。"); throw new Error("未找到 scripts/build.js,请在 Venus 仓库根目录执行该命令。");
process.exit(1);
} }
try { try {
child_process.execSync(`node ${JSON.stringify(buildScript)}`, { child_process.execSync(`node ${JSON.stringify(buildScript)}`, {
...@@ -435,7 +432,7 @@ async function runBuild() { ...@@ -435,7 +432,7 @@ async function runBuild() {
shell: process.platform === "win32" ? "powershell.exe" : "/bin/sh", shell: process.platform === "win32" ? "powershell.exe" : "/bin/sh",
}); });
} catch { } catch {
process.exit(1); throw new Error("构建失败");
} }
} }
...@@ -471,17 +468,16 @@ export async function main() { ...@@ -471,17 +468,16 @@ export async function main() {
} }
// 自动执行 // 自动执行
if (typeof process !== "undefined" && process.argv && process.argv[1]) { if (process !== undefined && process.argv && process.argv[1]) {
// 在作为 bin 执行时运行 main // 在作为 bin 执行时运行 main
main(); main();
} }
async function runListTemplates() { async function runListTemplates() {
const runtimeDir = typeof __dirname === "undefined" ? path.dirname(fileURLToPath(import.meta.url)) : __dirname; const runtimeDir = path.dirname(fileURLToPath(import.meta.url));
const base = path.resolve(runtimeDir, "../templates"); const base = path.resolve(runtimeDir, "../templates");
if (!fs.existsSync(base)) { if (!fs.existsSync(base)) {
console.error("未找到模板目录"); throw new Error("未找到模板目录");
process.exit(1);
} }
const templates = await fsp.readdir(base, { withFileTypes: true }); const templates = await fsp.readdir(base, { withFileTypes: true });
for (const t of templates) { for (const t of templates) {
......
...@@ -2,5 +2,5 @@ import react from "@vitejs/plugin-react"; ...@@ -2,5 +2,5 @@ import react from "@vitejs/plugin-react";
import { defineConfig } from "vite"; import { defineConfig } from "vite";
export default defineConfig({ export default defineConfig({
plugins: [react()], plugins: [ react() ],
}); });
...@@ -2,7 +2,7 @@ import type { RouteRecordRaw } from "vue-router"; ...@@ -2,7 +2,7 @@ import type { RouteRecordRaw } from "vue-router";
import { createRouter, createWebHistory } from "vue-router"; import { createRouter, createWebHistory } from "vue-router";
const routes: RouteRecordRaw[] = [{ path: "/", component: () => import("./App.vue") }]; const routes: RouteRecordRaw[] = [ { path: "/", component: () => import("./App.vue") } ];
export const router = createRouter({ export const router = createRouter({
history: createWebHistory(), history: createWebHistory(),
......
<script setup lang="ts">
import { onMounted } from "vue";
onMounted(() => {
console.log("Vue3 微应用已挂载");
});
</script>
<template> <template>
<div id="micro-app" class="micro-app-container"> <div id="micro-app" class="micro-app-container">
<header class="app-header"> <header class="app-header">
<h1>🚀 Vue3 微前端子应用</h1> <h1>🚀 Vue3 微前端子应用</h1>
<nav class="nav-menu"> <nav class="nav-menu">
<router-link to="/" class="nav-link">首页</router-link> <router-link class="nav-link" to="/">
<router-link to="/about" class="nav-link">关于</router-link> 首页
<router-link to="/communication" class="nav-link">通信示例</router-link> </router-link>
<router-link to="/user" class="nav-link">用户管理</router-link> <router-link class="nav-link" to="/about">
<router-link to="/settings" class="nav-link">系统设置</router-link> 关于
</router-link>
<router-link class="nav-link" to="/communication">
通信示例
</router-link>
<router-link class="nav-link" to="/user">
用户管理
</router-link>
<router-link class="nav-link" to="/settings">
系统设置
</router-link>
</nav> </nav>
</header> </header>
<main class="app-main"> <main class="app-main">
<router-view v-slot="{ Component }"> <router-view v-slot="{ Component }">
<transition name="fade" mode="out-in"> <transition mode="out-in" name="fade">
<component :is="Component" /> <component :is="Component" />
</transition> </transition>
</router-view> </router-view>
...@@ -33,6 +35,14 @@ onMounted(() => { ...@@ -33,6 +35,14 @@ onMounted(() => {
</div> </div>
</template> </template>
<script setup lang="ts">
import { onMounted } from "vue";
onMounted(() => {
console.log("Vue3 微应用已挂载");
});
</script>
<style scoped> <style scoped>
.micro-app-container { .micro-app-container {
display: flex; display: flex;
......
/// <reference types="vite/client" /> // / <reference types="vite/client" />
...@@ -155,7 +155,7 @@ class SubAppCommunicationManager { ...@@ -155,7 +155,7 @@ class SubAppCommunicationManager {
// 注意:这里需要基座的 communication manager 来处理通知添加逻辑 // 注意:这里需要基座的 communication manager 来处理通知添加逻辑
// 所以我们实际上是触发一个状态变化,让基座来处理 // 所以我们实际上是触发一个状态变化,让基座来处理
this.setGlobalState({ this.setGlobalState({
notifications: [newNotification] as any, // 基座会合并到现有通知列表 notifications: [ newNotification ] as any, // 基座会合并到现有通知列表
}); });
} }
......
<script setup lang="ts">
// About 页面
</script>
<template> <template>
<div class="about-view"> <div class="about-view">
<div class="content-card"> <div class="content-card">
...@@ -52,20 +48,28 @@ ...@@ -52,20 +48,28 @@
<section class="section"> <section class="section">
<h2>快速开始</h2> <h2>快速开始</h2>
<div class="code-block"> <div class="code-block">
<pre><code># 安装依赖 <pre>
<code>
# 安装依赖
pnpm install pnpm install
# 启动开发服务器 # 启动开发服务器
pnpm dev pnpm dev
# 构建生产版本 # 构建生产版本
pnpm build</code></pre> pnpm build
</code>
</pre>
</div> </div>
</section> </section>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts">
// About 页面
</script>
<style scoped> <style scoped>
.about-view { .about-view {
max-width: 900px; max-width: 900px;
......
<script setup lang="ts">
import type { GlobalState } from "@/utils/communication";
import { computed, ref } from "vue";
import { useRoute } from "vue-router";
import { notify, useGlobalState } from "@/utils/communication";
import { qiankunWindow } from "vite-plugin-qiankun/dist/helper";
const route = useRoute();
const counter = ref(0);
const globalState = ref<GlobalState | null>(null);
const runMode = computed(() => {
return qiankunWindow.__POWERED_BY_QIANKUN__ ? "🔗 基座模式" : "🏠 独立模式";
});
const currentRoute = computed(() => route.fullPath);
const increment = () => {
counter.value++;
};
const decrement = () => {
counter.value--;
};
// 监听主应用传递的全局状态
if (qiankunWindow.__POWERED_BY_QIANKUN__) {
useGlobalState((state, prev) => {
console.log("📥 接收到主应用数据:", state);
console.log("📝 之前的数据:", prev);
globalState.value = state;
});
}
// 发送测试通知到主应用
const sendTestNotification = () => {
notify("success", "来自微应用的通知", `这是一条测试通知,发送时间: ${new Date().toLocaleTimeString()}`);
};
</script>
<template> <template>
<div class="home-view"> <div class="home-view">
<div class="hero-section"> <div class="hero-section">
<h1 class="hero-title">🎉 欢迎使用 Vue3 微前端子应用AAA</h1> <h1 class="hero-title">
<p class="hero-subtitle">基于 qiankun + Vue3 + Vite + TypeScript 构建</p> 🎉 欢迎使用 Vue3 微前端子应用AAA
</h1>
<p class="hero-subtitle">
基于 qiankun + Vue3 + Vite + TypeScript 构建
</p>
</div> </div>
<div class="cards-grid"> <div class="cards-grid">
<div class="card"> <div class="card">
<div class="card-icon">🚀</div> <div class="card-icon">
🚀
</div>
<h3>快速启动</h3> <h3>快速启动</h3>
<p>使用 Vite 构建,开发体验极速</p> <p>使用 Vite 构建,开发体验极速</p>
</div> </div>
<div class="card"> <div class="card">
<div class="card-icon">🎯</div> <div class="card-icon">
🎯
</div>
<h3>独立运行</h3> <h3>独立运行</h3>
<p>支持独立开发和集成运行两种模式</p> <p>支持独立开发和集成运行两种模式</p>
</div> </div>
<div class="card"> <div class="card">
<div class="card-icon">🔧</div> <div class="card-icon">
🔧
</div>
<h3>开箱即用</h3> <h3>开箱即用</h3>
<p>集成路由、状态管理等常用功能</p> <p>集成路由、状态管理等常用功能</p>
</div> </div>
<div class="card"> <div class="card">
<div class="card-icon">💡</div> <div class="card-icon">
💡
</div>
<h3>TypeScript</h3> <h3>TypeScript</h3>
<p>完整的类型支持,开发更安全</p> <p>完整的类型支持,开发更安全</p>
</div> </div>
<div class="card"> <div class="card">
<div class="card-icon">💡</div> <div class="card-icon">
💡
</div>
<p>{{ globalState }}</p> <p>{{ globalState }}</p>
</div> </div>
</div> </div>
...@@ -92,8 +64,12 @@ const sendTestNotification = () => { ...@@ -92,8 +64,12 @@ const sendTestNotification = () => {
<div class="info-item"> <div class="info-item">
<span class="info-label">计数器:</span> <span class="info-label">计数器:</span>
<span class="info-value">{{ counter }}</span> <span class="info-value">{{ counter }}</span>
<button @click="increment" class="btn-primary">+1</button> <button class="btn-primary" @click="increment">
<button @click="decrement" class="btn-secondary">-1</button> +1
</button>
<button class="btn-secondary" @click="decrement">
-1
</button>
</div> </div>
</div> </div>
</div> </div>
...@@ -104,7 +80,9 @@ const sendTestNotification = () => { ...@@ -104,7 +80,9 @@ const sendTestNotification = () => {
<div class="info-content"> <div class="info-content">
<!-- 用户信息 --> <!-- 用户信息 -->
<div v-if="globalState?.user" class="data-group"> <div v-if="globalState?.user" class="data-group">
<h3 class="data-group-title">👤 用户信息</h3> <h3 class="data-group-title">
👤 用户信息
</h3>
<div class="info-item"> <div class="info-item">
<span class="info-label">用户ID:</span> <span class="info-label">用户ID:</span>
<span class="info-value">{{ globalState.user.id }}</span> <span class="info-value">{{ globalState.user.id }}</span>
...@@ -125,7 +103,9 @@ const sendTestNotification = () => { ...@@ -125,7 +103,9 @@ const sendTestNotification = () => {
<!-- 主题配置 --> <!-- 主题配置 -->
<div v-if="globalState?.theme" class="data-group"> <div v-if="globalState?.theme" class="data-group">
<h3 class="data-group-title">🎨 主题配置</h3> <h3 class="data-group-title">
🎨 主题配置
</h3>
<div class="info-item"> <div class="info-item">
<span class="info-label">主题模式:</span> <span class="info-label">主题模式:</span>
<span class="info-value">{{ globalState.theme.mode }}</span> <span class="info-value">{{ globalState.theme.mode }}</span>
...@@ -142,7 +122,9 @@ const sendTestNotification = () => { ...@@ -142,7 +122,9 @@ const sendTestNotification = () => {
<!-- 配置信息 --> <!-- 配置信息 -->
<div v-if="globalState?.config" class="data-group"> <div v-if="globalState?.config" class="data-group">
<h3 class="data-group-title">⚙️ 配置信息</h3> <h3 class="data-group-title">
⚙️ 配置信息
</h3>
<div class="info-item"> <div class="info-item">
<span class="info-label">API地址:</span> <span class="info-label">API地址:</span>
<span class="info-value">{{ globalState.config.apiBaseUrl }}</span> <span class="info-value">{{ globalState.config.apiBaseUrl }}</span>
...@@ -155,14 +137,15 @@ const sendTestNotification = () => { ...@@ -155,14 +137,15 @@ const sendTestNotification = () => {
<!-- 通知消息 --> <!-- 通知消息 -->
<div v-if="globalState?.notifications && globalState.notifications.length > 0" class="data-group"> <div v-if="globalState?.notifications && globalState.notifications.length > 0" class="data-group">
<h3 class="data-group-title">📢 通知消息 ({{ globalState.notifications.length }})</h3> <h3 class="data-group-title">
<div 📢 通知消息 ({{ globalState.notifications.length }})
v-for="notification in globalState.notifications.slice(0, 3)" </h3>
<div v-for="notification in globalState.notifications.slice(0, 3)"
:key="notification.id" :key="notification.id"
class="notification-item"> class="notification-item">
<span class="notification-type" :class="[notification.type]">{{ notification.type }}</span> <span class="notification-type" :class="[notification.type]">{{ notification.type }}</span>
<span class="notification-title">{{ notification.title }}</span> <span class="notification-title">{{ notification.title }}</span>
<span class="notification-from" v-if="notification.from">来自: {{ notification.from }}</span> <span v-if="notification.from" class="notification-from">来自: {{ notification.from }}</span>
</div> </div>
</div> </div>
...@@ -174,12 +157,56 @@ const sendTestNotification = () => { ...@@ -174,12 +157,56 @@ const sendTestNotification = () => {
<!-- 操作按钮 --> <!-- 操作按钮 -->
<div class="actions"> <div class="actions">
<button @click="sendTestNotification" class="btn-action">📤 发送测试通知到主应用</button> <button class="btn-action" @click="sendTestNotification">
📤 发送测试通知到主应用
</button>
</div> </div>
</div> </div>
</div> </div>
</template> </template>
<script setup lang="ts">
import type { GlobalState } from "@/utils/communication";
import { computed, ref } from "vue";
import { useRoute } from "vue-router";
import { notify, useGlobalState } from "@/utils/communication";
import { qiankunWindow } from "vite-plugin-qiankun/dist/helper";
const route = useRoute();
const counter = ref(0);
const globalState = ref<GlobalState | null>(null);
const runMode = computed(() => {
return qiankunWindow.__POWERED_BY_QIANKUN__ ? "🔗 基座模式" : "🏠 独立模式";
});
const currentRoute = computed(() => route.fullPath);
const increment = () => {
counter.value++;
};
const decrement = () => {
counter.value--;
};
// 监听主应用传递的全局状态
if (qiankunWindow.__POWERED_BY_QIANKUN__) {
useGlobalState((state, prev) => {
console.log("📥 接收到主应用数据:", state);
console.log("📝 之前的数据:", prev);
globalState.value = state;
});
}
// 发送测试通知到主应用
const sendTestNotification = () => {
notify("success", "来自微应用的通知", `这是一条测试通知,发送时间: ${new Date().toLocaleTimeString()}`);
};
</script>
<style scoped> <style scoped>
.home-view { .home-view {
max-width: 1200px; max-width: 1200px;
......
<template>
<div class="notfound-view">
<div class="content-card">
<div class="error-code">
404
</div>
<h1>页面未找到</h1>
<p>抱歉,您访问的页面不存在或已被删除</p>
<button class="btn-home" @click="goHome">
🏠 返回首页
</button>
</div>
</div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import { useRouter } from "vue-router"; import { useRouter } from "vue-router";
...@@ -8,17 +23,6 @@ const goHome = () => { ...@@ -8,17 +23,6 @@ const goHome = () => {
}; };
</script> </script>
<template>
<div class="notfound-view">
<div class="content-card">
<div class="error-code">404</div>
<h1>页面未找到</h1>
<p>抱歉,您访问的页面不存在或已被删除</p>
<button @click="goHome" class="btn-home">🏠 返回首页</button>
</div>
</div>
</template>
<style scoped> <style scoped>
.notfound-view { .notfound-view {
display: flex; display: flex;
......
<script setup lang="ts">
import { reactive } from "vue";
interface Settings {
darkMode: boolean;
language: string;
notifications: {
desktop: boolean;
email: boolean;
sms: boolean;
};
security: {
sessionTimeout: number;
twoFactor: boolean;
};
theme: string;
timezone: string;
}
const defaultSettings: Settings = {
theme: "purple",
darkMode: false,
notifications: {
desktop: true,
email: true,
sms: false,
},
language: "zh-CN",
timezone: "Asia/Shanghai",
security: {
twoFactor: false,
sessionTimeout: 30,
},
};
const settings = reactive<Settings>({ ...defaultSettings });
const saveSettings = () => {
console.log("保存设置:", settings);
alert("设置已保存!");
};
const resetSettings = () => {
if (confirm("确定要重置为默认设置吗?")) {
Object.assign(settings, defaultSettings);
alert("已重置为默认设置!");
}
};
</script>
<template> <template>
<div class="settings-view"> <div class="settings-view">
<div class="content-card"> <div class="content-card">
...@@ -59,15 +9,25 @@ const resetSettings = () => { ...@@ -59,15 +9,25 @@ const resetSettings = () => {
<div class="setting-item"> <div class="setting-item">
<label>主题色:</label> <label>主题色:</label>
<select v-model="settings.theme" class="select-input"> <select v-model="settings.theme" class="select-input">
<option value="purple">紫色</option> <option value="purple">
<option value="blue">蓝色</option> 紫色
<option value="green">绿色</option> </option>
<option value="orange">橙色</option> <option value="blue">
蓝色
</option>
<option value="green">
绿色
</option>
<option value="orange">
橙色
</option>
</select> </select>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>暗黑模式:</label> <label>暗黑模式:</label>
<input type="checkbox" v-model="settings.darkMode" class="checkbox-input" /> <input v-model="settings.darkMode"
class="checkbox-input"
type="checkbox" />
</div> </div>
</div> </div>
...@@ -75,15 +35,21 @@ const resetSettings = () => { ...@@ -75,15 +35,21 @@ const resetSettings = () => {
<h2>🔔 通知设置</h2> <h2>🔔 通知设置</h2>
<div class="setting-item"> <div class="setting-item">
<label>桌面通知:</label> <label>桌面通知:</label>
<input type="checkbox" v-model="settings.notifications.desktop" class="checkbox-input" /> <input v-model="settings.notifications.desktop"
class="checkbox-input"
type="checkbox" />
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>邮件通知:</label> <label>邮件通知:</label>
<input type="checkbox" v-model="settings.notifications.email" class="checkbox-input" /> <input v-model="settings.notifications.email"
class="checkbox-input"
type="checkbox" />
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>短信通知:</label> <label>短信通知:</label>
<input type="checkbox" v-model="settings.notifications.sms" class="checkbox-input" /> <input v-model="settings.notifications.sms"
class="checkbox-input"
type="checkbox" />
</div> </div>
</div> </div>
...@@ -92,17 +58,29 @@ const resetSettings = () => { ...@@ -92,17 +58,29 @@ const resetSettings = () => {
<div class="setting-item"> <div class="setting-item">
<label>界面语言:</label> <label>界面语言:</label>
<select v-model="settings.language" class="select-input"> <select v-model="settings.language" class="select-input">
<option value="zh-CN">简体中文</option> <option value="zh-CN">
<option value="en-US">English</option> 简体中文
<option value="ja-JP">日本語</option> </option>
<option value="en-US">
English
</option>
<option value="ja-JP">
日本語
</option>
</select> </select>
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>时区:</label> <label>时区:</label>
<select v-model="settings.timezone" class="select-input"> <select v-model="settings.timezone" class="select-input">
<option value="Asia/Shanghai">北京时间 (UTC+8)</option> <option value="Asia/Shanghai">
<option value="America/New_York">纽约时间 (UTC-5)</option> 北京时间 (UTC+8)
<option value="Europe/London">伦敦时间 (UTC+0)</option> </option>
<option value="America/New_York">
纽约时间 (UTC-5)
</option>
<option value="Europe/London">
伦敦时间 (UTC+0)
</option>
</select> </select>
</div> </div>
</div> </div>
...@@ -111,23 +89,28 @@ const resetSettings = () => { ...@@ -111,23 +89,28 @@ const resetSettings = () => {
<h2>🔒 安全设置</h2> <h2>🔒 安全设置</h2>
<div class="setting-item"> <div class="setting-item">
<label>双因素认证:</label> <label>双因素认证:</label>
<input type="checkbox" v-model="settings.security.twoFactor" class="checkbox-input" /> <input v-model="settings.security.twoFactor"
class="checkbox-input"
type="checkbox" />
</div> </div>
<div class="setting-item"> <div class="setting-item">
<label>会话超时 (分钟):</label> <label>会话超时 (分钟):</label>
<input <input v-model="settings.security.sessionTimeout"
type="number"
v-model="settings.security.sessionTimeout"
class="number-input" class="number-input"
max="120"
min="5" min="5"
max="120" /> type="number" />
</div> </div>
</div> </div>
</div> </div>
<div class="actions"> <div class="actions">
<button @click="saveSettings" class="btn-save">💾 保存设置</button> <button class="btn-save" @click="saveSettings">
<button @click="resetSettings" class="btn-reset">🔄 重置默认</button> 💾 保存设置
</button>
<button class="btn-reset" @click="resetSettings">
🔄 重置默认
</button>
</div> </div>
<div class="current-settings"> <div class="current-settings">
...@@ -138,6 +121,59 @@ const resetSettings = () => { ...@@ -138,6 +121,59 @@ const resetSettings = () => {
</div> </div>
</template> </template>
<script setup lang="ts">
import { reactive } from "vue";
interface Settings {
darkMode: boolean;
language: string;
notifications: {
desktop: boolean;
email: boolean;
sms: boolean;
};
security: {
sessionTimeout: number;
twoFactor: boolean;
};
theme: string;
timezone: string;
}
const defaultSettings: Settings = {
theme: "purple",
darkMode: false,
notifications: {
desktop: true,
email: true,
sms: false,
},
language: "zh-CN",
timezone: "Asia/Shanghai",
security: {
twoFactor: false,
sessionTimeout: 30,
},
};
const settings = reactive<Settings>({ ...defaultSettings });
const saveSettings = () => {
console.log("保存设置:", settings);
// eslint-disable-next-line
alert("设置已保存!");
};
const resetSettings = () => {
// eslint-disable-next-line
if (confirm("确定要重置为默认设置吗?")) {
Object.assign(settings, defaultSettings);
// eslint-disable-next-line
alert("已重置为默认设置!");
}
};
</script>
<style scoped> <style scoped>
.settings-view { .settings-view {
max-width: 1200px; max-width: 1200px;
......
<template>
<div class="user-view">
<div class="content-card">
<h1>👥 用户管理</h1>
<div class="toolbar">
<button class="btn-add" @click="addUser">
➕ 新增用户
</button>
</div>
<div class="table-container">
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>邮箱</th>
<th>角色</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users" :key="user.id">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
<td>{{ user.email }}</td>
<td>
<span class="badge" :class="`badge-${user.role}`">
{{ user.role }}
</span>
</td>
<td>
<span class="status" :class="user.active ? 'status-active' : 'status-inactive'">
{{ user.active ? "在线" : "离线" }}
</span>
</td>
<td>
<button class="btn-edit" @click="editUser(user)">
编辑
</button>
<button class="btn-delete" @click="deleteUser(user.id)">
删除
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from "vue"; import { ref } from "vue";
...@@ -53,65 +107,19 @@ const addUser = () => { ...@@ -53,65 +107,19 @@ const addUser = () => {
const editUser = (user: User) => { const editUser = (user: User) => {
console.log("编辑用户:", user); console.log("编辑用户:", user);
// eslint-disable-next-line
alert(`编辑用户: ${user.name}`); alert(`编辑用户: ${user.name}`);
}; };
const deleteUser = (id: number) => { const deleteUser = (id: number) => {
const index = users.value.findIndex((u) => u.id === id); const index = users.value.findIndex((u) => u.id === id);
// eslint-disable-next-line
if (index !== -1 && confirm(`确定要删除用户 ${users.value[index].name} 吗?`)) { if (index !== -1 && confirm(`确定要删除用户 ${users.value[index].name} 吗?`)) {
users.value.splice(index, 1); users.value.splice(index, 1);
} }
}; };
</script> </script>
<template>
<div class="user-view">
<div class="content-card">
<h1>👥 用户管理</h1>
<div class="toolbar">
<button @click="addUser" class="btn-add">➕ 新增用户</button>
</div>
<div class="table-container">
<table class="user-table">
<thead>
<tr>
<th>ID</th>
<th>姓名</th>
<th>邮箱</th>
<th>角色</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody>
<tr v-for="user in users" :key="user.id">
<td>{{ user.id }}</td>
<td>{{ user.name }}</td>
<td>{{ user.email }}</td>
<td>
<span class="badge" :class="`badge-${user.role}`">
{{ user.role }}
</span>
</td>
<td>
<span class="status" :class="user.active ? 'status-active' : 'status-inactive'">
{{ user.active ? "在线" : "离线" }}
</span>
</td>
<td>
<button @click="editUser(user)" class="btn-edit">编辑</button>
<button @click="deleteUser(user.id)" class="btn-delete">删除</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</template>
<style scoped> <style scoped>
.user-view { .user-view {
max-width: 1200px; max-width: 1200px;
......
...@@ -21,7 +21,7 @@ export default defineConfig(({ mode, command }) => { ...@@ -21,7 +21,7 @@ export default defineConfig(({ mode, command }) => {
vueJsx(), vueJsx(),
// 自动导入 Vue 相关函数 // 自动导入 Vue 相关函数
AutoImport({ AutoImport({
imports: ["vue", "vue-router", "pinia"], imports: [ "vue", "vue-router", "pinia" ],
dts: "src/auto-imports.d.ts", dts: "src/auto-imports.d.ts",
eslintrc: { eslintrc: {
enabled: false, enabled: false,
...@@ -38,7 +38,7 @@ export default defineConfig(({ mode, command }) => { ...@@ -38,7 +38,7 @@ export default defineConfig(({ mode, command }) => {
], ],
resolve: { resolve: {
alias: { alias: {
"@": resolve(__dirname, "src"), "@": resolve(import.meta.dirname, "src"),
}, },
}, },
server: { server: {
......
...@@ -3,6 +3,6 @@ import { defineBuildConfig } from "unbuild"; ...@@ -3,6 +3,6 @@ import { defineBuildConfig } from "unbuild";
export default defineBuildConfig({ export default defineBuildConfig({
clean: true, clean: true,
declaration: true, declaration: true,
entries: ["src/index"], entries: [ "src/index" ],
externals: ["vue", "element-plus", "@vueuse/core"], externals: [ "vue", "element-plus", "@vueuse/core" ],
}); });
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
} }
} }
}, },
"peerDependencies": {
"@element-plus/icons-vue": ">=2.0.0",
"element-plus": ">=2.0.0",
"vue": ">=3.3.0"
},
"dependencies": { "dependencies": {
"@element-plus/icons-vue": "catalog:", "@element-plus/icons-vue": "catalog:",
"@vueuse/core": "catalog:", "@vueuse/core": "catalog:",
...@@ -46,10 +51,5 @@ ...@@ -46,10 +51,5 @@
"@types/node": "catalog:", "@types/node": "catalog:",
"typescript": "catalog:", "typescript": "catalog:",
"unbuild": "catalog:" "unbuild": "catalog:"
},
"peerDependencies": {
"@element-plus/icons-vue": ">=2.0.0",
"element-plus": ">=2.0.0",
"vue": ">=3.3.0"
} }
} }
import VButton from "./index.vue";
export { VButton };
export default VButton;
export { default, default as VButton } from "./index.vue";
\ No newline at end of file \ No newline at end of file
<template>
<!-- 用计算属性过滤并批量绑定 -->
<ElButton v-bind="elButtonProps" @click="debouncedClick">
<slot />
</ElButton>
</template>
<script setup lang="ts"> <script setup lang="ts">
import type { VButtonProps } from "../../types";
import { computed, ref } from "vue"; import { computed, ref } from "vue";
import { ElButton, ElMessageBox } from "element-plus";
import { useDebounceFn } from "@vueuse/core"; import { useDebounceFn } from "@vueuse/core";
import type { VButtonProps } from "../../types"; import { ElButton, ElMessageBox } from "element-plus";
/** /**
* VButton - 增强型按钮组件 * VButton - 增强型按钮组件
...@@ -74,10 +83,3 @@ const handleClick = async (event: MouseEvent) => { ...@@ -74,10 +83,3 @@ const handleClick = async (event: MouseEvent) => {
// 防抖处理 // 防抖处理
const debouncedClick = props.debounce ? useDebounceFn(handleClick, props.debounce) : handleClick; const debouncedClick = props.debounce ? useDebounceFn(handleClick, props.debounce) : handleClick;
</script> </script>
<template>
<!-- 用计算属性过滤并批量绑定 -->
<ElButton v-bind="elButtonProps" @click="debouncedClick">
<slot />
</ElButton>
</template>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!