Luckysheet
Luckysheet copied to clipboard
[BUG]设置保护单元格,无法对已有数据的单元格进行保护
#Describe the bug
设置保护单元格,无法对已有数据的单元格进行保护
To Reproduce
- 在单元格内输入数据
- 设置可输入区域或不设置
- 空白单元格正常保护
- 有数据的单元格可以正常编辑
What is expected? 1.git打包的和cdn引用都是同样的问题,上个cdn版本可以正常工作 2.vue项目开发,vue开发模版中也存在同样的问题
Screenshots or demo https://s3.ax1x.com/2021/01/19/sRktv6.png https://s3.ax1x.com/2021/01/19/sRkD5d.png
Environment
- OS: Mac
- Browser Version: Chrome 版本 87.0.4280.141(正式版本) (x86_64)
- Luckysheet Version: latest
有什么解决方法吗?
您好,这个bug什么时候可以解决?
@Havord @chenshouying 能不能录一个gif或视频,我没有复现
这个是保护单元格部分不生效
@mengshukeji
请问这个问题解决了吗?
问题还没解决吗?能否给个答复,谢谢
同问,这个功能很重要,要不然在线协作,就无法实现,大佬们,辛苦,加油,给个方案,谢谢
create 配置config.authority 单元格有数据 不受保护,空单元格保护成功,
我也有同样的问题,有谁解决了吗
同样问题
配置文件中 单元格属性添加 lo :1 就能锁定单元格 ,偶然发现的,在文档里没找到
配置文件中 单元格属性添加 lo :1 就能锁定单元格 ,偶然发现的,在文档里没找到
试过了还是无效
终极解决方案:
- 打开
src/controllers/protection.js
文件; - 找到如下两个方法并做对应修改;
//cell locked state
export function checkProtectionLocked(r, c, sheetIndex) {
let sheetFile = sheetmanage.getSheetByIndex(sheetIndex);
if (sheetFile == null) {
return true;
}
if (sheetFile.config == null || sheetFile.config.authority == null) {
return true;
}
let data = sheetFile.data, cell = data[r][c], aut = sheetFile.config.authority;
if (aut == null || aut.sheet == null || aut.sheet === 0) {
return true;
}
// FIXME:注释掉这个判断以解决当启用表格保护时(即:config.authority.sheet === 1),未开启编辑权限的表格如果有值依然可以编辑的BUG。
// if (cell && !cell.lo) {
// return true;
// }
const _locale = locale();
const local_protection = _locale.protection;
return checkProtectionLockedSqref(r, c, aut, local_protection);
}
//selectLockedCells , selectunLockedCells and cell state
export function checkProtectionSelectLockedOrUnLockedCells(r, c, sheetIndex) {
const _locale = locale();
const local_protection = _locale.protection;
let sheetFile = sheetmanage.getSheetByIndex(sheetIndex);
if (sheetFile == null) {
return true;
}
if (sheetFile.config == null || sheetFile.config.authority == null) {
return true;
}
let data = sheetFile.data, cell = data[r][c], aut = sheetFile.config.authority;
if (aut == null || aut.sheet == null || aut.sheet === 0) {
return true;
}
// FIXME: 原始代码
// if (cell && !cell.lo) { // unlocked
// return aut.selectunLockedCells === 1 || aut.selectunLockedCells == null;
// } else { // locked??
// let isAllEdit = checkProtectionLockedSqref(r, c, aut, local_protection, false); //don't alert password model
// if (isAllEdit) { // unlocked
// return aut.selectunLockedCells === 1 || aut.selectunLockedCells == null;
// } else { // locked
// return aut.selectLockedCells === 1 || aut.selectLockedCells == null;
// }
// }
// FIXME: 使用以下代码(即:移除掉对 cell && !cell.lo 的判断)以解决当启用表格保护时(即:config.authority.sheet === 1),未开启编辑权限的表格如果有值依然可以编辑的BUG。
// Locked??
let isAllEdit = checkProtectionLockedSqref(r, c, aut, local_protection, false); // don't alert password model
if (isAllEdit) { // unlocked
return aut.selectunLockedCells === 1 || aut.selectunLockedCells == null;
} else { // locked
return aut.selectLockedCells === 1 || aut.selectLockedCells == null;
}
}
- 修改完成后,使用
npm run build
重新打包即可。
总结:设置保护后之所以有值的单元格失效,是因为这两个方法中均对cell的值做了判断,移除掉对应的判断即可。
PS:很多开发者不知道 lo
这个参数是啥,在这个文件里就能看出来他的作用,只是官方文档并未提及。
只要在对应的数据加lo:1然后启用工作区保护就可以了,就能实现表格锁定无法编辑,且无法选择的情况