|
|
- import http from './http.js'
-
-
- let limit = {}
- let debounce = {}
-
- const config = {
- // 示例
- // wxLogin : {url : '/api/wxLogin', method : 'POST',
- // auth : false, showLoading : true, loadingTitle : '加载中...',
- // limit : 1000
- // },
-
- getConfig: {url: '/api/getConfig', method: 'GET', limit: 500},
-
-
- // 微信登录接口
- wxLogin: {
- url: '/login/login',
- method: 'POST',
- limit: 500,
- showLoading: true,
- },
- // 修改个人信息接口
- updateInfo: {
- url: '/info/updateInfo',
- method: 'POST',
- auth: true,
- limit: 500,
- showLoading: true,
- },
- //隐私政策
- getPrivacyPolicy: {
- url: '/login/getPrivacyPolicy',
- method: 'GET',
- },
- //用户协议
- getUserAgreement: {
- url: '/login/getUserAgreement',
- method: 'GET',
- },
-
- // ========================用户登录注册===============================
- //用户登录
- loginUser: {
- url: '/alUser/login',
- method: 'POST',
- },
- //用户注册
- registerUser: {
- url: '/alUser/regUesr',
- method: 'POST',
- },
- // 发送短信接口
- sendSms: {
- url: '/alUser/sendSms',
- method: 'POST',
- },
- // 选择身份
- roleOption: {
- url: '/alUser/role',
- method: 'POST',
- },
-
- // ========================产品报价===============================
- // 清关申请
- addCustoms: {
- url: '/product/addCustoms',
- method: 'POST',
- },
- // 产品报价
- addProduct: {
- url: '/product/addProduct',
- method: 'POST',
- },
- // 下订单
- addProductOrder: {
- url: '/product/addProductOrder',
- method: 'POST',
- },
- // 我的挂单列表
- getMyProductlist: {
- url: '/product/myProductlist',
- method: 'GET',
- },
- // 撤单
- noShow: {
- url: '/product/noShow',
- method: 'GET',
- },
- // 产品报价分页列表
- productList: {
- url: '/product/productList',
- method: 'GET',
- },
- // 交易平台挂单列表
- productlist: {
- url: '/product/productList',
- method: 'GET',
- },
- // ========================用户地址===============================
- // 用户地址表-添加
- addAddress: {
- url: '/address/add',
- method: 'POST',
- },
- // 用户地址表-编辑
- editAddress: {
- url: '/address/add',
- method: 'POST',
- },
- // 用户地址表-分页列表查询
- addressList: {
- url: '/address/list',
- method: 'GET',
- },
- // ========================首页等展示接口===============================
- // 帮助与反馈
- addSuggest: {
- url: '/index/addSuggest',
- method: 'POST',
- },
- // 铝价接口
- getAlPrice: {
- url: '/index/alprice',
- method: 'POST',
- },
- // 我的头像昵称,平台客户电话等信息
- getImagePhoneOther: {
- url: '/index/index',
- method: 'POST',
- },
-
-
- }
-
-
- export function api(key, data, callback, loadingTitle) {
- let req = config[key]
-
- if (!req) {
- console.error('无效key' + key);
- return
- }
-
- if (typeof callback == 'string') {
- loadingTitle = callback
- }
-
- if (typeof data == 'function') {
- callback = data
- data = {}
- }
-
- // 接口限流
- if (req.limit) {
- let storageKey = req.url
- let storage = limit[storageKey]
- if (storage && new Date().getTime() - storage < req.limit) {
- return
- }
- limit[storageKey] = new Date().getTime()
- }
-
- //必须登录
- if (req.auth) {
- if (!uni.getStorageSync('token')) {
- uni.navigateTo({
- url: '/pages_order/auth/wxLogin'
- })
- console.error('需要登录')
- return
- }
- }
-
- // 接口防抖
- 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)
- }
-
-
- export default api
|