From e2eaa8a22bf7709ba95bc19172c2c85dc8e4c944 Mon Sep 17 00:00:00 2001 From: mullins <476823686@qq.com> Date: Mon, 11 May 2020 19:26:31 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AF=B7=E6=B1=82=E5=9C=B0=E5=9D=80=E6=8F=90?= =?UTF-8?q?=E5=8F=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/store/modules/myOrder.js | 41 ++++++++++++++++++++++++++++++ src/store/modules/test.js | 59 +++++++++++++++++++++++++++++--------------- src/store/request.js | 24 ++++++++++++++++++ src/store/url.js | 6 +++++ 4 files changed, 110 insertions(+), 20 deletions(-) create mode 100644 src/store/modules/myOrder.js create mode 100644 src/store/request.js create mode 100644 src/store/url.js diff --git a/src/store/modules/myOrder.js b/src/store/modules/myOrder.js new file mode 100644 index 0000000..7afe72b --- /dev/null +++ b/src/store/modules/myOrder.js @@ -0,0 +1,41 @@ +const state = { + orderList: [], +}; + +const mutations = { + getOrder: (state, data) => { + state.orderList = data; + }, +}; + +const actions = { + fetch({ commit }, param) { + uni + .request({ + url: "", + method: "post", + data: {}, + header: { + "Content-Type": "application/x-www-form-urlencoded", + }, + timeout: 3000, + withCredentials: false, + success: (res) => { + commit('getOrder', res.data.data) + }, + fail: (res) => { + console.log("fail status === > ", res); + }, + complete: (res) => { + console.log("complete status === > ", res); + } + }) + } +} + +export default { + namespaced: true, + state, + mutations, + actions, +} \ No newline at end of file diff --git a/src/store/modules/test.js b/src/store/modules/test.js index 8bedb5d..9f66495 100644 --- a/src/store/modules/test.js +++ b/src/store/modules/test.js @@ -1,3 +1,10 @@ + import urlAlias from '../url'; + import request from '../request'; + + const { + shopList + } = urlAlias; + const state = { list: [], }; @@ -10,26 +17,38 @@ const mutations = { const actions = { fetch({ commit }, param) { - uni - .request({ - url: "https://api.glass.xiuyetang.com/app/prod/list", - method: "post", - data: {}, - header: { - "Content-Type": "application/x-www-form-urlencoded", - }, - timeout: 3000, - withCredentials: false, - success: (res) => { - commit('INIT', res.data.data) - }, - fail: (res) => { - console.log("fail status === > ", res); - }, - complete: (res) => { - console.log("complete status === > ", res); - }, - }); + request({ + url: shopList, + success: (res) => { + commit('INIT', res.data.data) + }, + fail: (res) => { + console.log("fail status === > ", res); + }, + complete: (res) => { + console.log("complete status === > ", res); + }, + }) + // uni + // .request({ + // url: "https://api.glass.xiuyetang.com/app/prod/list", + // method: "post", + // data: {}, + // header: { + // "Content-Type": "application/x-www-form-urlencoded", + // }, + // timeout: 3000, + // withCredentials: false, + // success: (res) => { + // commit('INIT', res.data.data) + // }, + // fail: (res) => { + // console.log("fail status === > ", res); + // }, + // complete: (res) => { + // console.log("complete status === > ", res); + // }, + // }); }, }; diff --git a/src/store/request.js b/src/store/request.js new file mode 100644 index 0000000..2e3300c --- /dev/null +++ b/src/store/request.js @@ -0,0 +1,24 @@ +const DOMAIN = 'https://api.glass.xiuyetang.com/'; + +export default async function request({ + url, + success, + fail, + complete, +}) { + console.log("DOMAIN", DOMAIN, url); + uni + .request({ + url: DOMAIN + url, + method: "post", + data: {}, + header: { + "Content-Type": "application/x-www-form-urlencoded", + }, + timeout: 3000, + withCredentials: false, + success, + fail, + complete, + }) +} \ No newline at end of file diff --git a/src/store/url.js b/src/store/url.js new file mode 100644 index 0000000..96225a3 --- /dev/null +++ b/src/store/url.js @@ -0,0 +1,6 @@ +const urlAlias = { + // 获取首页商品列表 + shopList: 'app/prod/list', +} + +export default urlAlias; -- 2.0.0