Skip to content

Commit 81e77fe

Browse files
committed
feat: update app and lock
1 parent f8c5636 commit 81e77fe

Some content is hidden

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

50 files changed

+19581
-1
lines changed

.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ vite.config.ts.*
5454
.changeset
5555
.github
5656
backend-mock
57-
web-antd
5857
web-ele
5958
web-naive
6059
docs

apps/web-antd/.env

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# 应用标题
2+
VITE_APP_TITLE=FBA
3+
4+
# 应用命名空间,用于缓存、store等功能的前缀,确保隔离
5+
VITE_APP_NAMESPACE=fba-ui

apps/web-antd/.env.analyze

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
VITE_BASE=/
2+
3+
# Basic interface address SPA
4+
VITE_GLOB_API_URL=https://xxx/api
5+
6+
VITE_VISUALIZER=true

apps/web-antd/.env.development

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
VITE_BASE=/
2+
3+
# 端口号
4+
VITE_PORT=5173
5+
6+
# 接口地址
7+
VITE_GLOB_API_URL=http://localhost:8000/api
8+
9+
# 是否打开 devtools,true 为打开,false 为关闭
10+
VITE_DEVTOOLS=false
11+
12+
# 是否注入全局loading
13+
VITE_INJECT_APP_LOADING=true

apps/web-antd/.env.production

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
VITE_BASE=/
2+
3+
# 接口地址
4+
VITE_GLOB_API_URL=https://xxx/api
5+
6+
# 是否开启压缩,可以设置为 none, brotli, gzip
7+
VITE_COMPRESS=gzip
8+
9+
# 是否开启 PWA
10+
VITE_PWA=false
11+
12+
# vue-router 的模式
13+
VITE_ROUTER_HISTORY=hash
14+
15+
# 是否注入全局loading
16+
VITE_INJECT_APP_LOADING=true
17+
18+
# 打包后是否生成dist.zip
19+
VITE_ARCHIVER=true

apps/web-antd/index.html

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<!doctype html>
2+
<html lang="zh">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
6+
<meta name="renderer" content="webkit" />
7+
<meta name="description" content="A Modern Back-end Management System" />
8+
<meta name="keywords" content="FBA" />
9+
<meta name="author" content="FastAPI Practices" />
10+
<meta
11+
name="viewport"
12+
content="width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=0"
13+
/>
14+
<!-- 由 vite 注入 VITE_APP_TITLE 变量,在 .env 文件内配置 -->
15+
<title><%= VITE_APP_TITLE %></title>
16+
<link
17+
rel="icon"
18+
href="https://wu-clan.github.io/picx-images-hosting/logo/fba.svg"
19+
/>
20+
</head>
21+
<body>
22+
<div id="app"></div>
23+
<script type="module" src="/src/main.ts"></script>
24+
</body>
25+
</html>

apps/web-antd/package.json

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
{
2+
"name": "fba_ui",
3+
"version": "0.0.1",
4+
"scripts": {
5+
"build": "pnpm vite build --mode production",
6+
"build:analyze": "pnpm vite build --mode analyze",
7+
"dev": "pnpm vite --mode development",
8+
"preview": "vite preview",
9+
"typecheck": "vue-tsc --noEmit --skipLibCheck"
10+
},
11+
"imports": {
12+
"#/*": "./src/*"
13+
},
14+
"dependencies": {
15+
"@vben/access": "workspace:*",
16+
"@vben/common-ui": "workspace:*",
17+
"@vben/constants": "workspace:*",
18+
"@vben/hooks": "workspace:*",
19+
"@vben/icons": "workspace:*",
20+
"@vben/layouts": "workspace:*",
21+
"@vben/locales": "workspace:*",
22+
"@vben/plugins": "workspace:*",
23+
"@vben/preferences": "workspace:*",
24+
"@vben/request": "workspace:*",
25+
"@vben/stores": "workspace:*",
26+
"@vben/styles": "workspace:*",
27+
"@vben/types": "workspace:*",
28+
"@vben/utils": "workspace:*",
29+
"@vueuse/core": "catalog:",
30+
"ant-design-vue": "catalog:",
31+
"dayjs": "catalog:",
32+
"pinia": "catalog:",
33+
"vue": "catalog:",
34+
"vue-router": "catalog:"
35+
}
36+
}

