DialoguePreview.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <!-- eslint-disable vue/no-v-html -->
  2. <template>
  3. <div class="dialogue-preview">
  4. <div class="stem">
  5. <span class="question-number">{{ data.property.question_number }}.</span>
  6. <span v-html="sanitizeHTML(data.stem)"></span>
  7. </div>
  8. <div v-if="isEnable(data.property.is_enable_description)" class="description">{{ data.description }}</div>
  9. <div class="dialogue-wrapper">
  10. <ul>
  11. <li
  12. v-for="(item, i) in data.option_list"
  13. :key="i"
  14. :style="{ flexDirection: item.direction }"
  15. class="dialogue-item"
  16. >
  17. <span class="name" :style="{ backgroundColor: item.direction === 'row' ? '#4F73F4' : '#3ABD38' }">
  18. {{ item.name }}
  19. </span>
  20. <div class="content" :style="{ backgroundColor: item.direction === 'row' ? '#fff' : '#d0f3de' }">
  21. <template v-if="item.type === 'text'">
  22. {{ item.content }}
  23. </template>
  24. <template v-else>
  25. <div v-for="(li, j) in item.content" :key="j">
  26. <template v-if="li.type === 'input'">
  27. <el-input v-model="li.content" :class="[item.direction === 'row' ? 'is_left' : 'is_right']" />
  28. </template>
  29. <template v-else>
  30. {{ li.content }}
  31. </template>
  32. </div>
  33. </template>
  34. </div>
  35. <SoundRecordPreview
  36. v-if="item.type === 'input' && isEnable(data.property.is_enable_voice_answer)"
  37. :wav-blob.sync="item.audio_file_id"
  38. type="small"
  39. />
  40. </li>
  41. </ul>
  42. </div>
  43. </div>
  44. </template>
  45. <script>
  46. import { isEnable } from '../data/common';
  47. import PreviewMixin from './components/PreviewMixin';
  48. import SoundRecordPreview from './components/common/SoundRecordPreview.vue';
  49. export default {
  50. name: 'DialoguePreview',
  51. components: {
  52. SoundRecordPreview,
  53. },
  54. mixins: [PreviewMixin],
  55. data() {
  56. return {};
  57. },
  58. watch: {
  59. 'data.option_list': {
  60. handler(val) {
  61. if (!val) return;
  62. this.answer.answer_list = val
  63. .map(({ type, content, audio_file_id, mark }) => {
  64. if (type === 'text') return;
  65. let _content = content
  66. .filter((item) => item.type === 'input')
  67. .map(({ content, ...data }) => {
  68. return {
  69. value: content,
  70. ...data,
  71. };
  72. });
  73. return {
  74. content: _content,
  75. mark,
  76. audio_file_id,
  77. };
  78. })
  79. .filter((item) => item);
  80. },
  81. deep: true,
  82. immediate: true,
  83. },
  84. },
  85. methods: {},
  86. };
  87. </script>
  88. <style lang="scss" scoped>
  89. @use '@/styles/mixin.scss' as *;
  90. .dialogue-preview {
  91. @include preview;
  92. .dialogue-wrapper {
  93. padding: 24px;
  94. background-color: $content-color;
  95. border-radius: 16px;
  96. ul {
  97. display: flex;
  98. flex-direction: column;
  99. row-gap: 24px;
  100. .dialogue-item {
  101. display: flex;
  102. column-gap: 16px;
  103. .name {
  104. display: flex;
  105. align-items: center;
  106. justify-content: center;
  107. width: 40px;
  108. min-width: 40px;
  109. height: 40px;
  110. min-height: 40px;
  111. font-size: 12px;
  112. font-weight: bold;
  113. color: #fff;
  114. border-radius: 50%;
  115. }
  116. .content {
  117. display: flex;
  118. flex-wrap: wrap;
  119. align-items: flex-end;
  120. padding: 8px 16px;
  121. color: #000;
  122. border-radius: 8px;
  123. .el-input {
  124. :deep .el-input__inner {
  125. border-width: 0;
  126. border-bottom: 1px solid #000;
  127. border-radius: 0;
  128. }
  129. &.is_left {
  130. :deep .el-input__inner {
  131. background-color: #fff;
  132. }
  133. }
  134. &.is_right {
  135. :deep .el-input__inner {
  136. background-color: #d0f3de;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. }
  145. </style>