Ver código fonte

Merge remote-tracking branch 'origin/master'

Csy817 7 anos atrás
pai
commit
082a57d119

+ 1 - 2
src/case/ShopApp/src/App.css

@@ -11,7 +11,6 @@
     width: 300px;
     height: 534px;
     overflow: hidden;
-    padding: 15px 0;
     overflow-x: hidden;
     overflow-y: hidden;
     background:#fff;
@@ -38,7 +37,7 @@ p.p1,p.p2,p.p3{
 .pageWrap{
     margin-top: 45px;
     background: #ffffff;
-    border: 2px solid red;
+    /*border: 2px solid red;*/
     height: 100%;
 }
 

+ 15 - 1
src/case/ShopApp/src/components/ProductDetailPage/Card.css

@@ -1,5 +1,5 @@
 .card {
-    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2);
+    box-shadow: 0 0px 2px 0 rgba(0,0,0,0.2);
     transition: 0.3s;
     width: 100%;
     border-radius: 5px;
@@ -8,5 +8,19 @@
 
 
 .container {
+    position: relative;
     padding: 2px 16px;
+    padding-top: 10px;
+}
+
+.price{
+    position: absolute;
+    top: 10px;
+    right: 10px;
+    color: red;
+    
+}
+
+.footer{
+    padding: 5px 0;
 }

+ 5 - 1
src/case/ShopApp/src/components/ProductDetailPage/Card.jsx

@@ -27,7 +27,11 @@ export default class Card extends Component{
                 <img src={product.img} alt="Avatar" style={{width:"100%",height:'200px'}}/>
                 <div className="container">
                     <h4>{product.name}</h4> 
-                    <p>www.runoob.com</p> 
+                    <p>{product.intro}</p>
+                    <span className="price">¥{product.price}</span>
+                    <div className="footer">
+                        <span>剩余:{product.stock}</span>
+                    </div>
                 </div>
             </div>
         )

+ 20 - 16
src/components/common/schema/Schema.jsx

@@ -35,7 +35,8 @@ class Schema extends Component {
             editSchemaName: '',
             data: '',
             page: '',
-            pageSize: ''
+            pageSize: '',
+            once: 0
         };
     }
 
@@ -84,7 +85,6 @@ class Schema extends Component {
         })
     };
 
-
     fetchData = (referenceID) => {
         let schemaData;
         if (localStorage.getItem('ecommerce') && localStorage.getItem('bills') && localStorage.getItem('subscribe')) {
@@ -151,7 +151,8 @@ class Schema extends Component {
             currentTable: next.location.state === undefined ? '' : next.location.state.create ? 'add' : '',
             schemaID: next.schemaID,
             schemaName: next.schemaName,
-            data: ''
+            data: '',
+            once: 0
         });
     }
 
@@ -171,9 +172,23 @@ class Schema extends Component {
                         }
 
                         // let schemaName = data.schema_by_id.schemaName;
+                        let reference = data.schema_by_id.reference;
 
                         if (data.schema_by_id === null) data = [];
-                        else data = JSON.parse(data.schema_by_id.schemaData);
+                        else {
+                            data = JSON.parse(data.schema_by_id.schemaData);
+                            if (data.length === 0 && reference !== '' && this.state.once === 0) {
+                                this.fetchData(reference).then((data) => {
+                                    // 会执行好多好多次
+                                    this.setState({
+                                        data: JSON.parse(data),
+                                        once: 1
+                                    })
+                                });
+
+                            }
+
+                        }
 
                         return (
                             <div>
@@ -409,18 +424,7 @@ class CopySchemaButton extends Component {
             <div>
                 <Mutation
                     mutation={gql(ADD_SCHEMA)}
-                    update={(cache, {data: {create_schema}}) => {
-                        let data = cache.readQuery({query: gql(SHOW_SCHEMA), variables: {user_id: userID}});
-                        let trialCaseSchemaData = cache.readQuery({query: gql(SHOW_SCHEMA), variables: {user_id: 'ioobot'}});
-                        let index = schemaName === 'subscribe'? 0: 'bills' ? 1: 2;
-                        // console.log('trial-case-schemadata', trialCaseSchemaData);
-                        // console.log('create-schemadata', create_schema.schemaData);
-                        create_schema.schemaData = trialCaseSchemaData.schema_by_props[index].schemaData;
-                        // console.log('create-schemadata-after-modify', create_schema.schemaData);
-                        data.schema_by_props.push(create_schema);
-                        cache.writeQuery({query: gql(SHOW_SCHEMA), variables: {user_id: userID}, data});
-                        console.log(cache);
-                    }}
+                    refetchQueries={[{query: gql(SHOW_SCHEMA), variables: {user_id: userID}}]}
                 >
                     {(create_schema, {loading, error}) => {
                         if (loading)

+ 1 - 0
src/components/gql.js

@@ -149,6 +149,7 @@ const SHOW_TABLE = `
                 schema_by_id(id: $schema_id) {
                     schemaData
                     schemaName
+                    reference
                 }
             }
         `;