apps/web-antd/postcss.config.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from '@vben/tailwind-config/postcss';
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/**
2+
* 通用组件共同的使用的基础组件,原先放在 adapter/form 内部,限制了使用范围,这里提取出来,方便其他地方使用
3+
* 可用于 vben-form、vben-modal、vben-drawer 等组件使用,
4+
*/
5+
6+
import type { Component, SetupContext } from 'vue';
7+
8+
import type { BaseFormComponentType } from '@vben/common-ui';
9+
10+
import { h } from 'vue';
11+
12+
import { ApiComponent, globalShareState, IconPicker } from '@vben/common-ui';
13+
import { $t } from '@vben/locales';
14+
15+
import {
16+
AutoComplete,
17+
Button,
18+
Checkbox,
19+
CheckboxGroup,
20+
DatePicker,
21+
Divider,
22+
Input,
23+
InputNumber,
24+
InputPassword,
25+
Mentions,
26+
notification,
27+
Radio,
28+
RadioGroup,
29+
RangePicker,
30+
Rate,
31+
Select,
32+
Space,
33+
Switch,
34+
Textarea,
35+
TimePicker,
36+
TreeSelect,
37+
Upload,
38+
} from 'ant-design-vue';
39+
40+
const withDefaultPlaceholder = <T extends Component>(
41+
component: T,
42+
type: 'input' | 'select',
43+
) => {
44+
return (props: any, { attrs, slots }: Omit<SetupContext, 'expose'>) => {
45+
const placeholder = props?.placeholder || $t(`ui.placeholder.${type}`);
46+
return h(component, { ...props, ...attrs, placeholder }, slots);
47+
};
48+
};
49+
50+
// 这里需要自行根据业务组件库进行适配,需要用到的组件都需要在这里类型说明
51+
export type ComponentType =
52+
| 'ApiSelect'
53+
| 'ApiTreeSelect'
54+
| 'AutoComplete'
55+
| 'Checkbox'
56+
| 'CheckboxGroup'
57+
| 'DatePicker'
58+
| 'DefaultButton'
59+
| 'Divider'
60+
| 'IconPicker'
61+
| 'Input'
62+
| 'InputNumber'
63+
| 'InputPassword'
64+
| 'Mentions'
65+
| 'PrimaryButton'
66+
| 'Radio'
67+
| 'RadioGroup'
68+
| 'RangePicker'
69+
| 'Rate'
70+
| 'Select'
71+
| 'Space'
72+
| 'Switch'
73+
| 'Textarea'
74+
| 'TimePicker'
75+
| 'TreeSelect'
76+
| 'Upload'
77+
| BaseFormComponentType;
78+
79+
async function initComponentAdapter() {
80+
const components: Partial<Record<ComponentType, Component>> = {
81+
// 如果你的组件体积比较大,可以使用异步加载
82+
// Button: () =>
83+
// import('xxx').then((res) => res.Button),
84+
ApiSelect: (props, { attrs, slots }) => {
85+
return h(
86+
ApiComponent,
87+
{
88+
placeholder: $t('ui.placeholder.select'),
89+
...props,
90+
...attrs,
91+
component: Select,
92+
loadingSlot: 'suffixIcon',
93+
visibleEvent: 'onDropdownVisibleChange',
94+
modelPropName: 'value',
95+
},
96+
slots,
97+
);
98+
},
99+
ApiTreeSelect: (props, { attrs, slots }) => {
100+
return h(
101+
ApiComponent,
102+
{
103+
placeholder: $t('ui.placeholder.select'),
104+
...props,
105+
...attrs,
106+
component: TreeSelect,
107+
fieldNames: { label: 'label', value: 'value', children: 'children' },
108+
loadingSlot: 'suffixIcon',
109+
modelPropName: 'value',
110+
optionsPropName: 'treeData',
111+
visibleEvent: 'onVisibleChange',
112+
},
113+
slots,
114+
);
115+
},
116+
AutoComplete,
117+
Checkbox,
118+
CheckboxGroup,
119+
DatePicker,
120+
// 自定义默认按钮
121+
DefaultButton: (props, { attrs, slots }) => {
122+
return h(Button, { ...props, attrs, type: 'default' }, slots);
123+
},
124+
Divider,
125+
IconPicker: (props, { attrs, slots }) => {
126+
return h(
127+
IconPicker,
128+
{ iconSlot: 'addonAfter', inputComponent: Input, ...props, ...attrs },
129+
slots,
130+
);
131+
},
132+
Input: withDefaultPlaceholder(Input, 'input'),
133+
InputNumber: withDefaultPlaceholder(InputNumber, 'input'),
134+
InputPassword: withDefaultPlaceholder(InputPassword, 'input'),
135+
Mentions: withDefaultPlaceholder(Mentions, 'input'),
136+
// 自定义主要按钮
137+
PrimaryButton: (props, { attrs, slots }) => {
138+
return h(Button, { ...props, attrs, type: 'primary' }, slots);
139+
},
140+
Radio,
141+
RadioGroup,
142+
RangePicker,
143+
Rate,
144+
Select: withDefaultPlaceholder(Select, 'select'),
145+
Space,
146+
Switch,
147+
Textarea: withDefaultPlaceholder(Textarea, 'input'),
148+
TimePicker,
149+
TreeSelect: withDefaultPlaceholder(TreeSelect, 'select'),
150+
Upload,
151+
};
152+
153+
// 将组件注册到全局共享状态中
154+
globalShareState.setComponents(components);
155+
156+
// 定义全局共享状态中的消息提示
157+
globalShareState.defineMessage({
158+
// 复制成功消息提示
159+
copyPreferencesSuccess: (title, content) => {
160+
notification.success({
161+
description: content,
162+
message: title,
163+
placement: 'bottomRight',
164+
});
165+
},
166+
});
167+
}
168+
169+
export { initComponentAdapter };

