From 888c45b0e09e6289221d9173f8dd34f957c59f03 Mon Sep 17 00:00:00 2001 From: Bowen Date: Fri, 5 Oct 2018 18:41:24 +0800 Subject: [PATCH] feat: all submitting logic for step-form --- mock/server/config/routes.js | 23 +++++++++++++++ src/services/index.js | 4 +++ src/services/routes.js | 4 ++- src/store/modules/formStep/actions.js | 17 +++++++++++ src/store/modules/formStep/index.js | 4 ++- src/view/Form/Step/Confirm.vue | 42 ++++++++++++++++----------- 6 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 src/store/modules/formStep/actions.js diff --git a/mock/server/config/routes.js b/mock/server/config/routes.js index 02656ed..1721512 100644 --- a/mock/server/config/routes.js +++ b/mock/server/config/routes.js @@ -38,5 +38,28 @@ module.exports = { status: 'error', currentAuthority: 'guest' }) + }, + + 'POST /api/form/step': (req, res) => { + const { + payAccount, + receiverAccount, + receiverType, + receiverName, + amount, + password + } = req.body + if (password === 'admin') { + res.send({ + errno: 0, + status: 'ok' + }) + } else { + res.send({ + errno: 1, + status: 'error', + message: 'Invalid username or password' + }) + } } } diff --git a/src/services/index.js b/src/services/index.js index 93e9635..85105a7 100644 --- a/src/services/index.js +++ b/src/services/index.js @@ -5,6 +5,10 @@ export function userLogin (token) { return baseRequest.post(routes.USER_TOKEN, token) } +export function pushStepForm (formData) { + return baseRequest.post(routes.STEP_FORM, formData) +} + export function fetchAllAnalysis () { return baseRequest.get(routes.ANALYSIS) } diff --git a/src/services/routes.js b/src/services/routes.js index e182ef4..998d5df 100644 --- a/src/services/routes.js +++ b/src/services/routes.js @@ -6,6 +6,8 @@ export const baseURL = isDevMode export const USER_TOKEN = '/login' +export const CURRENT_USER = '/user' + export const ANALYSIS = '/analysis' export const WORKSPACE = '/workspace' @@ -18,4 +20,4 @@ export const WORKSPACE_RADAR = '/workspace/radar' export const WORKSPACE_TEAMS = '/workspace/teams' -export const CURRENT_USER = '/user' +export const STEP_FORM = '/form/step' diff --git a/src/store/modules/formStep/actions.js b/src/store/modules/formStep/actions.js new file mode 100644 index 0000000..9a3c93b --- /dev/null +++ b/src/store/modules/formStep/actions.js @@ -0,0 +1,17 @@ +import { pushStepForm } from 'SERVICES' + +export default { + // Should secure password to transport (under HTTPS protocol) + // eg. md5(salt + form['password']) + pushStepForm ({ commit, state }, password) { + return pushStepForm({ + ...state.form, + password + }) + .then(res => res.data) + .then(res => { + if (res.errno !== 0) throw new Error(`[pushStepForm]: ${res.message}`) + return res + }) + } +} diff --git a/src/store/modules/formStep/index.js b/src/store/modules/formStep/index.js index 5d12cee..c5d475e 100644 --- a/src/store/modules/formStep/index.js +++ b/src/store/modules/formStep/index.js @@ -1,7 +1,9 @@ import state from './state' import mutations from './mutations' +import actions from './actions' export default { state, - mutations + mutations, + actions } diff --git a/src/view/Form/Step/Confirm.vue b/src/view/Form/Step/Confirm.vue index 2042b6d..71c9c7b 100644 --- a/src/view/Form/Step/Confirm.vue +++ b/src/view/Form/Step/Confirm.vue @@ -46,21 +46,19 @@ type="primary" :loading="loading" @click="onSubmit" - >{{submitText}} - {{cancelText}} + >{{text.submit}} + {{text.cancel}}