From a2298b81696c40ae4367093ce822f8ff39e1fb3b Mon Sep 17 00:00:00 2001 From: huliyong <2783385703@qq.com> Date: Tue, 12 Nov 2024 11:10:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/api.js | 51 ++++++++-------------- api/http.js | 5 +-- api/model/order.js | 40 +++++++++++++++++ .../components/product/submitUnitSelect.vue | 1 + pages_order/order/order.vue | 2 +- pages_order/order/orderDetail.vue | 15 ++++++- utils/utils.js | 15 ++++++- 7 files changed, 91 insertions(+), 38 deletions(-) create mode 100644 api/model/order.js diff --git a/api/api.js b/api/api.js index 8e2e739..35fd363 100644 --- a/api/api.js +++ b/api/api.js @@ -1,4 +1,5 @@ import http from './http.js' +import utils from '../utils/utils.js' let limit = {} @@ -304,38 +305,13 @@ const config = { showLoading : true, }, - - // 商城-立即兑换商品 - createPointsOrder : { - url: '/city/createPointsOrder', - method: 'POST', - auth : true, - showLoading : true, - limit : 1000, - }, - // 商城-立即兑换商品,微信支付购买商品 - createOrder : { - url: '/city/createOrder', - method: 'POST', - auth : true, - showLoading : true, - limit : 1000, - }, - // 商城-订单列表 - getOrderList : { - url: '/city/getOrderList', - method: 'POST', - auth : true, - }, - // 商城-订单详情 - getOrderDetail : { - url: '/city/getOrderDetail', - method: 'POST', - auth : true, - }, } +const models = ['order'] +models.forEach(key => { + addApiModel(require(`./model/${key}.js`).default, key) +}) export function api(key, data, callback, loadingTitle) { let req = config[key] @@ -367,9 +343,7 @@ export function api(key, data, callback, loadingTitle) { //必须登录 if (req.auth) { if (!uni.getStorageSync('token')) { - uni.navigateTo({ - url: '/pages_order/auth/wxLogin' - }) + utils.toLogin() console.error('需要登录') return } @@ -404,4 +378,17 @@ export function api(key, data, callback, loadingTitle) { +function addApiModel(model, key){ + for(let k in model){ + if(config[`${k}`]){ + console.error(`重名api------model=${key},key=${k}`); + continue + } + config[`${k}`] = model[k] + // config[`${key}_${k}`] = model[k] + } +} + + + export default api \ No newline at end of file diff --git a/api/http.js b/api/http.js index 8f7078e..3c18457 100644 --- a/api/http.js +++ b/api/http.js @@ -1,5 +1,6 @@ import Vue from 'vue' +import utils from '../utils/utils.js' function http(uri, data, callback, method = 'GET', showLoading, title) { @@ -29,9 +30,7 @@ function http(uri, data, callback, method = 'GET', showLoading, title) { res.data.message == '操作失败,用户不存在!'){ uni.removeStorageSync('token') console.error('登录过期'); - uni.navigateTo({ - url: '/pages_order/auth/wxLogin' - }) + utils.toLogin() } if(res.statusCode == 200 && res.data.code != 200){ diff --git a/api/model/order.js b/api/model/order.js new file mode 100644 index 0000000..78093ab --- /dev/null +++ b/api/model/order.js @@ -0,0 +1,40 @@ + + +// 商城接口 + +const api = { + + // 商城-立即兑换商品 + createPointsOrder : { + url: '/order/createPointsOrder', + method: 'POST', + auth : true, + showLoading : true, + limit : 1000, + }, + + // 商城-立即兑换商品,微信支付购买商品 + createOrder : { + url: '/order/createOrder', + method: 'POST', + auth : true, + showLoading : true, + limit : 1000, + }, + + // 商城-订单列表 + getOrderList : { + url: '/order/getOrderList', + method: 'POST', + auth : true, + }, + + // 商城-订单详情 + getOrderDetail : { + url: '/order/getOrderDetail', + method: 'POST', + auth : true, + }, +} + +export default api \ No newline at end of file diff --git a/pages_order/components/product/submitUnitSelect.vue b/pages_order/components/product/submitUnitSelect.vue index 5f49eda..234c297 100644 --- a/pages_order/components/product/submitUnitSelect.vue +++ b/pages_order/components/product/submitUnitSelect.vue @@ -204,6 +204,7 @@ } this.$api('createPointsOrder', data, res => { + // this.$api('order_createPointsOrder', data, res => { if(res.code == 200){ uni.redirectTo({ diff --git a/pages_order/order/order.vue b/pages_order/order/order.vue index 936205f..01908c5 100644 --- a/pages_order/order/order.vue +++ b/pages_order/order/order.vue @@ -11,7 +11,7 @@ lineColor="#FD5100" lineHeight="8rpx" lineWidth="50rpx" - :scrollable="true" + :scrollable="false" @click="clickTabs"> diff --git a/pages_order/order/orderDetail.vue b/pages_order/order/orderDetail.vue index d06ffba..4bed699 100644 --- a/pages_order/order/orderDetail.vue +++ b/pages_order/order/orderDetail.vue @@ -241,10 +241,23 @@ createTime : '2024-01-18 15:39', projectName : '桌布租赁' }, + id : 0, } }, + onLoad(args) { + this.id = args.id + }, + onShow() { + this.getDetail() + }, methods: { - + getDetail(){ + this.$api('getOrderDetail', { + id : this.id + }, res => { + + }) + }, } } diff --git a/utils/utils.js b/utils/utils.js index a827c38..2b07dde 100644 --- a/utils/utils.js +++ b/utils/utils.js @@ -178,6 +178,18 @@ export function navigateBack(num = -1){ export function redirectTo(...args){ uni.redirectTo(params(...args)) } +export const toLogin = function(){ + let time = 0 + return () => { + if(new Date().getTime() - time < 1000){ + return + } + time = new Date().getTime() + uni.navigateTo({ + url: '/pages_order/auth/wxLogin' + }) + } +}() export default { toArray, @@ -192,5 +204,6 @@ export default { navigateBack, redirectTo, copyText, - stringFormatHtml + stringFormatHtml, + toLogin } \ No newline at end of file