Browse Source

fix(app): 优化圈子

EvilDragon 4 months ago
parent
commit
e9867cef29

+ 6 - 18
packages/app/src/core/libs/requests.ts

@@ -9,9 +9,9 @@ import {
   MaterialDealerHomePage,
   MaterialDealerRes,
   Moment,
+  Comment,
 } from '../models/moment'
 import dayjs from 'dayjs'
-import { getMaterialDealers } from '../../../../merchant/src/core/libs/requests'
 
 export const getUserInfo = () =>
   httpGetMock<any>({
@@ -153,7 +153,7 @@ export const createUserAuthInfo = (
     remark: string
   }>,
 ) => httpPost<any>('/app-api/member/user-auth-info/create', data)
-export const getCircles = (query) =>
+export const getCircles = (query: { tagName?: string }) =>
   httpGet<{
     list: {
       id: number
@@ -184,6 +184,8 @@ export const createCircle = (data: Partial<Circle>) =>
 export const getCircle = (id: string) =>
   httpGet<Partial<CircleRes>>('/app-api/member/circle/get', { id })
 export const shareCircle = (id: string) => httpGet('/app-api/member/circle/share', { id })
+export const getCircleUpvotes = (id) =>
+  httpGet('/app-api/member/circle-upvote/page', { circleId: id })
 export const createCircleUpvote = (data: { circleId: number; userId: number; userName: string }) =>
   httpPost('/app-api/member/circle-upvote/create', data)
 export const cancelCircleUpvote = (query: { id: string }) =>
@@ -197,24 +199,10 @@ export const createCircleReview = (
     replayReviewId: string
   }>,
 ) => httpPost<any>('/app-api/member/circle-review/create', data)
+export const deleteCircleReview = (id) => httpGet('/app-api/member/circle-review/delete', { id })
 export const getCircleReviews = (query: { circleId: string }) =>
   httpGet<{
-    list: Partial<{
-      id: number
-      circleId: number
-      userId: number
-      userName: string
-      reviewContent: string
-      upvoteCount: any
-      replayReviewId: any
-      reviewTime: number
-      createTime: number
-      replayToUserName: any
-      replayToUserId: any
-      replayFirstId: any
-      upvote: boolean
-      ownDel: boolean
-    }>[]
+    list: Comment[]
   }>('/app-api/member/circle-review/getCircleReviewByCircleId', query)
 export const createCircleReviewUpvote = (data: {
   circleId: number

+ 1 - 0
packages/app/src/core/models/moment.ts

@@ -32,6 +32,7 @@ export interface Comment {
   circleId: number
   userId: number
   userName: string
+  userAvatar: string
   reviewContent: string
   upvoteCount: any
   replayReviewId: any

+ 21 - 0
packages/app/src/core/utils/common.ts

@@ -11,3 +11,24 @@ export const isImageOrVideo = (url) => {
     return 'unknown'
   }
 }
+export const requestToast = async <T>(
+  func: () => Promise<IResData<T>>,
+  options: { error?: boolean; errorTitle?: string; success?: boolean; successTitle?: string } = {
+    error: true,
+  },
+) => {
+  const { code, data, msg } = await func()
+  if (code === 0 && options.success) {
+    uni.showToast({
+      title: options.successTitle,
+      icon: 'none',
+    })
+  }
+  if (code !== 0 && options.error) {
+    uni.showToast({
+      title: options.errorTitle || msg,
+      icon: 'none',
+    })
+  }
+  return { code, data, msg }
+}

+ 26 - 4
packages/app/src/pages/home/components/comment-item.vue

@@ -3,6 +3,7 @@ import { useUserStore } from '../../../store'
 import {
   cancelCircleReviewUpvote,
   createCircleReviewUpvote,
+  deleteCircleReview,
   getReviewReplay,
 } from '../../../core/libs/requests'
 import { thumbsUp, thumbsUpActive } from '../../../core/libs/svgs'
@@ -20,7 +21,7 @@ const props = defineProps({
     default: false,
   },
 })
-const emits = defineEmits<{ upvote: [] }>()
+const emits = defineEmits<{ upvote: []; delete: [] }>()
 const userStore = useUserStore()
 const { userInfo } = storeToRefs(userStore)
 const handleUpvote = async () => {
@@ -42,6 +43,24 @@ const handleUpvote = async () => {
   }
   emits('upvote')
 }
+const handleDelect = async () => {
+  uni.showModal({
+    content: '确定删除评论?',
+    showCancel: true,
+    success: async (res) => {
+      if (res.confirm) {
+        // TODO: 删除评论
+        const { code, msg } = await deleteCircleReview(props.options.id)
+        if (code === 0) {
+          uni.showToast({ title: '删除评论成功', icon: 'none' })
+        } else {
+          uni.showToast({ title: msg, icon: 'none' })
+        }
+        emits('delete')
+      }
+    },
+  })
+}
 onMounted(async () => {
   const { data } = await getReviewReplay({ id: props.options.id.toString() })
   console.log(data)
@@ -53,7 +72,7 @@ onMounted(async () => {
       custom-class="rounded-full overflow-hidden col-start-1 row-start-1"
       width="28"
       height="28"
-      :src="''"
+      :src="options.userAvatar"
     />
     <view class="col-start-2 row-start-1">
       <div class="text-black/40 text-xs font-normal font-['PingFang SC'] leading-[10.18px]">
@@ -62,13 +81,16 @@ onMounted(async () => {
       <div class="my-3 text-black/90 text-sm font-normal font-['PingFang SC'] leading-[10.18px]">
         {{ options.reviewContent }}
       </div>
-      <view class="flex items-center mt--2">
+      <view class="flex items-center mt--2 gap-3">
         <div class="text-black/30 text-[10px] font-normal font-['PingFang SC'] leading-[10.18px]">
           {{ dayjs(options.reviewTime).format('YYYY/MM/DD') }}
         </div>
-        <view class="ml-3">
+        <view class="">
           <wd-button custom-class="text-2.5!" type="text">回复</wd-button>
         </view>
+        <div v-if="userInfo.userId === options.userId">
+          <wd-button custom-class="text-2.5!" type="text" @click="handleDelect">删除</wd-button>
+        </div>
       </view>
     </view>
     <view class="col-start-3 row-start-1 flex flex-col items-center" @click="handleUpvote">

+ 18 - 5
packages/app/src/pages/home/moment/index.vue

@@ -12,6 +12,7 @@ import {
   createCircleReview,
   getCircle,
   getCircleReviews,
+  getCircleUpvotes,
   shareCircle,
 } from '../../../core/libs/requests'
 import { handleUpvoteClick } from '../../../core/libs/actions'
@@ -21,6 +22,8 @@ import AvatarGroupCasual from '@/components/avatar-group-casual/avatar-group-cas
 import { useUserStore } from '../../../store'
 import { storeToRefs } from 'pinia'
 import { isImageOrVideo } from '../../../core/utils/common'
+import { list } from 'radash'
+import dayjs from 'dayjs'
 
 const userStore = useUserStore()
 const { userInfo } = storeToRefs(userStore)
@@ -34,7 +37,10 @@ const { data: reviews, run: runGetReviews } = useRequest(
     },
   },
 )
-const current = ref(0)
+const { data: circleUpvotes, run: setCircleUpvotes } = useRequest(
+  () => getCircleUpvotes(id.value),
+  { initialData: { list: [], count: 0 } },
+)
 const swiperSizes = ref()
 const swiperStyle = ref()
 const reviewContent = ref('')
@@ -69,6 +75,7 @@ const handleSend = async () => {
   } else {
     reviewContent.value = ''
     uni.showToast({ title: '评论成功', icon: 'none' })
+    await runGetReviews()
   }
 }
 onMounted(async () => {})
@@ -77,6 +84,7 @@ onLoad(async (query: { id: string }) => {
   await run()
   await runGetReviews()
   await setSwiperStyle()
+  await setCircleUpvotes()
 })
 onShareAppMessage(async () => {
   await shareCircle(id.value)
@@ -122,7 +130,7 @@ onShareAppMessage(async () => {
         </template>
       </view>
       <div class="text-black/30 text-xs font-normal font-['PingFang SC'] leading-[10.18px]">
-        2024-5-31 10:06
+        {{ dayjs(data.createTime).format('YYYY-MM-DD HH:mm') }}
       </div>
       <view class="flex items-center my-4">
         <view class="flex items-center">
@@ -168,10 +176,15 @@ onShareAppMessage(async () => {
       <view>
         <template v-if="reviews?.list.length">
           <template v-for="it of reviews?.list" :key="it.id">
-            <CommentItem :options="it" :isChild="false" @upvote="runGetReviews()"></CommentItem>
-            <template v-for="child of it.childrens" :key="child.id">
+            <CommentItem
+              :options="it"
+              :isChild="false"
+              @upvote="runGetReviews()"
+              @delete="runGetReviews()"
+            ></CommentItem>
+            <!-- <template v-for="child of it.childrens" :key="child.id">
               <CommentItem :options="child" :isChild="true"></CommentItem>
-            </template>
+            </template> -->
           </template>
         </template>
         <template v-else>

+ 13 - 5
packages/app/src/pages/home/study-tour/index.vue

@@ -12,7 +12,7 @@ import MomentItem from '@/components/moment-item.vue'
 import SectionHeading from '@/components/section-heading.vue'
 import ClassItem from '../components/class-item.vue'
 import TimeLine from './components/time-line.vue'
-import { getContents } from '../../../core/libs/requests'
+import { getCircles, getContents } from '../../../core/libs/requests'
 import { NetImages } from '../../../core/libs/net-images'
 
 const { data: studyTours, run: setStudyTours } = useRequest(() => getContents({ contentType: '1' }))
@@ -20,12 +20,13 @@ const { data: classmates, run: setClassmates } = useRequest(
   () => getContents({ contentType: '1', contentCategory: '101', pageSize: '2' }),
   { initialData: { list: [] } },
 )
+const { data: circles, run: setCircles } = useRequest(() => getCircles({ tagName: '' }), {
+  initialData: { list: [] },
+})
 onMounted(async () => {
   await setStudyTours()
   await setClassmates()
-  console.log(classmates.value)
-
-  console.log(studyTours.value)
+  // await setCircles()
 })
 </script>
 <template>
@@ -118,6 +119,13 @@ onMounted(async () => {
       tip="暂无内容"
     ></wd-status-tip>
     <section-heading custom-class="my-6" title="设计圈"></section-heading>
-    <moment-item></moment-item>
+    <template v-for="(it, i) in circles.list" :key="i">
+      <moment-item :options="it"></moment-item>
+    </template>
+    <wd-status-tip
+      v-if="!circles.list?.length"
+      :image="NetImages.NotContent"
+      tip="暂无内容"
+    ></wd-status-tip>
   </view>
 </template>