Files
code-bang/frontend/miniapp/pages/home/home.js
T
2026-10-14 18:00:26 +08:00

161 lines
3.1 KiB
JavaScript

import { fetchHome, fetchConfig } from '../../services/home/home';
import { fetchPerson } from '../../services/usercenter/fetchPerson';
import { withPromoter, promoterQuery } from '../../utils/promoter';
Page({
data: {
imgSrcs: [],
tabList: [],
demandList: [],
demandListLoadStatus: 0,
pageLoading: false,
current: 1,
role: '',
image: '',
imageSrc: '',
autoplay: true,
duration: '500',
interval: 5000,
navigation: {
type: 'dots'
},
swiperImageProps: {
mode: 'scaleToFill'
},
img1: '',
img2: '',
img3: '',
tabList: [],
},
demandListPagination: {
index: 0,
num: 20,
},
privateData: {
tabIndex: 0,
},
onShow() {
this.getTabBar().init();
this.refreshRole();
},
onLoad() {
// 先用本地缓存渲染入口按钮,避免接口返回前闪烁;随后由 onShow 用接口数据校正
const role = (wx.getStorageSync('userInfo') || {}).role || '';
this.setData({ role });
this.init();
},
onReachBottom() {
if (this.data.demandListLoadStatus === 0) {
}
},
onPullDownRefresh() {
this.init();
this.refreshRole();
},
init() {
this.loadHomePage();
},
/**
* 拉取最新角色并写回本地缓存
* 入驻审核通过后,用户回到小程序触发 onShow 即可看到「进入接单大厅」入口
*/
refreshRole() {
return fetchPerson().then((res) => {
if (res.code === 1 && res.data) {
const role = res.data.role || '';
this.setData({ role });
const userInfo = wx.getStorageSync('userInfo');
if (userInfo && userInfo.role !== role) {
userInfo.role = role;
wx.setStorageSync('userInfo', userInfo);
}
}
});
},
loadHomePage() {
wx.stopPullDownRefresh();
this.setData({
pageLoading: true
});
fetchConfig().then(
(res) => {
console.log(res);
if (res.code == 1) {
let resData = res.data;
this.setData({
pageLoading: false,
tabList: resData.developTypes
});
}
}
);
},
toSubscribe() {
let tmpIds = [];
wx.requestSubscribeMessage({
tmplIds: tmpIds,
success(re) {
console.log(re);
},
fail(res) {
console.log(res.errMsg, res.errCode);
}
});
},
publish(e) {
wx.navigateTo({
url: `/pages/demand/publish/index`
});
},
joinUs(e) {
wx.navigateTo({
url: `/pages/developer/join/index`
});
},
onReTry() {
},
toDemandHall() {
wx.navigateTo({
url: `/pages/demand/list/index?opType=all`,
});
},
navToActivityDetail({
detail
}) {
const {
index: promotionID = 0
} = detail || {};
wx.navigateTo({
url: `/pages/promotion-detail/index?promotion_id=${promotionID}`,
});
},
onShareAppMessage() {
return {
title: '代码邦 - 软件商城与定制开发平台',
path: withPromoter('/pages/home/home'),
};
},
onShareTimeline() {
return {
title: '代码邦 - 软件商城与定制开发平台',
query: promoterQuery(),
};
},
});