ソースを参照

support save to cloud

Xiaopeng Zhang 6 ヶ月 前
コミット
ccd00ab479
6 ファイル変更75 行追加10 行削除
  1. 17 6
      front/src/App2.js
  2. 12 2
      front/src/Qingdan.js
  3. 26 1
      front/src/Service.js
  4. 8 0
      main.py
  5. 11 0
      subdir/db.py
  6. 1 1
      test.py

+ 17 - 6
front/src/App2.js

@@ -30,7 +30,8 @@ import AccordionSummary from '@mui/material/AccordionSummary';
 import AccordionDetails from '@mui/material/AccordionDetails';
 import Stack from '@mui/material/Stack';
 import { DataGrid } from '@mui/x-data-grid';
-
+import Backdrop from '@mui/material/Backdrop';
+import CircularProgress from '@mui/material/CircularProgress';
 
 registerAllModules();
 const MUI_X_PRODUCTS = [
@@ -105,6 +106,7 @@ const MUI_X_PRODUCTS = [
     const [beizhu, setBeizhu] = React.useState(null);
     const [clde, setClde] = React.useState(null);
     const [jxde, setJxde] = React.useState(null);
+    const [open, setOpen] = React.useState(false);
     const relation = React.useRef({});
     const columns =[
     
@@ -163,11 +165,11 @@ const MUI_X_PRODUCTS = [
         return result;
     };
 
-    const clickCallback_ = (qdbm, debh) => {
-      console.log('####################################zylb#####################'.concat(zylb.toString()));
-      //console.log(debh);
-      setExpandedQd(false);
-      setExpandedDe(true);//1 jianzhu 2 zhuangshi 3 anzhuang 4 shizheng 5 yuanlin 6 guidao 7 xiushantujian 8 xiushananzhuang 9 xiushanjiagu  
+    const loadingCallback = () => {
+      setOpen(true); 
+      Service.save().then(x=>{
+        setOpen(false);
+      });
     };
 
     const clickCallback = (qdbm, debh) => {
@@ -757,6 +759,7 @@ const MUI_X_PRODUCTS = [
                                 clde={clde}
                                 beizhu={beizhu}
                                 clickCallback={clickCallback}
+                                loadingCallback={loadingCallback}
                              />                     
                      </TabPanel>
                       )}
@@ -791,6 +794,14 @@ const MUI_X_PRODUCTS = [
             </Grid>
 
           </Grid>
+
+          <Backdrop
+              sx={(theme) => ({ color: '#fff', zIndex: theme.zIndex.drawer + 1 })}
+              open={open}
+          >
+                <CircularProgress color="inherit" />
+         </Backdrop>
+          
             
         </Box>
     );

+ 12 - 2
front/src/Qingdan.js

@@ -22,7 +22,8 @@ import ButtonGroup from '@mui/material/ButtonGroup';
 import {danxiangdinge_index} from './utils';
 import {shanchu, undo, redo, quanbushanchu, danxiangdinge, updateDercj} from './editor';
 import { ConfigValueTooSmallError, HyperFormula } from 'hyperformula';
-
+import Backdrop from '@mui/material/Backdrop';
+import CircularProgress from '@mui/material/CircularProgress';
 registerAllModules();
 
 
@@ -43,7 +44,7 @@ function copy(input) {
 
 
 
-export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCallback}) {
+export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCallback, loadingCallback}) {
      const hyperformulaInstance = HyperFormula.buildEmpty({
           // to use an external HyperFormula instance,
           // initialize it with the `'internal-use-in-handsontable'` license key
@@ -514,6 +515,12 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
                       
                       }}
                    >重做</Button>
+                   <Button variant="outlined" onClick={() => {
+                            console.log("save to cloud");
+                            loadingCallback();
+                      
+                      }}
+                   >保存</Button>
 
                   
                    </Stack>
@@ -682,6 +689,9 @@ export default function Qingdan({name, bh, bt, rgde, jxde, clde, beizhu, clickCa
                      </TabContext>
                   </Box>
                   </Stack>
+                  
+
+
 
 
 

+ 26 - 1
front/src/Service.js

@@ -41,7 +41,9 @@ class Service{
 
             x["key"] = x["序号"];
             x["children"] = x["children"].map(y=>{
-                y['key'] = uuidv4();
+                if (y.hasOwnProperty('key')) {
+                    y['key'] = uuidv4();
+                }
                 return y;
             })
             return x;
@@ -774,6 +776,29 @@ async generateQingdanTuijian(name, bh, bt, bm) {
     }
 
 
+    async save() {
+        const response = await fetch(this.ip().concat( ":8000/save/"), {
+            method : "POST",
+            headers: {
+                "Content-type": "application/json"
+            },
+            body: JSON.stringify(
+                {
+                    
+                    "name": JSON.stringify(this.cache)
+                }
+            )
+        });
+        if (!response.ok) {
+            //const error = await response.json();
+            console.error('error');
+        } else {
+            const data = await response.json();
+            return data;
+        }
+    }
+
+
 
 
     ///////////////////////////////////editor//////////////////////////////////

+ 8 - 0
main.py

@@ -422,6 +422,14 @@ async def read_singledexilie(r: SingleDingeXilieRequest):
     return json.dumps(result3, ensure_ascii=False)
 
 
+@app.post("/save/")
+async def save(r: Info):
+    data = json.loads(r.name)
+    print(data)
+ 
+    return await db.save(client, data)
+
+
 
 
 async def resolve(websocket, data):

+ 11 - 0
subdir/db.py

@@ -678,3 +678,14 @@ async def getDingercj(client, name, bh, bt, qdbm, debm):
             if child["清单编码"] == debm:
                 result = child["dercj"]
     return result
+
+
+async def save(client, data):
+    db = client["baojia"]
+    collection = db["qdxm"]
+    for entry in data:
+        entry["__children"] = entry["children"]
+        del entry["children"]
+        await collection.replace_one({"biao_id": entry["biao_id"], "Dwgcbh": entry["Dwgcbh"], "bt": entry["bt"], "清单编码": entry["清单编码"]}, entry)
+
+    return {"result": "ok"}

+ 1 - 1
test.py

@@ -404,7 +404,7 @@ for root, dirs, files in os.walk("/Users/xiaopengzhang/Downloads/qingdan/data",
         ##print(os.path.join(root, name))
         file_data = os.path.join(root, name)
         ttt.append(file_data)
-asyncio.run(resolve(ttt[2]))
+asyncio.run(resolve(ttt[0]))