-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
463e66d
commit e52a4b2
Showing
2 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React, { useContext, useRef } from 'react'; | ||
import { TagComponent } from '../type'; | ||
import { LayoutStateContext } from '../../context/LayoutStateContext'; | ||
import { StateActionType } from '../../types'; | ||
import _isEqual from 'lodash/isEqual'; | ||
import _isString from 'lodash/isString'; | ||
import _isNil from 'lodash/isNil'; | ||
import { parseDataText } from '../../processor'; | ||
import { TMemo } from '@shared/components/TMemo'; | ||
|
||
interface TagProps { | ||
name: string; | ||
value: any; | ||
} | ||
export const TagStaticShared: TagComponent<TagProps> = TMemo((props) => { | ||
const context = useContext(LayoutStateContext); | ||
const isRunRef = useRef(false); | ||
|
||
if (isRunRef.current === false) { | ||
isRunRef.current = true; | ||
|
||
if (_isString(props.value)) { | ||
// 需要处理数据 | ||
try { | ||
const realVal = parseDataText(`{{(${props.value})}}`, context); | ||
|
||
context.dispatch({ | ||
type: StateActionType.SetGlobal, | ||
payload: { | ||
name: props.name, | ||
value: realVal, | ||
}, | ||
}); | ||
} catch (e) { | ||
// 不处理解析错误的变量 | ||
console.warn('Cannot parse attr:', props.name, props.value, e); | ||
} | ||
|
||
return; | ||
} | ||
} | ||
|
||
return null; | ||
}); | ||
TagStaticShared.displayName = 'TagStaticShared'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters