api

parent b75c85a3
<script setup>
import { getTokenUser } from './api/index';
import testJson from './static/json/test.json';
import { getToken } from './utils/auth';
onLaunch(() => {
if (!getToken()) signIn();
console.log('App Launch');
});
......@@ -10,6 +14,14 @@ onShow(() => {
onHide(() => {
console.log('App Hide');
});
// 登录
const signIn = () => {
getTokenUser(testJson).then((res) => {
const token = res.data.access_token;
xma.setStorageSync('Authorization', token);
console.log('登录...');
});
};
</script>
<style>
.multi-line {
......
......@@ -16,3 +16,28 @@ export function groupBuyList() {
method: 'GET',
});
}
// 根据父级分类id查询子分类列表
export function getByParentId(id) {
return request({
url: `/sgyrdd/category/getByParentId?parentId=${id}`,
method: 'GET',
});
}
// 获取团购专区主页轮播图
export function groupImgList() {
return request({
url: `/sgyrdd/carousel/groupBuyList`,
method: 'GET',
});
}
// 附近人气美食分页
export function popularityPage(data) {
return request({
url: `/sgyrdd/shop/popularityPage`,
method: 'POST',
data,
});
}
......@@ -87,12 +87,29 @@ import Search from '../../components/index/Search.vue';
import Classification from '../../components/index/Classification.vue';
import Position from '../../components/index/Position.vue';
import Sort from '../../components/index/Sort.vue';
import { getByParentId } from '../../api/index';
const business = reactive(['优选商家', '超值半价', '今日可订', '经典单人']);
const active = ref(null);
const rotate = ref(false);
const rotate2 = ref(false);
const rotate3 = ref(false);
onLoad((option) => {
const { parentId } = option;
query(parentId);
});
// 根据父级分类id查询子分类列表
const query = (parentId) => {
getByParentId(parentId).then((res) => {
console.log('打印res', res);
});
};
// onLoad(option) {
// //option为object类型,会序列化上个页面传递的参数
// console.log(option.id); //打印出上个页面传递的参数。
// console.log(option.name); //打印出上个页面传递的参数。
// },
const choice = (index) => {
active.value = index;
};
......
......@@ -9,24 +9,24 @@
<view class="classification">
<view class="classification-top">
<view
@tap="jingang(index)"
@tap="jingang(item.categoryId)"
class="choice"
v-for="(item, index) in classificationT"
:key="index"
>
<image class="imgs" :src="'../../static/index/' + item.img + '.png'" mode="widthFix" />
<text class="introduce">{{ item.text }}</text>
<image class="imgs" :src="item.icon" mode="widthFix" />
<text class="introduce">{{ item.categoryName }}</text>
</view>
</view>
<view class="classification-bottom">
<view
@tap="jingang(index)"
@tap="jingang(item.categoryId)"
class="choice"
v-for="(item, index) in classificationB"
:key="index"
>
<image class="imgs" :src="'../../static/index/' + item.img + '.png'" mode="widthFix" />
<text class="introduce">{{ item.text }}</text>
<image class="imgs" :src="item.icon" mode="widthFix" />
<text class="introduce">{{ item.categoryName }}</text>
</view>
</view>
</view>
......@@ -128,15 +128,17 @@ import FoodDetails from '../../components/index/FoodDetails.vue';
import ShopCard from '../../components/index/ShopCard.vue';
import Marketing from '../../components/index/Marketing.vue';
import Position from '../../components/index/Position.vue';
import { getTokenUser, groupBuyList } from '../../api/index';
import testJson from '../../static/json/test.json';
import { getToken } from '../../utils/auth';
import { groupBuyList, groupImgList, popularityPage } from '../../api/index';
// import testJson from '../../static/json/test.json';
// import { getToken } from '../../utils/auth';
const title = ref('小程序平台');
const { countInfo, addCount } = useCountStore();
onMounted(async () => {
if (!getToken()) await signIn();
// 轮播图数据
let lunboData;
onMounted(() => {
getClassification();
rotatingBroadcast();
nearbyFood();
// test(testJson).then((res) => {
// console.log('打印', res);
// });
......@@ -153,19 +155,49 @@ const signIn = () => {
// 获取分类
const getClassification = () => {
groupBuyList().then((res) => {
console.log('res', res);
res.data.forEach((item) => {
item.icon = import.meta.env.VITE_APP_IMG_URL + item.icon;
item.pic = import.meta.env.VITE_APP_IMG_URL + item.pic;
});
classificationT.value = res.data.slice(0, 4);
classificationB.value = res.data.slice(4);
});
};
// 附近人气美食分页
const nearbyFood = () => {
console.log('位置名称:');
xma.getLocation({
isHighAccuracy: true,
success: function (res) {
console.log('位置名称:', res);
},
fail: function (err) {
console.log('获取位置失败:', err);
},
});
};
// 轮播图
const rotatingBroadcast = () => {
groupImgList().then((res) => {
console.log('lunbo', res);
res.data.forEach((item) => {
item.imgUrl = import.meta.env.VITE_APP_IMG_URL + item.imgUrl;
});
lunboData = res.data;
swiperList.value = res.data.map((item) => {
return item.imgUrl;
});
});
};
const light = ref(0);
const rotate = ref(false);
const classificationT = reactive([
const classificationT = ref([
{ img: 'hotPot', text: '火锅' },
{ img: 'barbecue', text: '烧烤烤肉' },
{ img: 'stirFriedDishes', text: '地方菜系' },
{ img: 'hamburg', text: '小吃快餐' },
]);
const classificationB = reactive([
const classificationB = ref([
{ img: 'seafood', text: '鱼鲜海鲜' },
{ img: 'foreignLand', text: '异域风味' },
{ img: 'selfHelp', text: '自助餐' },
......@@ -189,19 +221,22 @@ const choice = (index) => {
light.value = index;
};
// 金刚区分类选择
const jingang = (index) => {
switch (index) {
case 0:
xma.navigateTo({
url: '/pages/index/foodClassification',
});
break;
case 1:
xma.navigateTo({});
break;
case 2:
xma.navigateTo({});
}
const jingang = (id) => {
// switch (index) {
// case 0:
// xma.navigateTo({
// url: '/pages/index/foodClassification',
// });
// break;
// case 1:
// xma.navigateTo({});
// break;
// case 2:
// xma.navigateTo({});
// }
xma.navigateTo({
url: '/pages/index/foodClassification?parentId=' + id,
});
};
const locationFiltering = () => {
rotate.value = !rotate.value;
......
......@@ -3,12 +3,12 @@ let domain = {};
if (env === 'dev') {
domain = {
apiPrefix: '/api',
// imgPrefix: 'https://gdlxy-images.wjzpgz.com/',
imgPrefix: 'http://file.rhhzkj.com:8080',
};
} else {
domain = {
apiPrefix: 'https://api.rddyz.com',
// imgPrefix: 'https://gdlxy-images.wjzpgz.com/',
imgPrefix: 'https://file.rddyz.com',
};
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment