Ver código fonte

空格,换行,回车,tab

MaiXinRong 5 anos atrás
pai
commit
78eae4c12b
4 arquivos alterados com 41 adições e 33 exclusões
  1. 4 0
      app/public/js/global.js
  2. 13 10
      app/public/js/ledger.js
  3. 9 8
      app/public/js/revise.js
  4. 15 15
      app/public/js/stage.js

+ 4 - 0
app/public/js/global.js

@@ -532,3 +532,7 @@ function toastMessageUniq (obj) {
         obj.once = true;
     }
 }
+
+function trimInvalidChar(str) {
+    return $.trim(str).replace('\n', '').replace('\r', '').replace('\t', '');
+}

+ 13 - 10
app/public/js/ledger.js

@@ -412,7 +412,8 @@ $(document).ready(function() {
                 };
                 // 未改变值则不提交
                 const orgValue = node[col.field];
-                if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (info.editingText === ''))) {
+                const newValue = trimInvalidChar(info.editingText);
+                if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
                     return;
                 }
                 // 台账模式,检查计量单元相关
@@ -440,13 +441,13 @@ $(document).ready(function() {
                 }
                 // 获取更新数据
                 if (col.type === 'Number') {
-                    if (info.editingText) {
-                        const num = _.toNumber(info.editingText);
+                    if (newValue) {
+                        const num = _.toNumber(newValue);
                         if (num) {
                             data[col.field] = num;
                         } else {
                             try {
-                                data[col.field] = math.evaluate(transExpr(info.editingText));
+                                data[col.field] = math.evaluate(transExpr(newValue));
                             } catch(err) {
                                 toastr.error('输入的表达式非法');
                                 SpreadJsObj.reLoadRowData(info.sheet, info.row);
@@ -457,7 +458,7 @@ $(document).ready(function() {
                         data[col.field] = null;
                     }
                 } else {
-                    data[col.field] = info.editingText;
+                    data[col.field] = newValue;
                 }
                 // 更新至服务器
                 postData(window.location.pathname + '/update', {postType: 'update', postData: data}, function (result) {
@@ -489,7 +490,7 @@ $(document).ready(function() {
                         for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
                             const curCol = info.cellRange.col + iCol;
                             const colSetting = info.sheet.zh_setting.cols[curCol];
-                            const value = info.sheet.getText(curRow, curCol).replace('\n', '');
+                            const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
                             const lPos = pos.getLedgerPos(node.id);
                             if (lPos && lPos.length > 0) {
                                 if (value === '' && colSetting.field === 'b_code') {
@@ -519,6 +520,7 @@ $(document).ready(function() {
                                         data[colSetting.field] = math.evaluate(transExpr(value));
                                         bPaste = true;
                                     } catch(err) {
+                                        delete data[colSetting.field];
                                         if (!bHint) {
                                             toastr.warning('输入的表达式非法');
                                             bHint = true;
@@ -873,7 +875,7 @@ $(document).ready(function() {
             const expr = $(this);
             const sheet = ledgerSpread.getActiveSheet();
             const select = SpreadJsObj.getSelectObject(sheet);
-            const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
+            const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 
             const data = {
@@ -1109,7 +1111,7 @@ $(document).ready(function() {
                 const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
                 const col = info.sheet.zh_setting.cols[info.col];
                 const orgText = posData ? posData[col.field] : null;
-                const newText = info.sheet.getCell(info.row, info.col).text();
+                const newText = trimInvalidChar(info.sheet.getCell(info.row, info.col).text());
                 if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) {
                     return;
                 }
@@ -1305,7 +1307,7 @@ $(document).ready(function() {
                     for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
                         const curCol = info.cellRange.col + iCol;
                         const colSetting = info.sheet.zh_setting.cols[curCol];
-                        posData[colSetting.field] = info.sheet.getText(curRow, curCol);
+                        posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
 
                         if (colSetting.type === 'Number') {
                             const num = _.toNumber(posData[colSetting.field]);
@@ -1317,6 +1319,7 @@ $(document).ready(function() {
                                     posData[colSetting.field] = math.evaluate(transExpr(posData[colSetting.field]));
                                     bPaste = true;
                                 } catch(err) {
+                                    delete posData[colSetting.field];
                                     toastr.warning('粘贴了表达式非法,已过滤');
                                 }
                             }
@@ -1366,7 +1369,7 @@ $(document).ready(function() {
             const expr = $(this);
             const posSheet = posSpread.getActiveSheet();
             const select = SpreadJsObj.getSelectObject(posSheet);
-            const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val(), row = expr.attr('row');
+            const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val(), row = trimInvalidChar(expr.attr('row'));
             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 
             const data = {id: select.id};

+ 9 - 8
app/public/js/revise.js

@@ -315,7 +315,8 @@ $(document).ready(() => {
                 };
                 // 未改变值则不提交
                 const orgValue = node[col.field];
-                if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (info.editingText === ''))) {
+                const newValue = trimInvalidChar(info.editingText);
+                if (orgValue == info.editingText || ((!orgValue || orgValue === '') && (newValue === ''))) {
                     return;
                 }
                 // 台账模式,检查计量单元相关
@@ -332,7 +333,7 @@ $(document).ready(() => {
                             }
                         }
                     }
-                    if (col.field === 'b_code' && (info.editingText === '' || !info.editingText)) {
+                    if (col.field === 'b_code' && (newValue === '' || !newValue)) {
                         const lPos = pos.getLedgerPos(node.id);
                         if (lPos && lPos.length > 0) {
                             toastr.error('清单含有计量单元,请先删除计量单元,再删除清单编号');
@@ -343,7 +344,7 @@ $(document).ready(() => {
                 }
                 // 获取更新数据
                 if (info.editingText) {
-                    const text = info.editingText.replace('\n', '');
+                    const text = newValue;
                     if (node.used && (col.field === 'code' || col.field ==='b_code') && orgValue !== '' && text === '') {
                         toastr.error('节点已计量,请勿删除编号');
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
@@ -417,7 +418,7 @@ $(document).ready(() => {
                     for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
                         const curCol = info.cellRange.col + iCol;
                         const colSetting = info.sheet.zh_setting.cols[curCol];
-                        const value = info.sheet.getText(curRow, curCol).replace('\n', '');
+                        const value = trimInvalidChar(info.sheet.getText(curRow, curCol));
                         const lPos = pos.getLedgerPos(node.id);
                         if (lPos && lPos.length > 0) {
                             if (value === '' && colSetting.field === 'b_code') {
@@ -568,7 +569,7 @@ $(document).ready(() => {
 
             const expr = $(this);
             const select = SpreadJsObj.getSelectObject(billsSheet);
-            const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
+            const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 
             const data = {
@@ -670,7 +671,7 @@ $(document).ready(() => {
             const posData = info.sheet.zh_data ? info.sheet.zh_data[info.row] : null;
             const col = info.sheet.zh_setting.cols[info.col];
             const orgText = posData ? posData[col.field] : null;
-            const newText = info.sheet.getCell(info.row, info.col).text();
+            const newText = trimInvalidChar(info.sheet.getCell(info.row, info.col).text());
             if (orgText === newText || ((!orgText || orgText === '') && (newText === ''))) return;
 
             const node = posSpreadObj.billsNode;
@@ -880,7 +881,7 @@ $(document).ready(() => {
                 for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
                     const curCol = info.cellRange.col + iCol;
                     const colSetting = info.sheet.zh_setting.cols[curCol];
-                    posData[colSetting.field] = info.sheet.getText(curRow, curCol);
+                    posData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
                     if (colSetting.type === 'Number') {
                         const num = _.toNumber(posData[colSetting.field]);
                         if (num) {
@@ -942,7 +943,7 @@ $(document).ready(() => {
 
             const expr = $(this);
             const select = SpreadJsObj.getSelectObject(posSheet);
-            const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = expr.val();
+            const field = expr.attr('field'), orgValue = expr.attr('org'), newValue = trimInvalidChar(expr.val());
             if (orgValue === newValue || (!orgValue && newValue == '')) { return; }
 
             const data = {id: select.id};

+ 15 - 15
app/public/js/stage.js

@@ -518,7 +518,7 @@ $(document).ready(() => {
                 const node = sortData[info.row], updateData = {};
 
                 const orgValue = node[col.field];
-                let newValue = info.editingText;
+                let newValue = trimInvalidChar(info.editingText);
                 if (orgValue == newValue || ((!orgValue || orgValue === '') && (!newValue || newValue === ''))) {
                     return;
                 }
@@ -708,7 +708,7 @@ $(document).ready(() => {
                             if (nodePos && nodePos.length > 0) continue;
                         }
 
-                        const text = sheet.getText(curRow, curCol);
+                        const text = trimInvalidChar(sheet.getText(curRow, curCol));
                         if (setting.dgnUpFields.indexOf(col.field) !== -1) {
                             const num = _.toNumber(text);
                             if (num) {
@@ -922,7 +922,8 @@ $(document).ready(() => {
                 const posData = sortData ? sortData[info.row] : null;
                 const col = info.sheet.zh_setting.cols[info.col];
                 const orgText = posData ? posData[col.field] : null;
-                if (orgText === info.editingText || ((!orgText || orgText === '') && (info.editingText === ''))) {
+                const newText = trimInvalidChar(info.editingText);
+                if (orgText === info.editingText || ((!orgText || orgText === '') && (newText === ''))) {
                     return;
                 }
                 // 台账模式下,不可新增
@@ -938,11 +939,11 @@ $(document).ready(() => {
                     toastr.warning('数据错误, 请刷新页面后再试');
                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
-                } else if (info.editingText !== '' && node.children && node.children > 0) {
+                } else if (newText !== '' && node.children && node.children > 0) {
                     toastr.error('父节点不可插入计量单元');
                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
-                } else if (info.editingText !== '' && !node.b_code || node.b_code === '') {
+                } else if (newText !== '' && !node.b_code || node.b_code === '') {
                     toastr.error('项目节不可插入计量单元');
                     SpreadJsObj.reLoadRowData(info.sheet, info.row);
                     return;
@@ -950,22 +951,22 @@ $(document).ready(() => {
                 // 生成提交数据
                 const data = {};
                 if (col.field === 'name') {
-                    if ((!info.editingText || info.editingText === '') && posData) {
+                    if ((!newText || newText === '') && posData) {
                         toastr.error('部位名称不可为空');
                         SpreadJsObj.reLoadRowData(info.sheet, info.row);
                         return;
                     } else if (!posData) {
-                        if (info.editingText !== '') {
+                        if (newText !== '') {
                             data.updateType = 'add';
                             const order = (!sortData || sortData.length === 0) ? 1 : Math.max(sortData[sortData.length - 1].porder + 1, sortData.length + 1);
-                            data.updateData = {name: info.editingText, lid: node.id, tid: tender.id, porder: order};
+                            data.updateData = {name: newText, lid: node.id, tid: tender.id, porder: order};
                         } else {
                             SpreadJsObj.reLoadRowData(info.sheet, info.row);
                             return;
                         }
                     } else {
                         data.updateType = 'update';
-                        data.updateData = {pid: posData.id, lid: posData.lid, name: info.editingText};
+                        data.updateData = {pid: posData.id, lid: posData.lid, name: newText};
                     }
                 } else if (!posData) {
                     toastr.warning('新增部位请先输入名称');
@@ -973,12 +974,12 @@ $(document).ready(() => {
                     data.updateType = 'update';
                     data.updateData = {pid: posData.id, lid: posData.lid};
                     if (col.type === 'Number') {
-                        const num = _.toNumber(info.editingText);
+                        const num = _.toNumber(newText);
                         if (num) {
                             data.updateData[col.field] = num;
                         } else {
                             try {
-                                data.updateData[col.field] = math.evaluate(transExpr(info.editingText));
+                                data.updateData[col.field] = math.evaluate(transExpr(newText));
                             } catch(err) {
                                 toastr.error('输入的表达式非法');
                                 SpreadJsObj.reLoadRowData(info.sheet, info.row);
@@ -986,7 +987,7 @@ $(document).ready(() => {
                             }
                         }
                     } else {
-                        data.updateData[col.field] = info.editingText;
+                        data.updateData[col.field] = newText;
                     }
                 }
                 // 提交数据到服务器
@@ -1060,7 +1061,7 @@ $(document).ready(() => {
                         for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
                             const curCol = info.cellRange.col + iCol;
                             const colSetting = info.sheet.zh_setting.cols[curCol];
-                            newData[colSetting.field] = info.sheet.getText(curRow, curCol);
+                            newData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
                             if (colSetting.type === 'Number') {
                                 const num = _.toNumber(newData[colSetting.field]);
                                 if (num) {
@@ -1089,7 +1090,7 @@ $(document).ready(() => {
                             for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {
                                 const curCol = info.cellRange.col + iCol;
                                 const colSetting = info.sheet.zh_setting.cols[curCol];
-                                newData[colSetting.field] = info.sheet.getText(curRow, curCol);
+                                newData[colSetting.field] = trimInvalidChar(info.sheet.getText(curRow, curCol));
                                 if (colSetting.type === 'Number') {
                                     const num = _.toNumber(newData[colSetting.field]);
                                     if (num) {
@@ -1109,7 +1110,6 @@ $(document).ready(() => {
                         }
                     }
                 }
-                console.log(data);
                 postData(window.location.pathname + '/update', {pos: data}, function (result) {
                     if (result.pos) {
                         stagePos.updateDatas(result.pos.pos);