DialoguePreview.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 v-if="item.type === 'input'" :wav-blob.sync="item.audio_file_id" type="small" />
  36. </li>
  37. </ul>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import PreviewMixin from './components/PreviewMixin';
  43. import SoundRecordPreview from './components/common/SoundRecordPreview.vue';
  44. export default {
  45. name: 'DialoguePreview',
  46. components: {
  47. SoundRecordPreview,
  48. },
  49. mixins: [PreviewMixin],
  50. data() {
  51. return {};
  52. },
  53. watch: {
  54. 'data.option_list': {
  55. handler(val) {
  56. if (!val) return;
  57. this.answer.answer_list = val
  58. .map(({ type, content, audio_file_id, mark }) => {
  59. if (type === 'text') return;
  60. let _content = content
  61. .filter((item) => item.type === 'input')
  62. .map(({ content, ...data }) => {
  63. return {
  64. value: content,
  65. ...data,
  66. };
  67. });
  68. return {
  69. content: _content,
  70. mark,
  71. audio_file_id,
  72. };
  73. })
  74. .filter((item) => item);
  75. },
  76. deep: true,
  77. immediate: true,
  78. },
  79. },
  80. methods: {},
  81. };
  82. </script>
  83. <style lang="scss" scoped>
  84. @use '@/styles/mixin.scss' as *;
  85. .dialogue-preview {
  86. @include preview;
  87. .dialogue-wrapper {
  88. padding: 24px;
  89. background-color: #f9f8f9;
  90. border-radius: 16px;
  91. ul {
  92. display: flex;
  93. flex-direction: column;
  94. row-gap: 24px;
  95. .dialogue-item {
  96. display: flex;
  97. column-gap: 16px;
  98. .name {
  99. display: flex;
  100. align-items: center;
  101. justify-content: center;
  102. width: 40px;
  103. min-width: 40px;
  104. height: 40px;
  105. min-height: 40px;
  106. font-size: 12px;
  107. font-weight: bold;
  108. color: #fff;
  109. border-radius: 50%;
  110. }
  111. .content {
  112. display: flex;
  113. flex-wrap: wrap;
  114. align-items: flex-end;
  115. padding: 8px 16px;
  116. color: #000;
  117. border-radius: 8px;
  118. .el-input {
  119. :deep .el-input__inner {
  120. border-width: 0;
  121. border-bottom: 1px solid #000;
  122. border-radius: 0;
  123. }
  124. &.is_left {
  125. :deep .el-input__inner {
  126. background-color: #fff;
  127. }
  128. }
  129. &.is_right {
  130. :deep .el-input__inner {
  131. background-color: #d0f3de;
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. </style>