Commit c8374d00487bff8dfa7a7e2e278d21215e0225df
1 parent
50f4ebce
feat(api) save form data to db
Showing
10 changed files
with
167 additions
and
2 deletions
back-end/h5-api/api/work/config/routes.json
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
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
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
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) |