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;