hookehuyr

✨ feat(作品详情页): 视频操作功能API联调

...@@ -12,20 +12,20 @@ ...@@ -12,20 +12,20 @@
12 | 12 |
13 </van-col> 13 </van-col>
14 <van-col span="8"> 14 <van-col span="8">
15 - <span @click="setCollect"> 15 + <span @click="handleAction('favor', detail.id)">
16 <van-icon v-if="!detail.is_favor" :name="icon_shoucang1" size="1.2rem" style="vertical-align: bottom;" /> 16 <van-icon v-if="!detail.is_favor" :name="icon_shoucang1" size="1.2rem" style="vertical-align: bottom;" />
17 <van-icon v-else :name="icon_shoucang2" size="1.2rem" style="vertical-align: bottom;" /> 17 <van-icon v-else :name="icon_shoucang2" size="1.2rem" style="vertical-align: bottom;" />
18 - {{ item.favor_num }} 18 + {{ detail.favor_num }}
19 </span> 19 </span>
20 </van-col> 20 </van-col>
21 <van-col span="1" style="color: #EEEDED;"> 21 <van-col span="1" style="color: #EEEDED;">
22 | 22 |
23 </van-col> 23 </van-col>
24 <van-col span="7"> 24 <van-col span="7">
25 - <span @click="setLike()"> 25 + <span @click="handleAction('like', detail.id)">
26 <van-icon v-if="!detail.is_like" :name="icon_dianzan1" size="1.2rem" style="vertical-align: bottom;" /> 26 <van-icon v-if="!detail.is_like" :name="icon_dianzan1" size="1.2rem" style="vertical-align: bottom;" />
27 <van-icon v-else :name="icon_dianzan2" size="1.2rem" style="vertical-align: bottom;" /> 27 <van-icon v-else :name="icon_dianzan2" size="1.2rem" style="vertical-align: bottom;" />
28 - {{ item.like_num }} 28 + {{ detail.like_num }}
29 </span> 29 </span>
30 </van-col> 30 </van-col>
31 </van-row> 31 </van-row>
...@@ -85,20 +85,44 @@ export default { ...@@ -85,20 +85,44 @@ export default {
85 {attrKey:'x5-video-player-type',attrValue:'h5-page'}, 85 {attrKey:'x5-video-player-type',attrValue:'h5-page'},
86 ] 86 ]
87 }) 87 })
88 - this.detail = _.cloneDeep(this.item) 88 + this.detail = _.cloneDeep(this.item);
89 + var video = mp.video();
90 + // 监听原生video事件
91 + var _this = this;
92 + video.addEventListener('play', function (event) {
93 + _this.handleAction('play', _this.item.id)
94 + });
89 }, 500) 95 }, 500)
90 }, 96 },
91 methods: { 97 methods: {
92 - setCollect() { 98 + /**
93 - console.warn(this.detail.is_favor); 99 + * 用户相关操作
94 - // this.detail.is_favor = this.detail.is_favor ? 1 : 0 100 + * @param {String} type 动作类型:like, favor, play
101 + * @param {String} id 作品 ID
102 + */
103 + handleAction (type, id) { // 用户操作
95 axios.post('/srv/?a=prod_action', { 104 axios.post('/srv/?a=prod_action', {
96 - action_type: 'favo', 105 + action_type: type,
97 - prod_id: this.detail.id 106 + prod_id: id
98 }) 107 })
99 .then(res => { 108 .then(res => {
100 if (res.data.code === 1) { 109 if (res.data.code === 1) {
101 - console.warn(res.data.data); 110 + if (res.data.msg === `${type}-add-OK`) { // 动作操作成功
111 + this.detail[`is_${type}`] = 1;
112 + this.detail[`${type}_num`] = this.detail[`${type}_num`] + 1;
113 + if (type === 'favor') {
114 + Toast('收藏成功');
115 + }
116 + if (type === 'like') {
117 + Toast('点赞成功');
118 + }
119 + } else { // 取消操作
120 + this.detail[`is_${type}`] = 0;
121 + this.detail[`${type}_num`] -= this.detail[`${type}_num`];
122 + if (type !== 'play') {
123 + Toast('取消成功');
124 + }
125 + }
102 } else { 126 } else {
103 console.warn(res); 127 console.warn(res);
104 Toast({ 128 Toast({
...@@ -109,11 +133,7 @@ export default { ...@@ -109,11 +133,7 @@ export default {
109 }) 133 })
110 .catch(err => { 134 .catch(err => {
111 console.error(err); 135 console.error(err);
112 - }) 136 + });
113 - },
114 - setLike() {
115 - console.warn(this.detail.is_like);
116 - // this.detail.is_like = this.detail.is_like ? 1 : 0
117 }, 137 },
118 setCommit() { 138 setCommit() {
119 console.warn('跳转详情页,移动到留言页'); 139 console.warn('跳转详情页,移动到留言页');
......