Skip to content

Commit 13bcfcc

Browse files
committed
feat: bump to vben main branch
2 parents 27b9763 + e815f0f commit 13bcfcc

File tree

409 files changed

+11260
-3879
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

409 files changed

+11260
-3879
lines changed

.editorconfig

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
root = true
2+
3+
[*]
4+
charset=utf-8
5+
end_of_line=lf
6+
insert_final_newline=true
7+
indent_style=space
8+
indent_size=2
9+
max_line_length = 100
10+
trim_trailing_whitespace = true
11+
quote_type = single
12+
13+
[*.{yml,yaml,json}]
14+
indent_style = space
15+
indent_size = 2
16+
17+
[*.md]
18+
trim_trailing_whitespace = false

.gitconfig

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[core]
2+
ignorecase = false

.gitignore

+15-1
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,24 @@ vite.config.ts.*
4242

4343
# Editor directories and files
4444
.idea
45-
.vscode
4645
*.suo
4746
*.ntvs*
4847
*.njsproj
4948
*.sln
5049
*.sw?
5150
.history
51+
52+
# 升级vben时需要删除的文件
53+
.vscode
54+
.changeset
55+
.github
56+
backend-mock
57+
web-ele
58+
web-naive
59+
docs
60+
playground
61+
.gitpod.yml
62+
README.*.md
63+
tea.yaml
64+
vben-admin.code-workspace
65+
scripts/deploy

.husky/commit-msg

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
echo Start running commit-msg hook...
2+
3+
# Check whether the git commit information is standardized
4+
pnpm exec commitlint --edit "$1"
5+
6+
echo Run commit-msg hook done.

.husky/post-merge

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# 每次 git pull 之后, 安装依赖
2+
3+
pnpm install

.husky/pre-commit

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# update `.vscode/vben-admin.code-workspace` file
2+
pnpm vsh code-workspace --auto-commit
3+
4+
# Format and submit code according to lintstagedrc.js configuration
5+
pnpm exec lint-staged
6+
7+
echo Run pre-commit hook done.

.lintstagedrc.mjs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
11
export default {
2+
'*.md': ['prettier --cache --ignore-unknown --write'],
3+
'*.vue': [
4+
'prettier --write',
5+
'eslint --cache --fix',
6+
'stylelint --fix --allow-empty-input',
7+
],
28
'*.{js,jsx,ts,tsx}': [
39
'prettier --cache --ignore-unknown --write',
410
'eslint --cache --fix',
@@ -7,14 +13,8 @@ export default {
713
'prettier --cache --ignore-unknown --write',
814
'stylelint --fix --allow-empty-input',
915
],
10-
'*.md': ['prettier --cache --ignore-unknown --write'],
11-
'*.vue': [
12-
'prettier --write',
13-
'eslint --cache --fix',
14-
'stylelint --fix --allow-empty-input',
15-
],
16+
'package.json': ['prettier --cache --write'],
1617
'{!(package)*.json,*.code-snippets,.!(browserslist)*rc}': [
1718
'prettier --cache --write--parser json',
1819
],
19-
'package.json': ['prettier --cache --write'],
2020
};

.node-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
20.14.0

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
registry = "https://registry.npmmirror.com"
2+
public-hoist-pattern[]=husky
23
public-hoist-pattern[]=eslint
34
public-hoist-pattern[]=prettier
45
public-hoist-pattern[]=prettier-plugin-tailwindcss

apps/web-antd/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"preview": "vite preview",
99
"typecheck": "vue-tsc --noEmit --skipLibCheck"
1010
},
11+
"type": "module",
1112
"imports": {
1213
"#/*": "./src/*"
1314
},

apps/web-antd/public/favicon.ico

5.3 KB
Binary file not shown.

apps/web-antd/src/adapter/component/index.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33
* 可用于 vben-form、vben-modal、vben-drawer 等组件使用,
44
*/
55

6+
import type { Component, SetupContext } from 'vue';
7+
68
import type { BaseFormComponentType } from '@vben/common-ui';
79

8-
import type { Component, SetupContext } from 'vue';
910
import { h } from 'vue';
1011

