Commit c8374d00487bff8dfa7a7e2e278d21215e0225df

Authored by ly525
1 parent 50f4ebce

feat(api) save form data to db

back-end/h5-api/api/work/config/routes.json
@@ -55,6 +55,14 @@ @@ -55,6 +55,14 @@
55 "config": { 55 "config": {
56 "policies": [] 56 "policies": []
57 } 57 }
  58 + },
  59 + {
  60 + "method": "POST",
  61 + "path": "/works/form/submit/:id",
  62 + "handler": "Work.submitForm",
  63 + "config": {
  64 + "policies": []
  65 + }
58 } 66 }
59 ] 67 ]
60 } 68 }
back-end/h5-api/api/work/controllers/Work.js
@@ -11,5 +11,14 @@ module.exports = { @@ -11,5 +11,14 @@ module.exports = {
11 previewOne: async (ctx) => { 11 previewOne: async (ctx) => {
12 const work = await strapi.services.work.findOne(ctx.params); 12 const work = await strapi.services.work.findOne(ctx.params);
13 return ctx.render('engine', { work }); 13 return ctx.render('engine', { work });
14 - } 14 + },
  15 + submitForm: async (ctx) => {
  16 + const work = await strapi.services.work.findOne(ctx.params);
  17 + const formData = ctx.request.body.fields;
  18 + // eslint-disable-next-line no-unused-vars
  19 + const workform = await strapi.services.workform.create({ form: formData, work });
  20 +
  21 + // eslint-disable-next-line require-atomic-updates
  22 + ctx.body = { message: 'success', status: 0 };
  23 + },
15 }; 24 };
back-end/h5-api/api/work/models/Work.settings.json
@@ -37,6 +37,9 @@ @@ -37,6 +37,9 @@
37 }, 37 },
38 "pages": { 38 "pages": {
39 "type": "json" 39 "type": "json"
  40 + },
  41 + "formData": {
  42 + "type": "json"
40 } 43 }
41 } 44 }
42 } 45 }
43 \ No newline at end of file 46 \ No newline at end of file
back-end/h5-api/api/workform/config/routes.json 0 → 100644
  1 +{
  2 + "routes": [
  3 + {
  4 + "method": "GET",
  5 + "path": "/workforms",
  6 + "handler": "Workform.find",
  7 + "config": {
  8 + "policies": []
  9 + }
  10 + },
  11 + {
  12 + "method": "GET",
  13 + "path": "/workforms/count",
  14 + "handler": "Workform.count",
  15 + "config": {
  16 + "policies": []
  17 + }
  18 + },
  19 + {
  20 + "method": "GET",
  21 + "path": "/workforms/:id",
  22 + "handler": "Workform.findOne",
  23 + "config": {
  24 + "policies": []
  25 + }
  26 + },
  27 + {
  28 + "method": "POST",
  29 + "path": "/workforms",
  30 + "handler": "Workform.create",
  31 + "config": {
  32 + "policies": []
  33 + }
  34 + },
  35 + {
  36 + "method": "PUT",
  37 + "path": "/workforms/:id",
  38 + "handler": "Workform.update",
  39 + "config": {
  40 + "policies": []
  41 + }
  42 + },
  43 + {
  44 + "method": "DELETE",
  45 + "path": "/workforms/:id",
  46 + "handler": "Workform.delete",
  47 + "config": {
  48 + "policies": []
  49 + }
  50 + }
  51 + ]
  52 +}
back-end/h5-api/api/workform/controllers/Workform.js 0 → 100644
  1 +'use strict';
  2 +
  3 +/**
  4 + * Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/guides/controllers.html#core-controllers)
  5 + * to customize this controller
  6 + */
  7 +
  8 +module.exports = {};
