接口对接1

pull/42/head
Suk1No 2 months ago
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
}

@ -1,11 +1,12 @@
{ {
"pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages "pages": [ //pageshttps://uniapp.dcloud.io/collocation/pages
/* {
"path": "pages/address/address",
"style": {
"navigationBarTitleText": ""
}
}, */
{ {
"path": "pages/address/address",
"style": {
"navigationBarTitleText": ""
}
}, {
"path": "pages/index/index", "path": "pages/index/index",
"style": { "style": {
"navigationBarTitleText": "首页" "navigationBarTitleText": "首页"
@ -16,27 +17,35 @@
"navigationBarTitleText": "分类", "navigationBarTitleText": "分类",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, { }, {
"path": "pages/car/car", "path": "pages/car/car",
"style": { "style": {
"navigationBarTitleText": "购物车", "navigationBarTitleText": "购物车",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, { }, {
"path": "pages/mine/mine", "path": "pages/mine/mine",
"style": { "style": {
"navigationBarTitleText": "我的", "navigationBarTitleText": "我的",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
}, {
},
{
"path": "pages/detail/detail", "path": "pages/detail/detail",
"style": { "style": {
"navigationBarTitleText": "" "navigationBarTitleText": ""
} }
}, {
"path": "pages/address/address",
"style": {
"navigationBarTitleText": ""
}
},
{
"path" : "common/common",
"style" :
{
"navigationBarTitleText" : ""
}
} }
], ],
"globalStyle": { "globalStyle": {

@ -5,7 +5,7 @@
<view v-for="(item,index) in tabbar" :key="index" class="u-tab-item" <view v-for="(item,index) in tabbar" :key="index" class="u-tab-item"
:class="[current==index ? 'u-tab-item-active' : '']" :data-current="index" :class="[current==index ? 'u-tab-item-active' : '']" :data-current="index"
@tap.stop="swichMenu(index)"> @tap.stop="swichMenu(index)">
<text class="u-line-1">{{item.name}}</text> <text class="u-line-1">{{item.categoryName}}</text>
</view> </view>
</scroll-view> </scroll-view>
<block v-for="(item,index) in tabbar" :key="index"> <block v-for="(item,index) in tabbar" :key="index">
@ -16,8 +16,9 @@
<text>{{item.name}}</text> <text>{{item.name}}</text>
</view> --> </view> -->
<view class="item-container"> <view class="item-container">
<view class="thumb-box" v-for="(item1, index1) in item.foods" :key="index1"> <view class="thumb-box" v-for="(item1, index1) in item.goods" :key="index1">
<image class="item-menu-image" :src="item1.icon" mode=""></image> <image @click="toDetails(item1)" class="item-menu-image"
:src="item1.goodsImage.split(',')[0]" mode=""></image>
<view class="item-menu-name">{{item1.name}}</view> <view class="item-menu-name">{{item1.name}}</view>
</view> </view>
</view> </view>
@ -30,84 +31,69 @@
</template> </template>
<script setup> <script setup>
import {
getCategoryListApi
} from "../../api/category";
import { import {
ref, ref,
getCurrentInstance getCurrentInstance
} from "vue" } from "vue"
// //
const instance = getCurrentInstance(); const instance = getCurrentInstance();
const tabbar = ref([{ const tabbar = ref([])
"name": "早点",
"foods": [{
"name": "豆浆",
"key": "豆浆",
"icon": "/static/test-5.png",
"cat": 6
},
{
"name": "油条",
"key": "糕点饼干",
"icon": "/static/test-8.png",
"cat": 6
},
{
"name": "油条",
"key": "糕点饼干",
"icon": "/static/test-8.png",
"cat": 6
}
]
},
{
"name": "米线",
"foods": [{
"name": "小锅米线",
"key": "豆浆",
"icon": "/static/test-5.png",
"cat": 6
},
{
"name": "豆花米线",
"key": "糕点饼干",
"icon": "/static/test-5.png",
"cat": 6
}
]
}
])
const scrollTop = ref(0) const scrollTop = ref(0)
const current = ref(0) const current = ref(0)
const menuHeight = ref(0) const menuHeight = ref(0)
const menuItemHeight = ref(0) const menuItemHeight = ref(0)
const getImg = ()=>{ const getImg = () => {
return Math.floor(Math.random() * 35) return Math.floor(Math.random() * 35)
} }
const swichMenu = async(index)=>{ const swichMenu = async (index) => {
if(index == current.value) return ; if (index == current.value) return;
current.value = index; current.value = index;
// 0 // 0
if(menuHeight.value == 0 || menuItemHeight.value == 0) { if (menuHeight.value == 0 || menuItemHeight.value == 0) {
await getElRect('menu-scroll-view', 'menuHeight'); await getElRect('menu-scroll-view', 'menuHeight');
await getElRect('u-tab-item', 'menuItemHeight'); await getElRect('u-tab-item', 'menuItemHeight');
} }
// item // item
scrollTop.value = index * menuItemHeight.value + menuItemHeight.value / 2 - menuHeight.value / 2; scrollTop.value = index * menuItemHeight.value + menuItemHeight.value / 2 - menuHeight.value / 2;
} }
const getElRect = (elClass, dataVal)=>{ const getElRect = (elClass, dataVal) => {
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
const query = uni.createSelectorQuery().in(instance); const query = uni.createSelectorQuery().in(instance);
query.select('.' + elClass).fields({size: true},res => { query.select('.' + elClass).fields({
size: true
}, res => {
// resnull // resnull
if(!res) { if (!res) {
setTimeout(() => { setTimeout(() => {
getElRect(elClass); getElRect(elClass);
}, 10); }, 10);
return ; return;
} }
instance[dataVal] = res.height; instance[dataVal] = res.height;
}).exec(); }).exec();
}) })
} }
//
const getCategoryList = async () => {
let res = await getCategoryListApi()
if (res && res.code == 200) {
tabbar.value = res.data;
}
}
//
const toDetails = (item) => {
console.log(item)
//details.vue
uni.navigateTo({
url: '../detail/detail?goods=' + JSON.stringify(item)
});
}
onLoad(() => {
getCategoryList()
})
</script> </script>
@ -230,4 +216,3 @@
height: 120rpx; height: 120rpx;
} }
</style> </style>

@ -32,22 +32,7 @@
<swiper-item class="swiper-item"> <swiper-item class="swiper-item">
<scroll-view scroll-y style="height: 100%;width: 100%;"> <scroll-view scroll-y style="height: 100%;width: 100%;">
<view class="page-box"> <view class="page-box">
我是内容一 <u-parse :html="content"></u-parse>
我是内容一
我是内容一
我是内容一
我是内容一
我是内容一
我是内容一
我是内容一
我是内容一
我是内容一
我是内容一
我是内容一
我是内容一
我是内容一
我是内容一
我是内容一
</view> </view>
</scroll-view> </scroll-view>
</swiper-item> </swiper-item>
@ -79,11 +64,11 @@
</swiper> </swiper>
<view class="navigation"> <view class="navigation">
<view class="left"> <view class="left">
<view class="item"> <view class="item" @click="toHome">
<u-icon name="home" :size="40" :color="$u.color['contentColor']"></u-icon> <u-icon name="home" :size="40" :color="$u.color['contentColor']"></u-icon>
<view class="text u-line-1">首页</view> <view class="text u-line-1">首页</view>
</view> </view>
<view class="item car"> <view class="item car" @click="toCar">
<u-badge class="car-num" :count="carCount" type="error" :offset="[-3, -6]"></u-badge> <u-badge class="car-num" :count="carCount" type="error" :offset="[-3, -6]"></u-badge>
<u-icon name="shopping-cart" :size="40" :color="$u.color['contentColor']"></u-icon> <u-icon name="shopping-cart" :size="40" :color="$u.color['contentColor']"></u-icon>
<view class="text u-line-1">购物车</view> <view class="text u-line-1">购物车</view>
@ -97,6 +82,9 @@
</template> </template>
<script setup> <script setup>
import {
userLogin
} from '../../api/user';
import { import {
onLoad onLoad
} from '@dcloudio/uni-app'; } from '@dcloudio/uni-app';
@ -107,10 +95,12 @@
import { import {
carStore carStore
} from '../../store/car'; } from '../../store/car';
//
const content = ref('')
//store //store
const store = carStore() const store = carStore()
// //
const carCount = computed(()=>{ const carCount = computed(() => {
return store.carList.length return store.carList.length
}) })
const current = ref(0) const current = ref(0)
@ -177,7 +167,20 @@
swiperCurrent.value = current; swiperCurrent.value = current;
tabIndex.value = current; tabIndex.value = current;
} }
//
const toHome = () => {
uni.switchTab({
url: '../index/index'
});
}
//
const toCar = () => {
uni.switchTab({
url: '../car/car'
});
}
onLoad((options) => { onLoad((options) => {
userLogin()
const goods = JSON.parse(options.goods) const goods = JSON.parse(options.goods)
swipperList.value = goods.goodsImage.split(',') swipperList.value = goods.goodsImage.split(',')
console.log(goods) console.log(goods)

@ -1,5 +1,6 @@
<template> <template>
<u-swiper border-radius='1' :duration='duration' :interval='interval' :height="height" :list="swiperList"> <u-swiper name='images' border-radius='1' :duration='duration' :interval='interval' :height="height"
:list="swiperList">
</u-swiper> </u-swiper>
<u-divider margin-top='20' margin-bottom='20' color="#F3AF28">店长推荐</u-divider> <u-divider margin-top='20' margin-bottom='20' color="#F3AF28">店长推荐</u-divider>
<view class="wrap"> <view class="wrap">
@ -7,13 +8,13 @@
<template v-slot:left="{leftList}"> <template v-slot:left="{leftList}">
<view class="demo-warter" v-for="(item, index) in leftList" :key="index"> <view class="demo-warter" v-for="(item, index) in leftList" :key="index">
<!-- 警告微信小程序中需要hx2.8.11版本才支持在template中结合其他组件比如下方的lazy-load组件 --> <!-- 警告微信小程序中需要hx2.8.11版本才支持在template中结合其他组件比如下方的lazy-load组件 -->
<u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> <u-lazy-load threshold="-450" border-radius="10" :image="item.goodsImage.split(',')[0]" :index="index"></u-lazy-load>
<view class="demo-title"> <view class="demo-title">
{{item.title}} {{item.goodsName}}
</view> </view>
<view class="price-item"> <view class="price-item">
<view class="demo-price"> <view class="demo-price">
{{item.price}} {{item.specs[0].goodsPrice}}
</view> </view>
<view class="demo-title"> <view class="demo-title">
/ /
@ -24,13 +25,13 @@
</template> </template>
<template v-slot:right="{rightList}"> <template v-slot:right="{rightList}">
<view class="demo-warter" v-for="(item, index) in rightList" :key="index"> <view class="demo-warter" v-for="(item, index) in rightList" :key="index">
<u-lazy-load threshold="-450" border-radius="10" :image="item.image" :index="index"></u-lazy-load> <u-lazy-load threshold="-450" border-radius="10" :image="item.goodsImage.split(',')[0]" :index="index"></u-lazy-load>
<view class="demo-title"> <view class="demo-title">
{{item.title}} {{item.goodsName}}
</view> </view>
<view class="price-item"> <view class="price-item">
<view class="demo-price"> <view class="demo-price">
{{item.price}} {{item.specs[0].goodsPrice}}
</view> </view>
<view class="demo-title"> <view class="demo-title">
/ /
@ -44,6 +45,10 @@
</template> </template>
<script setup> <script setup>
import {
getSwipperListApi,
getHotListApi
} from '../../api/home';
import { import {
ref ref
} from 'vue'; } from 'vue';
@ -59,16 +64,18 @@
// //
const duration = ref(500) const duration = ref(500)
// //
const swiperList = ref([{ const swiperList = ref([])
/* {
image: '/static/swipper1.png' image: '/static/swipper1.png'
}, { }, {
image: '/static/swipper2.png' image: '/static/swipper2.png'
}, { }, {
image: '/static/swipper3.png' image: '/static/swipper3.png'
}]) } */
// //
const flowList = ref([{ const flowList = ref([])
price: 20, /* {
price: 20,
title: '小炒肉盖饭', title: '小炒肉盖饭',
image: '/static/test-5.png', image: '/static/test-5.png',
}, },
@ -106,8 +113,25 @@
price: 15, price: 15,
title: '番茄鸡蛋盖饭', title: '番茄鸡蛋盖饭',
image: '/static/test-8.png', image: '/static/test-8.png',
} */
//
const getSwipperList = async () => {
let res = await getSwipperListApi()
if (res && res.code == 200) {
swiperList.value = res.data;
}
}
//
const getHotList = async()=>{
let res = await getHotListApi()
if(res && res.code == 200){
flowList.value = res.data;
} }
]) }
onLoad(()=>{
getSwipperList()
getHotList()
})
// //
const toDetails = (item) => { const toDetails = (item) => {
//details.vue //details.vue

Loading…
Cancel
Save