Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
tswj
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
hookehuyr
2022-06-12 23:11:02 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
c3ff2485c3a7c779a7ad0ea5cc2cf70287596611
c3ff2485
1 parent
fbb7214e
🦄 refactor(我的留言): 使用TS重写列表功能
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
82 additions
and
66 deletions
src/composables/index.js
src/composables/useBookList.js
src/composables/useMessageList.ts
src/views/me/message.vue
src/composables/index.js
View file @
c3ff248
...
...
@@ -2,7 +2,7 @@
* @Author: hookehuyr hookehuyr@gmail.com
* @Date: 2022-05-17 12:13:13
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-
09 09:40:35
* @LastEditTime: 2022-06-
12 22:50:29
* @FilePath: /tswj/src/composables/index.js
* @Description:
*/
...
...
@@ -13,6 +13,7 @@ import { useDefaultPerf } from '@/composables/useDefaultPerf.js'
import
{
useBookList
,
useAsyncBookList
}
from
'@/composables/useBookList.js'
import
{
useShortcutBar
}
from
'@/composables/useShortcutBar.js'
import
{
useScrollTop
}
from
'@/composables/useScrollTop.js'
import
{
useMessageList
}
from
'@/composables/useMessageList.ts'
export
{
useVideoList
,
...
...
@@ -20,7 +21,8 @@ export {
useBookList
,
useAsyncBookList
,
useShortcutBar
,
useScrollTop
useScrollTop
,
useMessageList
,
}
/**
...
...
@@ -30,6 +32,6 @@ export {
* @param {*} callback
*/
export
function
useEventListener
(
target
,
event
,
callback
)
{
onMounted
(()
=>
target
&&
target
.
addEventListener
(
event
,
callback
))
onUnmounted
(()
=>
target
&&
target
.
removeEventListener
(
event
,
callback
))
onMounted
(()
=>
target
?
.
addEventListener
(
event
,
callback
))
onUnmounted
(()
=>
target
?
.
removeEventListener
(
event
,
callback
))
}
...
...
src/composables/useBookList.js
View file @
c3ff248
...
...
@@ -2,7 +2,7 @@
* @Author: hookehuyr hookehuyr@gmail.com
* @Date: 2022-05-07 17:46:54
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-
09 11:26:42
* @LastEditTime: 2022-06-
12 22:55:58
* @FilePath: /tswj/src/composables/useBookList.js
* @Description:
*/
...
...
src/composables/useMessageList.ts
0 → 100644
View file @
c3ff248
/*
* @Date: 2022-06-12 22:51:21
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2022-06-12 23:00:04
* @FilePath: /tswj/src/composables/useMessageList.ts
* @Description: 文件描述
*/
import
{
ref
}
from
'vue'
import
{
myCommentAPI
}
from
'@/api/C/me'
import
_
from
'lodash'
export
const
useMessageList
=
()
=>
{
// 我的留言接口联调
interface
commentListType
{
id
:
string
;
avatar
:
string
;
name
:
string
;
kg_name
:
string
;
comment_time
:
string
;
note
:
string
;
c_action
:
string
;
c_name
:
string
;
cover
:
string
;
prod_id
:
string
;
perf_id
:
string
;
book_id
:
string
;
perf_name
:
string
;
book_name
:
string
;
localism_type
:
string
;
is_new
:
number
;
}
const
commentList
=
ref
<
commentListType
[]
>
([])
const
loading
=
ref
(
false
);
const
finished
=
ref
(
false
);
const
limit
=
ref
(
10
);
const
offset
=
ref
(
0
)
const
finishedTextStatus
=
ref
(
false
);
const
emptyStatus
=
ref
(
false
);
const
onLoad
=
async
()
=>
{
const
{
data
}
=
await
myCommentAPI
({
limit
:
limit
.
value
,
offset
:
offset
.
value
});
data
.
forEach
((
item
:
{
target_name
:
string
|
null
|
undefined
;
c_action
:
string
;
c_name
:
string
;
})
=>
{
let
arr
=
_
.
split
(
item
.
target_name
,
'@'
);
// 分割评论的动作和姓名
item
.
c_action
=
arr
[
0
];
// 评论动作
item
.
c_name
=
arr
[
1
];
// 评论姓名
});
// 数据全部加载完成
if
(
!
data
.
length
)
{
// 加载状态结束
finished
.
value
=
true
;
}
commentList
.
value
=
[...
commentList
.
value
,
...
data
];
offset
.
value
=
commentList
.
value
.
length
;
loading
.
value
=
false
;
// 隐藏loading标识,空列表图标
if
(
!
commentList
.
value
.
length
)
{
finishedTextStatus
.
value
=
false
;
emptyStatus
.
value
=
true
;
}
else
{
emptyStatus
.
value
=
false
;
}
}
return
{
onLoad
,
commentList
,
loading
,
finished
,
finishedTextStatus
,
emptyStatus
,
};
}
src/views/me/message.vue
View file @
c3ff248
...
...
@@ -53,79 +53,23 @@
<script lang="ts" setup>
// import { mainStore } from '@/store'
import { no_image, icon_avatar } from '@/utils/generateIcons.js'
import {
ref,
onActivated } from 'vue'
import { onActivated } from 'vue'
import { onBeforeRouteLeave } from 'vue-router'
import _ from 'lodash'
import { Toast, Dialog } from 'vant';
// import { addPages } from '@/hooks/useKeepAlive'
import goToVideoDetail from '@/router/methods/videoDetail'
import {
myCommentAPI,
delCommentAPI } from '@/api/C/me'
import { delCommentAPI } from '@/api/C/me'
import { myCommentTimeAPI } from '@/api/C/perf'
import { useMessageList } from '@/composables';
const { onLoad, commentList, loading, finished, finishedTextStatus, emptyStatus, } = useMessageList();
onBeforeRouteLeave(async () => {
// 更新留言阅读情况
await myCommentTimeAPI({ optr_type: 'my_comment' });
})
// 我的留言接口联调
const loading = ref(false);
const finished = ref(false);
interface commentListType {
id: string;
avatar: string;
name: string;
kg_name: string;
comment_time: string;
note: string;
c_action: string;
c_name: string;
cover: string;
prod_id: string;
perf_id: string;
book_id: string;
perf_name: string;
book_name: string;
localism_type: string;
is_new: number;
}
const commentList = ref<commentListType[]>([])
let limit = ref(10);
let offset = ref(0)
// 因为不能让空图标提前出来的写法
const finishedTextStatus = ref(false);
const emptyStatus = ref(false);
const onLoad = async () => {
const { data } = await myCommentAPI({ limit: limit.value, offset: offset.value });
//
// _.each(data, item => {
// let arr = _.split(item.target_name, '@'); // 分割评论的动作和姓名
// item.c_action = arr[0]; // 评论动作
// item.c_name = arr[1]; // 评论姓名
// })
data.forEach((item: { target_name: string | null | undefined; c_action: string; c_name: string; }) => {
let arr = _.split(item.target_name, '@'); // 分割评论的动作和姓名
item.c_action = arr[0]; // 评论动作
item.c_name = arr[1]; // 评论姓名
});
commentList.value = [...commentList.value, ...data];
// commentList.value = _.uniqBy(commentList.value, 'id');
offset.value = commentList.value.length;
loading.value = false;
// 数据全部加载完成
if (!data.length) {
// 加载状态结束
finished.value = true;
}
// 隐藏loading标识,空列表图标
if (!commentList.value.length) {
finishedTextStatus.value = false;
emptyStatus.value = true;
} else {
emptyStatus.value = false;
}
}
const deleteComment = (id: string) => { // 删除评论
Dialog.confirm({
title: '温馨提示',
...
...
Please
register
or
login
to post a comment