back-end/h5-api/api/workform/models/Workform.js 0 → 100644
  1 +'use strict';
  2 +
  3 +/**
  4 + * Lifecycle callbacks for the `Workform` model.
  5 + */
  6 +
  7 +module.exports = {
  8 + // Before saving a value.
  9 + // Fired before an `insert` or `update` query.
  10 + // beforeSave: async (model, attrs, options) => {},
  11 +
  12 + // After saving a value.
  13 + // Fired after an `insert` or `update` query.
  14 + // afterSave: async (model, response, options) => {},
  15 +
  16 + // Before fetching a value.
  17 + // Fired before a `fetch` operation.
  18 + // beforeFetch: async (model, columns, options) => {},
  19 +
  20 + // After fetching a value.
  21 + // Fired after a `fetch` operation.
  22 + // afterFetch: async (model, response, options) => {},
  23 +
  24 + // Before fetching all values.
  25 + // Fired before a `fetchAll` operation.
  26 + // beforeFetchAll: async (model, columns, options) => {},
  27 +
  28 + // After fetching all values.
  29 + // Fired after a `fetchAll` operation.
  30 + // afterFetchAll: async (model, response, options) => {},
  31 +
  32 + // Before creating a value.
  33 + // Fired before an `insert` query.
  34 + // beforeCreate: async (model, attrs, options) => {},
  35 +
  36 + // After creating a value.
  37 + // Fired after an `insert` query.
  38 + // afterCreate: async (model, attrs, options) => {},
  39 +
  40 + // Before updating a value.
  41 + // Fired before an `update` query.
  42 + // beforeUpdate: async (model, attrs, options) => {},
  43 +
  44 + // After updating a value.
  45 + // Fired after an `update` query.
  46 + // afterUpdate: async (model, attrs, options) => {},
  47 +
  48 + // Before destroying a value.
  49 + // Fired before a `delete` query.
  50 + // beforeDestroy: async (model, attrs, options) => {},
  51 +
  52 + // After destroying a value.
  53 + // Fired after a `delete` query.
  54 + // afterDestroy: async (model, attrs, options) => {}
  55 +};
back-end/h5-api/api/workform/models/Workform.settings.json 0 → 100644
  1 +{
  2 + "connection": "default",
  3 + "collectionName": "workforms",
  4 + "info": {
  5 + "name": "workform",
  6 + "description": ""
  7 + },
  8 + "options": {
  9 + "increments": true,
  10 + "timestamps": true,
  11 + "comment": ""
  12 + },
  13 + "attributes": {
  14 + "form": {
  15 + "type": "json"
  16 + },
  17 + "work": {
  18 + "model": "work"
  19 + }
  20 + }
  21 +}
0 \ No newline at end of file 22 \ No newline at end of file
back-end/h5-api/api/workform/services/Workform.js 0 → 100644
  1 +'use strict';
  2 +
  3 +/**
  4 + * Read the documentation (https://strapi.io/documentation/3.0.0-beta.x/guides/services.html#core-services)
  5 + * to customize this service
  6 + */
  7 +
  8 +module.exports = {};
front-end/h5/src/components/core/editor/canvas/edit.js
@@ -181,7 +181,7 @@ export default { @@ -181,7 +181,7 @@ export default {
181 return ( 181 return (
182 <Shape 182 <Shape
183 style={element.getStyle({ position: 'absolute' })} 183 style={element.getStyle({ position: 'absolute' })}
184 - defaultPosition={element.commonStyle} 184 + defaultPosition={element.commonStyle} // {top, left}
185 element={element} 185 element={element}
186 active={this.editingElement === element} 186 active={this.editingElement === element}
187 handleMousedownProp={() => { 187 handleMousedownProp={() => {
front-end/h5/src/store/modules/work.js
@@ -61,6 +61,7 @@ export const mutations = { @@ -61,6 +61,7 @@ export const mutations = {
61 state.works = works 61 state.works = works
62 }, 62 },
63 setWork (state, work) { 63 setWork (state, work) {
  64 + window.__work = work
64 work.pages = work.pages.map(page => { 65 work.pages = work.pages.map(page => {
65 page.elements = page.elements.map(element => new Element(element)) 66 page.elements = page.elements.map(element => new Element(element))
66 return new Page(page) 67 return new Page(page)