Jelajahi Sumber

try add danxiangdinge, need add cache layer

Xiaopeng Zhang 6 bulan lalu
induk
melakukan
7be26d5467
5 mengubah file dengan 146 tambahan dan 77 penghapusan
  1. 1 0
      front/package.json
  2. 84 61
      front/src/Qingdan.js
  3. 44 2
      front/src/Service.js
  4. 11 10
      front/src/editor.js
  5. 6 4
      subdir/db.py

+ 1 - 0
front/package.json

@@ -22,6 +22,7 @@
     "@mui/x-tree-view": "latest",
     "handsontable": "^15.3.0",
     "html-webpack-plugin": "^5.6.3",
+    "hyperformula": "^3.0.0",
     "react": "latest",
     "react-dom": "latest",
     "react-router": "latest",

+ 84 - 61
front/src/Qingdan.js

@@ -20,6 +20,8 @@ import Button from '@mui/material/Button';
 import ButtonGroup from '@mui/material/ButtonGroup';
 import {danxiangdinge_index} from './utils';
 import {shanchu, push_op, quanbushanchu, danxiangdinge} from './editor';
+import { HyperFormula } from 'hyperformula';
+
 registerAllModules();
 
 
@@ -41,7 +43,11 @@ function copy(input) {
 
 
 export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCallback}) {
-
+     const hyperformulaInstance = HyperFormula.buildEmpty({
+          // to use an external HyperFormula instance,
+          // initialize it with the `'internal-use-in-handsontable'` license key
+          licenseKey: 'internal-use-in-handsontable',
+        });
      const memory = React.useRef([]);
      const mem_pointer = React.useRef(0);
      function coverRenderer(_instance, td, _row, _col, _prop, value, _cellProperties) {
@@ -130,6 +136,7 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
     const [highlight, setHighlight] = React.useState([]);
     const selectedRow = React.useRef(-1);
     const hotRef = React.useRef(null);
+    const hotRcjRef = React.useRef(null);
     const rgdeRef = React.useRef(null);
     const jxdeRef = React.useRef(null);
     const cldeRef = React.useRef(null);
@@ -270,64 +277,10 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
         setValue(newValue);
       };
 
-
-    return (
-        <Stack spacing={2}>
-
-                   <Box>
-                   <Stack direction='row' spacing={2}>
-                   <Button variant="outlined" onClick={() => {
-                      //console.log(memory.current);
-                      const [success, data] = danxiangdinge(hotRef, selectedRow, detailRef);
-                      if(success) {
-                         setDetail(data);
-                         push_op(memory, mem_pointer, detailRef);
-                      }
-                 
-                      
-                      }}
-                   >单项定额</Button>
-                   <Button variant="outlined" onClick={() => {
-                      //console.log(memory.current);
-                      if (mem_pointer.current > 0) {
-                      setDetail(memory.current[mem_pointer.current - 1]);
-                      detailRef.current = memory.current[mem_pointer.current - 1];
-                      mem_pointer.current = mem_pointer.current - 1;
-                      console.log("after undo");
-                      console.log(memory.current);
-                      console.log(mem_pointer.current);
-                      }
-                      }}
-                   >撤销</Button>
-                   <Button variant="outlined" onClick={() => {
-                      //console.log(memory.current);
-                      if (mem_pointer.current + 1 != memory.current.length) {
-                      setDetail(memory.current[mem_pointer.current + 1]);
-                      detailRef.current = memory.current[mem_pointer.current + 1];
-                      mem_pointer.current = mem_pointer.current + 1;
-                      console.log("after redo");
-                      console.log(memory.current);
-                      console.log(mem_pointer.current);
-                      }
-                      }}
-                   >重做</Button>
-
-                  
-                   </Stack>
-                 <HotTable 
-                 nestedRows={true}
-                    data={detail
-                    }
-                    afterUpdateData={(x)=>{
-                         //console.log(x);
-                         hotRef.current?.hotInstance?.scrollViewportTo({ row: selectedRow.current });
-
-                    }}
-                    
-                    afterSelection={(row, column)=>{
-                        //console.log(row);
-                        selectedRow.current = row;
+      const handleSelection = (row, column) => {
+          selectedRow.current = row;
                         let selected = hotRef.current?.hotInstance?.getData()[row];
+                        if (!selected) return;
                         if (selected[1] != null) {
                              Service.generateQingdanrcj(name, bh,bt,selected[2]).then(x=>{
                               
@@ -353,7 +306,7 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
                             }
                              //console.log(name, bh,bt,qdbm, selected[1]);
                              clickCallback(qdbm, selected[2]);
-                             Service.generateDingercj(name, bh,bt,qdbm, selected[2]).then(x=>{
+                             Service.generateDingercj(name, bh,bt,qdbm, selected[2], selected[6]).then(x=>{
                                console.log(x);
                                setRcjhl(x);
                                isQdrcj.current = false;
@@ -425,9 +378,64 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
                              });
 
                         }
-                            
+      };
+
+
+    return (
+        <Stack spacing={2}>
+
+                   <Box>
+                   <Stack direction='row' spacing={2}>
+                   <Button variant="outlined" onClick={() => {
+                      //console.log(memory.current);
+                      const [success, data] = danxiangdinge(hotRef, selectedRow, detailRef);
+                      if(success) {
+                         setDetail(data);
+                         push_op(memory, mem_pointer, detailRef);
+                      }
+                 
+                      
+                      }}
+                   >单项定额</Button>
+                   <Button variant="outlined" onClick={() => {
+                      //console.log(memory.current);
+                      if (mem_pointer.current > 0) {
+                      setDetail(memory.current[mem_pointer.current - 1]);
+                      detailRef.current = memory.current[mem_pointer.current - 1];
+                      mem_pointer.current = mem_pointer.current - 1;
+                      console.log("after undo");
+                      console.log(memory.current);
+                      console.log(mem_pointer.current);
+                      }
+                      }}
+                   >撤销</Button>
+                   <Button variant="outlined" onClick={() => {
+                      //console.log(memory.current);
+                      if (mem_pointer.current + 1 != memory.current.length) {
+                      setDetail(memory.current[mem_pointer.current + 1]);
+                      detailRef.current = memory.current[mem_pointer.current + 1];
+                      mem_pointer.current = mem_pointer.current + 1;
+                      console.log("after redo");
+                      console.log(memory.current);
+                      console.log(mem_pointer.current);
+                      }
+                      }}
+                   >重做</Button>
+
+                  
+                   </Stack>
+                 <HotTable 
+                 nestedRows={true}
+                    data={detail
+                    }
+                    afterUpdateData={(x)=>{
+                         //-console.log(x);
+                         hotRef.current?.hotInstance?.scrollViewportTo({ row: selectedRow.current });
+                         //handleSelection(selectedRow.current, 0);
 
                     }}
+                    
+                    afterSelection={handleSelection}
                     ref = {hotRef}
                     cells={(row, col, prop) => {
                          if (row == selectedRow.current) {
@@ -510,11 +518,26 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
                              rowHeaders={true}
                              colHeaders={true}
                              height="300"
-                             readOnly={true}
+                             formulas={{
+                              engine: hyperformulaInstance,
+                              sheetName: 'Rcj',
+                            }}
+                             
+                              cells={(row, col) => {
+                                   if (row === 0) {
+                                     return { readOnly: true };
+                                   }
+                                   if (col <= 1 || col === 11) {
+                                        return { readOnly: true };
+                                   }
+                           
+                                   return {};
+                                 }}
                              fixedRowsTop={1}
                              selectionMode="single"
                              autoWrapRow={false}
                              autoWrapCol={false}
+                             ref = {hotRcjRef}
                              licenseKey="non-commercial-and-evaluation" // for non-commercial use only
                            />
 

+ 44 - 2
front/src/Service.js

@@ -495,7 +495,7 @@ class Service{
             return data;
         }
     }
-    async generateDingercj(name, bh, bt, qdbm, debm) {
+    async generateDingercj(name, bh, bt, qdbm, debm, danwei) {
         const response = await fetch(this.ip().concat( ":8000/dingercj/"), {
             method : "POST",
             headers: {
@@ -516,7 +516,49 @@ class Service{
             console.error('error');
         } else {
             const data = await response.json();
-            return data;
+            if (data.length == 0) {
+                return  [
+                    [
+                        "ID",
+                        "人材机编码",
+                        "名称",
+                        "规格型号",
+                        "单位",
+                        "单价",
+                        "产地",
+                        "供应厂商",
+                        "人材机类别",
+                        "甲供标志",
+                        "含量",
+                        "合价",
+                        "暂估价标志",
+                        "主要材料标志",
+                        "主材标志",
+                        "设备标志"
+                    ],
+                    [
+                        "",
+                        debm,
+                        "",
+                        "",
+                        danwei,
+                        "",//danjia
+                        "",//chandi
+                        "",//gongyingchangshang
+                        "2",//rencaijileibie
+                        "false",//jiagong
+                        "1",//hanliang
+                        "=F2*K2",//hejia
+                        "",
+                        "",
+                        "",
+                        ""
+                    ]
+                ];
+            }
+            else {
+                return data;
+            }
         }
     }
     async generateZjcs(name, bh) {

+ 11 - 10
front/src/editor.js

@@ -75,6 +75,7 @@ export const danxiangdinge = (hotRef, selectedRow, detailRef) => {
     let bh = danxiangdinge_index(detailRef.current);
     let selected = hotRef.current?.hotInstance?.getData()[selectedRow.current];
     if (selected && selected[1] != null) {
+        let danwei = selected[6];
        let newData = detailRef.current.map(
             x => {
                  if (x['序号'] == selected[1]) {
@@ -88,15 +89,15 @@ export const danxiangdinge = (hotRef, selectedRow, detailRef) => {
                                 '名称': '',
                                 '项目特征': null,
                                 '计算规则': null,
-                                '单位': 'm',
+                                '单位': danwei,
                                 '数量': '1',
-                                '综合单价': '150',
-                                '合价': '660000',
+                                '综合单价': '',
+                                '合价': '',
                                 '人工费': '0',
                                 '主材费': '0',
                                 '设备费': '0',
-                                '辅材费': '150',
-                                '材料费': '150',
+                                '辅材费': '',
+                                '材料费': '',
                                 '机械费': '0',
                                 '管理费': '0',
                                 '利润': '0',
@@ -114,15 +115,15 @@ export const danxiangdinge = (hotRef, selectedRow, detailRef) => {
                                '名称': '',
                                '项目特征': null,
                                '计算规则': null,
-                               '单位': 'm',
+                               '单位': danwei,
                                '数量': '1',
-                               '综合单价': '150',
-                               '合价': '660000',
+                               '综合单价': '',
+                               '合价': '',
                                '人工费': '0',
                                '主材费': '0',
                                '设备费': '0',
-                               '辅材费': '150',
-                               '材料费': '150',
+                               '辅材费': '',
+                               '材料费': '',
                                '机械费': '0',
                                '管理费': '0',
                                '利润': '0',

+ 6 - 4
subdir/db.py

@@ -670,9 +670,11 @@ async def getDingercj(client, name, bh, bt, qdbm, debm):
 
     collection = db["qdxm"]
     document = await collection.find_one({"Dwgcbh": bh, "清单编码": qdbm, "biao_id": name, "bt": bt})
-    children = document["__children"]
     result = []
-    for child in children:
-        if child["清单编码"] == debm:
-            result = child["dercj"]
+    if "__children" in document:
+        children = document["__children"]
+        
+        for child in children:
+            if child["清单编码"] == debm:
+                result = child["dercj"]
     return result