apps/web-antd/src/adapter/form.ts

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import type {
2+
VbenFormSchema as FormSchema,
3+
VbenFormProps,
4+
} from '@vben/common-ui';
5+
6+
import type { ComponentType } from './component';
7+
8+
import { setupVbenForm, useVbenForm as useForm, z } from '@vben/common-ui';
9+
import { $t } from '@vben/locales';
10+
11+
setupVbenForm<ComponentType>({
12+
config: {
13+
// ant design vue组件库默认都是 v-model:value
14+
baseModelPropName: 'value',
15+
16+
// 一些组件是 v-model:checked 或者 v-model:fileList
17+
modelPropNameMap: {
18+
Checkbox: 'checked',
19+
Radio: 'checked',
20+
Switch: 'checked',
21+
Upload: 'fileList',
22+
},
23+
},
24+
defineRules: {
25+
// 输入项目必填国际化适配
26+
required: (value, _params, ctx) => {
27+
if (value === undefined || value === null || value.length === 0) {
28+
return $t('ui.formRules.required', [ctx.label]);
29+
}
30+
return true;
31+
},
32+
// 选择项目必填国际化适配
33+
selectRequired: (value, _params, ctx) => {
34+
if (value === undefined || value === null) {
35+
return $t('ui.formRules.selectRequired', [ctx.label]);
36+
}
37+
return true;
38+
},
39+
},
40+
});
41+
42+
const useVbenForm = useForm<ComponentType>;
43+
44+
export { useVbenForm, z };
45+
46+
export type VbenFormSchema = FormSchema<ComponentType>;
47+
export type { VbenFormProps };

0 commit comments

Comments
 (0)