Commit 66fd0527 by vince

fix: fix known issues. fixed #59,fixed #61, fixed #67, fixed #68 [deploy]

1 parent b98f9f9b
......@@ -8,7 +8,7 @@ on:
jobs:
deploy-push-ftp:
name: Deploy Push Ftp
if: github.actor != 'dependabot[bot]' && !contains(github.event.head_commit.message, '[skip ci]')
if: github.actor != 'dependabot[bot]' && !contains(github.event.head_commit.message, '[skip ci]') && contains(github.event.head_commit.message, '[deploy]')
runs-on: ubuntu-latest
strategy:
matrix:
......
# 应用标题
VITE_GLOB_APP_TITLE=Vben Admin
VITE_APP_TITLE=Vben Admin
# 应用命名空间,用于缓存、store等功能的前缀,确保隔离
VITE_APP_NAMESPACE=vben-web-antd
......@@ -11,8 +11,8 @@
name="viewport"
content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0"
/>
<!-- 由 vite 注入 VITE_GLOB_APP_TITLE 变量,在 .env 文件内配置 -->
<title><%= VITE_GLOB_APP_TITLE %></title>
<!-- 由 vite 注入 VITE_APP_TITLE 变量,在 .env 文件内配置 -->
<title><%= VITE_APP_TITLE %></title>
<link rel="icon" href="/favicon.ico" />
<script>
// 生产环境下注入百度统计
......
import { useAppConfig } from '@vben/hooks';
import { defineOverridesPreferences } from '@vben/preferences';
const { appTitle } = useAppConfig(import.meta.env, import.meta.env.PROD);
/**
* @description 项目配置文件
* 只需要覆盖项目中的一部分配置,不需要的配置不用覆盖,会自动使用默认配置
*/
export const overridesPreferences = defineOverridesPreferences({
// overrides
app: {
name: appTitle,
},
});
import {
defaultImportmapOptions,
defineConfig,
getDefaultPwaOptions,
loadAndConvertEnv,
} from '@vben/vite-config';
import { defineConfig } from '@vben/vite-config';
export default defineConfig(async () => {
const { appTitle, base, port, ...envConfig } = await loadAndConvertEnv();
return {
application: {
...envConfig,
importmap: false,
importmapOptions: defaultImportmapOptions,
pwa: false,
pwaOptions: getDefaultPwaOptions(appTitle),
},
application: {},
vite: {
base,
server: {
port,
proxy: {
'/api': {
changeOrigin: true,
......
......@@ -8,11 +8,14 @@ import { findMonorepoRoot } from '@vben/node-utils';
import { defineConfig, loadEnv, mergeConfig } from 'vite';
import { getDefaultPwaOptions } from '../options';
import { loadApplicationPlugins } from '../plugins';
import { loadAndConvertEnv } from '../utils/env';
import { getCommonConfig } from './common';
function defineApplicationConfig(userConfigPromise: DefineApplicationOptions) {
return defineConfig(async (config) => {
const { appTitle, base, port, ...envConfig } = await loadAndConvertEnv();
const options = await userConfigPromise?.(config);
const { command, mode } = config;
const { application = {}, vite = {} } = options || {};
......@@ -40,12 +43,15 @@ function defineApplicationConfig(userConfigPromise: DefineApplicationOptions) {
'Vben Admin Docs': 'https://docs.vben.pro',
},
pwa: true,
pwaOptions: getDefaultPwaOptions(appTitle),
...envConfig,
...application,
});
const { injectGlobalScss = true } = application;
const applicationConfig: UserConfig = {
base,
build: {
rollupOptions: {
output: {
......@@ -69,6 +75,7 @@ function defineApplicationConfig(userConfigPromise: DefineApplicationOptions) {
plugins,
server: {
host: true,
port,
warmup: {
// 预热文件
clientFiles: ['./index.html', './src/{views,layouts}/*'],
......
......@@ -28,7 +28,7 @@ const getDefaultPwaOptions = (name: string): Partial<PwaPluginOptions> => ({
const defaultImportmapOptions: ImportmapPluginOptions = {
// 通过 Importmap CDN 方式引入,
// 目前只有esm.sh源兼容性好一点,jspm.io对于 esm 入口要求高
defaultProvider: 'esm.sh',
defaultProvider: 'jspm.io',
importmap: [
{ name: 'vue' },
{ name: 'pinia' },
......
......@@ -110,5 +110,5 @@
</style>
<div class="loading" id="__app-loading__">
<span class="dot dot-spin"><i></i><i></i><i></i><i></i></span>
<div class="title"><%= VITE_GLOB_APP_TITLE %></div>
<div class="title"><%= VITE_APP_TITLE %></div>
</div>
......@@ -109,5 +109,5 @@
</style>
<div class="loading" id="__app-loading__">
<div class="loader"></div>
<div class="title"><%= VITE_GLOB_APP_TITLE %></div>
<div class="title"><%= VITE_APP_TITLE %></div>
</div>
......@@ -64,10 +64,10 @@ async function loadAndConvertEnv(
> {
const envConfig = await loadEnv(match, confFiles);
const {
VITE_APP_TITLE,
VITE_BASE,
VITE_COMPRESS,
VITE_DEVTOOLS,
VITE_GLOB_APP_TITLE,
VITE_INJECT_APP_LOADING,
VITE_NITRO_MOCK,
VITE_PORT,
......@@ -80,7 +80,7 @@ async function loadAndConvertEnv(
.filter((item) => item === 'brotli' || item === 'gzip');
return {
appTitle: VITE_GLOB_APP_TITLE ?? 'Vben Admin',
appTitle: VITE_APP_TITLE ?? 'Vben Admin',
base: VITE_BASE || '/',
compress: !!compress,
compressTypes: compressTypes as ('brotli' | 'gzip')[],
......
......@@ -31,14 +31,13 @@
"build:analyze": "turbo build:analyze",
"build:docker": "./build-local-docker-image.sh",
"changeset": "pnpm exec changeset",
"check": "pnpm run check:dep && pnpm run check:circular && pnpm run check:type && pnpm run check:cspell",
"check": "pnpm run check:circular && pnpm run check:dep && pnpm run check:type",
"check:circular": "vsh check-circular",
"check:cspell": "cspell lint \"**/*.ts\" \"**/README.md\" \".changeset/*.md\" --no-progress",
"check:dep": "vsh check-dep",
"check:type": "turbo run typecheck",
"clean": "vsh clean",
"commit": "czg",
"dev": "cross-env TURBO_UI=1 turbo run dev",
"dev": "cross-env turbo run dev",
"dev:docs": "pnpm -F @vben/website run docs:dev",
"format": "vsh lint --format",
"lint": "vsh lint",
......@@ -56,7 +55,7 @@
"@changesets/cli": "^2.27.7",
"@ls-lint/ls-lint": "^2.2.3",
"@types/jsdom": "^21.1.7",
"@types/node": "^20.14.12",
"@types/node": "^22.0.0",
"@vben/commitlint-config": "workspace:*",
"@vben/eslint-config": "workspace:*",
"@vben/lint-staged-config": "workspace:*",
......@@ -95,11 +94,6 @@
"canvas",
"node-gyp",
"playwright"
],
"updateConfig": {
"ignoreDependencies": [
"zx"
]
}
]
}
}
......@@ -31,7 +31,7 @@ function handleClick(path?: string) {
>
<li>
<a href="javascript:void 0" @click.stop="handleClick(item.path)">
<span class="flex-center h-full">
<span class="flex-center z-10 h-full">
<VbenIcon
v-if="item.icon && showIcon"
:icon="item.icon"
......
......@@ -11,6 +11,7 @@ import { cn } from '@vben-core/toolkit';
interface Props {
class?: HTMLAttributes['class'];
horizontal?: boolean;
scrollBarClass?: HTMLAttributes['class'];
shadow?: boolean;
shadowBorder?: boolean;
}
......@@ -58,7 +59,11 @@ function handleScroll(event: Event) {
}"
class="scrollbar-bottom-shadow pointer-events-none absolute bottom-0 z-10 h-12 w-full opacity-0 transition-opacity duration-300 ease-in-out will-change-[opacity]"
></div>
<ScrollBar v-if="horizontal" orientation="horizontal" />
<ScrollBar
v-if="horizontal"
:class="scrollBarClass"
orientation="horizontal"
/>
</ScrollArea>
</template>
......
......@@ -71,7 +71,11 @@ function scrollIntoView() {
<template>
<div :style="style" class="tabs-chrome size-full flex-1 overflow-hidden pt-1">
<VbenScrollbar class="tabs-chrome__scrollbar h-full" horizontal>
<VbenScrollbar
class="tabs-chrome__scrollbar h-full"
horizontal
scroll-bar-class="z-10"
>
<!-- footer -> 4px -->
<div
ref="contentRef"
......
......@@ -72,7 +72,11 @@ function scrollIntoView() {
<template>
<div class="h-full flex-1 overflow-hidden">
<VbenScrollbar class="tabs-scrollbar h-full" horizontal>
<VbenScrollbar
class="tabs-scrollbar h-full"
horizontal
scroll-bar-class="z-10"
>
<div
:class="contentClass"
class="relative !flex h-full w-max items-center"
......
......@@ -45,6 +45,11 @@ async function initTabsSortable() {
const el = document.querySelectorAll(`.${contentClass}`)?.[0] as HTMLElement;
const resetElState = () => {
el.style.cursor = 'default';
el.classList.remove('dragging');
};
const { initializeSortable } = useSortable(el, {
filter: (_evt, target: HTMLElement) => {
const parent = findParentElement(target);
......@@ -57,16 +62,20 @@ async function initTabsSortable() {
const { srcElement } = (evt as any).originalEvent;
if (!srcElement) {
resetElState();
return;
}
const srcParent = findParentElement(srcElement);
if (!srcParent) {
resetElState();
return;
}
if (!srcParent.classList.contains('dragable')) {
resetElState();
return;
}
......@@ -79,8 +88,7 @@ async function initTabsSortable() {
) {
emit('sortTabs', oldIndex, newIndex);
}
el.classList.remove('dragging');
el.style.cursor = 'default';
resetElState();
},
onMove(evt) {
const parent = findParentElement(evt.related);
......
......@@ -15,10 +15,9 @@ export function useAppConfig(
? window._VBEN_ADMIN_PRO_APP_CONF_
: (env as VbenAdminProAppConfigRaw);
const { VITE_GLOB_API_URL, VITE_GLOB_APP_TITLE } = config;
const { VITE_GLOB_API_URL } = config;
return {
apiURL: VITE_GLOB_API_URL,
appTitle: VITE_GLOB_APP_TITLE,
};
}
......@@ -121,7 +121,10 @@ export const useCoreTabbarStore = defineStore('core-tabbar', {
} else {
// 页面已经存在,不重复添加选项卡,只更新选项卡参数
const currentTab = toRaw(this.tabs)[tabIndex];
this.tabs.splice(tabIndex, 1, { ...currentTab, ...tab });
if (!currentTab.meta.affixTab) {
const mergedTab = { ...currentTab, ...tab };
this.tabs.splice(tabIndex, 1, mergedTab);
}
}
this.updateCacheTab();
},
......@@ -269,7 +272,8 @@ export const useCoreTabbarStore = defineStore('core-tabbar', {
);
if (index !== -1) {
tab.meta.affixTab = true;
this.addTab(tab);
// this.addTab(tab);
this.tabs.splice(index, 1, tab);
}
},
......@@ -369,7 +373,8 @@ export const useCoreTabbarStore = defineStore('core-tabbar', {
if (index !== -1) {
tab.meta.affixTab = false;
this.addTab(tab);
// this.addTab(tab);
this.tabs.splice(index, 1, tab);
}
},
......
......@@ -8,12 +8,10 @@ declare module 'vue-router' {
export interface VbenAdminProAppConfigRaw {
VITE_GLOB_API_URL: string;
VITE_GLOB_APP_TITLE: string;
}
export interface ApplicationConfig {
apiURL: string;
appTitle: string;
}
declare global {
......
......@@ -20,6 +20,7 @@ async function runLint({ format }: LintCommandOptions) {
}
$.verbose = true;
await Promise.all([
$`cspell lint "**/*.ts" "**/README.md" ".changeset/*.md" --no-progress`,
$`eslint . --cache`,
// $`ls-lint`,
$`prettier . --ignore-unknown --check --cache`,
......
......@@ -18,7 +18,7 @@
::: tip
因为微信群人数有限制,加微信群前,你可以通过[赞助](../sponsor/personal.md)任意金额,并备注 `加入微信群`,作者会将你拉入微信群。也可以主动发送截图给作者。
因为微信群人数有限制,加微信群前,你可以通过[赞助](../sponsor/personal.md)任意金额,以主动发送截图给作者,备注`加入微信群`即可。
:::
......
......@@ -26,7 +26,7 @@
在 `package.json` 中引入包:
```json
```json {3}
{
"dependencies": {
"@vben/utils": "workspace:*"
......@@ -46,7 +46,7 @@ import { isString } from '@vben/utils';
在项目中,你可以看到一些 `#` 开头的路径,例如: `#/api`、`#/views`, 这些路径都是别名,用于快速定位到某个目录。它不是通过 `vite` 的 `alias` 实现的,而是通过 `Node.js` 本身的 [subpath imports](https://nodejs.org/api/packages.html#subpath-imports) 原理。只需要在 `package.json` 中配置 `imports` 字段即可。
```json
```json {3}
{
"imports": {
"#/*": "./src/*"
......@@ -56,7 +56,7 @@ import { isString } from '@vben/utils';
为了 IDE 能够识别这些别名,我们还需要在`tsconfig.json`内配置:
```json
```json {5}
{
"compilerOptions": {
"baseUrl": ".",
......
......@@ -55,11 +55,9 @@ npm 脚本是项目常见的配置,用于执行一些常见的任务,比如
// changeset 版本管理
"changeset": "pnpm exec changeset",
// 检查项目各种问题
"check": "pnpm run check:dep && pnpm run check:circular && pnpm run check:type && pnpm run check:cspell",
"check": "pnpm run check:circular && pnpm run check:dep && pnpm run check:type",,
// 检查循环引用
"check:circular": "vsh check-circular",
// 检查拼写
"check:cspell": "cspell lint \"**/*.ts\" \"**/README.md\" \".changeset/*.md\" --no-progress",
// 检查依赖
"check:dep": "vsh check-dep",
// 检查类型
......
......@@ -31,7 +31,7 @@
```bash [.env]
# 应用标题
VITE_GLOB_APP_TITLE=Vben Admin
VITE_APP_TITLE=Vben Admin
# 应用命名空间,用于缓存、store等功能的前缀,确保隔离
VITE_APP_NAMESPACE=vben-web-antd
......@@ -88,7 +88,6 @@ VITE_INJECT_APP_LOADING=true
```ts
window._VBEN_ADMIN_PRO_APP_CONF_ = {
VITE_GLOB_API_URL: 'https://mock-napi.vben.pro/api',
VITE_GLOB_APP_TITLE: 'Vben Admin',
};
Object.freeze(window._VBEN_ADMIN_PRO_APP_CONF_);
Object.defineProperty(window, '_VBEN_ADMIN_PRO_APP_CONF_', {
......@@ -124,13 +123,11 @@ const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
```ts
export interface VbenAdminProAppConfigRaw {
VITE_GLOB_API_URL: string;
VITE_GLOB_APP_TITLE: string;
VITE_GLOB_OTHER_API_URL: string; // [!code ++]
}
export interface ApplicationConfig {
apiURL: string;
appTitle: string;
otherApiURL: string; // [!code ++]
}
```
......@@ -159,17 +156,12 @@ const { otherApiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
import { useAppConfig } from '@vben/hooks';
import { defineOverridesPreferences } from '@vben/preferences';
const { appTitle } = useAppConfig(import.meta.env, import.meta.env.PROD);
/**
* @description 项目配置文件
* 只需要覆盖项目中的一部分配置,不需要的配置不用覆盖,会自动使用默认配置
*/
export const overridesPreferences = defineOverridesPreferences({
// overrides
app: {
name: appTitle,
},
});
```
......
......@@ -22,7 +22,7 @@ VITE_INJECT_APP_LOADING=false
::: tip
- 你可以使用跟`index.html`一样的语法,比如`VITE_GLOB_APP_TITLE`变量,来获取应用的标题。
- 你可以使用跟`index.html`一样的语法,比如`VITE_APP_TITLE`变量,来获取应用的标题。
- 必须保证有一个`id="__app-loading__"`的元素。
- 必须保证有一个`style[data-app-loading="inject-css"]`的元素。
......@@ -32,6 +32,6 @@ VITE_INJECT_APP_LOADING=false
</style>
<div id="__app-loading__">
<!-- ... -->
<div class="title"><%= VITE_GLOB_APP_TITLE %></div>
<div class="title"><%= VITE_APP_TITLE %></div>
</div>
```
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!