1:自定义一个命令(addRow):首行下面插入一行,且命令不允许撤销
2:执行流程
1>编辑单元格 ,比如第2行第1列,
2>执行命自定义命令(addRow)
3> ctr+z 进行撤销,因为第二步自定义命令不允许撤销,会执行第一步 编辑单元格的撤销,
实际撤销时,撤销的还是第2行,第1列,。因为插入了行,应该撤销第3行第1列。
这种情况,是否有办法可以解决? 否则有自定义命令不允许撤销的,其它编辑的撤销都可能位置错乱。
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta name="spreadjs culture" content="zh-cn" />
- <!-- 引入SpreadJS相关的CSS,默认会有一个CSS
- SpreadJS默认提供了7种CSS,可以选择一个适合当前项目的引入
- -->
- <link rel="stylesheet" type="text/css" href="./css/gc.spread.sheets.excel2013lightGray.16.0.2.css" />
- <!-- 核心资源,最小依赖资源,只要引入了该资源,组件运行时就能显示出来 -->
- <script type="text/javascript" src="./js/gc.spread.sheets.all.16.0.2.min.js"></script>
- <!-- 中文资源文件,组件运行时默认会用英文资源,使用中文资源需要引入并设置 -->
- <script type="text/javascript" src="./js/resources/zh/gc.spread.sheets.resources.zh.16.0.2.min.js"></script>
- <!-- 导入导出excel文件的相关资源 -->
- <script type="text/javascript" src="./js/plugins/gc.spread.sheets.io.16.0.2.min.js"></script>
- <title>原生js引入组件运行时</title>
- </head>
- <style>
- #ss {
- height: 97vh;
- }
- </style>
- <body>
- <br>
- <input type="button" id="addRowNotSupportUndo" value="第一行后插入行(不支持撤销)" class="button">
- <input type="button" id="addRowSupportUndo" value="第一行后插入行(支持撤销)" class="button">
- <div id="ss"></div>
- <script>
- window.onload = function () {
- // 创建一个工作表数量为1,显示上下文菜单
- let spread = new GC.Spread.Sheets.Workbook('ss', {
- sheetCount: 1,
- allowContextMenu: true
- })
- //注册自定义命令
- registerAddRowCmd(spread);
- document.getElementById('addRowNotSupportUndo').onclick = function () {
- doAddRowCmd(spread, false);
- }
- document.getElementById('addRowSupportUndo').onclick = function () {
- doAddRowCmd(spread, true);
- }
- }
- var registerAddRowCmd = function (spread) {
- var commandManager = spread.commandManager();
- var commandAddRowNotSupportUndo = {
- canUndo: false, //不支持撤销
- execute: addRowAction
- }
- commandManager.register('cus.addRowNotSupportUndo', commandAddRowNotSupportUndo, null, false, false, false, false);
- var commandAddRowSupportUndo = {
- canUndo: true, //支持撤销
- execute: addRowAction
- };
- commandManager.register('cus.addRowSupportUndo', commandAddRowSupportUndo, null, false, false, false, false);
- };
- var addRowAction = function (spread, options, isUndo) {
- var Commands = GC.Spread.Sheets.Commands;
- if (isUndo) {
- console.log(options)
- Commands.undoTransaction(spread, options);
- console.log("undo finish")
- return true;
- } else {
- Commands.startTransaction(spread, options);
- spread.suspendPaint();
- insertRow(spread);
- spread.resumePaint();
- Commands.endTransaction(spread, options);
- return true;
- }
- }
- var doAddRowCmd = function (spread, canUndo) {
- var commandName = canUndo ? "cus.addRowSupportUndo":"cus.addRowNotSupportUndo";
- var commandManager = spread.commandManager();
- var sheet = spread.getActiveSheet();
- commandManager.execute({
- cmd: commandName,
- sheetName: spread.getSheet(0).name()
- });
- }
- function insertRow(spread) {
- let sheet = spread.getActiveSheet()
- sheet.addRows(1, 1);
- }
- </script>
- </body>
- </html>
复制代码
|
|