MultilingualFill.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. <template>
  2. <el-dialog
  3. :visible="visible"
  4. width="800px"
  5. custom-class="multilingual-fill-dialog"
  6. :close-on-click-modal="false"
  7. @close="closeDialog"
  8. >
  9. <div class="multilingual-fill">
  10. <div class="left-menu">
  11. <span class="title">多语言</span>
  12. <ul class="lang-list">
  13. <li
  14. v-for="{ code } in selectedLangList"
  15. :key="code"
  16. :class="['lang-item', { active: curLang === code }]"
  17. @click="curLang = code"
  18. >
  19. {{ langList.find((item) => item.code === code).name }}
  20. </li>
  21. <li class="lang-item" @click="showAddLang">
  22. <i class="el-icon-plus"></i>
  23. <span>增加语种</span>
  24. </li>
  25. </ul>
  26. </div>
  27. <div class="right-content">
  28. <div class="operator">
  29. <div class="operator-left">
  30. <span class="btn" @click="isShowOriginal = !isShowOriginal">
  31. <i v-show="!isShowOriginal" class="el-icon-view"></i>
  32. <SvgIcon v-show="isShowOriginal" :size="12" icon-class="eye-invisible" />
  33. <span>{{ isShowOriginal ? '隐藏原文' : '显示原文' }}</span>
  34. </span>
  35. <span class="btn primary" @click="submitTranslation">
  36. <span>提交译文</span>
  37. </span>
  38. </div>
  39. <i class="el-icon-close" @click="closeDialog"></i>
  40. </div>
  41. <div class="content">
  42. <!-- eslint-disable-next-line vue/no-v-html -->
  43. <div v-show="isShowOriginal" class="original-text" v-html="sanitizeHTML(text)"></div>
  44. <el-input
  45. v-for="lang in selectedLangList"
  46. v-show="curLang === lang.code"
  47. :key="lang.code"
  48. v-model="lang.translation"
  49. type="textarea"
  50. :rows="27"
  51. resize="none"
  52. placeholder="输入译文"
  53. />
  54. </div>
  55. </div>
  56. </div>
  57. <UpdateLang :visible.sync="langVisible" :selected-langs="selectedLangList" @update-langs="handleUpdateLangs" />
  58. </el-dialog>
  59. </template>
  60. <script>
  61. import UpdateLang from './UpdateLang.vue';
  62. import { langList } from '@/views/book/courseware/data/common';
  63. import { sanitizeHTML } from '@/utils/common';
  64. export default {
  65. name: 'MultilingualFill',
  66. components: {
  67. UpdateLang,
  68. },
  69. props: {
  70. visible: {
  71. type: Boolean,
  72. required: true,
  73. },
  74. text: {
  75. type: String,
  76. default: '',
  77. },
  78. translations: {
  79. type: Array,
  80. default: () => [],
  81. },
  82. },
  83. data() {
  84. return {
  85. langList,
  86. sanitizeHTML,
  87. selectedLangList: [
  88. { code: 'en', translation: '' },
  89. { code: 'fr', translation: '' },
  90. { code: 'de', translation: '' },
  91. { code: 'es', translation: '' },
  92. { code: 'it', translation: '' },
  93. { code: 'pt', translation: '' },
  94. { code: 'ko', translation: '' },
  95. { code: 'ja', translation: '' },
  96. ],
  97. noSelectedLangList: ['ru', 'ar', 'tr', 'nl', 'pl', 'sv', 'el'],
  98. curLang: 'en',
  99. isShowOriginal: true, // 是否显示原文
  100. langVisible: false,
  101. };
  102. },
  103. watch: {
  104. translations: {
  105. handler(newVal) {
  106. if (!newVal || !Array.isArray(newVal) || newVal.length === 0) return;
  107. this.selectedLangList = newVal.map(({ code, translation }) => ({
  108. code,
  109. translation,
  110. }));
  111. },
  112. immediate: true,
  113. },
  114. },
  115. methods: {
  116. closeDialog() {
  117. this.$emit('update:visible', false);
  118. },
  119. showAddLang() {
  120. this.langVisible = true;
  121. },
  122. /**
  123. * 处理语言更新
  124. * @param {Array} langs
  125. */
  126. handleUpdateLangs(langs) {
  127. const newLangs = langs.filter((item) => !this.selectedLangList.map((i) => i.code).includes(item));
  128. const removedLangs = this.selectedLangList.map((i) => i.code).filter((item) => !langs.includes(item));
  129. this.selectedLangList = [
  130. ...this.selectedLangList.filter((item) => !removedLangs.includes(item.code)),
  131. ...newLangs.map((item) => ({ code: item, translation: '' })),
  132. ];
  133. },
  134. submitTranslation() {
  135. this.$emit('SubmitTranslation', this.selectedLangList);
  136. this.closeDialog();
  137. },
  138. },
  139. };
  140. </script>
  141. <style lang="scss" scoped>
  142. @use 'sass:color';
  143. .el-dialog__wrapper {
  144. :deep .multilingual-fill-dialog {
  145. > .el-dialog__header {
  146. display: none;
  147. }
  148. > .el-dialog__body {
  149. height: 650px;
  150. padding: 12px 16px;
  151. }
  152. }
  153. }
  154. .multilingual-fill {
  155. display: flex;
  156. column-gap: 8px;
  157. .left-menu {
  158. width: 90px;
  159. .title {
  160. font-size: 16px;
  161. font-weight: bold;
  162. color: #333;
  163. }
  164. .lang-list {
  165. display: flex;
  166. flex-direction: column;
  167. row-gap: 8px;
  168. height: 585px;
  169. margin-top: 12px;
  170. overflow: auto;
  171. .lang-item {
  172. padding: 4px 8px;
  173. text-align: center;
  174. cursor: pointer;
  175. background-color: #f5f5f5;
  176. border-radius: 4px;
  177. &:hover {
  178. background-color: #e0e0e0;
  179. }
  180. &.active {
  181. color: #fff;
  182. background-color: $main-color;
  183. }
  184. }
  185. }
  186. }
  187. .right-content {
  188. flex: 1;
  189. .operator {
  190. display: flex;
  191. justify-content: space-between;
  192. margin-bottom: 8px;
  193. &-left {
  194. display: flex;
  195. column-gap: 8px;
  196. align-items: center;
  197. .btn {
  198. display: flex;
  199. column-gap: 4px;
  200. align-items: center;
  201. padding: 6px 12px;
  202. font-size: 12px;
  203. cursor: pointer;
  204. background-color: #f5f5f5;
  205. border-radius: 4px;
  206. &.primary {
  207. color: #fff;
  208. background-color: $main-color;
  209. &:hover {
  210. background-color: color.adjust($main-color, $lightness: -5%);
  211. }
  212. }
  213. }
  214. }
  215. i {
  216. font-weight: bold;
  217. cursor: pointer;
  218. }
  219. }
  220. .content {
  221. display: flex;
  222. column-gap: 8px;
  223. .original-text {
  224. width: 100%;
  225. height: 579px;
  226. padding: 5px 15px;
  227. overflow: auto;
  228. background-color: #f2f3f5;
  229. border: 1px solid #f2f3f5;
  230. border-radius: 4px;
  231. :deep p {
  232. margin: 0;
  233. }
  234. }
  235. }
  236. }
  237. }
  238. </style>