rapid-spreadjs 1.0.113 → 1.0.116

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -1087,6 +1087,238 @@ const BusinessUtils = {
1087
1087
  created(cyclicCellsRange, allCellsByRow);
1088
1088
  }
1089
1089
  },
1090
+ /**
1091
+ * 显示超差提醒批注信息
1092
+ * @param spread 工作簿实例
1093
+ * @param cctxConfigs 超差提醒配置集合
1094
+ * @param cellRowIndex 发生改变值的单元格行索引
1095
+ * @param cellColIndex 发生改变值的单元格列索引
1096
+ * @param isValueChgedUse 是否为单元格值发生改变的时候调用
1097
+ * @param commentOptions 批注配置项,默认为:{color: '#E11010', size: 10, defaultTextIsSet: true, defaultText: '无效'}(color:批注颜色,size:批注大小,defaultTextIsSet:是否设置单元格默认值,defaultText:单元格默认值内容)
1098
+ */
1099
+ overRemindComments: (spread, cctxConfigs, cellRowIndex, cellColIndex, isValueChgedUse = true, commentOptions = {
1100
+ color: '#E11010',
1101
+ size: 10,
1102
+ defaultTextIsSet: true,
1103
+ defaultText: '无效',
1104
+ }) => {
1105
+ if (!cctxConfigs || cctxConfigs.length == 0) {
1106
+ return;
1107
+ }
1108
+ const sheet = spread.getActiveSheet();
1109
+ spread.suspendPaint();
1110
+ spread.suspendCalcService();
1111
+ spread.suspendEvent();
1112
+ // //批注颜色、大小、是否设置单元格默认值、单元格默认值内容
1113
+ // let commentColor = color,
1114
+ // commentSize = 10,
1115
+ // commentDefaultTextIsSet = true,
1116
+ // commentDefaultText = '无效';
1117
+ let commentColor = commentOptions.color ? commentOptions.color : '#E11010', commentSize = commentOptions.size ? commentOptions.size : 10, commentDefaultTextIsSet = commentOptions.defaultTextIsSet ? commentOptions.defaultTextIsSet : true, commentDefaultText = commentOptions.defaultText ? commentOptions.defaultText : '无效';
1118
+ //将a~f这些字母替换为具体的值
1119
+ const replaceVar = (itemExp, varJsonObjs) => {
1120
+ const letters = ['a', 'b', 'c', 'd', 'e', 'f'];
1121
+ letters.forEach((letter) => {
1122
+ if (itemExp.indexOf(letter) > -1) {
1123
+ itemExp = itemExp.replaceAll(letter, varJsonObjs.find((itemVar) => itemVar.var == letter).value);
1124
+ }
1125
+ });
1126
+ return itemExp;
1127
+ };
1128
+ //将1~20这些数字替换为具体的设置条件
1129
+ const replaceNum = (itemExp, conJsonArr) => {
1130
+ const nums = [];
1131
+ for (let iNum = 1; iNum <= 20; iNum++) {
1132
+ nums.push(iNum);
1133
+ }
1134
+ nums.forEach((num) => {
1135
+ if (itemExp.indexOf(num) > -1 && num <= conJsonArr.length) {
1136
+ //将条件公式【1 || (2 && 3)】中的数组替换为#1#的形式
1137
+ itemExp = itemExp.replaceAll(num, `#${num}#`);
1138
+ }
1139
+ });
1140
+ nums.forEach((num) => {
1141
+ if (itemExp.indexOf(num) > -1 && num <= conJsonArr.length) {
1142
+ //将条件公式中的#1#替换为具体的设置条件
1143
+ itemExp = itemExp.replaceAll(`#${num}#`, `(${conJsonArr[num - 1]})`);
1144
+ }
1145
+ });
1146
+ return itemExp;
1147
+ };
1148
+ //获取新的conJson配置集合
1149
+ const getConJsonArrNew = (conJsonArr, varJsonArr) => {
1150
+ let conJsonArrNew = [];
1151
+ conJsonArr.forEach((element) => {
1152
+ let newElement = element;
1153
+ //将abs替换为[###]
1154
+ newElement = newElement.replaceAll('jd(', '精度开始').replaceAll(')jd', '精度结束').replaceAll('abs', '[###]');
1155
+ //将a~f这些字母替换为具体的值
1156
+ newElement = replaceVar(newElement, varJsonArr);
1157
+ //将[###]替换为Math.abs
1158
+ newElement = newElement.replaceAll('[###]', 'Math.abs').replaceAll('精度开始', 'Number(').replaceAll('精度结束', ').toFixed(8)');
1159
+ //将设置条件添加到新的集合中
1160
+ conJsonArrNew.push(newElement);
1161
+ });
1162
+ return conJsonArrNew;
1163
+ };
1164
+ for (let i = 0; i < cctxConfigs.length; i++) {
1165
+ const item = cctxConfigs[i];
1166
+ //有前置条件
1167
+ if (item.isQz) {
1168
+ //获取所有值单元格集合,格式如:[{"var":"a","value":10,"row":,……}]
1169
+ let varJsonArr = JSON.parse(item.varJson);
1170
+ //获取所有前置条件单元格集合,格式如:[{"var":"a","value":10,"row":,……}]
1171
+ let qzCellJsonArr = JSON.parse(item.qzCellJson);
1172
+ const doEvent = () => {
1173
+ varJsonArr.forEach((element) => {
1174
+ element.value = sheet.getValue(element.row, element.col);
1175
+ });
1176
+ //获取所有设置条件集合
1177
+ let conJsonArr = JSON.parse(item.conJson), conJsonArrNew = getConJsonArrNew(conJsonArr, varJsonArr);
1178
+ qzCellJsonArr.forEach((element) => {
1179
+ element.value = sheet.getValue(element.row, element.col);
1180
+ });
1181
+ //获取所有前置条件公式集合,格式如:[{"var":"a","value":10,"row":,……}]
1182
+ let qzGsJsonArr = JSON.parse(item.qzGsJson);
1183
+ qzGsJsonArr.forEach((element) => {
1184
+ element.value = sheet.getValue(element.row, element.col);
1185
+ });
1186
+ //循环所有前置公式
1187
+ //记录是否所有前置公式对应的条件都没有超差
1188
+ let isAllNotCc = true;
1189
+ for (let j = 0; j < qzGsJsonArr.length; j++) {
1190
+ const itemQzgs = qzGsJsonArr[j];
1191
+ //当前公式中的前置条件
1192
+ let curGsQz = itemQzgs.qzFor.replaceAll('jd(', '精度开始').replaceAll(')jd', '精度结束').replaceAll('abs', '[###]');
1193
+ curGsQz = replaceVar(curGsQz, qzCellJsonArr);
1194
+ curGsQz = curGsQz.replaceAll('[###]', 'Math.abs').replaceAll('精度开始', 'Number(').replaceAll('精度结束', ').toFixed(8)');
1195
+ try {
1196
+ //满足其中一个前置条件时
1197
+ if (eval(curGsQz)) {
1198
+ //获取最终的条件公式
1199
+ const lastFor = replaceNum(itemQzgs.conFor, conJsonArrNew);
1200
+ try {
1201
+ //设置批注
1202
+ if (eval(lastFor)) {
1203
+ isAllNotCc = false;
1204
+ sheet.comments
1205
+ .add(item.row, item.col, itemQzgs.tipMsg)
1206
+ .indicatorColor(commentColor)
1207
+ .indicatorSize(commentSize)
1208
+ .fontSize('10pt')
1209
+ .width(200);
1210
+ if (commentDefaultTextIsSet) {
1211
+ sheet.setValue(item.row, item.col, commentDefaultText);
1212
+ }
1213
+ }
1214
+ //取消批注
1215
+ else {
1216
+ sheet.comments.remove(item.row, item.col);
1217
+ if (commentDefaultTextIsSet) {
1218
+ const cellVal = sheet.getValue(item.row, item.col);
1219
+ if (cellVal == commentDefaultText) {
1220
+ sheet.setValue(item.row, item.col, '');
1221
+ }
1222
+ }
1223
+ }
1224
+ }
1225
+ catch (error) {
1226
+ //取消批注
1227
+ sheet.comments.remove(item.row, item.col);
1228
+ if (commentDefaultTextIsSet) {
1229
+ const cellVal = sheet.getValue(item.row, item.col);
1230
+ if (cellVal == commentDefaultText) {
1231
+ sheet.setValue(item.row, item.col, '');
1232
+ }
1233
+ }
1234
+ }
1235
+ break;
1236
+ }
1237
+ }
1238
+ catch (error) {
1239
+ //
1240
+ }
1241
+ }
1242
+ //当所有公式条件都没有超差的时候,需要取消批注
1243
+ if (isAllNotCc) {
1244
+ //取消批注
1245
+ sheet.comments.remove(item.row, item.col);
1246
+ if (commentDefaultTextIsSet) {
1247
+ const cellVal = sheet.getValue(item.row, item.col);
1248
+ if (cellVal == commentDefaultText) {
1249
+ sheet.setValue(item.row, item.col, '');
1250
+ }
1251
+ }
1252
+ }
1253
+ };
1254
+ //如果当前改变值的单元格在varJsonArr集合中存在,则说明是修改的超差提醒配置的相关单元格
1255
+ if (isValueChgedUse) {
1256
+ if (varJsonArr.some((itemVar) => itemVar.row == cellRowIndex && itemVar.col == cellColIndex) ||
1257
+ qzCellJsonArr.some((itemVar) => itemVar.row == cellRowIndex && itemVar.col == cellColIndex)) {
1258
+ doEvent();
1259
+ }
1260
+ }
1261
+ else {
1262
+ doEvent();
1263
+ }
1264
+ }
1265
+ //无前置条件
1266
+ else {
1267
+ //获取所有值单元格集合,格式如:[{"var":"a","value":10,"row":,……}]
1268
+ let varJsonArr = JSON.parse(item.varJson);
1269
+ const doEvent = () => {
1270
+ varJsonArr.forEach((element) => {
1271
+ element.value = sheet.getValue(element.row, element.col);
1272
+ });
1273
+ //获取所有设置条件集合
1274
+ let conJsonArr = JSON.parse(item.conJson), conJsonArrNew = getConJsonArrNew(conJsonArr, varJsonArr);
1275
+ //获取最终的条件公式
1276
+ const lastFor = replaceNum(item.conFor, conJsonArrNew);
1277
+ try {
1278
+ //设置批注
1279
+ if (eval(lastFor)) {
1280
+ sheet.comments.add(item.row, item.col, item.tipMsg).indicatorColor(commentColor).indicatorSize(commentSize).fontSize('10pt').width(200);
1281
+ if (commentDefaultTextIsSet) {
1282
+ sheet.setValue(item.row, item.col, commentDefaultText);
1283
+ }
1284
+ }
1285
+ //取消批注
1286
+ else {
1287
+ sheet.comments.remove(item.row, item.col);
1288
+ if (commentDefaultTextIsSet) {
1289
+ const cellVal = sheet.getValue(item.row, item.col);
1290
+ if (cellVal == commentDefaultText) {
1291
+ sheet.setValue(item.row, item.col, '');
1292
+ }
1293
+ }
1294
+ }
1295
+ }
1296
+ catch (error) {
1297
+ //取消批注
1298
+ sheet.comments.remove(item.row, item.col);
1299
+ if (commentDefaultTextIsSet) {
1300
+ const cellVal = sheet.getValue(item.row, item.col);
1301
+ if (cellVal == commentDefaultText) {
1302
+ sheet.setValue(item.row, item.col, '');
1303
+ }
1304
+ }
1305
+ }
1306
+ };
1307
+ //如果当前改变值的单元格在varJsonArr集合中存在,则说明是修改的超差提醒配置的相关单元格
1308
+ if (isValueChgedUse) {
1309
+ if (varJsonArr.some((itemVar) => itemVar.row == cellRowIndex && itemVar.col == cellColIndex)) {
1310
+ doEvent();
1311
+ }
1312
+ }
1313
+ else {
1314
+ doEvent();
1315
+ }
1316
+ }
1317
+ }
1318
+ spread.resumeEvent();
1319
+ spread.resumeCalcService();
1320
+ spread.resumePaint();
1321
+ },
1090
1322
  };
1091
1323
 
1092
1324
  /**