Skip to content

Commit f815dcf

Browse files
authored
fix: after deleting the form item, you will also get the form value (vbenjs#4481)
* fix: after deleting the form item, you will also get the form value
1 parent 1197efe commit f815dcf

File tree

10 files changed

+92
-60
lines changed

10 files changed

+92
-60
lines changed

README.ja-JP.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ pnpm build
125125

126126
[@Vben](https://github.com/anncwb)
127127

128+
## スター歴史
129+
130+
[![Star History Chart](https://api.star-history.com/svg?repos=vbenjs/vue-vben-admin&type=Date)](https://star-history.com/#vbenjs/vue-vben-admin&Date)
131+
128132
## 寄付
129133

130134
このプロジェクトが役に立つと思われた場合、作者にコーヒーを一杯おごってサポートを示すことができます!
@@ -133,10 +137,6 @@ pnpm build
133137

134138
<a style="display: block;width: 100px;height: 50px;line-height: 50px; color: #fff;text-align: center; background: #408aed;border-radius: 4px;" href="https://www.paypal.com/paypalme/cvvben">Paypal Me</a>
135139

136-
## スター歴史
137-
138-
[![Star History Chart](https://api.star-history.com/svg?repos=vbenjs/vue-vben-admin&type=Date)](https://star-history.com/#vbenjs/vue-vben-admin&Date)
139-
140140
## 貢献者
141141

142142
<a href="https://github.com/vbenjs/vue-vben-admin/graphs/contributors">

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,10 @@ Support modern browsers, not IE
124124

125125
[@Vben](https://github.com/anncwb)
126126

127+
## Star History
128+
129+
[![Star History Chart](https://api.star-history.com/svg?repos=vbenjs/vue-vben-admin&type=Date)](https://star-history.com/#vbenjs/vue-vben-admin&Date)
130+
127131
## Donate
128132

129133
If you think this project is helpful to you, you can help the author buy a cup of coffee to show your support!
@@ -132,10 +136,6 @@ If you think this project is helpful to you, you can help the author buy a cup o
132136

133137
<a style="display: block;width: 100px;height: 50px;line-height: 50px; color: #fff;text-align: center; background: #408aed;border-radius: 4px;" href="https://www.paypal.com/paypalme/cvvben">Paypal Me</a>
134138

135-
## Star History
136-
137-
[![Star History Chart](https://api.star-history.com/svg?repos=vbenjs/vue-vben-admin&type=Date)](https://star-history.com/#vbenjs/vue-vben-admin&Date)
138-
139139
## Contributor
140140

141141
<a href="https://github.com/vbenjs/vue-vben-admin/graphs/contributors">

README.zh-CN.md

+8-8
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ pnpm dev
7777
pnpm build
7878
```
7979

80+
## 更新日志
81+
82+
[CHANGELOG](https://github.com/vbenjs/vue-vben-admin/releases)
83+
8084
## 如何贡献
8185

8286
非常欢迎你的加入![提一个 Issue](https://github.com/anncwb/vue-vben-admin/issues/new/choose) 或者提交一个 Pull Request。
@@ -120,6 +124,10 @@ pnpm build
120124

121125
[@Vben](https://github.com/anncwb)
122126

127+
## Star History
128+
129+
[![Star History Chart](https://api.star-history.com/svg?repos=vbenjs/vue-vben-admin&type=Date)](https://star-history.com/#vbenjs/vue-vben-admin&Date)
130+
123131
## 捐赠
124132

125133
如果你觉得这个项目对你有帮助,你可以帮作者买一杯咖啡表示支持!
@@ -128,14 +136,6 @@ pnpm build
128136

129137
<a style="display: block;width: 100px;height: 50px;line-height: 50px; color: #fff;text-align: center; background: #408aed;border-radius: 4px;" href="https://www.paypal.com/paypalme/cvvben">Paypal Me</a>
130138

131-
## 更新日志
132-
133-
[CHANGELOG](https://github.com/vbenjs/vue-vben-admin/releases)
134-
135-
## Star History
136-
137-
[![Star History Chart](https://api.star-history.com/svg?repos=vbenjs/vue-vben-admin&type=Date)](https://star-history.com/#vbenjs/vue-vben-admin&Date)
138-
139139
## Contributor
140140

141141
<a href="https://github.com/vbenjs/vue-vben-admin/graphs/contributors">

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ function createRequestClient(baseURL: string) {
9393

9494
// 通用的错误处理,如果没有进入上面的错误处理逻辑,就会进入这里
9595
client.addResponseInterceptor(
96-
errorMessageResponseInterceptor((msg: string) => message.error(msg)),
96+
errorMessageResponseInterceptor((msg: string, _error) => {
97+
// 这里可以根据业务进行定制,你可以拿到 error 内的信息进行定制化处理,根据不同的 code 做不同的提示,而不是直接使用 message.error 提示 msg
98+
message.error(msg);
99+
}),
97100
);
98101

99102
return client;

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,10 @@ function createRequestClient(baseURL: string) {
9393

9494
// 通用的错误处理,如果没有进入上面的错误处理逻辑,就会进入这里
9595
client.addResponseInterceptor(
96-
errorMessageResponseInterceptor((msg: string) => ElMessage.error(msg)),
96+
errorMessageResponseInterceptor((msg: string, _error) => {
97+
// 这里可以根据业务进行定制,你可以拿到 error 内的信息进行定制化处理,根据不同的 code 做不同的提示,而不是直接使用 message.error 提示 msg
98+
ElMessage.error(msg);
99+
}),
97100
);
98101

99102
return client;

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

+4-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,10 @@ function createRequestClient(baseURL: string) {
9292

9393
// 通用的错误处理,如果没有进入上面的错误处理逻辑,就会进入这里
9494
client.addResponseInterceptor(
95-
errorMessageResponseInterceptor((msg: string) => message.error(msg)),
95+
errorMessageResponseInterceptor((msg: string, _error) => {
96+
// 这里可以根据业务进行定制,你可以拿到 error 内的信息进行定制化处理,根据不同的 code 做不同的提示,而不是直接使用 message.error 提示 msg
97+
message.error(msg);
98+
}),
9699
);
97100

98101
return client;

packages/@core/ui-kit/form-ui/src/form-api.ts

+22-2
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ function getDefaultState(): VbenFormProps {
4343
}
4444

4545
export class FormApi {
46+
private prevState: null | VbenFormProps = null;
4647
// private api: Pick<VbenFormProps, 'handleReset' | 'handleSubmit'>;
4748
public form = {} as FormActions;
48-
isMounted = false;
4949

50-
// private prevState!: ModalState;
50+
isMounted = false;
5151
public state: null | VbenFormProps = null;
5252

5353
stateHandler: StateHandler;
@@ -66,7 +66,9 @@ export class FormApi {
6666
},
6767
{
6868
onUpdate: () => {
69+
this.prevState = this.state;
6970
this.state = this.store.state;
71+
this.updateState();
7072
},
7173
},
7274
);
@@ -87,6 +89,24 @@ export class FormApi {
8789
return this.form;
8890
}
8991

92+
private updateState() {
93+
const currentSchema = this.state?.schema ?? [];
94+
const prevSchema = this.prevState?.schema ?? [];
95+
// 进行了删除schema操作
96+
if (currentSchema.length < prevSchema.length) {
97+
const currentFields = new Set(
98+
currentSchema.map((item) => item.fieldName),
99+
);
100+
const deletedSchema = prevSchema.filter(
101+
(item) => !currentFields.has(item.fieldName),
102+
);
103+
104+
for (const schema of deletedSchema) {
105+
this.form?.setFieldValue(schema.fieldName, undefined);
106+
}
107+
}
108+
}
109+
90110
// 如果需要多次更新状态,可以使用 batch 方法
91111
batchStore(cb: () => void) {
92112
this.store.batch(cb);

playground/src/api/request.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ function createRequestClient(baseURL: string) {
9494

9595
// 通用的错误处理,如果没有进入上面的错误处理逻辑,就会进入这里
9696
client.addResponseInterceptor(
97-
errorMessageResponseInterceptor((msg: string) => message.error(msg)),
97+
errorMessageResponseInterceptor((msg: string, _error) => {
98+
// 这里可以根据业务进行定制,你可以拿到 error 内的信息进行定制化处理,根据不同的 code 做不同的提示,而不是直接使用 message.error 提示 msg
99+
message.error(msg);
100+
}),
98101
);
99102

100103
return client;

pnpm-lock.yaml

+31-31
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)