Commit 11cf705b by chenwq

```

feat(CombiForm): 新增表单控件属性扩展功能

新增了多个表单控件的属性扩展,包括 inputProps、textareaProps、
selectProps、cascaderProps 和 normalize 属性,使表单组件具有更
灵活的配置能力。同时修复了字段禁用逻辑,支持函数式动态禁用。

fix(AccountModal): 优化账户管理表单控件实现

移除了手动渲染的表单控件,改用 CombiForm 的扩展属性实现。
为账号、姓名、手机号字段添加了长度限制和输入模式控制,
手机号支持自动去除非数字字符。同时移除了按钮的小尺寸设置。

refactor(RoleModal): 重构角色管理表单控件配置

将角色模态框中的手动表单控件改为使用 CombiForm 扩展属性配置,
添加了字段长度限制、占位符提示和选择器配置,简化了代码实现。

fix(role.ts): 修正角色接口字段命名

将 RolePageItem 接口中的 accountCount 字段名更正为 userCount,
保持与实际数据结构的一致性。

fix(RoleManage): 更新角色管理页面字段映射

更新角色管理页面中用户计数字段的引用,从 accounts 改为
userCount,确保数据正确显示。

docs(.env): 更新后端API目标地址配置

将 VITE_API_TARGET 环境变量的值更新为测试环境地址
http://192.168.3.197:8788

refactor(StoreApprove): 移除审批页面范围提示文本

移除了店铺审批页面的数据可见范围提示文本,简化界面展示。

refactor(StoreListing): 移除列表页面范围提示文本

移除了店铺列表页面的数据可见范围提示文本,保持界面简洁。
```
1 parent 48a73ee1
Pipeline #319 for 11cf705b failed in 0 seconds
# 后端真实地址。proxy 模式下作为 Vite 代理的 target;direct 模式下就是浏览器直连的地址。 # 后端真实地址。proxy 模式下作为 Vite 代理的 target;direct 模式下就是浏览器直连的地址。
# 测试环境: http://192.168.3.197:8788 # 测试环境: http://192.168.3.197:8788
# 本地环境: http://localhost:8080 # 本地环境: http://localhost:8080
VITE_API_TARGET=http://192.168.1.117:8788 VITE_API_TARGET=http://192.168.3.197:8788
# ===== 代理 / 直连 开关(切换后端接法只需改这一行,保存后 dev server 会自动重启)===== # ===== 代理 / 直连 开关(切换后端接法只需改这一行,保存后 dev server 会自动重启)=====
# proxy (默认)前端打 /api,由 Vite 代理转发到 VITE_API_TARGET。 # proxy (默认)前端打 /api,由 Vite 代理转发到 VITE_API_TARGET。
......
...@@ -23,7 +23,7 @@ export interface RolePageItem { ...@@ -23,7 +23,7 @@ export interface RolePageItem {
roleName: string; roleName: string;
roleCode: string; roleCode: string;
defaultDataScope: number; defaultDataScope: number;
accountCount: number; userCount: number;
description?: string; description?: string;
isBuiltin: number; isBuiltin: number;
status: number; status: number;
......
...@@ -61,19 +61,38 @@ export function CombiForm<T extends Record<string, unknown>>({ ...@@ -61,19 +61,38 @@ export function CombiForm<T extends Record<string, unknown>>({
[], [],
); );
const defaultControl = (field: FieldSchema<T>) => { const defaultControl = (field: FieldSchema<T>) => {
const disabled = typeof field.disabled === 'function' ? field.disabled(data) : field.disabled;
if (field.type === 'cascader') if (field.type === 'cascader')
return <UCascader options={field.options} style={{ width: '100%' }} />; return (
<UCascader
options={field.options}
disabled={disabled}
style={{ width: '100%' }}
{...field.cascaderProps}
/>
);
if (field.type === 'select' || field.type === 'selectMultiple') if (field.type === 'select' || field.type === 'selectMultiple')
return ( return (
<USelect <USelect
options={field.options} options={field.options}
mode={field.type === 'selectMultiple' ? 'multiple' : undefined} mode={field.type === 'selectMultiple' ? 'multiple' : undefined}
disabled={disabled}
style={{ width: '100%' }} style={{ width: '100%' }}
{...field.selectProps}
/> />
); );
if (field.type === 'switch') return <USwitch />; if (field.type === 'switch') return <USwitch disabled={disabled} />;
if (field.type === 'textarea') return <UInput.TextArea placeholder={inputPlaceholder(field)} />; if (field.type === 'textarea')
return <UInput placeholder={inputPlaceholder(field)} />; return (
<UInput.TextArea
disabled={disabled}
placeholder={inputPlaceholder(field)}
{...field.textareaProps}
/>
);
return (
<UInput disabled={disabled} placeholder={inputPlaceholder(field)} {...field.inputProps} />
);
}; };
return ( return (
<UForm <UForm
...@@ -94,6 +113,7 @@ export function CombiForm<T extends Record<string, unknown>>({ ...@@ -94,6 +113,7 @@ export function CombiForm<T extends Record<string, unknown>>({
label={field.label} label={field.label}
rules={field.rules} rules={field.rules}
style={field.itemStyle} style={field.itemStyle}
normalize={field.normalize}
> >
{renderControl?.(field, form, data) ?? defaultControl(field)} {renderControl?.(field, form, data) ?? defaultControl(field)}
</UFormItem> </UFormItem>
......
import type { CSSProperties, ReactNode } from 'react'; import type { CSSProperties, ReactNode } from 'react';
import type { ButtonProps } from 'antd'; import type { ButtonProps, CascaderProps, FormItemProps, InputProps, SelectProps } from 'antd';
import type { TextAreaProps } from 'antd/es/input';
import type { Rule } from 'antd/es/form'; import type { Rule } from 'antd/es/form';
export type FieldType = export type FieldType =
...@@ -27,6 +28,16 @@ export interface FieldSchema<T extends Record<string, unknown> = Record<string, ...@@ -27,6 +28,16 @@ export interface FieldSchema<T extends Record<string, unknown> = Record<string,
rules?: Rule[]; rules?: Rule[];
section?: string; section?: string;
itemStyle?: CSSProperties; itemStyle?: CSSProperties;
/** input 类型的扩展属性,如最大长度、数字键盘等。 */
inputProps?: InputProps;
/** textarea 类型的扩展属性。 */
textareaProps?: TextAreaProps;
/** select 类型的扩展属性。 */
selectProps?: SelectProps;
/** cascader 类型的扩展属性,选项统一由 options 提供。 */
cascaderProps?: Omit<CascaderProps, 'options' | 'multiple'>;
/** 表单值标准化处理,例如手机号仅保留数字。 */
normalize?: FormItemProps['normalize'];
hidden?: boolean | ((values: T) => boolean); hidden?: boolean | ((values: T) => boolean);
disabled?: boolean | ((values: T) => boolean); disabled?: boolean | ((values: T) => boolean);
render?: (value: unknown, values: T) => ReactNode; render?: (value: unknown, values: T) => ReactNode;
......
import { useEffect } from 'react'; import { useEffect } from 'react';
import { message } from 'antd'; import { message } from 'antd';
import { useMutation } from '@tanstack/react-query'; import { useMutation } from '@tanstack/react-query';
import { UButton, UCascader, UForm, UInput, UModal, USelect } from '@uj/ui'; import { UButton, UForm, UModal } from '@uj/ui';
import { user, type OrgNode, type RoleOption, type UserPageItem } from '@/api'; import { user, type OrgNode, type RoleOption, type UserPageItem } from '@/api';
import { CombiForm, type FieldSchema } from '@/components'; import { CombiForm, type FieldSchema } from '@/components';
import { dataScopeOptions } from '@/constants/dataScope'; import { dataScopeOptions } from '@/constants/dataScope';
...@@ -86,6 +86,8 @@ export function AccountModal({ ...@@ -86,6 +86,8 @@ export function AccountModal({
label: '账号', label: '账号',
type: 'input', type: 'input',
section: '基本信息', section: '基本信息',
disabled: isEdit,
inputProps: { maxLength: 20 },
rules: [ rules: [
{ required: true, message: '请输入账号' }, { required: true, message: '请输入账号' },
{ min: 1, max: 20, message: '账号长度为 1-20 个字符' }, { min: 1, max: 20, message: '账号长度为 1-20 个字符' },
...@@ -96,6 +98,7 @@ export function AccountModal({ ...@@ -96,6 +98,7 @@ export function AccountModal({
label: '姓名', label: '姓名',
type: 'input', type: 'input',
section: '基本信息', section: '基本信息',
inputProps: { maxLength: 20 },
rules: [ rules: [
{ required: true, message: '请输入姓名' }, { required: true, message: '请输入姓名' },
{ min: 1, max: 20, message: '姓名长度为 1-20 个字符' }, { min: 1, max: 20, message: '姓名长度为 1-20 个字符' },
...@@ -106,6 +109,8 @@ export function AccountModal({ ...@@ -106,6 +109,8 @@ export function AccountModal({
label: '手机号', label: '手机号',
type: 'input', type: 'input',
section: '基本信息', section: '基本信息',
inputProps: { inputMode: 'numeric', maxLength: 11 },
normalize: (value) => (typeof value === 'string' ? value.replace(/\D/g, '') : value),
rules: [ rules: [
{ required: true, message: '请输入手机号' }, { required: true, message: '请输入手机号' },
{ pattern: /^1\d{10}$/, message: '请输入正确的 11 位手机号' }, { pattern: /^1\d{10}$/, message: '请输入正确的 11 位手机号' },
...@@ -123,6 +128,8 @@ export function AccountModal({ ...@@ -123,6 +128,8 @@ export function AccountModal({
label: '所属组织', label: '所属组织',
type: 'cascader', type: 'cascader',
section: '组织归属', section: '组织归属',
options: toOrgCascaderOptions(orgTree),
cascaderProps: { changeOnSelect: true, showSearch: true },
rules: [{ required: true, message: '请选择所属组织' }], rules: [{ required: true, message: '请选择所属组织' }],
}, },
{ {
...@@ -164,45 +171,6 @@ export function AccountModal({ ...@@ -164,45 +171,6 @@ export function AccountModal({
sectionContentStyle={twoColumnStyle} sectionContentStyle={twoColumnStyle}
renderSectionTitle={(title) => <SectionTitle>{title}</SectionTitle>} renderSectionTitle={(title) => <SectionTitle>{title}</SectionTitle>}
renderControl={(field) => { renderControl={(field) => {
if (field.name === 'account')
return (
<UInput disabled={isEdit} maxLength={20} placeholder="请输入登录账号" size="small" />
);
if (field.name === 'name')
return <UInput maxLength={20} placeholder="请输入姓名" size="small" />;
if (field.name === 'mobile')
return (
<UInput
inputMode="numeric"
maxLength={11}
placeholder="请输入手机号"
size="small"
onChange={(event) =>
form.setFieldValue('mobile', event.target.value.replace(/\D/g, ''))
}
/>
);
if (field.name === 'email') return <UInput placeholder="选填" size="small" />;
if (field.name === 'orgPath')
return (
<UCascader
options={toOrgCascaderOptions(orgTree)}
changeOnSelect
placeholder="请选择所属组织"
showSearch
size="small"
style={{ width: '100%' }}
/>
);
if (field.name === 'dataScope')
return (
<USelect
options={dataScopeOptions}
placeholder="请选择数据域"
size="small"
style={{ width: '100%' }}
/>
);
if (field.name === 'roleIds') if (field.name === 'roleIds')
return ( return (
<div style={roleListStyle}> <div style={roleListStyle}>
...@@ -210,7 +178,6 @@ export function AccountModal({ ...@@ -210,7 +178,6 @@ export function AccountModal({
<UButton <UButton
key={item.roleId} key={item.roleId}
type={selectedRoleIds.includes(item.roleId) ? 'primary' : 'default'} type={selectedRoleIds.includes(item.roleId) ? 'primary' : 'default'}
size="small"
style={roleOptionStyle} style={roleOptionStyle}
onClick={() => { onClick={() => {
const nextRoleIds = selectedRoleIds.includes(item.roleId) const nextRoleIds = selectedRoleIds.includes(item.roleId)
......
import { useEffect } from 'react'; import { useEffect } from 'react';
import { message } from 'antd'; import { message } from 'antd';
import { useMutation } from '@tanstack/react-query'; import { useMutation } from '@tanstack/react-query';
import { UForm, UInput, UModal, USelect } from '@uj/ui'; import { UForm, UModal } from '@uj/ui';
import { role, type RolePageItem } from '@/api'; import { role, type RolePageItem } from '@/api';
import { CombiForm, type FieldSchema } from '@/components'; import { CombiForm, type FieldSchema } from '@/components';
import { dataScopeOptions } from '@/constants/dataScope'; import { dataScopeOptions } from '@/constants/dataScope';
...@@ -68,6 +68,7 @@ export function RoleModal({ open, roleItem, onCancel, onSuccess }: RoleModalProp ...@@ -68,6 +68,7 @@ export function RoleModal({ open, roleItem, onCancel, onSuccess }: RoleModalProp
label: '角色名称', label: '角色名称',
type: 'input', type: 'input',
section: '基本信息', section: '基本信息',
inputProps: { maxLength: 20 },
rules: [ rules: [
{ required: true, message: '请输入角色名称' }, { required: true, message: '请输入角色名称' },
{ max: 20, message: '角色名称不能超过 20 个字符' }, { max: 20, message: '角色名称不能超过 20 个字符' },
...@@ -78,6 +79,9 @@ export function RoleModal({ open, roleItem, onCancel, onSuccess }: RoleModalProp ...@@ -78,6 +79,9 @@ export function RoleModal({ open, roleItem, onCancel, onSuccess }: RoleModalProp
label: '角色编码', label: '角色编码',
type: 'input', type: 'input',
section: '基本信息', section: '基本信息',
disabled: isEdit,
inputProps: { maxLength: 50 },
placeholder: '例如:REGION_OPS',
rules: [ rules: [
{ required: true, message: '请输入角色编码' }, { required: true, message: '请输入角色编码' },
{ pattern: /^[A-Z0-9_]+$/, message: '仅支持大写字母、数字和下划线' }, { pattern: /^[A-Z0-9_]+$/, message: '仅支持大写字母、数字和下划线' },
...@@ -88,15 +92,25 @@ export function RoleModal({ open, roleItem, onCancel, onSuccess }: RoleModalProp ...@@ -88,15 +92,25 @@ export function RoleModal({ open, roleItem, onCancel, onSuccess }: RoleModalProp
label: '显示排序', label: '显示排序',
type: 'input', type: 'input',
section: '基本信息', section: '基本信息',
inputProps: { inputMode: 'numeric' },
rules: [{ pattern: /^\d+$/, message: '请输入整数' }], rules: [{ pattern: /^\d+$/, message: '请输入整数' }],
}, },
{ name: 'status', label: '状态', type: 'select', section: '基本信息', options: statusOptions }, {
name: 'status',
label: '状态',
type: 'select',
section: '基本信息',
options: statusOptions,
selectProps: { allowClear: false },
},
{ {
name: 'description', name: 'description',
label: '角色描述', label: '角色描述',
type: 'textarea', type: 'textarea',
section: '基本信息', section: '基本信息',
itemStyle: { gridColumn: '1 / -1' }, itemStyle: { gridColumn: '1 / -1' },
textareaProps: { maxLength: 200, rows: 2 },
placeholder: '选填,用于说明角色的职责边界',
rules: [{ max: 200, message: '角色描述不能超过 200 个字符' }], rules: [{ max: 200, message: '角色描述不能超过 200 个字符' }],
}, },
{ {
...@@ -130,39 +144,6 @@ export function RoleModal({ open, roleItem, onCancel, onSuccess }: RoleModalProp ...@@ -130,39 +144,6 @@ export function RoleModal({ open, roleItem, onCancel, onSuccess }: RoleModalProp
onSubmit={(values) => saveMutation.mutate(values)} onSubmit={(values) => saveMutation.mutate(values)}
sectionContentStyle={twoColumnStyle} sectionContentStyle={twoColumnStyle}
renderSectionTitle={(title) => <SectionTitle>{title}</SectionTitle>} renderSectionTitle={(title) => <SectionTitle>{title}</SectionTitle>}
renderControl={(field) => {
if (field.name === 'roleName') return <UInput maxLength={20} size="small" />;
if (field.name === 'roleCode')
return (
<UInput
disabled={isEdit}
maxLength={50}
placeholder="例如:REGION_OPS"
size="small"
/>
);
if (field.name === 'sort') return <UInput inputMode="numeric" size="small" />;
if (field.name === 'status')
return (
<USelect
options={statusOptions}
allowClear={false}
size="small"
style={{ width: '100%' }}
/>
);
if (field.name === 'description')
return (
<UInput.TextArea
maxLength={200}
placeholder="选填,用于说明角色的职责边界"
rows={2}
/>
);
if (field.name === 'defaultDataScope')
return <USelect options={dataScopeOptions} size="small" style={{ width: '100%' }} />;
return undefined;
}}
/> />
</UModal> </UModal>
); );
......
...@@ -21,7 +21,7 @@ interface Row { ...@@ -21,7 +21,7 @@ interface Row {
name: string; name: string;
code: string; code: string;
scope: string; scope: string;
accounts: number; userCount: number;
description: string; description: string;
type: string; type: string;
status?: number; status?: number;
...@@ -66,7 +66,7 @@ export default function RoleManage() { ...@@ -66,7 +66,7 @@ export default function RoleManage() {
name: item.roleName, name: item.roleName,
code: item.roleCode, code: item.roleCode,
scope: getDataScopeLabel(item.defaultDataScope), scope: getDataScopeLabel(item.defaultDataScope),
accounts: item.accountCount, userCount: item.userCount,
description: item.description ?? '—', description: item.description ?? '—',
type: item.isBuiltin === 1 ? '内置' : '自定义', type: item.isBuiltin === 1 ? '内置' : '自定义',
status: item.status, status: item.status,
...@@ -104,7 +104,7 @@ export default function RoleManage() { ...@@ -104,7 +104,7 @@ export default function RoleManage() {
render: (v) => <UText style={{ color: '#315ce8', fontFamily: 'monospace' }}>{v}</UText>, render: (v) => <UText style={{ color: '#315ce8', fontFamily: 'monospace' }}>{v}</UText>,
}, },
{ title: '默认数据域', dataIndex: 'scope', width: 130 }, { title: '默认数据域', dataIndex: 'scope', width: 130 },
{ title: '账号数', dataIndex: 'accounts', width: 90, align: 'right' }, { title: '账号数', dataIndex: 'userCount', width: 90 },
{ title: '角色描述', dataIndex: 'description' }, { title: '角色描述', dataIndex: 'description' },
{ {
title: '类型', title: '类型',
......
...@@ -293,7 +293,6 @@ export default function StoreApprove() { ...@@ -293,7 +293,6 @@ export default function StoreApprove() {
onSearch={changeQuery} onSearch={changeQuery}
onReset={() => changeQuery({})} onReset={() => changeQuery({})}
/> />
<UText type="secondary">数据可见范围:{dataScope}</UText>
</UCard> </UCard>
{list.isError ? ( {list.isError ? (
<UAlert <UAlert
......
...@@ -222,7 +222,6 @@ export default function StoreListing() { ...@@ -222,7 +222,6 @@ export default function StoreListing() {
if (!exportFile.isPending) exportFile.reset(); if (!exportFile.isPending) exportFile.reset();
}} }}
/> />
<UText type="secondary">数据可见范围:{scopeLabel}</UText>
</UCard> </UCard>
{listing.error ? ( {listing.error ? (
<UAlert <UAlert
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!