parent
f32f1e1cae
commit
fe0dd8ad75
@ -0,0 +1,5 @@
|
||||
import http from '../common/http.js'
|
||||
//分类数据
|
||||
export const getCategoryListApi = () => {
|
||||
return http.get("/wxapi/category/getCategoryList")
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
import http from '../common/http.js'
|
||||
//轮播图
|
||||
export const getSwipperListApi = ()=>{
|
||||
return http.get("/api/home/getSwipperList")
|
||||
}
|
||||
//首页热推
|
||||
export const getHotListApi = ()=>{
|
||||
return http.get("/api/home/getHotList")
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
import http from '../common/http.js'
|
||||
//获取code
|
||||
export const getCode = () => {
|
||||
const promise = new Promise((resolve, reject) => {
|
||||
uni.login({
|
||||
provider: 'weixin', //使用微信登录
|
||||
success: function(loginRes) {
|
||||
console.log('8888888888')
|
||||
console.log(loginRes.code);
|
||||
//如果返回数据
|
||||
if (loginRes && loginRes.code) {
|
||||
//数据返回
|
||||
resolve(loginRes.code)
|
||||
} else {
|
||||
reject(loginRes)
|
||||
}
|
||||
}
|
||||
})
|
||||
}).catch(res => {
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: res.errMsg || '获取code失败!'
|
||||
})
|
||||
})
|
||||
return promise;
|
||||
}
|
||||
//小程序登录
|
||||
export const wxLoginApi = (code) => {
|
||||
return http.post('/wxapi/user/wxLogin', {
|
||||
code: code
|
||||
})
|
||||
}
|
||||
//封装登录
|
||||
export const userLogin = async () => {
|
||||
//获取code
|
||||
let res = await getCode()
|
||||
//登录: 调用我们自己的后端接口
|
||||
const {
|
||||
data
|
||||
} = await wxLoginApi(res)
|
||||
console.log('登录')
|
||||
console.log(data)
|
||||
if (data) {
|
||||
//存储
|
||||
uni.setStorageSync('openid', data.openid)
|
||||
uni.setStorageSync('sessionkey', data.sessionKey)
|
||||
}
|
||||
}
|
@ -0,0 +1,40 @@
|
||||
const baseUrl = 'http://localhost:8089'
|
||||
//const baseUrl = 'http://192.168.31.70:8089'
|
||||
const http = (options = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.request({
|
||||
url: baseUrl + options.url || '',
|
||||
method:options.type || 'GET' ,
|
||||
data: options.data || {},
|
||||
header: options.header || {},
|
||||
}).then((response) => {
|
||||
console.log(response)
|
||||
resolve(response.data);
|
||||
}).catch(error => {
|
||||
reject(error)
|
||||
})
|
||||
});
|
||||
}
|
||||
const get=(url,data,options={})=>{
|
||||
options.type='get';
|
||||
options.data = data;
|
||||
options.url = url;
|
||||
return http(options)
|
||||
}
|
||||
const post = (url, data, options = {}) => {
|
||||
options.type = 'post';
|
||||
options.data = data;
|
||||
options.url = url;
|
||||
return http(options)
|
||||
}
|
||||
const put = (url, data, options = {}) => {
|
||||
options.type = 'put';
|
||||
options.data = data;
|
||||
options.url = url;
|
||||
return http(options)
|
||||
}
|
||||
export default {
|
||||
get,
|
||||
post,
|
||||
put
|
||||
}
|
Loading…
Reference in new issue