123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- export default {
- data() {
- return {
- MIXIN_NowIndex: 0,
- MIXIN_ActiveIndex: 0,
- MIXIN_MoveBarLeft: 0,
- MIXIN_FinishedIndex: 0,
- MIXIN_ScrollViewHeight: 0, // scroll view 高
- MIXIN_ScreenWidth: this.$store.state.device.screenWidth, // 屏幕宽,
- MIXIN_api_all: false
- }
- },
- mounted() {
- this.$offset('.swiper').then(res => {
- this.MIXIN_ScrollViewHeight = res.height
- }) // 设置scrollview 高
- },
- methods: {
- MIXIN_transition({
- detail: {
- dx
- }
- }) { // swiper 切换时 ///////////////////////////////////////////////////////////////////<固定写法>
- // this.MIXIN_MoveBarLeft = this.MIXIN_FinishedIndex * (this.MIXIN_ScreenWidth / this.typeList.length) + dx / this.typeList.length
- },
- MIXIN_change({
- detail: {
- current
- }
- }) {
- this.MIXIN_ActiveIndex = current
- this.MIXIN_MoveBarLeft = this.MIXIN_ActiveIndex * (this.MIXIN_ScreenWidth / this.typeList.length)
- },
- MIXIN_animationfinish({
- detail: {
- current
- }
- }) { // swiper 停止切换
- this.MIXIN_FinishedIndex = this.MIXIN_NowIndex = current
- if (!this.lists[this.MIXIN_NowIndex].length && this.page[this.MIXIN_NowIndex] !==
- 0) { // 当当前类型数量为 0 且有不是 没有更多时请求列表
- this.MIXIN_request()
- }
- },
- switchSwiper(index) { // 点击导航栏切换
- this.MIXIN_NowIndex = this.MIXIN_ActiveIndex = index
- this.MIXIN_MoveBarLeft = (this.MIXIN_NowIndex + 1) * (this.MIXIN_ScreenWidth / this.typeList.length)
- }, /////////////////////////////////////////////////////////////////////////////////////////////////////////////////<固定写法>
- MIXIN_pulldownrefresh() { // 下拉刷新
- this.page[this.MIXIN_NowIndex] = 1
- this.MIXIN_request().then(() => {
- this.$refs.pulldownRefresher.pullup()
- })
- },
- MIXIN_scrolltolower() { // 上拉加载
- this._requesting ? '' : this.MIXIN_request('loadmore')
- },
- MIXIN_request(action) { // 请求数据
- if (this.MIXIN_api_all) {
- let a = []
- this.apis.forEach(api => {
- a.push(api({
- page: 1
- }))
- })
- return Promise.all(a).then(res => {
- this.MIXIN_api_all = false
- res.forEach(({
- data
- }, i) => {
- this.totalList[i] = data.total
- this.lists[i] = data.list
- if (data.list && data.list.length < data.size) {
- this.page[i] = 0
- } else {
- this.page = [2, 2]
- }
- })
- this.MIXIN_requestHandle ? this.MIXIN_requestHandle(res[0]) : '' // 执行请求结束处理函数
- })
- } else {
- return new Promise(resolve => { // 只有在 首次加载列表或者下拉刷新时才显示 liaoding
- if (this.page[this.MIXIN_NowIndex]) { // 当上一批数量不小于 size 时执行
- !action && uni.showLoading({
- mask: true
- }) // 开始 loading, 只有在 首次加载列表或者下拉刷新时才显示 liaoding
- this._requesting = true // 请求加锁防抖
- let params = {
- page: this.page[this.MIXIN_NowIndex]
- }
- this.queryParams ? Object.assign(params, this.queryParams) : params
- this.apis[this.MIXIN_NowIndex](params).then(res => {
- this.MIXIN_requestHandle ? this.MIXIN_requestHandle(res) : '' // 执行请求结束处理函数
- !action ? this.lists[this.MIXIN_NowIndex] = [] : '', // 如果是下拉刷新,清空列表
- this.lists[this.MIXIN_NowIndex] = [...this.lists[this.MIXIN_NowIndex],
- ...res.data.list
- ]
- res.data.list.length < +res.data.size ? this.page[this.MIXIN_NowIndex] = 0 :
- this.page[this.MIXIN_NowIndex] += 1 // 如果返回列表数量小于 10 表示没有更多了
- }).catch(() => { // 网络请求失败 进入失败状态
- this.page[this.MIXIN_NowIndex] = -1
- this.lists[this.MIXIN_NowIndex] = []
- }).finally(() => { // promise 结束
- this._requesting = false // 取消请求加锁防抖
- resolve() // 通知下拉刷新收起并把数据传出去
- })
- }
- })
- }
- } ///////////////////////////////////////////////////////////////////////////////////////<固定写法>
- }
- }
|