Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
flush
jerry24fc8ecaa310
diff --git a/packages/ui-plugin-sheets/src/Controller/CountBarController.ts b/packages/ui-plugin-sheets/src/Controller/CountBarUIController.tssimilarity index 60%rename from packages/ui-plugin-sheets/src/Controller/CountBarController.tsrename to packages/ui-plugin-sheets/src/Controller/CountBarUIController.tsindex ef4653a95a..1550a21e9d 100644--- a/packages/ui-plugin-sheets/src/Controller/CountBarController.ts+++ b/packages/ui-plugin-sheets/src/Controller/CountBarUIController.ts@@ -1,33 +1,10 @@-import { RangeList, Plugin, Tools } from '@univerjs/core';-import { CountBar } from '../UI/CountBar';--export class CountBarController {- protected _plugin: Plugin;+import { SheetPlugin } from '@univerjs/base-sheets';+import { RangeList, Plugin, Tools, PLUGIN_NAMES, CommandManager, SheetActionBase, SetZoomRatioAction } from '@univerjs/core';+import { CountBar } from '../View/CountBar';+export class CountBarUIController {protected _countBar: CountBar;-- protected _initialize(): void {- const plugin = this._plugin;- const context = plugin.getContext();- const workbook = context.getWorkBook();-- this._countBar.setState({- onChange: (v: any) => {- workbook.getActiveSheet().setZoomRatio(Tools.numberFixed(v / 100, 2));- },- });- }-- protected _initializeSelectedObserver(): void {- const plugin = this._plugin;- const manager = plugin.getSelectionManager();- plugin.getObserver('onChangeSelectionObserver')?.add(() => {- const rangeList = manager.getActiveRangeList();- if (rangeList && this._countBar) {- this._totalRangeList(rangeList);- }- });- }+ protected _plugin: Plugin;protected _totalRangeList(rangeList: RangeList): void {let rectList = rangeList.getRangeList();@@ -68,18 +45,54 @@ export class CountBarController {});}+ protected _refreshCountBarUI(): void {+ const workbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();+ this._countBar.setState({+ onChange: (v: any) => {+ workbook.getActiveSheet().setZoomRatio(Tools.numberFixed(v / 100, 2));+ },+ });+ }++ protected _refreshComponent(): void {+ this._refreshCountBarUI();+ }+constructor(plugin: Plugin) {this._plugin = plugin;+ CommandManager.getActionObservers().add((event) => {+ const action = event.action as SheetActionBase<any>;+ const data = event.data;+ const workbook = action.getWorkBook();+ const unitId = workbook.getUnitId();+ const currentWorkbook = this._plugin.getContext().getUniver().getCurrentUniverSheetInstance().getWorkBook();+ const currentUnitId = currentWorkbook.getUnitId();+ if (unitId === currentUnitId) {+ switch (data.actionName) {+ case SetZoomRatioAction.NAME: {+ this._refreshCountBarUI();+ break;+ }+ }+ }+ });+ const manager = plugin.getContext()+ .getUniver()+ .getCurrentUniverSheetInstance()+ .context+ .getPluginManager()+ .getRequirePluginByName<SheetPlugin>(PLUGIN_NAMES.SPREADSHEET)+ .getSelectionManager();+ plugin.getObserver('onChangeSelectionObserver')?.add(() => {+ const rangeList = manager.getActiveRangeList();+ if (rangeList && this._countBar) {+ this._totalRangeList(rangeList);+ }+ });}- // 获取CountBar组件- getComponent = (ref: CountBar) => {- this._countBar = ref;- // this.setCountBar()- };-// changeRatio- changeRatio(ratio: string) {}+ changeRatio(ratio: string) { }// 刷新组件setCountBar(content: string) {@@ -87,4 +100,11 @@ export class CountBarController {content,});}++ // 获取CountBar组件+ getComponent = (ref: CountBar) => {+ this._countBar = ref;+ this._refreshComponent();+ };+}diff --git a/packages/ui-plugin-sheets/src/Controller/SheetBarController.ts b/packages/ui-plugin-sheets/src/Controller/SheetBarController.tsdeleted file mode 100644index 65a2f3a0eb..0000000000--- a/packages/ui-plugin-sheets/src/Controller/SheetBarController.ts+++ /dev/null@@ -1,144 +0,0 @@-import { Nullable } from '@univerjs/core';-import { BaseComponentPlugin } from '..';-import { BaseMenuItem, BaseUlProps } from '../Components';-import { SheetBar } from '../UI/SheetBar';--interface CustomComponent {- name: string;- props?: Record<string, any>;-}--interface SheetUlProps extends BaseUlProps {- index: string;- color?: Nullable<string>;- sheetId: string;-}--interface SheetUl extends BaseMenuItem {- locale?: string;- customLabel?: CustomComponent;- children?: SheetUl[];-}--export class SheetBarControl {- private _plugin: BaseComponentPlugin;-- private _sheetBar: SheetBar;-- private _sheetUl: SheetUl[];-- private _sheetList: SheetUlProps[];-- private _menuList: SheetUlProps[];-- constructor(plugin: BaseComponentPlugin) {- this._plugin = plugin;-- this._sheetUl = [- {- locale: 'sheetConfig.delete',- onClick: () => {},- },- {- locale: 'sheetConfig.copy',- onClick: () => {},- },- {- locale: 'sheetConfig.rename',- onClick: () => {},- },- ];- }-- private _initializeData() {- const sheets = [1, 2, 3];- this._menuList = sheets.map((sheet, index) => ({- label: `sheet${index + 1}`,- index: String(index),- sheetId: '123',- hidden: 1,- selected: true,- onClick: (e: MouseEvent) => {},- }));- this._sheetList = sheets- // .filter((sheet) => {})- .map((sheet, index) => ({- sheetId: '123',- label: `sheet${index + 1}`,- index: String(index),- selected: true,- color: '#abcdef',- onDown: (e: MouseEvent) => {},- onClick: (e: MouseEvent) => {},- }));- }-- // 获取sheetBar组件- getComponent = (ref: SheetBar) => {- this._sheetBar = ref;- this._initializeData();- this.setSheetBar();- };-- setSheetBar() {- this._sheetBar.setValue({- menuList: this._menuList,- sheetUl: this._sheetUl,- sheetList: this._sheetList,- });- }-- /**- * 选中sheet- * @param args- */- selectSheet(id: string): void {}-- /**- * 隐藏sheet- */- hideSheet(): void {}-- /**- * 取消隐藏- */- unHideSheet(): void {}-- /**- * 增加sheet- */- addSheet(): void {}-- /**- * 删除sheet- */- deleteSheet(): void {}-- /**- * 向左向右移动sheet- * @param direct- */- moveSheet(direct: string): void {}-- /**- * 复制sheet- */- copySheet(): void {}-- /**- * 可以更改sheet名- */- reNameSheet(): void {}-- /**- * 重命名sheet- * @param e- */- changeSheetName(e: Event): void {}-- /**- * Set Sheet Color- * @param color- */- setSheetColor(color: string): void {}-}diff --git a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.tsindex 9bcb34ad9f..c7d91f6455 100644--- a/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts+++ b/packages/ui-plugin-sheets/src/Controller/SheetContainerUIController.ts@@ -5,6 +5,7 @@ import { ISheetUIPluginConfig } from '../Basics';import { SheetUIPlugin } from '../SheetUIPlugin';import { SheetContainer, UI } from '../View';import { CellEditorUIController } from './CellEditorUIController';+import { CountBarUIController } from './CountBarUIController';import { FormulaBarUIController } from './FormulaBarUIController';import { InfoBarUIController } from './InfoBarUIController';import { RightMenuUIController } from './RightMenuUIController';@@ -26,7 +27,7 @@ export class SheetContainerUIController {private _rightMenuController: RightMenuUIController;- // private _countBarController: CountBarController;+ private _countBarController: CountBarUIController;private _sheetBarController: SheetBarUIController;@@ -50,7 +51,7 @@ export class SheetContainerUIController {this._formulaBarUIController = new FormulaBarUIController(this._plugin);this._infoBarController = new InfoBarUIController(this._plugin);this._rightMenuController = new RightMenuUIController(this._plugin, this._config.layout?.rightMenuConfig);- // this._countBarController = new CountBarController(this._plugin);+ this._countBarController = new CountBarUIController(this._plugin);this._sheetBarController = new SheetBarUIController(this._plugin);// 初始化UI@@ -78,7 +79,7 @@ export class SheetContainerUIController {// getComponent: this._rightMenuController.getComponent,},countBar: {- // getComponent: this._countBarController.getComponent,+ getComponent: this._countBarController.getComponent,},sheetBar: {getComponent: this._sheetBarController.getComponent,diff --git a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsxindex ba5c12b091..854c673a71 100644--- a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx+++ b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx@@ -1,10 +1,11 @@-import { BaseCountBarProps } from '../../Components';-import { Component, createRef } from '../../Framework';+import { BaseCountBarProps, Button, Component, CountBarComponent, createRef, Icon, JSXComponent, Slider } from '@univerjs/base-ui';+import { PLUGIN_NAMES } from '@univerjs/core';import styles from './index.module.less';type CountState = {zoom: number;content: string;+ onChange?: (value: string) => void;};export class CountBar extends Component<BaseCountBarProps, CountState> {@@ -41,8 +42,11 @@ export class CountBar extends Component<BaseCountBarProps, CountState> {onChange = (e: Event) => {let target = e.target as HTMLInputElement;- this.props.changeRatio?.(target.value);+ if (this.state.onChange) {+ this.state.onChange(target.value);+ }this.setValue({ zoom: target.value });+ console.log(target.value);this.ref.current.changeInputValue(0, target.value);};@@ -55,7 +59,9 @@ export class CountBar extends Component<BaseCountBarProps, CountState> {let value = (number + 1) * 10;if (value >= this.max) value = this.max;this.setValue({ zoom: value });- this.props.changeRatio?.(String(value));+ if (this.state.onChange) {+ this.state.onChange(String(value));+ }};reduceZoom = () => {@@ -63,21 +69,18 @@ export class CountBar extends Component<BaseCountBarProps, CountState> {let value = (number - 1) * 10;if (value <= this.min) value = this.min;this.setValue({ zoom: value });- this.props.changeRatio?.(String(value));+ if (this.state.onChange) {+ this.state.onChange(String(value));+ }this.ref.current.changeInputValue(0, value);};componentDidMount() {- this.props.getComponent?.(this);+ this.getContext().getObserverManager().getObserver<CountBar>('onCountBarDidMountObservable', PLUGIN_NAMES.SPREADSHEET)?.notifyObservers(this);}render(props: BaseCountBarProps, state: CountState) {const { zoom, content } = state;- const ReduceIcon = this.getComponentRender().renderFunction('ReduceIcon');- const RegularIcon = this.getComponentRender().renderFunction('RegularIcon');- const Slider = this.getComponentRender().renderFunction('Slider');- const Button = this.getComponentRender().renderFunction('Button');- const AddIcon = this.getComponentRender().renderFunction('AddIcon');// const PageIcon = this.getComponentRender().renderFunction('PageIcon');// const LayoutIcon = this.getComponentRender().renderFunction('LayoutIcon');return (@@ -86,13 +89,13 @@ export class CountBar extends Component<BaseCountBarProps, CountState> {{zoom}</Button><Button type="text" onClick={this.addZoom}>- <AddIcon />+ <Icon.Math.AddIcon /></Button><div className={styles.countSlider}><Slider ref={this.ref} onChange={this.onChange} value={zoom} min={this.min} max={this.max} onClick={this.handleClick} /></div><Button type="text" onClick={this.reduceZoom}>- <ReduceIcon />+ <Icon.Math.ReduceIcon /></Button>{/* <Button type="text"><PageIcon />@@ -101,10 +104,16 @@ export class CountBar extends Component<BaseCountBarProps, CountState> {<LayoutIcon /></Button> */}<Button type="text">- <RegularIcon />+ <Icon.Sheet.RegularIcon /></Button><span className={styles.countStatistic}>{content}</span></div>);}}++export class UniverCountBar implements CountBarComponent {+ render(): JSXComponent<BaseCountBarProps> {+ return CountBar;+ }+}diff --git a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsxindex 45f6e2d02a..5930164c9c 100644--- a/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx+++ b/packages/ui-plugin-sheets/src/View/SheetContainer/SheetContainer.tsx@@ -198,7 +198,7 @@ export class SheetContainer extends Component<BaseSheetContainerProps, IState> {}}>{config.sheetBar && <SheetBar {...methods.sheetBar}></SheetBar>}- {/* {config.countBar && <CountBar {...methods.countBar}></CountBar>} */}+ {config.countBar && <CountBar {...methods.countBar}></CountBar>}</Footer></Layout><Sider