123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <template>
- <view class="question-card" :class="{'question-card--answered': question.answeredAt}">
- <view class="question-card__header">
- <view class="question-card__user">
- <image :src="question.playerAvatar" mode="aspectFill" class="question-card__avatar" />
- <text class="question-card__name">{{ question.playerName }}</text>
- </view>
- <view class="question-card__time">{{ formatTime(question.createdAt) }}</view>
- </view>
- <view class="question-card__content">
- {{ question.content }}
- </view>
- <view v-if="question.answeredAt" class="question-card__answer">
- <view class="question-card__answer-label">回答</view>
- <view class="question-card__answer-content">{{ question.answer }}</view>
- </view>
- <view v-else-if="isHost" class="question-card__actions">
- <nut-button size="small" type="primary" @click="onAnswer('是')">是</nut-button>
- <nut-button size="small" type="primary" @click="onAnswer('否')">否</nut-button>
- <nut-button size="small" @click="onAnswer('不相关')">不相关</nut-button>
- </view>
- </view>
- </template>
-
- <script setup lang="ts">
- import { defineProps, defineEmits } from 'vue';
- import type { Question } from '@/types/game';
- import { formatDistanceToNow } from 'date-fns';
- import { zhCN } from 'date-fns/locale';
-
- interface QuestionWithAvatar extends Question {
- playerAvatar: string;
- }
-
- const props = defineProps({
- question: {
- type: Object as () => QuestionWithAvatar,
- required: true
- },
- isHost: {
- type: Boolean,
- default: false
- }
- });
-
- const emit = defineEmits(['answer']);
-
- const formatTime = (date: Date) => {
- return formatDistanceToNow(new Date(date), {
- addSuffix: true,
- locale: zhCN
- });
- };
-
- const onAnswer = (answer: string) => {
- emit('answer', {
- questionId: props.question.id,
- answer
- });
- };
- </script>
-
- <style lang="scss">
- .question-card {
- background-color: $background-color-light;
- border-radius: $border-radius-small;
- padding: $spacing-base;
- margin-bottom: $spacing-base;
- box-shadow: $shadow-light;
-
- &--answered {
- background-color: $background-color-gray;
- }
-
- &__header {
- display: flex;
- justify-content: space-between;
- align-items: center;
- margin-bottom: $spacing-small;
- }
-
- &__user {
- display: flex;
- align-items: center;
- }
-
- &__avatar {
- width: 24px;
- height: 24px;
- border-radius: $border-radius-circle;
- margin-right: $spacing-mini;
- }
-
- &__name {
- font-size: $font-size-small;
- color: $text-color-primary;
- font-weight: $font-weight-medium;
- }
-
- &__time {
- font-size: $font-size-small;
- color: $text-color-secondary;
- }
-
- &__content {
- font-size: $font-size-base;
- color: $text-color-primary;
- margin-bottom: $spacing-base;
- line-height: $line-height-base;
- }
-
- &__answer {
- background-color: rgba($primary-color, 0.05);
- padding: $spacing-small;
- border-radius: $border-radius-small;
- display: flex;
- }
-
- &__answer-label {
- font-size: $font-size-small;
- color: $primary-color;
- font-weight: $font-weight-medium;
- margin-right: $spacing-small;
- }
-
- &__answer-content {
- font-size: $font-size-small;
- color: $text-color-primary;
- }
-
- &__actions {
- display: flex;
- gap: $spacing-small;
- }
- }
- </style>
|