MCPcopy Create free account
hub / github.com/baiwumm/react-admin / FigureLabels

Function FigureLabels

Xmw_web/src/components/FigureLabels/index.tsx:24–214  ·  view source on GitHub ↗
({ value, onChange, canCallback })

Source from the content-addressed store, hash-verified

22};
23
24const FigureLabels: FC<IProps> = ({ value, onChange, canCallback }) => {
25 // 获取全局状态
26 const { initialState, setInitialState } = useModel('@@initialState');
27 // hooks 调用
28 const { message } = App.useApp();
29 // 自定义默认标签
30 const [tags, setTags] = useState<string[]>([]);
31 // 控制 input 框显隐
32 const [inputVisible, { setTrue: setInputVisibleTrue, setFalse: setInputVisibleFalse }] =
33 useBoolean(false);
34 // 获取 input 的 value
35 const [inputValue, setInputValue] = useState('');
36 // 获取编辑状态下 input 的索引
37 const [editInputIndex, setEditInputIndex] = useState(-1);
38 // 获取编辑状态下 input 的 value
39 const [editInputValue, setEditInputValue] = useState('');
40 // 绑定 input 的 ref
41 const inputRef = useRef<InputRef>(null);
42 // 绑定编辑状态下 input 的 ref
43 const editInputRef = useRef<InputRef>(null);
44
45 // 表单收集字段
46 const triggerChange = (changedValue: string[]) => {
47 onChange?.([...changedValue]);
48 };
49
50 /**
51 * @description: 更新用户信息
52 * @author: 白雾茫茫丶
53 */
54 const { run: runUpdateUser } = useRequest(updateUser, {
55 manual: true,
56 onSuccess: async ({ code, msg }, params) => {
57 if (isSuccess(code)) {
58 const newTags = params[0]?.tags as string[];
59 message.success(msg);
60 setTags(newTags);
61 triggerChange(newTags);
62 // 更新全局状态
63 if (params[0]?.tags && initialState?.CurrentUser?.user_id) {
64 setInitialState((s: InitialStateTypes) => ({
65 ...s,
66 CurrentUser: { ...initialState?.CurrentUser, tags: newTags },
67 }));
68 }
69 }
70 },
71 });
72
73 // 当显示 input 框的时候,聚焦
74 useEffect(() => {
75 if (inputVisible) {
76 inputRef.current?.focus();
77 }
78 }, [inputVisible]);
79 // 当显示编辑 input 框的时候,聚焦
80 useEffect(() => {
81 if (editInputIndex !== -1) {

Callers

nothing calls this directly

Calls 4

isSuccessFunction · 0.90
randomTagColorFunction · 0.90
triggerChangeFunction · 0.85
handleCloseFunction · 0.85

Tested by

no test coverage detected