hookehuyr

🦄 refactor: 写法优化

...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
12 <p>{{ item.kg_name }}</p> 12 <p>{{ item.kg_name }}</p>
13 </van-col> 13 </van-col>
14 <van-col span="4" style="text-align: center;"> 14 <van-col span="4" style="text-align: center;">
15 - <p style="color: #333333; position: relative; text-align: right;" @click="setComment(item, 'reply')"> 15 + <p style="color: #333333; position: relative; text-align: right;" @click="openCommentBox(item, 'reply')">
16 回复 16 回复
17 <span v-if="item.is_new" class="spot">·</span> 17 <span v-if="item.is_new" class="spot">·</span>
18 </p> 18 </p>
...@@ -21,13 +21,17 @@ ...@@ -21,13 +21,17 @@
21 </van-row> 21 </van-row>
22 <van-row> 22 <van-row>
23 <van-col> 23 <van-col>
24 - <span style="color: #222222;">{{ item.c_action }}<span style="color: #0B3A72;">@{{ item.c_name }}</span>:{{ 24 + <span style="color: #222222;">
25 - item.note }}</span> 25 + {{ item.c_action }}
26 + <span style="color: #0B3A72;">@{{ item.c_name }}</span>
27 + :{{ item.note }}
28 + </span>
26 </van-col> 29 </van-col>
27 </van-row> 30 </van-row>
28 </div> 31 </div>
29 32
30 - <div style="padding: 1rem; background-color: #F7F7F7;" @click="openComment(item)"> 33 + <div style="padding: 1rem; background-color: #F7F7F7;"
34 + @click="go('/client/videoDetail/comment', { prod_id: item.prod_id, perf_id: item.perf_id, book_id: item.book_id })">
31 <van-row> 35 <van-row>
32 <van-col span="8" style="position: relative;"> 36 <van-col span="8" style="position: relative;">
33 <van-image width="8rem" height="5rem" fit="cover" :src="item.cover" style="vertical-align: text-bottom;"> 37 <van-image width="8rem" height="5rem" fit="cover" :src="item.cover" style="vertical-align: text-bottom;">
...@@ -57,17 +61,16 @@ ...@@ -57,17 +61,16 @@
57 import { no_image, icon_avatar } from '@/utils/generateIcons.js' 61 import { no_image, icon_avatar } from '@/utils/generateIcons.js'
58 import CommentBox from '@/components/CommentBox/index.vue' 62 import CommentBox from '@/components/CommentBox/index.vue'
59 import { ref, onActivated } from 'vue' 63 import { ref, onActivated } from 'vue'
60 -import { useRoute, useRouter, onBeforeRouteLeave } from 'vue-router' 64 +import { useRoute, onBeforeRouteLeave } from 'vue-router'
61 -// import axios from '@/utils/axios';
62 -import _ from 'lodash'
63 import { Toast } from 'vant'; 65 import { Toast } from 'vant';
64 // import { addPages, store } from '@/hooks/useKeepAlive' 66 // import { addPages, store } from '@/hooks/useKeepAlive'
65 import { myAtmeAPI } from '@/api/C/me' 67 import { myAtmeAPI } from '@/api/C/me'
66 import { addCommentAPI, addReplyAPI } from '@/api/C/perf' 68 import { addCommentAPI, addReplyAPI } from '@/api/C/perf'
67 import { myCommentTimeAPI } from '@/api/C/perf' 69 import { myCommentTimeAPI } from '@/api/C/perf'
70 +import { useGo } from '@/hooks/useGo'
68 71
72 +const go = useGo()
69 const $route = useRoute(); 73 const $route = useRoute();
70 -const $router = useRouter();
71 74
72 onBeforeRouteLeave(async () => { 75 onBeforeRouteLeave(async () => {
73 // 更新留言阅读情况 76 // 更新留言阅读情况
...@@ -85,11 +88,11 @@ const emptyStatus = ref(false); ...@@ -85,11 +88,11 @@ const emptyStatus = ref(false);
85 // 88 //
86 const onLoad = async () => { 89 const onLoad = async () => {
87 const { data } = await myAtmeAPI({ limit: limit.value, offset: offset.value }); 90 const { data } = await myAtmeAPI({ limit: limit.value, offset: offset.value });
88 - _.each(data, item => { 91 + data.forEach(item => {
89 - let arr = _.split(item.target_name, '@'); // 分割评论的动作和姓名 92 + const arr = item.target_name.split('@'); // 分割评论的动作和姓名
90 item.c_action = arr[0]; // 评论动作 93 item.c_action = arr[0]; // 评论动作
91 item.c_name = arr[1]; // 评论姓名 94 item.c_name = arr[1]; // 评论姓名
92 - }) 95 + });
93 commentList.value = [...commentList.value, ...data]; 96 commentList.value = [...commentList.value, ...data];
94 offset.value = commentList.value.length; 97 offset.value = commentList.value.length;
95 loading.value = false; 98 loading.value = false;
...@@ -109,35 +112,34 @@ const onLoad = async () => { ...@@ -109,35 +112,34 @@ const onLoad = async () => {
109 /******** 留言框相关操作 START *******/ 112 /******** 留言框相关操作 START *******/
110 // 回复评论控件 113 // 回复评论控件
111 const showCommentBoxPopup = ref(false); 114 const showCommentBoxPopup = ref(false);
112 -const commentType = ref(''); // 类型 comment 为评论 / 类型 reply 为回复 115 +const commentType = ref(''); // 类型 comment 为评论 | 类型 reply 为回复
113 - 116 +const commentId = ref('')
117 +const replayUser = ref('')
114 /** 118 /**
115 - * 回复/评论 功能 119 + * @param {*} name 评论姓名
116 - * @param {*} v 单行评论数据 120 + * @param {*} id 评论ID
117 * @param {*} type 类型 comment 为评论/类型 reply 为回复 121 * @param {*} type 类型 comment 为评论/类型 reply 为回复
122 + * @description 打开 回复/评论 控件
118 */ 123 */
119 -const commentId = ref('') 124 +const openCommentBox = ({ name, id }, type) => {
120 -const replayUser = ref('')
121 -// 打开评论弹框组件
122 -const setComment = (v, type) => {
123 showCommentBoxPopup.value = true; 125 showCommentBoxPopup.value = true;
124 commentType.value = type; 126 commentType.value = type;
125 - replayUser.value = v.name; 127 + replayUser.value = name;
126 - commentId.value = v.id; 128 + commentId.value = id;
127 } 129 }
128 130
129 /** 131 /**
130 - * 留言/回复 回调
131 * @param {*} note 留言内容 132 * @param {*} note 留言内容
132 * @param {*} prod_id 作品ID 133 * @param {*} prod_id 作品ID
133 * @param {*} comment_id 评论ID 134 * @param {*} comment_id 评论ID
135 + * @description 留言/回复 提交回调
134 */ 136 */
135 const submitCommentBox = async (note) => { 137 const submitCommentBox = async (note) => {
136 - let params = { note }; 138 + let params = { note }; // 基础传值结构,包含留言内容
137 if (commentType.value === 'comment') { 139 if (commentType.value === 'comment') {
138 params.prod_id = $route.query.prod_id; 140 params.prod_id = $route.query.prod_id;
139 - const { msg } = await addCommentAPI(params); 141 + const { code } = await addCommentAPI(params);
140 - if (msg === 'OK') { 142 + if (code) {
141 Toast.success('发布成功') 143 Toast.success('发布成功')
142 // 刷新列表 144 // 刷新列表
143 location.reload() 145 location.reload()
...@@ -145,8 +147,8 @@ const submitCommentBox = async (note) => { ...@@ -145,8 +147,8 @@ const submitCommentBox = async (note) => {
145 } 147 }
146 if (commentType.value === 'reply') { 148 if (commentType.value === 'reply') {
147 params.comment_id = commentId.value; 149 params.comment_id = commentId.value;
148 - const { msg } = await addReplyAPI(params); 150 + const { code } = await addReplyAPI(params);
149 - if (msg === 'OK') { 151 + if (code) {
150 Toast.success('发布成功') 152 Toast.success('发布成功')
151 // 刷新列表 153 // 刷新列表
152 location.reload() 154 location.reload()
...@@ -154,62 +156,38 @@ const submitCommentBox = async (note) => { ...@@ -154,62 +156,38 @@ const submitCommentBox = async (note) => {
154 } 156 }
155 } 157 }
156 158
157 -const closeCommentBox = (v) => { // 关闭留言框 159 +/**
160 + * @param {*} v
161 + * @description 关闭留言框回调
162 + */
163 +const closeCommentBox = (v) => {
158 showCommentBoxPopup.value = v; 164 showCommentBoxPopup.value = v;
159 } 165 }
160 /******** 留言框相关操作 START *******/ 166 /******** 留言框相关操作 START *******/
161 167
162 -const onClick = (item) => { 168 +// const onClick = (item) => {
163 - // 调整书籍详情页 169 +// // 调整书籍详情页
164 - $router.push({ 170 +// $router.push({
165 - path: '/client/videoDetail', 171 +// path: '/client/videoDetail',
166 - query: { 172 +// query: {
167 - prod_id: item.prod_id, 173 +// prod_id: item.prod_id,
168 - perf_id: item.perf_id, 174 +// perf_id: item.perf_id,
169 - book_id: item.book_id 175 +// book_id: item.book_id
170 - } 176 +// }
171 - }); 177 +// });
172 -} 178 +// }
173 -
174 -const openComment = (item) => {
175 - $router.push({
176 - path: '/client/videoDetail/comment',
177 - query: {
178 - prod_id: item.prod_id,
179 - perf_id: item.perf_id,
180 - book_id: item.book_id
181 - }
182 - });
183 -}
184 179
185 /****************** keepAlive 模块 *******************/ 180 /****************** keepAlive 模块 *******************/
186 181
187 // TAG: keepAlive 缓存页面 182 // TAG: keepAlive 缓存页面
188 // addPages(); 183 // addPages();
189 184
190 -onActivated(() => { // keepAlive 重置后执行回调 185 +// onActivated(() => { // keepAlive 重置后执行回调
191 -}); 186 +// });
192 187
193 /*********************************************************/ 188 /*********************************************************/
194 </script> 189 </script>
195 190
196 -<script>
197 -export default {
198 - name: 'callMe',
199 - data () {
200 - return {
201 -
202 - }
203 - },
204 - mounted () {
205 -
206 - },
207 - methods: {
208 -
209 - }
210 -}
211 -</script>
212 -
213 <style lang="less" scoped> 191 <style lang="less" scoped>
214 .comment-wrapper { 192 .comment-wrapper {
215 color: #999999; 193 color: #999999;
......