作者 燕成杰

初始化接口

... ... @@ -17,6 +17,52 @@
@import "uview-ui/index.scss";
uni-page-head {
display:none !important;
}
/*每个页面公共css */
.wh100 {
width: 100%;
height: 100%;
}
.flexC {
display: flex;
justify-content: center;
align-items: center;
}
.flex {
display: flex;
}
.flexA {
display: flex;
align-items: center;
}
.fw700 {
font-weight: 700;
}
.flexwrap {
display: flex;
flex-wrap: wrap;
align-items: center;
}
.flexcolum {
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.serviceBtn {
opacity: 0;
position: absolute;
left: 0;
bottom: 0;
width: 120rpx;
height: 120rpx;
}
</style>
<style>
... ...
import {
request
} from '@/utils/request.js'
// xxx
export const getDetail = () => request({url: '/gift/gift/list',method: 'post',data: {}})
... ...
... ... @@ -150,7 +150,7 @@
],
"globalStyle": {
"navigationBarTextStyle": "black",
"navigationBarTitleText": "首页",
"navigationBarTitleText": "元届印象",
"navigationBarBackgroundColor": "#F8F8F8",
"backgroundColor": "#F8F8F8"
}
... ...
export const checkLogin = ()=>{
return uni.getStorageSync('token') || ''
}
\ No newline at end of file
... ...
export const baseURL = 'https://antifakeshop.brofirst.cn/api/'
export const request = (options) => {
return new Promise((resolve, reject) => {
uni.request({
url: baseURL + options.url, //接口地址:前缀+方法中传入的地址
method: options.method || 'GET', //请求方法:传入的方法或者默认是“GET”
data: options.data || {}, //传递参数:传入的参数或者默认传递空集合
header: {
'token': uni.getStorageSync("token") || "" //自定义请求头信息
},
success: (res) => {
console.log(res, uni.getStorageSync('token'));
//返回的数据(不固定,看后端接口,这里是做了一个判断,如果不为true,用uni.showToast方法提示获取数据失败)
if (res.data.code == 1) {
resolve(res.data.data)
} else {
if(res.data.code== 401){
uni.navigateTo({
url:'/login/login'
})
uni.clearStorageSync()
}
reject(res.data.msg)
}
// 如果不满足上述判断就输出数据
},
// 这里的接口请求,如果出现问题就输出接口请求失败
fail: (err) => {
console.log(err)
reject(err)
}
})
})
}
... ...
export const toast = (title)=> uni.showToast({title,icon:'none'})
export const success = (title)=> uni.showToast({title})
export const loading = (title)=> uni.showLoading({title:'加载中'})
export const hideLoading = ()=> uni.hideLoading()
export const toa = {
toast : (title) => uni.showToast({title,icon:'none'}),
success : (title)=> uni.showToast({title}),
loading : (title)=> uni.showLoading({title: title || '加载中',mask:true}),
hideLoading : ()=> uni.hideLoading(),
}
export const router = {
back : (num)=> uni.navigateBack({delta: num || 1})
}
\ No newline at end of file
... ...
import {baseURL} from './request.js'
import {toast,toa} from './toast.js'
export const uploadFile = (tempFilePaths,data)=>{
return new Promise((resolve, reject) => {
toa.loading('上传中..')
uni.uploadFile({
url: baseURL + '/common/upload', //仅为示例,非真实的接口地址
filePath: tempFilePaths,
name: 'file',
formData: {...data,token:uni.getStorageSync('token') || ''},
success: (res) => {
toa.hideLoading()
console.log(res);
if(res.statusCode==200){
// return res
resolve(JSON.parse(res.data).data)
}
},
fail:(err)=>{
toa.hideLoading()
toast(JSON.parse(err.data).msg)
console.log(err,'上传报错');
// return
reject(err)
}
})
})
}
\ No newline at end of file
... ...