新增正则判断

This commit is contained in:
lyp 2024-12-03 11:58:34 +08:00
parent 82d446ffe2
commit 4c06fdc2f5
2 changed files with 46 additions and 12 deletions

View File

@ -1,12 +1,15 @@
import './ai-helper-mod.css' import './ai-helper-mod.css'
import { Button, import {
Button,
// Divider, Dropdown, Space, // Divider, Dropdown, Space,
Table, TableProps, Modal } from "antd"; Table, TableProps, Modal
} from "antd";
import { import {
// CheckOutlined, // CheckOutlined,
LoadingOutlined, LoadingOutlined,
// ReloadOutlined, // ReloadOutlined,
RedoOutlined } from "@ant-design/icons"; RedoOutlined
} from "@ant-design/icons";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { IProjMod } from "../../../interfaces/proj/IProj.ts"; import { IProjMod } from "../../../interfaces/proj/IProj.ts";
import EditModal from '../../EditModal/EditModal.tsx' import EditModal from '../../EditModal/EditModal.tsx'
@ -71,6 +74,11 @@ export default function AiHelperMod(props: PropsType) {
}) })
}, []) }, [])
const returnValue = (value:string) => {
// 如果value包含. / \ ` ! @ # $ % ^ & * ( ) 等特殊符号 去掉
// return value.replace(/[\\/:*?"<>|]/g, '');
return value.replace(/[./\\`!@#$%^&*()]/g, '');
}
const modColumnArray: TableProps<IProjMod>['columns'] = [ const modColumnArray: TableProps<IProjMod>['columns'] = [
{ {
title: '序号', title: '序号',
@ -82,7 +90,15 @@ export default function AiHelperMod(props: PropsType) {
return index + 1 return index + 1
} }
}, },
{ title: '模块名称', dataIndex: 'modName', key: 'name', width: 200, align: 'center' }, { title: '模块名称', dataIndex: 'modName', key: 'name', width: 200, align: 'center',
render: (value) => {
return (
<div>
{returnValue(value)}
</div>
)
}
},
{ title: '模块描述', dataIndex: 'modDesc', key: 'desc', align: 'center' }, { title: '模块描述', dataIndex: 'modDesc', key: 'desc', align: 'center' },
{ {
title: 'AI状态', title: 'AI状态',
@ -260,7 +276,16 @@ export default function AiHelperMod(props: PropsType) {
return index + 1 return index + 1
} }
}, },
{ title: '模块名称', dataIndex: 'name', key: 'name', width: 200, align: 'center' }, {
title: '模块名称', dataIndex: 'name', key: 'name', width: 200, align: 'center',
render: (value) => {
return (
<div>
{returnValue(value)}
</div>
)
}
},
{ title: '模块描述', dataIndex: 'desc', key: 'desc', align: 'center' }, { title: '模块描述', dataIndex: 'desc', key: 'desc', align: 'center' },
{ {
title: '操作', title: '操作',
@ -333,7 +358,7 @@ export default function AiHelperMod(props: PropsType) {
// </Modal> // </Modal>
// </> // </>
<div style={{ height: `${height}px`, border: '1px solid #D5D5D5',overflow:'auto' }}> <div style={{ height: `${height}px`, border: '1px solid #D5D5D5', overflow: 'auto' }}>
<div className="aiMod-top"> <div className="aiMod-top">
{modArray.length > 0 ? {modArray.length > 0 ?
<> <>
@ -392,7 +417,7 @@ export default function AiHelperMod(props: PropsType) {
<> <>
<span style={{ <span style={{
color: '#ABABAB', color: '#ABABAB',
fontSize:16 fontSize: 16
}}> AI自动生成后可自动生成模块管理...</span> }}> AI自动生成后可自动生成模块管理...</span>
</>} </>}
</div> </div>

View File

@ -43,6 +43,14 @@ export default function ModField(props: PropsType) {
setTableDataArray(props.modFiledArray) setTableDataArray(props.modFiledArray)
} }
}, [props.modFiledArray]) }, [props.modFiledArray])
const returnValue = (value:string) => {
if (value && value[0].match(/[0-9]/)) {
// 生成一个随机的小写字母
const randomChar = String.fromCharCode(97 + Math.floor(Math.random() * 26));
value = randomChar + value;
}
return value;
}
const columns: TableProps<IModField>['columns'] = [ const columns: TableProps<IModField>['columns'] = [
{ {
@ -51,7 +59,7 @@ export default function ModField(props: PropsType) {
render: (text, _record, index) => { render: (text, _record, index) => {
if (props.isEdit) { if (props.isEdit) {
return ( return (
<Input defaultValue={text} onChange={(e) => { <Input defaultValue={returnValue(text)} onChange={(e) => {
const item = tableDataArray[index]; const item = tableDataArray[index];
const value = e.target.value; const value = e.target.value;
const fieldName = pinyin(value, { const fieldName = pinyin(value, {
@ -72,9 +80,10 @@ export default function ModField(props: PropsType) {
setTableDataArray([...tableDataArray]); setTableDataArray([...tableDataArray]);
handleChange(); handleChange();
}}/> }}/>
) )
} else { } else {
return text; return returnValue(text);
} }
} }
}, },