feat: 原生首页联调
This commit is contained in:
parent
ac83ce20f7
commit
4ca8d1d0ed
@ -1,28 +1,28 @@
|
|||||||
/**
|
/**
|
||||||
* 获取小程序版本信息
|
* 获取小程序版本信息
|
||||||
* 值有:develop(开发版)、trial(体验版)、release(正式版)
|
* 值有:develop(开发版)、trial(体验版)、release(正式版)
|
||||||
*/
|
*/
|
||||||
const accountInfo = wx.getAccountInfoSync()
|
const accountInfo = wx.getAccountInfoSync();
|
||||||
const envVersion = accountInfo.miniProgram.envVersion || 'trial'
|
const envVersion = accountInfo.miniProgram.envVersion || "trial";
|
||||||
|
|
||||||
const GDEnvs = {
|
const GDEnvs = {
|
||||||
develop: {
|
develop: {
|
||||||
web: 'https://tlth5.yijiesudai.com/unicom',
|
web: "https://tlth5.yijiesudai.com/unicom",
|
||||||
host: 'https://tlth5.yijiesudai.com',
|
host: "https://api.1024api.com",
|
||||||
mdHost: 'https://tcomlog.yijiesudai.com'
|
mdHost: "https://tcomlog.yijiesudai.com",
|
||||||
},
|
},
|
||||||
trial: {
|
trial: {
|
||||||
web: 'https://tlth5.yijiesudai.com/unicom',
|
web: "https://tlth5.yijiesudai.com/unicom",
|
||||||
host: 'https://tlth5.yijiesudai.com',
|
host: "https://api.1024api.com",
|
||||||
mdHost: 'https://tcomlog.yijiesudai.com'
|
mdHost: "https://tcomlog.yijiesudai.com",
|
||||||
},
|
},
|
||||||
release: {
|
release: {
|
||||||
web: 'https://lth5.blingfintech.com/unicom',
|
web: "https://lth5.blingfintech.com/unicom",
|
||||||
host: 'https://lth5.blingfintech.com',
|
host: "https://lth5.blingfintech.com",
|
||||||
mdHost: 'https://comlog.yijiesudai.com'
|
mdHost: "https://comlog.yijiesudai.com",
|
||||||
},
|
},
|
||||||
}
|
};
|
||||||
|
|
||||||
export class allBaseUrl {
|
export class allBaseUrl {
|
||||||
static GDEnvs = GDEnvs[envVersion]
|
static GDEnvs = GDEnvs[envVersion];
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,41 +1,68 @@
|
|||||||
const baseUrl = require('../base').allBaseUrl.GDEnvs.host
|
const baseUrl = require("../base").allBaseUrl.GDEnvs.host;
|
||||||
import { httpRequest } from '../../utils/request'
|
import { httpRequest } from "../../utils/request";
|
||||||
import { wxInfo, mpInfo, miniProgramVersion } from '../../utils/getUserInfo'
|
import { wxInfo, mpInfo, miniProgramVersion } from "../../utils/getUserInfo";
|
||||||
|
|
||||||
// 获取首页数据
|
// 获取首页数据
|
||||||
export const apiGetHome = () => {
|
export const apiGetHome = (data: any) => {
|
||||||
return httpRequest.post<any>(`${baseUrl}/lt-web/xs/xcx/yj/wxUser/index`, {})
|
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) => {
|
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) => {
|
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) => {
|
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
|
// 排查问题log
|
||||||
export const apiProblemLog = (data: object) => {
|
export const apiProblemLog = (data: object) => {
|
||||||
try {
|
try {
|
||||||
const user_info = wx.getStorageSync('user_info')
|
const user_info = wx.getStorageSync("user_info");
|
||||||
if (user_info.phone) {
|
if (user_info.phone) {
|
||||||
Object.assign(data, { userName: user_info.phone })
|
Object.assign(data, { userName: user_info.phone });
|
||||||
}
|
}
|
||||||
Object.assign(data, {
|
Object.assign(data, {
|
||||||
osVersion: wxInfo.version, // 操作系统版本
|
osVersion: wxInfo.version, // 操作系统版本
|
||||||
opt: mpInfo.miniProgram.envVersion, // 操作
|
opt: mpInfo.miniProgram.envVersion, // 操作
|
||||||
appVersion: miniProgramVersion // app版本
|
appVersion: miniProgramVersion, // app版本
|
||||||
})
|
});
|
||||||
} catch (e) {
|
} 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({
|
App({
|
||||||
globalData: {
|
globalData: {
|
||||||
appName: "够de着",
|
appName: "够de着",
|
||||||
|
categoryId: NaN,
|
||||||
},
|
},
|
||||||
|
|
||||||
onLaunch(options) {
|
onLaunch(options) {
|
||||||
|
|||||||
@ -52,6 +52,8 @@ $theme-color: #02ce26;
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
.category-icon {
|
.category-icon {
|
||||||
|
width: 80rpx;
|
||||||
|
height: 80rpx;
|
||||||
background: #e3e3e3;
|
background: #e3e3e3;
|
||||||
border-radius: 32rpx;
|
border-radius: 32rpx;
|
||||||
border: 6rpx solid #e3e3e3;
|
border: 6rpx solid #e3e3e3;
|
||||||
@ -130,6 +132,7 @@ $theme-color: #02ce26;
|
|||||||
background: #ddd;
|
background: #ddd;
|
||||||
}
|
}
|
||||||
.product-info {
|
.product-info {
|
||||||
|
flex: 1;
|
||||||
margin-left: 20rpx;
|
margin-left: 20rpx;
|
||||||
border-bottom: 2rpx solid #eee;
|
border-bottom: 2rpx solid #eee;
|
||||||
.product-name {
|
.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";
|
import { getGlobalData } from "../../utils/common";
|
||||||
|
|
||||||
// pages/index/index.ts
|
// pages/index/index.ts
|
||||||
@ -9,17 +14,17 @@ Page({
|
|||||||
searchValue: "",
|
searchValue: "",
|
||||||
curCategoryId: NaN,
|
curCategoryId: NaN,
|
||||||
categories: [
|
categories: [
|
||||||
{ id: 1, name: "水果鲜花", icon: "🍎", categoryId: 1 },
|
/* { id: 1, name: "水果鲜花", icon: "🍎", categoryId: 1, children: [] },
|
||||||
{ id: 2, name: "蔬菜豆制品", icon: "🥬", categoryId: 2 },
|
{ id: 2, name: "蔬菜豆制品", icon: "🥬", categoryId: 2, children: [] },
|
||||||
{ id: 3, name: "肉禽蛋", icon: "🥩", categoryId: 3 },
|
{ id: 3, name: "肉禽蛋", icon: "🥩", categoryId: 3, children: [] },
|
||||||
{ id: 4, name: "海鲜水产", icon: "🐟", categoryId: 4 },
|
{ id: 4, name: "海鲜水产", icon: "🐟", categoryId: 4, children: [] },
|
||||||
{ id: 5, name: "乳品烘焙", icon: "🥛", categoryId: 5 },
|
{ id: 5, name: "乳品烘焙", icon: "🥛", categoryId: 5, children: [] },
|
||||||
{ id: 6, name: "熟食快", icon: "🍱", categoryId: 6 },
|
{ id: 6, name: "熟食快", icon: "🍱", categoryId: 6, children: [] }, */
|
||||||
],
|
],
|
||||||
recommendTags: ["销量", "折扣", "价格"],
|
recommendTags: ["销量", "折扣", "价格"],
|
||||||
activeTag: "荐 时令推荐",
|
activeTag: "荐 时令推荐",
|
||||||
leftCategories: [
|
leftCategories: [
|
||||||
{ id: 1, name: "鲜花/绿植", active: true },
|
/* { id: 1, name: "鲜花/绿植", active: true },
|
||||||
{ id: 2, name: "西梅/桃李枣", active: false },
|
{ id: 2, name: "西梅/桃李枣", active: false },
|
||||||
{ id: 3, name: "橘/柚/橙/柑", active: false },
|
{ id: 3, name: "橘/柚/橙/柑", active: false },
|
||||||
{ id: 4, name: "苹果/新梨/蕉", active: false },
|
{ id: 4, name: "苹果/新梨/蕉", active: false },
|
||||||
@ -30,10 +35,10 @@ Page({
|
|||||||
{ id: 9, name: "榴莲/热带果", active: false },
|
{ id: 9, name: "榴莲/热带果", active: false },
|
||||||
{ id: 7, name: "严选", active: false },
|
{ id: 7, name: "严选", active: false },
|
||||||
{ id: 8, name: "果切/小番茄", active: false },
|
{ id: 8, name: "果切/小番茄", active: false },
|
||||||
{ id: 9, name: "榴莲/热带果", active: false },
|
{ id: 9, name: "榴莲/热带果", active: false }, */
|
||||||
],
|
],
|
||||||
products: [
|
products: [
|
||||||
{
|
/* {
|
||||||
id: 1,
|
id: 1,
|
||||||
name: "【五彩心语】洋桔梗混色5枝",
|
name: "【五彩心语】洋桔梗混色5枝",
|
||||||
desc: "绚烂多姿 | 无刺玫瑰",
|
desc: "绚烂多姿 | 无刺玫瑰",
|
||||||
@ -83,12 +88,11 @@ Page({
|
|||||||
image: "/images/product5.jpg",
|
image: "/images/product5.jpg",
|
||||||
badge: "秒杀",
|
badge: "秒杀",
|
||||||
countdown: "01:18:44",
|
countdown: "01:18:44",
|
||||||
},
|
}, */
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.setData({ curCategoryId: getGlobalData("categoryId") });
|
|
||||||
const app = getApp();
|
const app = getApp();
|
||||||
this.setData({ appName: app.globalData.appName });
|
this.setData({ appName: app.globalData.appName });
|
||||||
this.getSystemInfo();
|
this.getSystemInfo();
|
||||||
@ -118,8 +122,16 @@ Page({
|
|||||||
|
|
||||||
// 选择大类目
|
// 选择大类目
|
||||||
onChooseCategory(e: any) {
|
onChooseCategory(e: any) {
|
||||||
this.setData({ curCategoryId: e.currentTarget.dataset.id });
|
this.setData({
|
||||||
// testzc 请求接口,获取左类目
|
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) {
|
onChooseLeftCategory(e: WechatMiniprogram.TouchEvent) {
|
||||||
@ -129,7 +141,24 @@ Page({
|
|||||||
active: i === index,
|
active: i === index,
|
||||||
}));
|
}));
|
||||||
this.setData({ leftCategories: categories });
|
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",
|
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 {
|
interface PageData {
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
<scroll-view class="category-scroll" scroll-x>
|
<scroll-view class="category-scroll" scroll-x>
|
||||||
<view class="category-list">
|
<view class="category-list">
|
||||||
<view class="category-item {{curCategoryId === item.id ? 'active' : ''}}" wx:for="{{categories}}" wx:key="id" data-id="{{ item.id }}" bindtap="onChooseCategory">
|
<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>
|
<text class="category-name">{{item.name}}</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
// pages/index/index.ts
|
// pages/index/index.ts
|
||||||
|
|
||||||
|
import { apiGetAppCategoryList, apiGetHome } from "../../api/index/index";
|
||||||
import { setGlobalData } from "../../utils/common";
|
import { setGlobalData } from "../../utils/common";
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
@ -115,6 +116,9 @@ Page({
|
|||||||
setGlobalData("categoryId", e.currentTarget.dataset.id);
|
setGlobalData("categoryId", e.currentTarget.dataset.id);
|
||||||
wx.switchTab({
|
wx.switchTab({
|
||||||
url: "/pages/category/index",
|
url: "/pages/category/index",
|
||||||
|
query: {
|
||||||
|
categoryId: e.currentTarget.dataset.id,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
// testzc 去商品详情
|
// 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() {
|
onLoad() {
|
||||||
const app = getApp();
|
const app = getApp();
|
||||||
// 页面加载时逻辑
|
// 页面加载时逻辑
|
||||||
this.setData({ appName: app.globalData.appName });
|
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