1112
import { ApiComponent, globalShareState, IconPicker } from '@vben/common-ui';
@@ -124,7 +125,13 @@ async function initComponentAdapter() {
124125
IconPicker: (props, { attrs, slots }) => {
125126
return h(
126127
IconPicker,
127-
{ iconSlot: 'addonAfter', inputComponent: Input, ...props, ...attrs },
128+
{
129+
iconSlot: 'addonAfter',
130+
inputComponent: Input,
131+
modelValueProp: 'value',
132+
...props,
133+
...attrs,
134+
},
128135
slots,
129136
);
130137
},

apps/web-antd/src/api/core/auth.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { baseRequestClient, requestClient } from '#/api/request';
2+
3+
export namespace AuthApi {
4+
/** 登录接口参数 */
5+
export interface LoginParams {
6+
password?: string;
7+
username?: string;
8+
}
9+
10+
/** 登录接口返回值 */
11+
export interface LoginResult {
12+
accessToken: string;
13+
}
14+
15+
export interface RefreshTokenResult {
16+
data: string;
17+
status: number;
18+
}
19+
}
20+
21+
/**
22+
* 登录
23+
*/
24+
export async function loginApi(data: AuthApi.LoginParams) {
25+
return requestClient.post<AuthApi.LoginResult>('/auth/login', data);
26+
}
27+
28+
/**
29+
* 刷新accessToken
30+
*/
31+
export async function refreshTokenApi() {
32+
return baseRequestClient.post<AuthApi.RefreshTokenResult>('/auth/refresh', {
33+
withCredentials: true,
34+
});
35+
}
36+
37+
/**
38+
* 退出登录
39+
*/
40+
export async function logoutApi() {
41+
return baseRequestClient.post('/auth/logout', {
42+
withCredentials: true,
43+
});
44+
}
45+
46+
/**
47+
* 获取用户权限码
48+
*/
49+
export async function getAccessCodesApi() {
50+
return requestClient.get<string[]>('/auth/codes');
51+
}

apps/web-antd/src/api/core/index.ts

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './auth';
2+
export * from './menu';
3+
export * from './user';

apps/web-antd/src/api/core/menu.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { RouteRecordStringComponent } from '@vben/types';
2+
3+
import { requestClient } from '#/api/request';
4+
5+
/**
6+
* 获取用户所有菜单
7+
*/
8+
export async function getAllMenusApi() {
9+
return requestClient.get<RouteRecordStringComponent[]>('/menu/all');
10+
}

apps/web-antd/src/api/core/user.ts

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import type { UserInfo } from '@vben/types';
2+
3+
import { requestClient } from '#/api/request';
4+
5+
/**
6+
* 获取用户信息
7+
*/
8+
export async function getUserInfoApi() {
9+
return requestClient.get<UserInfo>('/user/info');
10+
}

apps/web-antd/src/api/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './core';

apps/web-antd/src/api/request.ts

+20-17
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,29 @@
11
/**
22
* 该文件可自行根据业务逻辑进行调整
33
*/
4-
import type { HttpResponse } from '@vben/request';
4+
import type { RequestClientOptions } from '@vben/request';
55

66
import { useAppConfig } from '@vben/hooks';
77
import { preferences } from '@vben/preferences';
88
import {
99
authenticateResponseInterceptor,
10+
defaultResponseInterceptor,
1011
errorMessageResponseInterceptor,
1112
RequestClient,
1213
} from '@vben/request';
1314
import { useAccessStore } from '@vben/stores';
1415

1516
import { message } from 'ant-design-vue';
1617

17-
import { refreshTokenApi } from '#/api/auth';
1818
import { useAuthStore } from '#/store';
1919

20+
import { refreshTokenApi } from './core';
21+
2022
const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
2123

22-
function createRequestClient(baseURL: string) {
24+
function createRequestClient(baseURL: string, options?: RequestClientOptions) {
2325
const client = new RequestClient({
26+
...options,
2427
baseURL,
2528
});
2629

@@ -68,19 +71,14 @@ function createRequestClient(baseURL: string) {
6871
},
6972
});
7073

71-
// response数据解构
72-
client.addResponseInterceptor<HttpResponse>({
73-
fulfilled: (response) => {
74-
const { data: responseData, status } = response;
75-
76-
const { code, data } = responseData;
77-
if (status >= 200 && status < 400 && code === 200) {
78-
return data;
79-
}
80-
81-
throw Object.assign({}, response, { response });
82-
},
83-
});
74+
// 处理返回的响应数据格式
75+
client.addResponseInterceptor(
76+
defaultResponseInterceptor({
77+
codeField: 'code',
78+
dataField: 'data',
79+
successCode: 0,
80+
}),
81+
);
8482

8583
// token过期的处理
8684
client.addResponseInterceptor(
@@ -96,15 +94,20 @@ function createRequestClient(baseURL: string) {
9694
// 通用的错误处理,如果没有进入上面的错误处理逻辑,就会进入这里
9795
client.addResponseInterceptor(
9896
errorMessageResponseInterceptor((msg: string, error) => {
97+
// 这里可以根据业务进行定制,你可以拿到 error 内的信息进行定制化处理,根据不同的 code 做不同的提示,而不是直接使用 message.error 提示 msg
98+
// 当前mock接口返回的错误字段是 error 或者 message
9999
const responseData = error?.response?.data ?? {};
100100
const errorMessage = responseData?.error ?? responseData?.message ?? '';
101+
// 如果没有错误信息,则会根据状态码进行提示
101102
message.error(errorMessage || msg);
102103
}),
103104
);
104105

105106
return client;
106107
}
107108

108-
export const requestClient = createRequestClient(apiURL);
109+
export const requestClient = createRequestClient(apiURL, {
110+
responseReturn: 'data',
111+
});
109112

110113
export const baseRequestClient = new RequestClient({ baseURL: apiURL });

apps/web-antd/src/bootstrap.ts

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { createApp, watchEffect } from 'vue';
22

33
import { registerAccessDirective } from '@vben/access';
4+
import { initTippy, registerLoadingDirective } from '@vben/common-ui';
5+
import { MotionPlugin } from '@vben/plugins/motion';
46
import { preferences } from '@vben/preferences';
57
import { initStores } from '@vben/stores';
68
import '@vben/styles';
@@ -18,8 +20,23 @@ async function bootstrap(namespace: string) {
1820
// 初始化组件适配器
1921
await initComponentAdapter();
2022

23+
// // 设置弹窗的默认配置
24+
// setDefaultModalProps({
25+
// fullscreenButton: false,
26+
// });
27+
// // 设置抽屉的默认配置
28+
// setDefaultDrawerProps({
29+
// zIndex: 1020,
30+
// });
31+
2132
const app = createApp(App);
2233

34+
// 注册v-loading指令
35+
registerLoadingDirective(app, {
36+
loading: 'loading', // 在这里可以自定义指令名称,也可以明确提供false表示不注册这个指令
37+
spinning: 'spinning',
38+
});
39+
2340
// 国际化 i18n 配置
2441
await setupI18n(app);
2542

@@ -29,9 +46,15 @@ async function bootstrap(namespace: string) {
2946
// 安装权限指令
3047
registerAccessDirective(app);
3148

49+
// 初始化 tippy
50+
initTippy(app);
51+
3252
// 配置路由及路由守卫
3353
app.use(router);
3454

55+
// 配置Motion插件
56+
app.use(MotionPlugin);
57+
3558
// 动态更新标题
3659
watchEffect(() => {
3760
if (preferences.app.dynamicTitle) {

apps/web-antd/src/locales/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# locale
2+
3+
每个app使用的国际化可能不同,这里用于扩展国际化的功能,例如扩展 dayjs、antd组件库的多语言切换,以及app本身的国际化文件。

apps/web-antd/src/locales/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
import type { LocaleSetupOptions, SupportedLanguagesType } from '@vben/locales';
21
import type { Locale } from 'ant-design-vue/es/locale';
32

43
import type { App } from 'vue';
4+
5+
import type { LocaleSetupOptions, SupportedLanguagesType } from '@vben/locales';
6+
57
import { ref } from 'vue';
68

79
import {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"title": "Demos",
3+
"antd": "Ant Design Vue",
4+
"vben": {
5+
"title": "Project",
6+
"about": "About",
7+
"document": "Document",
8+
"antdv": "Ant Design Vue Version",
9+
"naive-ui": "Naive UI Version",
10+
"element-plus": "Element Plus Version"
11+
}
12+
}

apps/web-antd/src/locales/langs/en-US/page.json

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
},
1111
"dashboard": {
1212
"title": "Dashboard",
13+
"analytics": "Analytics",
1314
"workspace": "Workspace"
1415
}
1516
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"title": "演示",
3+
"antd": "Ant Design Vue",
4+
"vben": {
5+
"title": "项目",
6+
"about": "关于",
7+
"document": "文档",
8+
"antdv": "Ant Design Vue 版本",
9+
"naive-ui": "Naive UI 版本",
10+
"element-plus": "Element Plus 版本"
11+
}
12+
}

0 commit comments

Comments
 (0)