优化更新
This commit is contained in:
@@ -145,25 +145,25 @@ class ParamService(BaseService[Param]):
|
||||
```typescript
|
||||
// src/views/system/param/columns.ts
|
||||
{
|
||||
label: '参数类型',
|
||||
prop: 'type',
|
||||
title: '参数类型',
|
||||
dataIndex: 'type',
|
||||
width: 100,
|
||||
// 方式一:直接使用后端返回的 typeText 字段
|
||||
render(record) {
|
||||
return h(ElTag,
|
||||
{ type: record.row.type == 0 ? 'primary' : 'warning' },
|
||||
{ default: () => record.row.typeText });
|
||||
customRender: ({ record }) => {
|
||||
return h(Tag,
|
||||
{ color: record.type == 0 ? 'processing' : 'warning' },
|
||||
() => record.typeText);
|
||||
},
|
||||
},
|
||||
{
|
||||
label: '状态',
|
||||
prop: 'status',
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
width: 100,
|
||||
// 方式二:直接使用后端返回的 statusText 字段
|
||||
render(record) {
|
||||
return h(ElTag,
|
||||
{ type: record.row.status == 1 ? 'success' : 'danger' },
|
||||
{ default: () => record.row.statusText });
|
||||
customRender: ({ record }) => {
|
||||
return h(Tag,
|
||||
{ color: record.status == 1 ? 'success' : 'error' },
|
||||
() => record.statusText);
|
||||
},
|
||||
},
|
||||
```
|
||||
@@ -205,7 +205,7 @@ export const schemas: FormSchema[] = [
|
||||
label: '参数类型',
|
||||
componentProps: {
|
||||
placeholder: '请选择参数类型',
|
||||
clearable: true,
|
||||
allowClear: true,
|
||||
options: [
|
||||
{ label: '系统', value: 0 },
|
||||
{ label: '业务', value: 1 },
|
||||
@@ -218,7 +218,7 @@ export const schemas: FormSchema[] = [
|
||||
label: '状态',
|
||||
componentProps: {
|
||||
placeholder: '请选择状态',
|
||||
clearable: true,
|
||||
allowClear: true,
|
||||
options: [
|
||||
{ label: '正常', value: 1 },
|
||||
{ label: '禁用', value: 2 },
|
||||
@@ -309,8 +309,8 @@ const options = [
|
||||
// 业务字段为数字
|
||||
formData.type = 0;
|
||||
|
||||
// el-option 绑定时需要转换
|
||||
<el-option :value="Number(item.value)" />
|
||||
// a-select-option 绑定时需要转换
|
||||
<a-select-option :value="Number(item.value)" />
|
||||
```
|
||||
|
||||
搜索表单中的 `options` 的 `value` 为字符串 `'0'`/`'1'`,后端 `page_eq_fields` 中的 `type` 字段期望数字。前端 API 传参时自动转换。
|
||||
@@ -353,7 +353,7 @@ biz_ —— 业务类字典
|
||||
```
|
||||
1. 后台「字典管理」中新增字典类型和字典项
|
||||
2. 后端 service 设置 serialize_maps(字段名 → 字典编码)
|
||||
3. 前端 columns.ts 使用 render 函数渲染状态标签(直接用 xxxText 字段)
|
||||
3. 前端 columns.ts 使用 customRender 函数渲染状态标签(直接用 xxxText 字段)
|
||||
4. 前端 querySchemas.ts 中配置搜索选项(硬编码或 API 获取)
|
||||
5. 表单提交时 value 为字符串,后端存储时注意类型处理
|
||||
```
|
||||
@@ -362,4 +362,4 @@ biz_ —— 业务类字典
|
||||
|
||||
## 总结
|
||||
|
||||
字典数据联调通过后端字典 API + `serialize_maps` 映射显示名 + 前端 `render` 函数渲染标签实现。`serialize_maps` 的 value 为数据字典编码,BaseService 自动查询字典并以 `xxxText` 格式输出。字典值统一为字符串,前端使用时注意类型转换。简单场景硬编码选项,动态场景通过 API 获取。
|
||||
字典数据联调通过后端字典 API + `serialize_maps` 映射显示名 + 前端 `customRender` 函数渲染标签实现。`serialize_maps` 的 value 为数据字典编码,BaseService 自动查询字典并以 `xxxText` 格式输出。字典值统一为字符串,前端使用时注意类型转换。简单场景硬编码选项,动态场景通过 API 获取。
|
||||
|
||||
Reference in New Issue
Block a user