大概是这么个场景:
- function useCellEditable(cell: CellRange): boolean {
- const [isProtected, setIsProtected] = useState<boolean>(
- () => cell.sheet.options.isProtected,
- )
- const [locked, setLocked] = useState<boolean>(() => cell.locked())
- useEffect(() => {
- const workbook = cell.sheet.getParent()
- if (!workbook) return
- const onCellChanged = (
- e: any,
- args: Spread.Sheets.ICellChangedEventArgs,
- ): void => {
- if (args.propertyName !== '[styleinfo]') return
- const currentLocked = cell.locked()
- if (locked !== currentLocked) {
- setLocked(currentLocked)
- }
- }
- const onProtectChanged: EventListeners[EventNames.ProtectChanged] = ({
- sheetName,
- isProtected,
- }) => {
- if (cell.sheet.name() === sheetName) setIsProtected(isProtected)
- }
- cell.sheet.bind('CellChanged', onCellChanged)
- cell.sheet.bind('ProtectChanged', onProtectChanged)
- return () => {
- cell.sheet.unbind('CellChanged', onCellChanged)
- cell.sheet.unbind('ProtectChanged', onProtectChanged)
- }
- }, [cell, locked])
- return !(isProtected && locked)
- }
复制代码
|