import { fetchHome } from '../../services/home/home'; import Toast from 'tdesign-miniprogram/toast/index'; import { isLogin } from '../../services/permission/login' import { sessionUpload } from '../../services/api/session' import { articleList } from '../../services/api/article' Page({ data: { imgSrcs: [], tabList: [], goodsList: [], goodsListLoadStatus: 0, pageLoading: false, current: 0, autoplay: true, duration: 500, interval: 5000, navigation: { type: 'dots' }, loadingDialog: false, swiperList: [], }, goodListPagination: { index: 0, num: 20, }, privateData: { tabIndex: 0, }, onShow() { this.getTabBar().init(); }, onLoad() { this.init(); }, onReachBottom() {}, onPullDownRefresh() { this.init(); }, init() { isLogin() this.loadHomePage() }, loadHomePage() { articleList({ type: 2, isPublic: 2, pageNumber: 1, pageSize: 10 }).then(response => { if (response.code == 10000) { console.log(response.content); if (response.content.contentList.length == 0) { return } let tmp = [] for (let index = 0; index < response.content.contentList.length; index++) { const element = response.content.contentList[index]; tmp.push(element.headerUrl) } this.setData({ swiperList: response.content.contentList, imgSrcs: tmp }) console.log(this.data.imgSrcs); } }) // this.setData({ // imgSrcs: [ // 'https://webplus-cn-hangzhou-s-603871eef968dd14ced82ed5.oss-cn-hangzhou.aliyuncs.com/hextech/static/use_btn.jpg', // 'https://cdn-we-retail.ym.tencent.com/tsr/home/v2/banner2.png' // ], // }); }, onReTry() {}, // 上传图片 uploadPicture() { // 跳转扫描 wx.navigateTo({ url: `/pages/home/camera/index`, }); return // 打开摄像头 wx.chooseMedia({ count: 1, mediaType: ['image'], sourceType: ['album', 'camera'], maxDuration: 30, camera: 'back', success: (res) => { if (res.tempFiles.length >= 1) { this.setData({ loadingDialog: true }) sessionUpload({ urls: res.tempFiles, session: 0 }).then(tmp => { console.log(tmp); if (tmp.code == 10000) { if (this.data.loadingDialog) { this.goSession(tmp.content.sessionId); } } this.setData({ loadingDialog: false }) }) } else {} } }) }, onSwiperClick(e) { const id = this.data.swiperList[e.detail.index].id console.log(id); wx.navigateTo({ url: `/pages/info/content-page/index?id=${id}`, }); }, textButton(e) { // this.goSession(76) this.setData({ loadingDialog: !this.data.loadingDialog }) }, onCloseDialog() { this.setData({ loadingDialog: false }) }, goSession(sessionId) { wx.navigateTo({ url: `/pages/home/session/session?sessionId=${sessionId}`, }); }, onShareAppMessage() { var shareObj = { title: "食品配料分析", // 默认是小程序的名称(可以写slogan等) path: '/pages/home/home', // 默认是当前页面,必须是以‘/'开头的完整路径 imageUrl: 'https://webplus-cn-hangzhou-s-603871eef968dd14ced82ed5.oss-cn-hangzhou.aliyuncs.com/hextech/static/Hammer_and_Keyboard_2-svg.png', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4 success: function (res) { // 转发成功之后的回调 if (res.errMsg == 'shareAppMessage:ok') {} }, fail: function () { // 转发失败之后的回调 if (res.errMsg == 'shareAppMessage:fail cancel') { // 用户取消转发 } else if (res.errMsg == 'shareAppMessage:fail') { // 转发失败,其中 detail message 为详细失败信息 } } } return shareObj; } });