feat: 原生首页联调
This commit is contained in:
parent
ac83ce20f7
commit
4ca8d1d0ed
@ -1,28 +1,28 @@
|
||||
/**
|
||||
* 获取小程序版本信息
|
||||
* 值有:develop(开发版)、trial(体验版)、release(正式版)
|
||||
*/
|
||||
const accountInfo = wx.getAccountInfoSync()
|
||||
const envVersion = accountInfo.miniProgram.envVersion || 'trial'
|
||||
*/
|
||||
const accountInfo = wx.getAccountInfoSync();
|
||||
const envVersion = accountInfo.miniProgram.envVersion || "trial";
|
||||
|
||||
const GDEnvs = {
|
||||
develop: {
|
||||
web: 'https://tlth5.yijiesudai.com/unicom',
|
||||
host: 'https://tlth5.yijiesudai.com',
|
||||
mdHost: 'https://tcomlog.yijiesudai.com'
|
||||
web: "https://tlth5.yijiesudai.com/unicom",
|
||||
host: "https://api.1024api.com",
|
||||
mdHost: "https://tcomlog.yijiesudai.com",
|
||||
},
|
||||
trial: {
|
||||
web: 'https://tlth5.yijiesudai.com/unicom',
|
||||
host: 'https://tlth5.yijiesudai.com',
|
||||
mdHost: 'https://tcomlog.yijiesudai.com'
|
||||
web: "https://tlth5.yijiesudai.com/unicom",
|
||||
host: "https://api.1024api.com",
|
||||
mdHost: "https://tcomlog.yijiesudai.com",
|
||||
},
|
||||
release: {
|
||||
web: 'https://lth5.blingfintech.com/unicom',
|
||||
host: 'https://lth5.blingfintech.com',
|
||||
mdHost: 'https://comlog.yijiesudai.com'
|
||||
web: "https://lth5.blingfintech.com/unicom",
|
||||
host: "https://lth5.blingfintech.com",
|
||||
mdHost: "https://comlog.yijiesudai.com",
|
||||
},
|
||||
}
|
||||
};
|
||||
|
||||
export class allBaseUrl {
|
||||
static GDEnvs = GDEnvs[envVersion]
|
||||
}
|
||||
static GDEnvs = GDEnvs[envVersion];
|
||||
}
|
||||
|
||||
@ -1,41 +1,68 @@
|
||||
const baseUrl = require('../base').allBaseUrl.GDEnvs.host
|
||||
import { httpRequest } from '../../utils/request'
|
||||
import { wxInfo, mpInfo, miniProgramVersion } from '../../utils/getUserInfo'
|
||||
const baseUrl = require("../base").allBaseUrl.GDEnvs.host;
|
||||
import { httpRequest } from "../../utils/request";
|
||||
import { wxInfo, mpInfo, miniProgramVersion } from "../../utils/getUserInfo";
|
||||
|
||||
// 获取首页数据
|
||||
export const apiGetHome = () => {
|
||||
return httpRequest.post<any>(`${baseUrl}/lt-web/xs/xcx/yj/wxUser/index`, {})
|
||||
}
|
||||
export const apiGetHome = (data: any) => {
|
||||
return httpRequest.post<any>(`${baseUrl}/api-interface/app/index/page/list`, {
|
||||
frontPage: 1,
|
||||
...data,
|
||||
});
|
||||
};
|
||||
|
||||
// 获取首页数据
|
||||
export const apiGetCommodityList = (data: any) => {
|
||||
return httpRequest.post<any>(`${baseUrl}/api-interface/app/index/page/list`, {
|
||||
...data,
|
||||
});
|
||||
};
|
||||
|
||||
// 获取首页数据
|
||||
export const apiGetAppCategoryList = () => {
|
||||
return httpRequest.post<any>(
|
||||
`${baseUrl}/api-interface/app/category/list`,
|
||||
{}
|
||||
);
|
||||
};
|
||||
|
||||
// 去借款
|
||||
export const apiGoBorrow = (data: any) => {
|
||||
return httpRequest.post<any>(`${baseUrl}/lt-web/xs/xcx/common/wxUser/goBorrow`, data)
|
||||
}
|
||||
return httpRequest.post<any>(
|
||||
`${baseUrl}/lt-web/xs/xcx/common/wxUser/goBorrow`,
|
||||
data
|
||||
);
|
||||
};
|
||||
|
||||
// 查询多账号用户列表
|
||||
export const apiActIsMulPhones = (data: any) => {
|
||||
return httpRequest.post<any>(`${baseUrl}/lt-web/xs/app/act/isMulPhones`, data)
|
||||
}
|
||||
return httpRequest.post<any>(
|
||||
`${baseUrl}/lt-web/xs/app/act/isMulPhones`,
|
||||
data
|
||||
);
|
||||
};
|
||||
|
||||
// 确认切换账号为主号
|
||||
export const apiActChangeAccount = (data: any) => {
|
||||
return httpRequest.post<any>(`${baseUrl}/lt-web/xs/app/act/changeAccount`, data)
|
||||
}
|
||||
return httpRequest.post<any>(
|
||||
`${baseUrl}/lt-web/xs/app/act/changeAccount`,
|
||||
data
|
||||
);
|
||||
};
|
||||
|
||||
// 排查问题log
|
||||
export const apiProblemLog = (data: object) => {
|
||||
try {
|
||||
const user_info = wx.getStorageSync('user_info')
|
||||
const user_info = wx.getStorageSync("user_info");
|
||||
if (user_info.phone) {
|
||||
Object.assign(data, { userName: user_info.phone })
|
||||
Object.assign(data, { userName: user_info.phone });
|
||||
}
|
||||
Object.assign(data, {
|
||||
osVersion: wxInfo.version, // 操作系统版本
|
||||
opt: mpInfo.miniProgram.envVersion, // 操作
|
||||
appVersion: miniProgramVersion // app版本
|
||||
})
|
||||
appVersion: miniProgramVersion, // app版本
|
||||
});
|
||||
} catch (e) {
|
||||
console.log('获取首页接口catch:', e)
|
||||
console.log("获取首页接口catch:", e);
|
||||
}
|
||||
return httpRequest.post(`${baseUrl}/lt-web/xs/user/front/problem`, data)
|
||||
}
|
||||
return httpRequest.post(`${baseUrl}/lt-web/xs/user/front/problem`, data);
|
||||
};
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
App({
|
||||
globalData: {
|
||||
appName: "够de着",
|
||||
categoryId: NaN,
|
||||
},
|
||||
|
||||
onLaunch(options) {
|
||||
|
||||
@ -52,6 +52,8 @@ $theme-color: #02ce26;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
.category-icon {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
background: #e3e3e3;
|
||||
border-radius: 32rpx;
|
||||
border: 6rpx solid #e3e3e3;
|
||||
@ -130,6 +132,7 @@ $theme-color: #02ce26;
|
||||
background: #ddd;
|
||||
}
|
||||
.product-info {
|
||||
flex: 1;
|
||||
margin-left: 20rpx;
|
||||
border-bottom: 2rpx solid #eee;
|
||||
.product-name {
|
||||
|
||||
@ -1,3 +1,8 @@
|
||||
import { Option } from "./../../miniprogram_npm/@vant/weapp/dropdown-item/shared.d";
|
||||
import {
|
||||
apiGetAppCategoryList,
|
||||
apiGetCommodityList,
|
||||
} from "../../api/index/index";
|
||||
import { getGlobalData } from "../../utils/common";
|
||||
|
||||
// pages/index/index.ts
|
||||
@ -9,17 +14,17 @@ Page({
|
||||
searchValue: "",
|
||||
curCategoryId: NaN,
|
||||
categories: [
|
||||
{ id: 1, name: "水果鲜花", icon: "🍎", categoryId: 1 },
|
||||
{ id: 2, name: "蔬菜豆制品", icon: "🥬", categoryId: 2 },
|
||||
{ id: 3, name: "肉禽蛋", icon: "🥩", categoryId: 3 },
|
||||
{ id: 4, name: "海鲜水产", icon: "🐟", categoryId: 4 },
|
||||
{ id: 5, name: "乳品烘焙", icon: "🥛", categoryId: 5 },
|
||||
{ id: 6, name: "熟食快", icon: "🍱", categoryId: 6 },
|
||||
/* { id: 1, name: "水果鲜花", icon: "🍎", categoryId: 1, children: [] },
|
||||
{ id: 2, name: "蔬菜豆制品", icon: "🥬", categoryId: 2, children: [] },
|
||||
{ id: 3, name: "肉禽蛋", icon: "🥩", categoryId: 3, children: [] },
|
||||
{ id: 4, name: "海鲜水产", icon: "🐟", categoryId: 4, children: [] },
|
||||
{ id: 5, name: "乳品烘焙", icon: "🥛", categoryId: 5, children: [] },
|
||||
{ id: 6, name: "熟食快", icon: "🍱", categoryId: 6, children: [] }, */
|
||||
],
|
||||
recommendTags: ["销量", "折扣", "价格"],
|
||||
activeTag: "荐 时令推荐",
|
||||
leftCategories: [
|
||||
{ id: 1, name: "鲜花/绿植", active: true },
|
||||
/* { id: 1, name: "鲜花/绿植", active: true },
|
||||
{ id: 2, name: "西梅/桃李枣", active: false },
|
||||
{ id: 3, name: "橘/柚/橙/柑", active: false },
|
||||
{ id: 4, name: "苹果/新梨/蕉", active: false },
|
||||
@ -30,10 +35,10 @@ Page({
|
||||
{ id: 9, name: "榴莲/热带果", active: false },
|
||||
{ id: 7, name: "严选", active: false },
|
||||
{ id: 8, name: "果切/小番茄", active: false },
|
||||
{ id: 9, name: "榴莲/热带果", active: false },
|
||||
{ id: 9, name: "榴莲/热带果", active: false }, */
|
||||
],
|
||||
products: [
|
||||
{
|
||||
/* {
|
||||
id: 1,
|
||||
name: "【五彩心语】洋桔梗混色5枝",
|
||||
desc: "绚烂多姿 | 无刺玫瑰",
|
||||
@ -83,12 +88,11 @@ Page({
|
||||
image: "/images/product5.jpg",
|
||||
badge: "秒杀",
|
||||
countdown: "01:18:44",
|
||||
},
|
||||
}, */
|
||||
],
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
this.setData({ curCategoryId: getGlobalData("categoryId") });
|
||||
const app = getApp();
|
||||
this.setData({ appName: app.globalData.appName });
|
||||
this.getSystemInfo();
|
||||
@ -118,8 +122,16 @@ Page({
|
||||
|
||||
// 选择大类目
|
||||
onChooseCategory(e: any) {
|
||||
this.setData({ curCategoryId: e.currentTarget.dataset.id });
|
||||
// testzc 请求接口,获取左类目
|
||||
this.setData({
|
||||
curCategoryId: e.currentTarget.dataset.id,
|
||||
leftCategories: this.data.categories
|
||||
.find((item: any) => item.id === e.currentTarget.dataset.id)
|
||||
?.children.map((item: any, index: number) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
active: index === 0,
|
||||
})),
|
||||
});
|
||||
},
|
||||
// 选择左边的类目
|
||||
onChooseLeftCategory(e: WechatMiniprogram.TouchEvent) {
|
||||
@ -129,7 +141,24 @@ Page({
|
||||
active: i === index,
|
||||
}));
|
||||
this.setData({ leftCategories: categories });
|
||||
// testzc 请求接口,获取商品列表
|
||||
this.handleGetProducts(this.data.leftCategories[index].id);
|
||||
},
|
||||
// 获取商品列表
|
||||
handleGetProducts(categoryId: number) {
|
||||
apiGetCommodityList({ categoryId }).then((res: any) => {
|
||||
// console.warn("----- my data is res2444: ", res);
|
||||
this.setData({
|
||||
products: res.data.rows.map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.title,
|
||||
desc: item.description,
|
||||
tags: [],
|
||||
currentPrice: item.showPromotionPrice,
|
||||
originalPrice: item.showSalePrice,
|
||||
image: item.mainImageUrl,
|
||||
})),
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
// 选择排序
|
||||
@ -153,6 +182,46 @@ Page({
|
||||
icon: "success",
|
||||
});
|
||||
},
|
||||
handleGetAppCategory() {
|
||||
console.warn(
|
||||
'----- my data is getGlobalData("categoryId"): ',
|
||||
getGlobalData("categoryId")
|
||||
);
|
||||
const initCategoryId = getGlobalData("categoryId");
|
||||
apiGetAppCategoryList().then((res: any) => {
|
||||
console.warn("----- my data is res2333: ", res);
|
||||
let curCategoryIdIndex = res.data.findIndex(
|
||||
(item: any) => item.id == initCategoryId
|
||||
);
|
||||
curCategoryIdIndex = curCategoryIdIndex === -1 ? 0 : curCategoryIdIndex;
|
||||
this.setData({
|
||||
curCategoryId: initCategoryId ? initCategoryId : res.data[0].id,
|
||||
categories: res.data.map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
icon: item.categoryImageUrl,
|
||||
categoryId: "",
|
||||
children: item.childrens.map((child: any) => ({
|
||||
id: child.id,
|
||||
name: child.name,
|
||||
})),
|
||||
})),
|
||||
leftCategories: res.data[curCategoryIdIndex].childrens.map(
|
||||
(item: any, index: number) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
active: index === 0,
|
||||
})
|
||||
),
|
||||
});
|
||||
this.handleGetProducts(res.data[0].childrens[0].id);
|
||||
});
|
||||
},
|
||||
async onShow() {
|
||||
wx.showLoading({ title: "加载中", mask: true });
|
||||
await this.handleGetAppCategory();
|
||||
wx.hideLoading();
|
||||
},
|
||||
});
|
||||
|
||||
interface PageData {
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
<scroll-view class="category-scroll" scroll-x>
|
||||
<view class="category-list">
|
||||
<view class="category-item {{curCategoryId === item.id ? 'active' : ''}}" wx:for="{{categories}}" wx:key="id" data-id="{{ item.id }}" bindtap="onChooseCategory">
|
||||
<text class="category-icon">{{item.icon}}</text>
|
||||
<image class="category-icon" src="{{item.icon}}" />
|
||||
<text class="category-name">{{item.name}}</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
// pages/index/index.ts
|
||||
|
||||
import { apiGetAppCategoryList, apiGetHome } from "../../api/index/index";
|
||||
import { setGlobalData } from "../../utils/common";
|
||||
|
||||
Page({
|
||||
@ -115,6 +116,9 @@ Page({
|
||||
setGlobalData("categoryId", e.currentTarget.dataset.id);
|
||||
wx.switchTab({
|
||||
url: "/pages/category/index",
|
||||
query: {
|
||||
categoryId: e.currentTarget.dataset.id,
|
||||
},
|
||||
});
|
||||
},
|
||||
// testzc 去商品详情
|
||||
@ -125,10 +129,45 @@ Page({
|
||||
)}`,
|
||||
});
|
||||
},
|
||||
handleGetHomePage() {
|
||||
apiGetHome().then((res: any) => {
|
||||
// console.warn("----- my data is res222: ", res);
|
||||
this.setData({
|
||||
recommendedProducts: res.data.rows.map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.title,
|
||||
price: item.showPromotionPrice,
|
||||
originalPrice: "",
|
||||
image: item.mainImageUrl,
|
||||
tags: [],
|
||||
sales: item.sales,
|
||||
})),
|
||||
});
|
||||
});
|
||||
},
|
||||
handleGetAppCategory() {
|
||||
apiGetAppCategoryList().then((res: any) => {
|
||||
// console.warn("----- my data is res2333: ", res);
|
||||
this.setData({
|
||||
categories: res.data.map((item: any) => ({
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
icon: item.categoryImageUrl,
|
||||
categoryId: "",
|
||||
})),
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
const app = getApp();
|
||||
// 页面加载时逻辑
|
||||
this.setData({ appName: app.globalData.appName });
|
||||
},
|
||||
async onShow() {
|
||||
wx.showLoading({ title: "加载中", mask: true });
|
||||
await this.handleGetHomePage();
|
||||
await this.handleGetAppCategory();
|
||||
wx.hideLoading();
|
||||
},
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user