//https.js文件内
//用BASEURL来表示域名地址
// const BASE_URL = ""
const BASE_URL = ""
//封装请求方法
export const myRequest = (url, data, method,sum) => {
let header = ""
if (method == "POST") {
header = "'content-type': 'application/json;charset:utf-8'"
} else {
header = ""
}
// let token = this.$time.get('token')
// if(sum!==1 &&token!==undefined){
// uni.redirectTo({
// url: "/pages//login/login"
// })
// }
return new Promise((resolve, reject) => {
//请求路径拼接,,其中options.url就是通过下面方法myRequest获取到接口部分的url
//method--请求方法,不是method的post就是get
//请求的参数,当没有参数的时候就是空对象\
let urls = BASE_URL + url
// console.log("地址", urls)
uni.request({
url:urls.replace (/\s*/g,"") ,
method: method || 'GET',
data: data || {},
header: {
header,
// token,
},
success: (res) => {
resolve(res)
},
//请求失败
fail: (err) => {
// uni.showToast({
// title: '请求接口失败'
// })
reject(err)
}
})
})
}
//引入封装的https.js封装的接口在index.js (api/https.js“api是文件夹”)
import {
myRequest
} from '@/api/https.js'
//验证码
export const doSendSms = (data) => {
return myRequest(" /WeixinSwapApi/doSendSms", data, "get",2)
}
//登录
export const apiLogin = (data) => {
return myRequest("/WeixinSwapApi/login", data, "get",2)
}
//首页兑换数据汇总
export const mysumdata = (data) => {
return myRequest("/WeixinSwapApi/mysumdata", data, "get",1)
}
//业务员扫码详情
export const scanfordetail = (data) => {
return myRequest("/WeixinSwapApi/scanfordetail", data, "get",1)
}
//确认码兑换
export const doswap = (data) => {
return myRequest("/WeixinSwapApi/doswap", data, "get",1)
}
//数据统计
export const getswaptotal = (data) => {
return myRequest("/WeixinSwapApi/getswaptotal", data, "get",1)
}
//数据统计明细
export const getswapdetail = (data) => {
return myRequest("/WeixinSwapApi/getswapdetail", data, "get",1)
}
//正常使用
//引入你封装的接口地址字段名
iimport { scanfordetail,doSendSms } from "@/api/index.js"
doSendSms() {
doSendSms({
...this.info
}).then((res) => {
if (res.data.code == 0) {
console.log("成功", res)
}
})
},
async scanfordetail() {
let res = await scanfordetail({
token: uni.getStorageSync('token'),
code: this.info.code
})
if (res.data.code == 0) {
this.info={
productimg: res.data.data.productimg,
product_name: res.data.data.product_name,
code: this.info.code
}
} else{
this.$u.toast(res.data.msg)
}
},