Procházet zdrojové kódy

Merge branch 'develop' of http://git.zanxiangnet.com/wjx/ad-manage

wjx před 2 roky
rodič
revize
d987e0d1be
1 změnil soubory, kde provedl 14 přidání a 16 odebrání
  1. 14 16
      src/components/InputName/index.tsx

+ 14 - 16
src/components/InputName/index.tsx

@@ -15,7 +15,6 @@ interface Props extends TextAreaProps {
 const InputName: React.FC<Props> = ({ value, onChange, length, ...props }) => {
 
     /******************************/
-    const [newValue, setNewValue] = useState(value)
     const [status, setStatus] = useState<{ status?: string }>({})
     /******************************/
 
@@ -26,39 +25,38 @@ const InputName: React.FC<Props> = ({ value, onChange, length, ...props }) => {
                 {
                     key: '<广告版位>',
                     label: '广告版位',
-                    disabled: newValue?.toString()?.includes('<广告版位>')
+                    disabled: value?.toString()?.includes('<广告版位>')
                 },
                 {
                     key: '<账号备注>',
                     label: '账号备注',
-                    disabled: newValue?.toString()?.includes('<账号备注>')
+                    disabled: value?.toString()?.includes('<账号备注>')
                 },
                 {
                     key: '<商品ID>',
                     label: '商品ID',
-                    disabled: newValue?.toString()?.includes('<商品ID>')
+                    disabled: value?.toString()?.includes('<商品ID>')
                 },
                 {
                     key: '<账号ID>',
                     label: '账号ID',
-                    disabled: newValue?.toString()?.includes('<账号ID>')
+                    disabled: value?.toString()?.includes('<账号ID>')
                 },
                 {
                     key: '<日期>',
                     label: '日期',
-                    disabled: newValue?.toString()?.includes('<日期>')
+                    disabled: value?.toString()?.includes('<日期>')
                 },
                 {
                     key: '<时分秒>',
                     label: '时分秒',
-                    disabled: newValue?.toString()?.includes('<时分秒>')
+                    disabled: value?.toString()?.includes('<时分秒>')
                 },
             ]}
         />
-    }, [newValue])
+    }, [value])
 
     useEffect(() => {
-        setNewValue(value)
         if (length && txtLength(value as any) > length) {
             setStatus({ status: 'error' })
         } else {
@@ -68,23 +66,23 @@ const InputName: React.FC<Props> = ({ value, onChange, length, ...props }) => {
 
     /** 插入通配符 */
     const insertMatching = (matching: string) => {
-        onChange?.(newValue + `-${matching}` as any)
+        onChange?.(value + `-${matching}` as any)
     }
 
     return <Space direction="vertical">
         <Space align="end">
-            <Input.TextArea {...props} value={newValue} onChange={(e) => {
+            <Input.TextArea value={value} {...props} onChange={(e) => {
                 onChange?.(e)
             }} />
-            {length && <span style={Object.keys(status).length > 0 ? { color: 'red' } : {}}>{txtLength(newValue as any)}/{length}</span>}
+            {length && <span style={Object.keys(status).length > 0 ? { color: 'red' } : {}}>{txtLength(value as any)}/{length}</span>}
         </Space>
         {/* <div className="matching">
             <span>通配符:</span>
             <Space>
-                <Button type="link" onClick={() => insertMatching('<定向名>')} style={{ padding: 0 }} disabled={newValue?.toString()?.includes('<定向名>')}>+定向名</Button>
-                <Button type="link" onClick={() => insertMatching('<素材名>')} style={{ padding: 0 }} disabled={newValue?.toString()?.includes('<素材名>')}>+素材名</Button>
-                <Button type="link" onClick={() => insertMatching('<落地页名>')} style={{ padding: 0 }} disabled={newValue?.toString()?.includes('<落地页名>')}>+落地页名</Button>
-                <Button type="link" onClick={() => insertMatching('<优化目标>')} style={{ padding: 0 }} disabled={newValue?.toString()?.includes('<优化目标>')}>+优化目标</Button>
+                <Button type="link" onClick={() => insertMatching('<定向名>')} style={{ padding: 0 }} disabled={value?.toString()?.includes('<定向名>')}>+定向名</Button>
+                <Button type="link" onClick={() => insertMatching('<素材名>')} style={{ padding: 0 }} disabled={value?.toString()?.includes('<素材名>')}>+素材名</Button>
+                <Button type="link" onClick={() => insertMatching('<落地页名>')} style={{ padding: 0 }} disabled={value?.toString()?.includes('<落地页名>')}>+落地页名</Button>
+                <Button type="link" onClick={() => insertMatching('<优化目标>')} style={{ padding: 0 }} disabled={value?.toString()?.includes('<优化目标>')}>+优化目标</Button>
 
                 <Dropdown overlay={menu} trigger={['click']}>
                     <a style={{ marginLeft: 50 }} onClick={e => e.preventDefault()}><DiffOutlined /> 插入更多</a>