diff --git a/common/api/account.js b/common/api/account.js index 7f555ec..9531aed 100644 --- a/common/api/account.js +++ b/common/api/account.js @@ -2,6 +2,23 @@ * @Author: ch * @Date: 2022-03-17 16:38:39 * @LastEditors: ch - * @LastEditTime: 2022-03-17 16:38:39 + * @LastEditTime: 2022-03-30 17:58:33 * @Description: file content */ + +import {ToAsyncAwait, Request} from '@/common/utils'; + +import orderList from '@/mock/orderList' + +const ApiGetCurrentUser = () => + ToAsyncAwait(Request.get('/user/current')); + +const ApiPutUser = (data) => + ToAsyncAwait(Request.put('/user/', data)) +export { + // 获取当前登录用户信息 + ApiGetCurrentUser, + // 修改用户信息 + ApiPutUser +} + diff --git a/common/api/order.js b/common/api/order.js index b6e516f..1b232c8 100644 --- a/common/api/order.js +++ b/common/api/order.js @@ -2,17 +2,27 @@ * @Author: ch * @Date: 2022-03-29 17:38:17 * @LastEditors: ch - * @LastEditTime: 2022-03-29 18:07:01 + * @LastEditTime: 2022-03-30 15:25:23 * @Description: file content */ import {ToAsyncAwait, Request} from '@/common/utils'; import orderList from '@/mock/orderList' -const ApiGetOrderList = (params) => ToAsyncAwait(new Promise((resolve)=>resolve(orderList.data))) - // ToAsyncAwait(Request.get('/app/tradeOrder/page', params)); +const ApiGetOrderList = (params) => + ToAsyncAwait(Request.get('/app/tradeOrder/page', params)); + +const ApiPostSubmitOrder = (data) => + ToAsyncAwait(Request.post('/app/tradeOrder/submitOrder', data)); + +const ApiPostWxPay = (data) => + ToAsyncAwait(Request.post('/pay/wxPay/app', data)); export { // 获取订单列表 - ApiGetOrderList + ApiGetOrderList, + // 提交订单 + ApiPostSubmitOrder, + // 获取支付参数 + ApiPostWxPay } \ No newline at end of file diff --git a/common/plugins/msbUniRequest.js b/common/plugins/msbUniRequest.js index 0e57e65..a74f58a 100644 --- a/common/plugins/msbUniRequest.js +++ b/common/plugins/msbUniRequest.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-03-17 16:36:59 * @LastEditors: ch - * @LastEditTime: 2022-03-28 18:16:44 + * @LastEditTime: 2022-03-30 10:14:44 * @Description: 针对uniapp request请求做了一次封装,使用思维参考axios * * @@ -78,7 +78,6 @@ class MsbUniRequest { this.hook[hookName] = cb; } get(url, data, header){ - console.log(data) return this.method({method : 'GET', url, data, header}); } post(url, data, header){ diff --git a/common/store/index.js b/common/store/index.js index a0bf63c..b4e6713 100644 --- a/common/store/index.js +++ b/common/store/index.js @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-03-22 18:28:52 * @LastEditors: ch - * @LastEditTime: 2022-03-29 11:08:32 + * @LastEditTime: 2022-03-30 16:58:03 * @Description: file content */ import Vue from 'vue' @@ -12,12 +12,17 @@ Vue.use(Vuex) export default new Vuex.Store({ state : { - token : uni.getStorageSync('tk') || '' + token : uni.getStorageSync('tk') || '', + userInfo : JSON.parse(uni.getStorageSync('ui') || '{}') }, mutations:{ SET_TOKEN (state, token = ''){ state.token = token; uni.setStorageSync('tk', token); + }, + SET_USER_INFO (state, userInfo = {}){ + state.userInfo = userInfo; + uni.setStorageSync('ui', JSON.stringify(userInfo)); } }, getters:{ diff --git a/common/utils/requset.js b/common/utils/requset.js index 05280fb..cf7d757 100644 --- a/common/utils/requset.js +++ b/common/utils/requset.js @@ -2,11 +2,13 @@ * @Author: ch * @Date: 2022-03-17 17:42:32 * @LastEditors: ch - * @LastEditTime: 2022-03-28 18:15:37 + * @LastEditTime: 2022-03-30 10:22:01 * @Description: 项目接口请求统一处理器,返回一个需要token和不需要token的请求封装方法 */ -const { default: MsbUniRequest } = require("../plugins/msbUniRequest"); +import MsbUniRequest from '@/common/plugins/msbUniRequest'; +import $store from '@/common/store'; + const ENV = 'test'; const BASE_URL = { // 'test' : 'http://39.103.236.147/api', @@ -15,7 +17,6 @@ const BASE_URL = { 'prod' : '' }; const successIntercept = (response) =>{ - console.log(response) if(response.statusCode === 200){ const result = response.data; if(result.code === 'SUCCESS'){ @@ -38,6 +39,7 @@ Request.baseUrl = BASE_URL[ENV]; Request.use('request', (option) => { + $store.state.token && (option.header = {...option.header, Authorization:$store.state.token}); return option; }) Request.use('success', successIntercept); @@ -46,11 +48,11 @@ Request.use('error', errorIntercept); // 需要token的接口 const RequestTk = new MsbUniRequest(); RequestTk.baseUrl = BASE_URL[ENV]; -Request.use('request', (option) => { +RequestTk.use('request', (option) => { return option; }) -Request.use('success', successIntercept); -Request.use('error', errorIntercept); +RequestTk.use('success', successIntercept); +RequestTk.use('error', errorIntercept); export { // 不需要Token的接口请求用这个实例 diff --git a/components/UiButton.vue b/components/UiButton.vue index cfaba35..cd0a4d2 100644 --- a/components/UiButton.vue +++ b/components/UiButton.vue @@ -2,7 +2,7 @@ * @Author: ch * @Date: 2022-03-26 10:06:38 * @LastEditors: ch - * @LastEditTime: 2022-03-29 18:20:53 + * @LastEditTime: 2022-03-30 15:12:56 * @Description: file content -->