diff --git a/api/api.js b/api/api.js index 56ad30e..7df253e 100644 --- a/api/api.js +++ b/api/api.js @@ -1,5 +1,9 @@ import http from './http.js' + +let limit = {} +let debounce = {} + const config = { // 示例 // wxLogin : {url : '/api/wxLogin', method : 'POST', @@ -30,46 +34,69 @@ const config = { -export function api(key, data, callback, loadingTitle){ +export function api(key, data, callback, loadingTitle) { let req = config[key] - + if (!req) { console.error('无效key' + key); return } - - if(typeof callback == 'string'){ + + if (typeof callback == 'string') { loadingTitle = callback } - - if(typeof data == 'function'){ + + if (typeof data == 'function') { callback = data data = {} } - + // 接口限流 - if(req.limit){ - let storageKey = 'limit:' + req.url - let storage = uni.getStorageSync(storageKey) - if(storage && new Date().getTime() - parseInt(storage) < req.limit){ + if (req.limit) { + let storageKey = req.url + let storage = limit[storageKey] + if (storage && new Date().getTime() - storage < req.limit) { return } - uni.setStorageSync(storageKey, new Date().getTime()) + limit[storageKey] = new Date().getTime() } - + //必须登录 if (req.auth) { if (!uni.getStorageSync('token')) { uni.navigateTo({ - url: '/pages/login/mobile' + url: '/pages_order/auth/wxLogin' }) console.error('需要登录') return } } - http.http(req.url, data, callback, req.method, - loadingTitle || req.showLoading, loadingTitle || req.loadingTitle) + // 接口防抖 + if(req.debounce){ + + let storageKey = req.url + let storage = debounce[storageKey] + + if (storage) { + clearTimeout(storage) + } + + debounce[storageKey] = setTimeout(() => { + + clearTimeout(storage) + + delete debounce[storageKey] + + http.http(req.url, data, callback, req.method, + loadingTitle || req.showLoading, loadingTitle || req.loadingTitle) + }, req.debounce) + + return + } + + http.http(req.url, data, callback, req.method, + loadingTitle || req.showLoading, loadingTitle || req.loadingTitle) } diff --git a/pages_order/components/address/addressList.vue b/pages_order/components/address/addressList.vue index 489449f..a296dad 100644 --- a/pages_order/components/address/addressList.vue +++ b/pages_order/components/address/addressList.vue @@ -1,52 +1,67 @@ diff --git a/pages_order/components/address/redactAddress.vue b/pages_order/components/address/redactAddress.vue index 1775a92..e11d971 100644 --- a/pages_order/components/address/redactAddress.vue +++ b/pages_order/components/address/redactAddress.vue @@ -1,126 +1,140 @@ diff --git a/pages_order/mine/address.vue b/pages_order/mine/address.vue index c5f9ba8..d76d7e1 100644 --- a/pages_order/mine/address.vue +++ b/pages_order/mine/address.vue @@ -3,77 +3,22 @@ - - + + @editAddress="editAddress" + @editDefault="editDefault"/> - - - - - - - + :addressDetail="addressDetail" + @saveOrUpdate="saveOrUpdate" + :title="title"> + @@ -86,7 +31,6 @@ @@ -355,115 +158,6 @@ .address-list { padding: 40rpx 20rpx 120rpx 20rpx; - - // .address-item { - // background: white; - // border-radius: 20rpx; - // overflow: hidden; - // margin-bottom: 20rpx; - // padding: 15rpx 15rpx 0rpx 15rpx; - // width: 680rpx; - - // .address-item-top { - // border-bottom: 1px dashed #D3D1D1; - // display: flex; - // align-items: center; - // padding: 0rpx 0rpx 15rpx 0rpx; - - // .img-box { - // width: 120rpx; - // height: 120rpx; - - // image { - // width: 75%; - // height: 75%; - // display: block; - // margin: 12.5% auto; - // } - // } - - // .address-info { - // width: calc(100% - 120rpx); - // height: 100%; - // display: flex; - // flex-direction: column; - // justify-content: space-between; - - // .user-info { - // display: flex; - // align-items: center; - - // text { - // display: block; - // line-height: 40rpx; - // margin-right: 20rpx; - // } - - // .user-name, - // .user-phone { - // font-size: 30rpx; - // } - - // .is-default { - // display: flex; - // align-items: center; - // justify-content: center; - // background: #FEB773; - // color: white; - // width: 80rpx; - // height: 35rpx; - // border-radius: 20rpx; - // font-size: 22rpx; - // } - // } - - // .address-detail { - // color: #4a4a4a; - // font-size: 26rpx; - // overflow: hidden; - // display: -webkit-box; - // -webkit-box-orient: vertical; - // -webkit-line-clamp: 2; - // text-overflow: ellipsis; - // } - // } - // } - - // .controls { - // display: flex; - // align-items: center; - // justify-content: space-between; - // align-items: center; - // font-size: 26rpx; - // padding: 15rpx 15rpx 25rpx 15rpx; - - // .default-checkbox { - // display: flex; - - // text { - // margin-left: 8rpx; - // } - // } - - // .control-title { - // height: 30rpx; - // line-height: 30rpx; - // color: #666666; - // } - - // view { - // display: flex; - // align-items: center; - // } - - // image { - // width: 23rpx; - // height: 23rpx; - // vertical-align: middle; - // margin-right: 8rpx; - // } - // } - // } } .add-btn {