var app = getApp(); var defaultAvatarUrl = ''; import AuthService from '../../utils/api/testapi'; Page({ data: { motto: 'Hello World', userInfo: { avatarUrl: defaultAvatarUrl, nickName: '', }, hasUserInfo: false, canIUseGetUserProfile: wx.canIUse('getUserProfile'), canIUseNicknameComp: wx.canIUse('input.type.nickname'), triggered: false, list: [], isLoading: false, count: 1, hasMore: true, isFixed: false, opacity: 1, tabs: [{ title: '测试1' }, { title: '测试2' }, { title: '测试3' }, { title: '测试4' }, { title: '测试5' }, { title: '测试6' }, { title: '测试7' }, { title: '测试8' }, { title: '测试9' }, { title: '测试10' }], activeTab: 0 }, onLoad(e) { for (var i = 0; i < 80; i++) { this.data.list.push(`ssss==${i}`) } this.setData({ list: this.data.list }) }, doRefresh() { var _self = this; console.log('刷新中...') setTimeout(() => { var tempList = []; for (var i = 0; i < 30; i++) { tempList.push("ssss") } _self.setData({ list: tempList, hasMore: true, triggered: false }) }, 3000); }, onPageScroll(e) { console.log(e) if (e.scrollTop < 10) { this.setData({ opacity: 1 }) } else { this.setData({ opacity: e.scrollTop / 100 }) } if (e.scrollTop >= 130) { this.setData({ isFixed: true }) } else { this.setData({ isFixed: false }) } }, doLoadMore() { var _self = this; if (_self.data.isLoading || !_self.data.hasMore) { return } console.log('触底了') _self.setData({ isLoading: true }) setTimeout(() => { var tempList = [] for (let i = 0; i < 20; i++) { tempList.push(`新添加==${i}`) } var c = ++_self.data.count console.log(`页面=${c}`) _self.setData({ count: c, hasMore: c < 3 }) _self.setData({ list: _self.data.list.concat(tempList), isLoading: false }) }, 3000); }, bindViewTap() { AuthService.login({ name: '223', pwd: '1234' }) .then(res => { console.log(res) }, err => { console.log(err) }) }, onChooseAvatar(e) { const { avatarUrl } = e.detail const { nickName } = this.data.userInfo this.setData({ "userInfo.avatarUrl": avatarUrl, hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, }) }, onInputChange(e) { const nickName = e.detail.value const { avatarUrl } = this.data.userInfo this.setData({ "userInfo.nickName": nickName, hasUserInfo: nickName && avatarUrl && avatarUrl !== defaultAvatarUrl, }) }, getUserProfile(e) { // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗 wx.getUserProfile({ desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写 success: (res) => { console.log(res) this.setData({ userInfo: res.userInfo, hasUserInfo: true }) } }) }, onTabClick(e) { const index = e.detail.index this.setData({ activeTab: index }) }, onChange(e) { const index = e.detail.index this.setData({ activeTab: index }) }, handleClick(e) { wx.navigateTo({ url: './webview', }) } })