Showing
9 changed files
with
153 additions
and
26 deletions
| ... | @@ -120,7 +120,8 @@ export default { | ... | @@ -120,7 +120,8 @@ export default { |
| 120 | this.$router.push({ | 120 | this.$router.push({ |
| 121 | path: '/client/videoDetail', | 121 | path: '/client/videoDetail', |
| 122 | query: { | 122 | query: { |
| 123 | - prod_id: this.item.id | 123 | + prod_id: this.item.id, |
| 124 | + path: this.item.path // 特殊标识,判断入口 为keepAlive使用 | ||
| 124 | } | 125 | } |
| 125 | }); | 126 | }); |
| 126 | }, | 127 | }, | ... | ... |
| ... | @@ -28,6 +28,9 @@ export const useUnwatchList = () => { | ... | @@ -28,6 +28,9 @@ export const useUnwatchList = () => { |
| 28 | if (res.data.code === 1) { | 28 | if (res.data.code === 1) { |
| 29 | prod_list.value = _.concat(prod_list.value, res.data.data.prod); | 29 | prod_list.value = _.concat(prod_list.value, res.data.data.prod); |
| 30 | prod_list.value = _.uniqBy(prod_list.value, 'id'); | 30 | prod_list.value = _.uniqBy(prod_list.value, 'id'); |
| 31 | + _.each(prod_list.value, (item) => { | ||
| 32 | + item.path = 'unWatchList' | ||
| 33 | + }) | ||
| 31 | offset.value = prod_list.value.length; | 34 | offset.value = prod_list.value.length; |
| 32 | loading.value = false; | 35 | loading.value = false; |
| 33 | // 数据全部加载完成 | 36 | // 数据全部加载完成 | ... | ... |
| ... | @@ -197,7 +197,8 @@ export default [{ | ... | @@ -197,7 +197,8 @@ export default [{ |
| 197 | name: '未看作品', | 197 | name: '未看作品', |
| 198 | component: () => import('./views/me/unwatchList.vue'), | 198 | component: () => import('./views/me/unwatchList.vue'), |
| 199 | meta: { | 199 | meta: { |
| 200 | - title: '未看作品' | 200 | + title: '未看作品', |
| 201 | + keepAlive: true | ||
| 201 | }, | 202 | }, |
| 202 | children: [] | 203 | children: [] |
| 203 | }, { | 204 | }, { | ... | ... |
| ... | @@ -9,6 +9,8 @@ export const mainStore = defineStore('main', { | ... | @@ -9,6 +9,8 @@ export const mainStore = defineStore('main', { |
| 9 | comment_num: 0, | 9 | comment_num: 0, |
| 10 | video_detail: {}, | 10 | video_detail: {}, |
| 11 | scrollTop: 0, | 11 | scrollTop: 0, |
| 12 | + scrollTopCollection: 0, | ||
| 13 | + scrollTopLike: 0, | ||
| 12 | }; | 14 | }; |
| 13 | }, | 15 | }, |
| 14 | getters: {}, | 16 | getters: {}, |
| ... | @@ -25,5 +27,11 @@ export const mainStore = defineStore('main', { | ... | @@ -25,5 +27,11 @@ export const mainStore = defineStore('main', { |
| 25 | changeScrollTop (v) { | 27 | changeScrollTop (v) { |
| 26 | this.scrollTop = v; | 28 | this.scrollTop = v; |
| 27 | }, | 29 | }, |
| 30 | + changeScrollTopCollection (v) { | ||
| 31 | + this.scrollTopCollection = v; | ||
| 32 | + }, | ||
| 33 | + changeScrollTopLike (v) { | ||
| 34 | + this.scrollTopLike = v; | ||
| 35 | + }, | ||
| 28 | }, | 36 | }, |
| 29 | }); | 37 | }); | ... | ... |
| ... | @@ -9,28 +9,51 @@ | ... | @@ -9,28 +9,51 @@ |
| 9 | 9 | ||
| 10 | <script setup> | 10 | <script setup> |
| 11 | import VideoCard from '@/components/VideoCard/index.vue' | 11 | import VideoCard from '@/components/VideoCard/index.vue' |
| 12 | +import Cookies from 'js-cookie' | ||
| 12 | 13 | ||
| 13 | import { ref } from 'vue' | 14 | import { ref } from 'vue' |
| 14 | import axios from '@/utils/axios'; | 15 | import axios from '@/utils/axios'; |
| 15 | import { Toast } from 'vant'; | 16 | import { Toast } from 'vant'; |
| 17 | +import $ from 'jquery' | ||
| 18 | +import _ from 'lodash' | ||
| 19 | + | ||
| 20 | +/******************** 返回点击位置 ********************/ | ||
| 21 | +window.addEventListener('scroll', () => { | ||
| 22 | + if (window.scrollY) { | ||
| 23 | + Cookies.set('scrollTopCollection', window.scrollY); | ||
| 24 | + } | ||
| 25 | +}) | ||
| 26 | + | ||
| 27 | +const scrollTopCollection = Cookies.get('scrollTopCollection') ? Number(Cookies.get('scrollTopCollection')) : 0; | ||
| 28 | +if (scrollTopCollection) { | ||
| 29 | + setTimeout(() => { | ||
| 30 | + $("html,body").animate({ "scrollTop": scrollTopCollection }) | ||
| 31 | + }, 500) | ||
| 32 | +} | ||
| 33 | +/*****************************************************/ | ||
| 16 | 34 | ||
| 17 | // 处理书籍下作品列表 | 35 | // 处理书籍下作品列表 |
| 18 | const prodList = ref([]) | 36 | const prodList = ref([]) |
| 19 | axios.get('/srv/?a=my_favor') | 37 | axios.get('/srv/?a=my_favor') |
| 20 | -.then(res => { | 38 | + .then(res => { |
| 21 | - if (res.data.code === 1) { | 39 | + if (res.data.code === 1) { |
| 22 | - prodList.value = res.data.data.prod; | 40 | + prodList.value = res.data.data.prod; |
| 23 | - } else { | 41 | + _.each(prodList.value, (item) => { |
| 24 | - console.warn(res); | 42 | + item.path = 'myCollection' |
| 25 | - Toast({ | 43 | + }) |
| 26 | - icon: 'close', | 44 | + } else { |
| 27 | - message: res.data.msg | 45 | + console.warn(res); |
| 28 | - }); | 46 | + Toast({ |
| 29 | - } | 47 | + icon: 'close', |
| 30 | -}) | 48 | + message: res.data.msg |
| 31 | -.catch(err => { | 49 | + }); |
| 32 | - console.error(err); | 50 | + } |
| 33 | -}) | 51 | + }) |
| 52 | + .catch(err => { | ||
| 53 | + console.error(err); | ||
| 54 | + }); | ||
| 55 | + | ||
| 56 | + | ||
| 34 | </script> | 57 | </script> |
| 35 | 58 | ||
| 36 | <script> | 59 | <script> |
| ... | @@ -38,12 +61,12 @@ import mixin from 'common/mixin'; | ... | @@ -38,12 +61,12 @@ import mixin from 'common/mixin'; |
| 38 | 61 | ||
| 39 | export default { | 62 | export default { |
| 40 | mixins: [mixin.init], | 63 | mixins: [mixin.init], |
| 41 | - data () { | 64 | + data() { |
| 42 | return { | 65 | return { |
| 43 | 66 | ||
| 44 | } | 67 | } |
| 45 | }, | 68 | }, |
| 46 | - mounted () { | 69 | + mounted() { |
| 47 | 70 | ||
| 48 | }, | 71 | }, |
| 49 | methods: { | 72 | methods: { |
| ... | @@ -53,5 +76,4 @@ export default { | ... | @@ -53,5 +76,4 @@ export default { |
| 53 | </script> | 76 | </script> |
| 54 | 77 | ||
| 55 | <style lang="less" scoped> | 78 | <style lang="less" scoped> |
| 56 | - | ||
| 57 | -</style> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 79 | +</style> | ... | ... |
| ... | @@ -286,6 +286,7 @@ const getUnwatch = () => { | ... | @@ -286,6 +286,7 @@ const getUnwatch = () => { |
| 286 | 286 | ||
| 287 | <script> | 287 | <script> |
| 288 | import mixin from 'common/mixin'; | 288 | import mixin from 'common/mixin'; |
| 289 | +import Cookies from 'js-cookie' | ||
| 289 | 290 | ||
| 290 | export default { | 291 | export default { |
| 291 | mixins: [mixin.init], | 292 | mixins: [mixin.init], |
| ... | @@ -295,7 +296,9 @@ export default { | ... | @@ -295,7 +296,9 @@ export default { |
| 295 | } | 296 | } |
| 296 | }, | 297 | }, |
| 297 | mounted() { | 298 | mounted() { |
| 298 | - | 299 | + // 重置位置缓存 |
| 300 | + Cookies.set('scrollTopCollection', 0); | ||
| 301 | + Cookies.set('scrollTopLike', 0); | ||
| 299 | }, | 302 | }, |
| 300 | methods: { | 303 | methods: { |
| 301 | 304 | ... | ... |
| ... | @@ -9,10 +9,28 @@ | ... | @@ -9,10 +9,28 @@ |
| 9 | 9 | ||
| 10 | <script setup> | 10 | <script setup> |
| 11 | import VideoCard from '@/components/VideoCard/index.vue' | 11 | import VideoCard from '@/components/VideoCard/index.vue' |
| 12 | +import Cookies from 'js-cookie' | ||
| 12 | 13 | ||
| 13 | import { ref } from 'vue' | 14 | import { ref } from 'vue' |
| 14 | import axios from '@/utils/axios'; | 15 | import axios from '@/utils/axios'; |
| 15 | import { Toast } from 'vant'; | 16 | import { Toast } from 'vant'; |
| 17 | +import $ from 'jquery' | ||
| 18 | +import _ from 'lodash' | ||
| 19 | + | ||
| 20 | +/******************** 返回点击位置 ********************/ | ||
| 21 | +window.addEventListener('scroll', () => { | ||
| 22 | + if (window.scrollY) { | ||
| 23 | + Cookies.set('scrollTopLike', window.scrollY); | ||
| 24 | + } | ||
| 25 | +}) | ||
| 26 | + | ||
| 27 | +const scrollTopLike = Cookies.get('scrollTopLike') ? Number(Cookies.get('scrollTopLike')) : 0; | ||
| 28 | +if (scrollTopLike) { | ||
| 29 | + setTimeout(() => { | ||
| 30 | + $("html,body").animate({ "scrollTop": scrollTopLike }) | ||
| 31 | + }, 500) | ||
| 32 | +} | ||
| 33 | +/*****************************************************/ | ||
| 16 | 34 | ||
| 17 | // 处理书籍下作品列表 | 35 | // 处理书籍下作品列表 |
| 18 | const prodList = ref([]) | 36 | const prodList = ref([]) |
| ... | @@ -20,6 +38,9 @@ axios.get('/srv/?a=my_like') | ... | @@ -20,6 +38,9 @@ axios.get('/srv/?a=my_like') |
| 20 | .then(res => { | 38 | .then(res => { |
| 21 | if (res.data.code === 1) { | 39 | if (res.data.code === 1) { |
| 22 | prodList.value = res.data.data.prod; | 40 | prodList.value = res.data.data.prod; |
| 41 | + _.each(prodList.value, (item) => { | ||
| 42 | + item.path = 'myLike' | ||
| 43 | + }) | ||
| 23 | } else { | 44 | } else { |
| 24 | console.warn(res); | 45 | console.warn(res); |
| 25 | Toast({ | 46 | Toast({ |
| ... | @@ -30,7 +51,7 @@ axios.get('/srv/?a=my_like') | ... | @@ -30,7 +51,7 @@ axios.get('/srv/?a=my_like') |
| 30 | }) | 51 | }) |
| 31 | .catch(err => { | 52 | .catch(err => { |
| 32 | console.error(err); | 53 | console.error(err); |
| 33 | -}) | 54 | +}); |
| 34 | </script> | 55 | </script> |
| 35 | 56 | ||
| 36 | <script> | 57 | <script> |
| ... | @@ -54,4 +75,4 @@ export default { | ... | @@ -54,4 +75,4 @@ export default { |
| 54 | 75 | ||
| 55 | <style lang="less" scoped> | 76 | <style lang="less" scoped> |
| 56 | 77 | ||
| 57 | -</style> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 78 | +</style> | ... | ... |
| ... | @@ -15,8 +15,75 @@ import { useUnwatchList } from '@/composables/useUnwatchList.js' | ... | @@ -15,8 +15,75 @@ import { useUnwatchList } from '@/composables/useUnwatchList.js' |
| 15 | 15 | ||
| 16 | import VideoCard from '@/components/VideoCard/index.vue' | 16 | import VideoCard from '@/components/VideoCard/index.vue' |
| 17 | 17 | ||
| 18 | +import { ref, onActivated } from 'vue' | ||
| 19 | +import { mainStore } from '@/store' | ||
| 20 | +import { storeToRefs } from 'pinia' | ||
| 21 | +import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router' | ||
| 22 | +import $ from 'jquery' | ||
| 23 | +import _ from 'lodash'; | ||
| 24 | +import { wxInfo } from '@/utils/tools'; | ||
| 25 | + | ||
| 26 | +const $route = useRoute(); | ||
| 27 | +const $router = useRouter(); | ||
| 28 | + | ||
| 18 | const { onLoad, prod_list, finished, loading } = useUnwatchList(); | 29 | const { onLoad, prod_list, finished, loading } = useUnwatchList(); |
| 19 | 30 | ||
| 31 | +/****************** keepAlive 模块 *******************/ | ||
| 32 | + | ||
| 33 | +onActivated(() => { // keepAlive 重置后执行回调 | ||
| 34 | + // TAG: pinia应用,动态刷新数据 | ||
| 35 | + const store = mainStore() | ||
| 36 | + // 处理数据未刷新数据显示问题 | ||
| 37 | + // Pinia 解构方法:storeToRefs | ||
| 38 | + const { video_detail } = storeToRefs(store); | ||
| 39 | + // 如果作品信息有变化及时修正 | ||
| 40 | + const arr = ref([]); | ||
| 41 | + _.each(prod_list.value, (item) => { | ||
| 42 | + if (item.id === video_detail.value.id) { | ||
| 43 | + item = video_detail.value | ||
| 44 | + } | ||
| 45 | + arr.value.push(item); | ||
| 46 | + }) | ||
| 47 | + // 触发更新 | ||
| 48 | + prod_list.value = arr.value; | ||
| 49 | + /** | ||
| 50 | + * 判断微信环境 | ||
| 51 | + */ | ||
| 52 | + if (wxInfo().isiOS || wxInfo().isAndroid) { | ||
| 53 | + // TODO: 手机微信浏览器位置变动了,需要手动调整位置,但是无刷新是起作用的 | ||
| 54 | + const { scrollTop } = storeToRefs(store); | ||
| 55 | + if (scrollTop.value) { | ||
| 56 | + $("html,body").animate({ "scrollTop": scrollTop.value }) | ||
| 57 | + } | ||
| 58 | + window.addEventListener('scroll',()=>{ | ||
| 59 | + if (window.scrollY) { | ||
| 60 | + store.changeScrollTop(window.scrollY) | ||
| 61 | + } | ||
| 62 | + }); | ||
| 63 | + } | ||
| 64 | +}); | ||
| 65 | + | ||
| 66 | +const changeRouterKeepAlive = (path, keepAlive) => { | ||
| 67 | + $router.options.routes.map((item) => { | ||
| 68 | + if (item.path === path) { | ||
| 69 | + item.meta.keepAlive = keepAlive; | ||
| 70 | + } | ||
| 71 | + }); | ||
| 72 | +}; | ||
| 73 | + | ||
| 74 | +onBeforeRouteLeave((to, from) => { | ||
| 75 | + // 如果是从页面返回,需要重置keepAlive状态 | ||
| 76 | + // 列表页 =》 详情页 | ||
| 77 | + // TAG: keepAlive | ||
| 78 | + if (to.path === '/client/videoDetail' && to.query.path) { | ||
| 79 | + changeRouterKeepAlive(from.path, true); | ||
| 80 | + } else { | ||
| 81 | + changeRouterKeepAlive(from.path, false); | ||
| 82 | + } | ||
| 83 | +}) | ||
| 84 | + | ||
| 85 | +/*********************************************************/ | ||
| 86 | + | ||
| 20 | </script> | 87 | </script> |
| 21 | 88 | ||
| 22 | <script> | 89 | <script> |
| ... | @@ -40,4 +107,4 @@ export default { | ... | @@ -40,4 +107,4 @@ export default { |
| 40 | 107 | ||
| 41 | <style lang="less" scoped> | 108 | <style lang="less" scoped> |
| 42 | .unwatch-list-page {} | 109 | .unwatch-list-page {} |
| 43 | -</style> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 110 | +</style> | ... | ... |
| ... | @@ -20,7 +20,8 @@ axios.get('/srv/?a=my_prod') | ... | @@ -20,7 +20,8 @@ axios.get('/srv/?a=my_prod') |
| 20 | .then(res => { | 20 | .then(res => { |
| 21 | if (res.data.code === 1) { | 21 | if (res.data.code === 1) { |
| 22 | res.data.data.prod.forEach(v => { | 22 | res.data.data.prod.forEach(v => { |
| 23 | - v.status = v.status.toUpperCase() | 23 | + v.status = v.status.toUpperCase(); |
| 24 | + v.path = 'myVideoList' | ||
| 24 | }) | 25 | }) |
| 25 | prodList.value = res.data.data.prod; | 26 | prodList.value = res.data.data.prod; |
| 26 | } else { | 27 | } else { |
| ... | @@ -56,4 +57,4 @@ export default { | ... | @@ -56,4 +57,4 @@ export default { |
| 56 | 57 | ||
| 57 | <style lang="less" scoped> | 58 | <style lang="less" scoped> |
| 58 | 59 | ||
| 59 | -</style> | ||
| ... | \ No newline at end of file | ... | \ No newline at end of file |
| 60 | +</style> | ... | ... |
-
Please register or login to post a comment