简单封装uniapp接口 (是按需引入的)

40 篇文章 0 订阅
27 篇文章 0 订阅
//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)
				}
			},

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

呱嗨喵

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值