Browse Source

mock数据

pull/19/head
zyronon 4 years ago
parent
commit
016cafaa17
  1. 7859
      src/assets/data/resource.js
  2. 3
      src/components/slide/SlideColumnVirtualList.vue
  3. 2
      src/components/slide/SlideRowList.vue
  4. 53
      src/mock/index.js
  5. 13
      src/pages/home/Index2.vue
  6. 1
      src/pages/me/Me.vue

7859
src/assets/data/resource.js

File diff suppressed because it is too large Load Diff

3
src/components/slide/SlideColumnVirtualList.vue

@ -64,6 +64,7 @@ export default {
watch: { watch: {
watchList: { watchList: {
handler(newVal, oldVal) { handler(newVal, oldVal) {
console.log('watch', newVal.length, oldVal.length)
let that = this let that = this
if (oldVal.length === 0) { if (oldVal.length === 0) {
let startIndex = 0 let startIndex = 0
@ -221,7 +222,7 @@ export default {
} else { } else {
this.currentSlideItemIndex -= 1 this.currentSlideItemIndex -= 1
} }
console.log('gapTime', this.currentSlideItemIndex) // console.log('gapTime', this.currentSlideItemIndex)
// console.log(this.slideItems.length) // console.log(this.slideItems.length)
let that = this let that = this

2
src/components/slide/SlideRowList.vue

@ -188,7 +188,7 @@ export default {
this.tabIndicatorRelationActiveIndexLefts.push( this.tabIndicatorRelationActiveIndexLefts.push(
item.getBoundingClientRect().x - tabs.children[0].getBoundingClientRect().x + (this.isHome ? this.tabWidth * 0.15 : 0)) item.getBoundingClientRect().x - tabs.children[0].getBoundingClientRect().x + (this.isHome ? this.tabWidth * 0.15 : 0))
} }
console.log(this.tabIndicatorRelationActiveIndexLefts) // console.log(this.tabIndicatorRelationActiveIndexLefts)
this.indicatorSpace = this.tabIndicatorRelationActiveIndexLefts[1] - this.tabIndicatorRelationActiveIndexLefts[0] this.indicatorSpace = this.tabIndicatorRelationActiveIndexLefts[1] - this.tabIndicatorRelationActiveIndexLefts[0]
if (this.isHome) { if (this.isHome) {
this.$setCss(this.indicatorRef, 'transition-duration', `300ms`) this.$setCss(this.indicatorRef, 'transition-duration', `300ms`)

53
src/mock/index.js

@ -1,10 +1,30 @@
import Mock from 'mockjs' import Mock from 'mockjs'
import globalMethods from '../utils/global-methods' import globalMethods from '../utils/global-methods'
import {da} from "pinyin/data/dict-zi-web"; import resource from "../assets/data/resource.js";
Mock.setup({ Mock.setup({
timeout: '500-1000' timeout: '500-1000'
}) })
let allRecommendVideos = []
for (let i = 0; i < 10; i++) {
allRecommendVideos = allRecommendVideos.concat(resource.videos)
}
Mock.mock(/recommended/, options => {
let params = globalMethods.$parseURL(options.url).params
params.pageNo = ~~params.pageNo
params.pageSize = ~~params.pageSize
let offset = params.pageNo * params.pageSize
let limit = params.pageNo * params.pageSize + params.pageSize
return Mock.mock({
data: {
total: allRecommendVideos.length,
list: allRecommendVideos.slice(offset, limit),
}, code: 200, msg: '',
})
}
)
Mock.Random.extend({ Mock.Random.extend({
imgs: function (date) { imgs: function (date) {
@ -49,32 +69,19 @@ Mock.Random.extend({
Mock.mock('me', data) Mock.mock('me', data)
}()) }())
let pageSize = 15
Mock.mock(/my/, options => { Mock.mock(/my/, options => {
let params = globalMethods.$parseURL(options.url).params let params = globalMethods.$parseURL(options.url).params
params.pageNo = ~~params.pageNo params.pageNo = ~~params.pageNo
params.pageSize = ~~params.pageSize params.pageSize = ~~params.pageSize
params.total = ~~params.total let offset = params.pageNo * params.pageSize
// console.log(params) let limit = params.pageNo * params.pageSize + params.pageSize
// let data = {total: Mock.Random.natural(1, 20)} return Mock.mock({
// data[`list|${data.total > pageSize ? pageSize : data.total}`] = [{'like|10000-990000': 1000000, src: '@imgs'}] data: {
// data[`list|${data.total}`] = [{'like|10000-990000': 1000000, src: '@imgs'}] pageNo: params.pageNo,
let data = { total: resource.my.length,
total: params.total === -1 ? 20 : params.total, list: resource.my.slice(offset, limit),
pageNo: params.pageNo, }, code: 200, msg: '',
pageSize: params.pageSize })
}
let listLength = 0
if (params.pageNo !== 0) {
let remainder = data.total - (params.pageNo * params.pageSize)
listLength = remainder > params.pageSize ? params.pageSize : remainder
} else {
listLength = data.total > params.pageSize ? params.pageSize : data.total
}
data[`list|${listLength}`] = [{'like|10000-990000': 1000000, src: '@imgs'}]
// console.log(data)
Mock.mock(/my/, Mock.mock({data, code: 200, msg: '',}))
return Mock.mock({data, code: 200, msg: '',})
}) })

13
src/pages/home/Index2.vue

@ -241,7 +241,7 @@ export default {
activeIndex: 1, activeIndex: 1,
totalSize: 52, totalSize: 52,
pageSize: 10, pageSize: 10,
pageNo: 1, pageNo: 0,
loading: false, loading: false,
render: (item, itemIndex, play) => { render: (item, itemIndex, play) => {
return ( return (
@ -276,11 +276,14 @@ export default {
} }
}, },
created() { created() {
this.getData()
}, },
mounted() { mounted() {
this.height = document.body.clientHeight this.height = document.body.clientHeight
this.width = document.body.clientWidth this.width = document.body.clientWidth
this.getData()
}, },
methods: { methods: {
delayShowDialog(cb) { delayShowDialog(cb) {
@ -290,10 +293,11 @@ export default {
}, },
dislike() { dislike() {
this.$refs.virtualList.dislike(this.videos[10]) this.$refs.virtualList.dislike(this.videos[10])
this.videos[this.currentSlideItemIndex] = this.videos[10]
this.$notice('操作成功,将减少此类视频的推荐') this.$notice('操作成功,将减少此类视频的推荐')
}, },
async getData() { async getData() {
if (process.env.NODE_ENV === 'development') { if (process.env.NODE_ENV !== 'development') {
this.totalSize = 11 this.totalSize = 11
// return this.videos = this.$clone(this.localVideos) // return this.videos = this.$clone(this.localVideos)
// await this.$sleep(200) // await this.$sleep(200)
@ -302,9 +306,10 @@ export default {
} }
this.loading = true this.loading = true
let res = await this.$api.videos.recommended({pageNo: this.pageNo, pageSize: this.pageSize}) let res = await this.$api.videos.recommended({pageNo: this.pageNo, pageSize: this.pageSize})
console.log(res)
this.loading = false this.loading = false
if (res.code === this.SUCCESS) { if (res.code === this.SUCCESS) {
this.totalSize = res.data.count this.totalSize = res.data.total
this.videos = this.videos.concat(res.data.list) this.videos = this.videos.concat(res.data.list)
// this.videos = this.$clone(this.localVideos) // this.videos = this.$clone(this.localVideos)
} else { } else {

1
src/pages/me/Me.vue

@ -482,6 +482,7 @@ export default {
switch (newVal) { switch (newVal) {
case 0: case 0:
res = await this.$api.videos.my({pageNo: this.videos.my.pageNo, pageSize: this.pageSize,}) res = await this.$api.videos.my({pageNo: this.videos.my.pageNo, pageSize: this.pageSize,})
console.log(res)
if (res.code === this.SUCCESS) this.videos.my = res.data if (res.code === this.SUCCESS) this.videos.my = res.data
break break
case 1: case 1:

Loading…
Cancel
Save