Showing
4 changed files
with
82 additions
and
66 deletions
| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | * @Author: hookehuyr hookehuyr@gmail.com | 2 | * @Author: hookehuyr hookehuyr@gmail.com |
| 3 | * @Date: 2022-05-17 12:13:13 | 3 | * @Date: 2022-05-17 12:13:13 |
| 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 5 | - * @LastEditTime: 2022-06-09 09:40:35 | 5 | + * @LastEditTime: 2022-06-12 22:50:29 |
| 6 | * @FilePath: /tswj/src/composables/index.js | 6 | * @FilePath: /tswj/src/composables/index.js |
| 7 | * @Description: | 7 | * @Description: |
| 8 | */ | 8 | */ |
| ... | @@ -13,6 +13,7 @@ import { useDefaultPerf } from '@/composables/useDefaultPerf.js' | ... | @@ -13,6 +13,7 @@ import { useDefaultPerf } from '@/composables/useDefaultPerf.js' |
| 13 | import { useBookList, useAsyncBookList } from '@/composables/useBookList.js' | 13 | import { useBookList, useAsyncBookList } from '@/composables/useBookList.js' |
| 14 | import { useShortcutBar } from '@/composables/useShortcutBar.js' | 14 | import { useShortcutBar } from '@/composables/useShortcutBar.js' |
| 15 | import { useScrollTop } from '@/composables/useScrollTop.js' | 15 | import { useScrollTop } from '@/composables/useScrollTop.js' |
| 16 | +import { useMessageList } from '@/composables/useMessageList.ts' | ||
| 16 | 17 | ||
| 17 | export { | 18 | export { |
| 18 | useVideoList, | 19 | useVideoList, |
| ... | @@ -20,7 +21,8 @@ export { | ... | @@ -20,7 +21,8 @@ export { |
| 20 | useBookList, | 21 | useBookList, |
| 21 | useAsyncBookList, | 22 | useAsyncBookList, |
| 22 | useShortcutBar, | 23 | useShortcutBar, |
| 23 | - useScrollTop | 24 | + useScrollTop, |
| 25 | + useMessageList, | ||
| 24 | } | 26 | } |
| 25 | 27 | ||
| 26 | /** | 28 | /** |
| ... | @@ -30,6 +32,6 @@ export { | ... | @@ -30,6 +32,6 @@ export { |
| 30 | * @param {*} callback | 32 | * @param {*} callback |
| 31 | */ | 33 | */ |
| 32 | export function useEventListener(target, event, callback) { | 34 | export function useEventListener(target, event, callback) { |
| 33 | - onMounted(() => target && target.addEventListener(event, callback)) | 35 | + onMounted(() => target?.addEventListener(event, callback)) |
| 34 | - onUnmounted(() => target && target.removeEventListener(event, callback)) | 36 | + onUnmounted(() => target?.removeEventListener(event, callback)) |
| 35 | } | 37 | } | ... | ... |
| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | * @Author: hookehuyr hookehuyr@gmail.com | 2 | * @Author: hookehuyr hookehuyr@gmail.com |
| 3 | * @Date: 2022-05-07 17:46:54 | 3 | * @Date: 2022-05-07 17:46:54 |
| 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 5 | - * @LastEditTime: 2022-06-09 11:26:42 | 5 | + * @LastEditTime: 2022-06-12 22:55:58 |
| 6 | * @FilePath: /tswj/src/composables/useBookList.js | 6 | * @FilePath: /tswj/src/composables/useBookList.js |
| 7 | * @Description: | 7 | * @Description: |
| 8 | */ | 8 | */ | ... | ... |
src/composables/useMessageList.ts
0 → 100644
| 1 | +/* | ||
| 2 | + * @Date: 2022-06-12 22:51:21 | ||
| 3 | + * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 4 | + * @LastEditTime: 2022-06-12 23:00:04 | ||
| 5 | + * @FilePath: /tswj/src/composables/useMessageList.ts | ||
| 6 | + * @Description: 文件描述 | ||
| 7 | + */ | ||
| 8 | +import { ref } from 'vue' | ||
| 9 | +import { myCommentAPI } from '@/api/C/me' | ||
| 10 | +import _ from 'lodash' | ||
| 11 | + | ||
| 12 | +export const useMessageList = () => { | ||
| 13 | + // 我的留言接口联调 | ||
| 14 | + interface commentListType { | ||
| 15 | + id: string; | ||
| 16 | + avatar: string; | ||
| 17 | + name: string; | ||
| 18 | + kg_name: string; | ||
| 19 | + comment_time: string; | ||
| 20 | + note: string; | ||
| 21 | + c_action: string; | ||
| 22 | + c_name: string; | ||
| 23 | + cover: string; | ||
| 24 | + prod_id: string; | ||
| 25 | + perf_id: string; | ||
| 26 | + book_id: string; | ||
| 27 | + perf_name: string; | ||
| 28 | + book_name: string; | ||
| 29 | + localism_type: string; | ||
| 30 | + is_new: number; | ||
| 31 | + } | ||
| 32 | + const commentList = ref<commentListType[]>([]) | ||
| 33 | + const loading = ref(false); | ||
| 34 | + const finished = ref(false); | ||
| 35 | + const limit = ref(10); | ||
| 36 | + const offset = ref(0) | ||
| 37 | + const finishedTextStatus = ref(false); | ||
| 38 | + const emptyStatus = ref(false); | ||
| 39 | + const onLoad = async () => { | ||
| 40 | + const { data } = await myCommentAPI({ limit: limit.value, offset: offset.value }); | ||
| 41 | + data.forEach((item: { target_name: string | null | undefined; c_action: string; c_name: string; }) => { | ||
| 42 | + let arr = _.split(item.target_name, '@'); // 分割评论的动作和姓名 | ||
| 43 | + item.c_action = arr[0]; // 评论动作 | ||
| 44 | + item.c_name = arr[1]; // 评论姓名 | ||
| 45 | + }); | ||
| 46 | + // 数据全部加载完成 | ||
| 47 | + if (!data.length) { | ||
| 48 | + // 加载状态结束 | ||
| 49 | + finished.value = true; | ||
| 50 | + } | ||
| 51 | + commentList.value = [...commentList.value, ...data]; | ||
| 52 | + offset.value = commentList.value.length; | ||
| 53 | + loading.value = false; | ||
| 54 | + // 隐藏loading标识,空列表图标 | ||
| 55 | + if (!commentList.value.length) { | ||
| 56 | + finishedTextStatus.value = false; | ||
| 57 | + emptyStatus.value = true; | ||
| 58 | + } else { | ||
| 59 | + emptyStatus.value = false; | ||
| 60 | + } | ||
| 61 | + } | ||
| 62 | + return { | ||
| 63 | + onLoad, | ||
| 64 | + commentList, | ||
| 65 | + loading, | ||
| 66 | + finished, | ||
| 67 | + finishedTextStatus, | ||
| 68 | + emptyStatus, | ||
| 69 | + }; | ||
| 70 | +} |
| ... | @@ -53,79 +53,23 @@ | ... | @@ -53,79 +53,23 @@ |
| 53 | <script lang="ts" setup> | 53 | <script lang="ts" setup> |
| 54 | // import { mainStore } from '@/store' | 54 | // import { mainStore } from '@/store' |
| 55 | import { no_image, icon_avatar } from '@/utils/generateIcons.js' | 55 | import { no_image, icon_avatar } from '@/utils/generateIcons.js' |
| 56 | -import { ref, onActivated } from 'vue' | 56 | +import { onActivated } from 'vue' |
| 57 | import { onBeforeRouteLeave } from 'vue-router' | 57 | import { onBeforeRouteLeave } from 'vue-router' |
| 58 | import _ from 'lodash' | 58 | import _ from 'lodash' |
| 59 | import { Toast, Dialog } from 'vant'; | 59 | import { Toast, Dialog } from 'vant'; |
| 60 | // import { addPages } from '@/hooks/useKeepAlive' | 60 | // import { addPages } from '@/hooks/useKeepAlive' |
| 61 | import goToVideoDetail from '@/router/methods/videoDetail' | 61 | import goToVideoDetail from '@/router/methods/videoDetail' |
| 62 | -import { myCommentAPI, delCommentAPI } from '@/api/C/me' | 62 | +import { delCommentAPI } from '@/api/C/me' |
| 63 | import { myCommentTimeAPI } from '@/api/C/perf' | 63 | import { myCommentTimeAPI } from '@/api/C/perf' |
| 64 | +import { useMessageList } from '@/composables'; | ||
| 65 | + | ||
| 66 | +const { onLoad, commentList, loading, finished, finishedTextStatus, emptyStatus, } = useMessageList(); | ||
| 64 | 67 | ||
| 65 | onBeforeRouteLeave(async () => { | 68 | onBeforeRouteLeave(async () => { |
| 66 | // 更新留言阅读情况 | 69 | // 更新留言阅读情况 |
| 67 | await myCommentTimeAPI({ optr_type: 'my_comment' }); | 70 | await myCommentTimeAPI({ optr_type: 'my_comment' }); |
| 68 | }) | 71 | }) |
| 69 | 72 | ||
| 70 | -// 我的留言接口联调 | ||
| 71 | -const loading = ref(false); | ||
| 72 | -const finished = ref(false); | ||
| 73 | -interface commentListType { | ||
| 74 | - id: string; | ||
| 75 | - avatar: string; | ||
| 76 | - name: string; | ||
| 77 | - kg_name: string; | ||
| 78 | - comment_time: string; | ||
| 79 | - note: string; | ||
| 80 | - c_action: string; | ||
| 81 | - c_name: string; | ||
| 82 | - cover: string; | ||
| 83 | - prod_id: string; | ||
| 84 | - perf_id: string; | ||
| 85 | - book_id: string; | ||
| 86 | - perf_name: string; | ||
| 87 | - book_name: string; | ||
| 88 | - localism_type: string; | ||
| 89 | - is_new: number; | ||
| 90 | -} | ||
| 91 | -const commentList = ref<commentListType[]>([]) | ||
| 92 | -let limit = ref(10); | ||
| 93 | -let offset = ref(0) | ||
| 94 | - | ||
| 95 | -// 因为不能让空图标提前出来的写法 | ||
| 96 | -const finishedTextStatus = ref(false); | ||
| 97 | -const emptyStatus = ref(false); | ||
| 98 | -const onLoad = async () => { | ||
| 99 | - const { data } = await myCommentAPI({ limit: limit.value, offset: offset.value }); | ||
| 100 | - // | ||
| 101 | - // _.each(data, item => { | ||
| 102 | - // let arr = _.split(item.target_name, '@'); // 分割评论的动作和姓名 | ||
| 103 | - // item.c_action = arr[0]; // 评论动作 | ||
| 104 | - // item.c_name = arr[1]; // 评论姓名 | ||
| 105 | - // }) | ||
| 106 | - data.forEach((item: { target_name: string | null | undefined; c_action: string; c_name: string; }) => { | ||
| 107 | - let arr = _.split(item.target_name, '@'); // 分割评论的动作和姓名 | ||
| 108 | - item.c_action = arr[0]; // 评论动作 | ||
| 109 | - item.c_name = arr[1]; // 评论姓名 | ||
| 110 | - }); | ||
| 111 | - commentList.value = [...commentList.value, ...data]; | ||
| 112 | - // commentList.value = _.uniqBy(commentList.value, 'id'); | ||
| 113 | - offset.value = commentList.value.length; | ||
| 114 | - loading.value = false; | ||
| 115 | - // 数据全部加载完成 | ||
| 116 | - if (!data.length) { | ||
| 117 | - // 加载状态结束 | ||
| 118 | - finished.value = true; | ||
| 119 | - } | ||
| 120 | - // 隐藏loading标识,空列表图标 | ||
| 121 | - if (!commentList.value.length) { | ||
| 122 | - finishedTextStatus.value = false; | ||
| 123 | - emptyStatus.value = true; | ||
| 124 | - } else { | ||
| 125 | - emptyStatus.value = false; | ||
| 126 | - } | ||
| 127 | -} | ||
| 128 | - | ||
| 129 | const deleteComment = (id: string) => { // 删除评论 | 73 | const deleteComment = (id: string) => { // 删除评论 |
| 130 | Dialog.confirm({ | 74 | Dialog.confirm({ |
| 131 | title: '温馨提示', | 75 | title: '温馨提示', | ... | ... |
-
Please register or login to post a comment