hookehuyr

✨ feat(我的留言): TS改写测试

1 +/*
2 + * @Author: hookehuyr hookehuyr@gmail.com
3 + * @Date: 2022-05-18 22:16:10
4 + * @LastEditors: hookehuyr hookehuyr@gmail.com
5 + * @LastEditTime: 2022-06-08 12:21:53
6 + * @FilePath: /tswj/src/api/C/me.js
7 + * @Description: 我的页面接口操作
8 + */
1 import { fn, fetch } from '@/api/fn'; 9 import { fn, fetch } from '@/api/fn';
2 10
3 const Api = { 11 const Api = {
...@@ -6,6 +14,8 @@ const Api = { ...@@ -6,6 +14,8 @@ const Api = {
6 MY_PERFORMER: '/srv/?a=my_performer', 14 MY_PERFORMER: '/srv/?a=my_performer',
7 MY_LIKE: '/srv/?a=my_like', 15 MY_LIKE: '/srv/?a=my_like',
8 MY_FAVOR: '/srv/?a=my_favor', 16 MY_FAVOR: '/srv/?a=my_favor',
17 + MY_COMMENT: '/srv/?a=my_comment',
18 + DEL_COMMENT: '/srv/?a=del_comment',
9 } 19 }
10 20
11 /** 21 /**
...@@ -42,3 +52,18 @@ export const myLikeAPI = (params) => fn(fetch.get(Api.MY_LIKE, params)); ...@@ -42,3 +52,18 @@ export const myLikeAPI = (params) => fn(fetch.get(Api.MY_LIKE, params));
42 * @returns 52 * @returns
43 */ 53 */
44 export const myFavorAPI = (params) => fn(fetch.get(Api.MY_FAVOR, params)); 54 export const myFavorAPI = (params) => fn(fetch.get(Api.MY_FAVOR, params));
55 +
56 +/**
57 + * @description: 用户评论列表
58 + * @param {string} limit
59 + * @param {string} offset
60 + * @returns
61 + */
62 +export const myCommentAPI = (params) => fn(fetch.get(Api.MY_COMMENT, params));
63 +
64 +/**
65 + * @description: 删除用户评论
66 + * @param {string} comment_id 评论ID
67 + * @returns
68 + */
69 +export const delCommentAPI = (params) => fn(fetch.post(Api.DEL_COMMENT, params));
......
1 +/*
2 + * @Author: hookehuyr hookehuyr@gmail.com
3 + * @Date: 2022-06-07 18:03:50
4 + * @LastEditors: hookehuyr hookehuyr@gmail.com
5 + * @LastEditTime: 2022-06-07 20:17:14
6 + * @FilePath: /tswj/src/router/methods/goToVideoDetail.ts
7 + * @Description:
8 + */
9 +// import { useRouter } from 'vue-router';
10 +import $router from '@/router';
11 +
12 +/**
13 + * 路由跳转视频详情页
14 + * @param prodId 作品ID
15 + * @param perfId 表演者ID
16 + * @param bookId 书籍ID
17 + * @param type 特殊标识,判断入口 为keepAlive使用
18 + */
19 +const fn = (prodId: string, perfId: string, bookId: string, type?: string): void => {
20 + $router.push({
21 + path: '/client/videoDetail',
22 + query: {
23 + prod_id: prodId,
24 + perf_id: perfId,
25 + book_id: bookId,
26 + type,
27 + },
28 + });
29 +};
30 +
31 +export default fn;
...@@ -13,19 +13,20 @@ ...@@ -13,19 +13,20 @@
13 <p>{{ item.kg_name }}</p> 13 <p>{{ item.kg_name }}</p>
14 </van-col> 14 </van-col>
15 <van-col span="5" style="text-align: right;"> 15 <van-col span="5" style="text-align: right;">
16 - <p style="color: #333333;" @click="deleteComment(item)">删除</p> 16 + <p style="color: #333333;" @click="deleteComment(item.id)">删除</p>
17 <p>{{ item.comment_time }}</p> 17 <p>{{ item.comment_time }}</p>
18 </van-col> 18 </van-col>
19 </van-row> 19 </van-row>
20 <van-row> 20 <van-row>
21 <van-col> 21 <van-col>
22 <span style="color: #222222;">{{ item.c_action }}<span style="color: #0B3A72;">@{{ item.c_name }}</span>:{{ 22 <span style="color: #222222;">{{ item.c_action }}<span style="color: #0B3A72;">@{{ item.c_name }}</span>:{{
23 - item.note }}</span> 23 + item.note
24 + }}</span>
24 </van-col> 25 </van-col>
25 </van-row> 26 </van-row>
26 </div> 27 </div>
27 28
28 - <div class="raw-ref" @click="onClick(item)"> 29 + <div class="raw-ref" @click="goToVideoDetail(item.prod_id, item.perf_id, item.book_id)">
29 <van-row> 30 <van-row>
30 <van-col span="8" class="image"> 31 <van-col span="8" class="image">
31 <van-image width="8rem" height="5rem" fit="cover" lazy-load :src="item.cover" 32 <van-image width="8rem" height="5rem" fit="cover" lazy-load :src="item.cover"
...@@ -47,27 +48,48 @@ ...@@ -47,27 +48,48 @@
47 <van-empty v-if="emptyStatus" class="custom-image" :image="no_image" description="暂无留言" /> 48 <van-empty v-if="emptyStatus" class="custom-image" :image="no_image" description="暂无留言" />
48 </template> 49 </template>
49 50
50 -<script setup> 51 +<script lang="ts" setup>
51 -import { mainStore } from '@/store' 52 +// import { mainStore } from '@/store'
52 53
53 -import icon_player from '@images/bofang@2x.png' 54 +// import icon_player from '@images/bofang@2x.png'
54 import no_image from '@images/que-shuju@2x.png' 55 import no_image from '@images/que-shuju@2x.png'
55 import icon_avatar from '@images/que-touxiang@2x.png' 56 import icon_avatar from '@images/que-touxiang@2x.png'
56 57
57 -import { ref, reactive, onMounted, onActivated } from 'vue' 58 +import { ref, onActivated } from 'vue'
58 -import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router' 59 +// import { useRouter } from 'vue-router'
59 -import axios from '@/utils/axios'; 60 +// import axios from '@/utils/axios';
60 import _ from 'lodash' 61 import _ from 'lodash'
61 import { Toast, Dialog } from 'vant'; 62 import { Toast, Dialog } from 'vant';
62 -import { addPages, store } from '@/hooks/useKeepAlive' 63 +// import { addPages } from '@/hooks/useKeepAlive'
63 64
64 -const $route = useRoute(); 65 +import goToVideoDetail from '@/router/methods/videoDetail'
65 -const $router = useRouter(); 66 +
67 +import { myCommentAPI, delCommentAPI } from '@/api/C/me.js'
68 +
69 +// const $route = useRoute();
70 +// const $router = useRouter();
66 71
67 // 我的留言接口联调 72 // 我的留言接口联调
68 const loading = ref(false); 73 const loading = ref(false);
69 const finished = ref(false); 74 const finished = ref(false);
70 -const commentList = ref([]) 75 +interface commentListType {
76 + id: string;
77 + avatar: string;
78 + name: string;
79 + kg_name: string;
80 + comment_time: string;
81 + note: string;
82 + c_action: string;
83 + c_name: string;
84 + cover: string;
85 + prod_id: string;
86 + perf_id: string;
87 + book_id: string;
88 + perf_name: string;
89 + book_name: string;
90 + localism_type: string;
91 +}
92 +const commentList = ref<commentListType[]>([])
71 let limit = ref(10); 93 let limit = ref(10);
72 let offset = ref(0) 94 let offset = ref(0)
73 95
...@@ -75,86 +97,49 @@ let offset = ref(0) ...@@ -75,86 +97,49 @@ let offset = ref(0)
75 const finishedTextStatus = ref(false); 97 const finishedTextStatus = ref(false);
76 const emptyStatus = ref(false); 98 const emptyStatus = ref(false);
77 99
78 -const onLoad = () => { 100 +const onLoad = async () => {
79 - axios.get('/srv/?a=my_comment', { 101 + const { data } = await myCommentAPI({ limit: limit.value, offset: offset.value });
80 - params: { 102 + //
81 - limit: limit.value, 103 + // _.each(data, item => {
82 - offset: offset.value 104 + // let arr = _.split(item.target_name, '@'); // 分割评论的动作和姓名
83 - } 105 + // item.c_action = arr[0]; // 评论动作
84 - }) 106 + // item.c_name = arr[1]; // 评论姓名
85 - .then(res => { 107 + // })
86 - if (res.data.code === 1) { 108 + data.forEach((item: { target_name: string | null | undefined; c_action: string; c_name: string; }) => {
87 - _.each(res.data.data, item => {
88 let arr = _.split(item.target_name, '@'); // 分割评论的动作和姓名 109 let arr = _.split(item.target_name, '@'); // 分割评论的动作和姓名
89 item.c_action = arr[0]; // 评论动作 110 item.c_action = arr[0]; // 评论动作
90 item.c_name = arr[1]; // 评论姓名 111 item.c_name = arr[1]; // 评论姓名
91 - }) 112 + });
92 - commentList.value = _.concat(commentList.value, res.data.data); 113 + commentList.value = [...commentList.value, ...data];
93 - commentList.value = _.uniqBy(commentList.value, 'id'); 114 + // commentList.value = _.uniqBy(commentList.value, 'id');
94 offset.value = commentList.value.length; 115 offset.value = commentList.value.length;
95 loading.value = false; 116 loading.value = false;
96 // 数据全部加载完成 117 // 数据全部加载完成
97 - if (!res.data.data.length) { 118 + if (!data.length) {
98 // 加载状态结束 119 // 加载状态结束
99 finished.value = true; 120 finished.value = true;
100 } 121 }
122 + // 隐藏loading标识,空列表图标
101 if (!commentList.value.length) { 123 if (!commentList.value.length) {
102 finishedTextStatus.value = false; 124 finishedTextStatus.value = false;
103 emptyStatus.value = true; 125 emptyStatus.value = true;
104 } 126 }
105 - } else {
106 - console.warn(res);
107 - if (!res.data.show) return false;
108 - Toast({
109 - icon: 'close',
110 - message: res.data.msg
111 - });
112 - }
113 - })
114 - .catch(err => {
115 - console.error(err);
116 - })
117 -}
118 -
119 -const onClick = (item) => { // 跳转作品详情页
120 - $router.push({
121 - path: '/client/videoDetail',
122 - query: {
123 - prod_id: item.prod_id,
124 - perf_id: item.perf_id,
125 - book_id: item.book_id
126 - }
127 - });
128 } 127 }
129 128
130 -const deleteComment = (item) => { // 删除评论 129 +const deleteComment = (id: string) => { // 删除评论
131 Dialog.confirm({ 130 Dialog.confirm({
132 title: '温馨提示', 131 title: '温馨提示',
133 message: '是否确认删除该评论?', 132 message: '是否确认删除该评论?',
134 confirmButtonColor: '#713610' 133 confirmButtonColor: '#713610'
135 }) 134 })
136 - .then(() => { 135 + .then(async () => {
137 - axios.post('/srv/?a=del_comment', { 136 + const result = await delCommentAPI({ comment_id: id });
138 - comment_id: item.id 137 + if (result) {
139 - })
140 - .then(res => {
141 - if (res.data.code === 1) {
142 // 移除当前选中评论,避免刷新页面 138 // 移除当前选中评论,避免刷新页面
143 - _.remove(commentList.value, comment => comment.id === item.id); 139 + _.remove(commentList.value, comment => comment.id === id);
144 Toast.success('删除成功'); 140 Toast.success('删除成功');
145 - } else {
146 - console.warn(res);
147 - if (!res.data.show) return false;
148 - Toast({
149 - icon: 'close',
150 - message: res.data.msg
151 - });
152 } 141 }
153 }) 142 })
154 - .catch(err => {
155 - console.error(err);
156 - });
157 - })
158 .catch(() => { 143 .catch(() => {
159 // on cancel 144 // on cancel
160 }); 145 });
...@@ -163,7 +148,7 @@ const deleteComment = (item) => { // 删除评论 ...@@ -163,7 +148,7 @@ const deleteComment = (item) => { // 删除评论
163 /****************** keepAlive 模块 *******************/ 148 /****************** keepAlive 模块 *******************/
164 149
165 // TAG: keepAlive 缓存页面 150 // TAG: keepAlive 缓存页面
166 -addPages() 151 +// addPages()
167 152
168 onActivated(() => { // keepAlive 重置后执行回调 153 onActivated(() => { // keepAlive 重置后执行回调
169 }); 154 });
...@@ -171,26 +156,6 @@ onActivated(() => { // keepAlive 重置后执行回调 ...@@ -171,26 +156,6 @@ onActivated(() => { // keepAlive 重置后执行回调
171 /*********************************************************/ 156 /*********************************************************/
172 </script> 157 </script>
173 158
174 -<script>
175 -import mixin from 'common/mixin';
176 -
177 -export default {
178 - name: 'message',
179 - mixins: [mixin.init],
180 - data() {
181 - return {
182 -
183 - }
184 - },
185 - mounted() {
186 -
187 - },
188 - methods: {
189 -
190 - }
191 -}
192 -</script>
193 -
194 <style lang="less" scoped> 159 <style lang="less" scoped>
195 .comment-wrapper { 160 .comment-wrapper {
196 color: #999999; 161 color: #999999;
...@@ -209,12 +174,15 @@ export default { ...@@ -209,12 +174,15 @@ export default {
209 } 174 }
210 } 175 }
211 } 176 }
177 +
212 .raw-ref { 178 .raw-ref {
213 padding: 1rem; 179 padding: 1rem;
214 background-color: #F7F7F7; 180 background-color: #F7F7F7;
181 +
215 .image { 182 .image {
216 position: relative; 183 position: relative;
217 } 184 }
185 +
218 .text { 186 .text {
219 line-height: 2; 187 line-height: 2;
220 margin-left: 1rem; 188 margin-left: 1rem;
......
...@@ -43,7 +43,8 @@ ...@@ -43,7 +43,8 @@
43 "node_modules", 43 "node_modules",
44 "dist" 44 "dist"
45 ], 45 ],
46 - // "vueCompilerOptions": { 46 + "vueCompilerOptions": {
47 - // "experimentalSuppressInvalidJsxElementTypeErrors": true 47 + "target": 2,
48 - // } 48 + "experimentalSuppressInvalidJsxElementTypeErrors": true
49 + }
49 } 50 }
......