|
@@ -0,0 +1,125 @@
|
|
|
+import { CloseOutlined, PlusOutlined } from "@ant-design/icons"
|
|
|
+import { Button, Form, Modal, Space, Spin, Tabs, Tooltip, Typography } from "antd"
|
|
|
+import React, { useEffect, useState } from "react"
|
|
|
+import { LABEL_TYPE_ENUM } from "../../const"
|
|
|
+import style from './index.less'
|
|
|
+import '../../index.less'
|
|
|
+import { useAjax } from "@/Hook/useAjax"
|
|
|
+import { getAdLabelApi } from "@/services/adqV3/global"
|
|
|
+const { Text, Title } = Typography;
|
|
|
+
|
|
|
+
|
|
|
+interface Props {
|
|
|
+ arrayProperty: { maxNumber: number, minNumber: number }
|
|
|
+ value?: { content: string, type: LABEL_TYPE_ENUM }[]
|
|
|
+ onChange?: (value?: { content: string, type: LABEL_TYPE_ENUM }[]) => void
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 选择标签
|
|
|
+ * @returns
|
|
|
+ */
|
|
|
+const SelectLabel: React.FC<Props> = ({ value, onChange, arrayProperty }) => {
|
|
|
+
|
|
|
+ /************************************/
|
|
|
+ const [visible, setVisible] = useState<boolean>(false)
|
|
|
+ const [activeKey, setActiveKey] = useState<string>('1')
|
|
|
+
|
|
|
+ const getAdLabel = useAjax((params) => getAdLabelApi(params))
|
|
|
+ /************************************/
|
|
|
+
|
|
|
+ useEffect(() => {
|
|
|
+ if (visible) {
|
|
|
+ getAdLabel.run({})
|
|
|
+ }
|
|
|
+ }, [visible])
|
|
|
+
|
|
|
+ const handleOk = () => {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ return <>
|
|
|
+ <a className={style.selectLabelBtn} onClick={() => setVisible(true)}><PlusOutlined /><span>选择标签</span></a>
|
|
|
+ {visible && <Modal
|
|
|
+ title={<strong>选择标签</strong>}
|
|
|
+ visible={visible}
|
|
|
+ className="modalResetCss"
|
|
|
+ width={900}
|
|
|
+ onCancel={() => setVisible(false)}
|
|
|
+ bodyStyle={{ padding: '0px 32px' }}
|
|
|
+ footer={<div className={style.showLabel}>
|
|
|
+ <div style={{ textAlign: 'left' }}>
|
|
|
+ <Tooltip
|
|
|
+ title={`${(value?.length || 0) > arrayProperty.maxNumber ? `最多可选 ${arrayProperty.maxNumber} 个标签` : ''},${(value || []).reduce((pre: number, cur) => pre + cur.content.length, 0) > 16 ? '标签总字数上限不超过 16 个字,中英文均算 1 个字' : ''}`}
|
|
|
+ visible={((value?.length || 0) > arrayProperty.maxNumber || (value || []).reduce((pre: number, cur) => pre + cur.content.length, 0) > 16)}
|
|
|
+ >
|
|
|
+ <Text strong>文字标签 ({value?.length || 0}/{arrayProperty.maxNumber})</Text>
|
|
|
+ </Tooltip>
|
|
|
+ <div className={style.toggleLabels}>
|
|
|
+ {value?.map((item, tIndex) => <div
|
|
|
+ key={tIndex}
|
|
|
+ className={`${style.toggleLabel} ${style.showLabel} ${((value?.length || 0) > arrayProperty.maxNumber || value.reduce((pre: number, cur) => pre + cur.content.length, 0) > 16) ? style.errorSHowLabel : ''}`}
|
|
|
+ >
|
|
|
+ <Space>
|
|
|
+ <span>{item.content}</span>
|
|
|
+ <CloseOutlined className={style.clearLable} />
|
|
|
+ </Space>
|
|
|
+ </div>)}
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <Space>
|
|
|
+ <Button onClick={() => setVisible(false)}>取消</Button>
|
|
|
+ <Button type="primary" onClick={handleOk}>确定</Button>
|
|
|
+ </Space>
|
|
|
+ </div>}
|
|
|
+ >
|
|
|
+ <Tabs
|
|
|
+ accessKey={activeKey}
|
|
|
+ onChange={(e) => setActiveKey(e)}
|
|
|
+ tabBarExtraContent={<Text type="secondary" style={{ fontSize: 12 }}>最多可选 {arrayProperty.maxNumber} 个标签,且标签总字数上限不超过 16 个字,中英文均算 1 个字</Text>}
|
|
|
+ >
|
|
|
+ <Tabs.TabPane tab="选择已有" key="1" >
|
|
|
+ <Spin spinning={getAdLabel.loading}>
|
|
|
+ <div className={style.labelContent}>
|
|
|
+ <div className={style.tips}>
|
|
|
+ <strong>行业通用</strong>
|
|
|
+ </div>
|
|
|
+ <Form
|
|
|
+ name="basicSelectLabel"
|
|
|
+ labelCol={{ span: 3 }}
|
|
|
+ wrapperCol={{ span: 21 }}
|
|
|
+ labelAlign="left"
|
|
|
+ colon={false}
|
|
|
+ >
|
|
|
+ {getAdLabel.data?.map((item: { labelCategory: string, label: string[], labelTypeName: string }, index: number) => <Form.Item className={style.toggleLabelForm} label={<strong>{item.labelCategory}</strong>} key={index}>
|
|
|
+ <div className={style.toggleLabels}>
|
|
|
+ {item.label.map((text, tIndex) => {
|
|
|
+ let activeIndex = (value || [])?.findIndex(i => i.content === text)
|
|
|
+ return <div
|
|
|
+ key={tIndex}
|
|
|
+ className={`${style.toggleLabel} ${(activeIndex !== -1) ? style.active : ''}`}
|
|
|
+ onClick={() => {
|
|
|
+ let newValue: { content: string, type: LABEL_TYPE_ENUM }[] = JSON.parse(JSON.stringify(value || []))
|
|
|
+ if (activeIndex !== -1) {
|
|
|
+ newValue = newValue.filter((_, index) => activeIndex !== index)
|
|
|
+ } else {
|
|
|
+ newValue.push({ content: text, type: (item.labelTypeName === '普通文本标签' ? 'LABEL_TYPE_COMMON' : 'LABEL_TYPE_UNKNOWN') as LABEL_TYPE_ENUM })
|
|
|
+ }
|
|
|
+ onChange?.(newValue)
|
|
|
+ }}
|
|
|
+ >{text}</div>
|
|
|
+ })}
|
|
|
+ </div>
|
|
|
+ </Form.Item>)}
|
|
|
+ </Form>
|
|
|
+ </div>
|
|
|
+ </Spin>
|
|
|
+ </Tabs.TabPane>
|
|
|
+ <Tabs.TabPane tab="新建标签" key="2" >
|
|
|
+ </Tabs.TabPane>
|
|
|
+ </Tabs>
|
|
|
+ </Modal>}
|
|
|
+ </>
|
|
|
+}
|
|
|
+
|
|
|
+export default React.memo(SelectLabel)
|