资讯收藏调整
This commit is contained in:
parent
8c48b47cf4
commit
85e8d2d390
|
|
@ -29,15 +29,19 @@
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<view class="panel-btn flex items-center px-[34rpx]" @click="handleAddCollect(newsData.id)">
|
<view class="panel-btn flex items-center px-[34rpx]" @click="handleAddCollect(newsData.id)">
|
||||||
<u-icon :name="newsData.collect ? 'star-fill' : 'star'" size="36"></u-icon>
|
<u-icon
|
||||||
|
:name="newsData.collect ? 'star-fill' : 'star'"
|
||||||
|
size="34"
|
||||||
|
:color="newsData.collect ? '#4173ff' : '#333'"
|
||||||
|
></u-icon>
|
||||||
<text class="ml-[10rpx]">收藏</text>
|
<text class="ml-[10rpx]">收藏</text>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts" setup>
|
<script lang="ts" setup>
|
||||||
import { ref, reactive, computed } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { onLoad, onShow, onReady } from '@dcloudio/uni-app'
|
import { onLoad } from '@dcloudio/uni-app'
|
||||||
import { getArticleDetail, addCollect, cancelCollect } from '@/api/news'
|
import { getArticleDetail, addCollect, cancelCollect } from '@/api/news'
|
||||||
|
|
||||||
const newsData = ref<any>({})
|
const newsData = ref<any>({})
|
||||||
|
|
@ -51,7 +55,11 @@ const handleAddCollect = async (articleId: number) => {
|
||||||
try {
|
try {
|
||||||
if (newsData.value.collect) {
|
if (newsData.value.collect) {
|
||||||
await cancelCollect({ articleId })
|
await cancelCollect({ articleId })
|
||||||
} else await addCollect({ articleId })
|
uni.$u.toast('取消收藏成功')
|
||||||
|
} else {
|
||||||
|
await addCollect({ articleId })
|
||||||
|
uni.$u.toast('收藏成功')
|
||||||
|
}
|
||||||
getData(newsId)
|
getData(newsId)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
//TODO handle the exception
|
//TODO handle the exception
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue