假如下拉的选项是后端指定,而不是用户可以自定义的,可以后端定义dto和接口。 假如要用户自定义,可以使用字典模块,这样用户可以在网页修改。
public async Task<List<PageCustomerTypeOutput>> AllCustomerTypeAsync() { var result = new List<PageCustomerTypeOutput>(); var list = await _customerManager.AllCustomerTypeAsync(); //需要在Application项目的ERPApplicationAutoMapperProfile增加映射 result = ObjectMapper.Map<List<CustomerTypeDto>, List<PageCustomerTypeOutput>>(list); return result; }
public class CustomerTypeDto { public string DisplayText { get; set; } public string Code { get; set; } }
public async Task<List<CustomerTypeDto>> AllCustomerTypeAsync() { List<CustomerTypeDto> result = new List<CustomerTypeDto>(); await Task.Run(() => { foreach (int i in Enum.GetValues(typeof(CustomerType))) { result.Add(new CustomerTypeDto() { Code = i.ToString(), DisplayText = Enum.GetName(typeof(CustomerType), i) }); } }); return result; }
后端项目build后,在前端vben28\nswag\refresh.bat , "..\node_modules\.bin\nswag" run /runtime:Net70 这个会更新\src\services\里面的ServiceProxies.ts

/** * 查询客户类型信息 * @return Success */ customerType( cancelToken?: CancelToken | undefined): Promise<PageCustomerTypeOutput[]> { let url_ = this.baseUrl + "/Customers/CustomerType"; url_ = url_.replace(/[?&]$/, ""); let options_ = <AxiosRequestConfig>{ method: "POST", url: url_, headers: { "Accept": "text/plain" }, cancelToken }; return this.transformOptions(options_).then(transformedOptions_ => { return this.instance.request(transformedOptions_); }).catch((_error: any) => { if (isAxiosError(_error) && _error.response) { return _error.response; } else { throw _error; } }).then((_response: AxiosResponse) => { return this.transformResult(url_, _response, (_response: AxiosResponse) => this.processCustomerType(_response)); }); } protected processCustomerType(response: AxiosResponse): Promise<PageCustomerTypeOutput[]> { const status = response.status; let _headers: any = {}; if (response.headers && typeof response.headers === "object") { for (let k in response.headers) { if (response.headers.hasOwnProperty(k)) { _headers[k] = response.headers[k]; } } } if (status === 200) { const _responseText = response.data; let result200: any = null; let resultData200 = _responseText; if (Array.isArray(resultData200)) { result200 = [] as any; for (let item of resultData200) result200!.push(PageCustomerTypeOutput.fromJS(item)); } else { result200 = <any>null; } return Promise.resolve<PageCustomerTypeOutput[]>(result200); } else if (status === 403) { const _responseText = response.data; let result403: any = null; let resultData403 = _responseText; result403 = RemoteServiceErrorResponse.fromJS(resultData403); return throwException("Forbidden", status, _responseText, _headers, result403); } else if (status === 401) { const _responseText = response.data; let result401: any = null; let resultData401 = _responseText; result401 = RemoteServiceErrorResponse.fromJS(resultData401); return throwException("Unauthorized", status, _responseText, _headers, result401); } else if (status === 400) { const _responseText = response.data; let result400: any = null; let resultData400 = _responseText; result400 = RemoteServiceErrorResponse.fromJS(resultData400); return throwException("Bad Request", status, _responseText, _headers, result400); } else if (status === 404) { const _responseText = response.data; let result404: any = null; let resultData404 = _responseText; result404 = RemoteServiceErrorResponse.fromJS(resultData404); return throwException("Not Found", status, _responseText, _headers, result404); } else if (status === 501) { const _responseText = response.data; let result501: any = null; let resultData501 = _responseText; result501 = RemoteServiceErrorResponse.fromJS(resultData501); return throwException("Server Error", status, _responseText, _headers, result501); } else if (status === 500) { const _responseText = response.data; let result500: any = null; let resultData500 = _responseText; result500 = RemoteServiceErrorResponse.fromJS(resultData500); return throwException("Server Error", status, _responseText, _headers, result500); } else if (status !== 200 && status !== 204) { const _responseText = response.data; return throwException("An unexpected server error occurred.", status, _responseText, _headers); } return Promise.resolve<PageCustomerTypeOutput[]>(null as any); }
前端参考这个写法,component: 'ApiSelect', api: getLanguageAsync,
export const createFormSchema: FormSchema[] = [
{
field: 'cultureName',
label: t('routes.admin.language_cultureName'),
component: 'ApiSelect',
required: true,
colProps: { span: 18 },
componentProps: () => {
return {
api: getLanguageAsync,
labelField: 'displayName',
valueField: 'cultureName',
showSearch: true,
optionFilterProp: 'label',
};
},
},
假如要改成从字典模块取值,则后端代码可以省略。前端改成这样 api:dataDictAsync
export async function dataDictAsync() { const dataDictionaryServiceProxy = new DataDictionaryServiceProxy(); const input = new PagingDataDictionaryDetailInput(); input.dataDictionaryId = '3a0cd740-f56e-db56-2a4e-00c1e9fb6880'; console.log(input); return (await dataDictionaryServiceProxy.pageDetail(input)).items; }
如果要在列表页的BasicTable把Code转成Text,可以考虑把Code,Text 在app启动的事后放入全局的map里
Vben Admin 源码学习:状态管理-项目配置 - Anduril - 博客园 (cnblogs.com)
https://www.cnblogs.com/hexiaobang/p/15184822.html
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· 什么是nginx的强缓存和协商缓存
· 一文读懂知识蒸馏
· Manus爆火,是硬核还是营销?
2018-08-09 Swagger 路径过滤 -PreSerializeFilters