123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <template>
- <el-dialog
- :visible="visible"
- width="800px"
- custom-class="multilingual-fill-dialog"
- :close-on-click-modal="false"
- @close="closeDialog"
- >
- <div class="multilingual-fill">
- <div class="left-menu">
- <span class="title">多语言</span>
- <ul class="lang-list">
- <li
- v-for="{ code } in selectedLangList"
- :key="code"
- :class="['lang-item', { active: curLang === code }]"
- @click="curLang = code"
- >
- {{ langList.find((item) => item.code === code).name }}
- </li>
- <li class="lang-item" @click="showAddLang">
- <i class="el-icon-plus"></i>
- <span>增加语种</span>
- </li>
- </ul>
- </div>
- <div class="right-content">
- <div class="operator">
- <div class="operator-left">
- <span class="btn" @click="isShowOriginal = !isShowOriginal">
- <i v-show="!isShowOriginal" class="el-icon-view"></i>
- <SvgIcon v-show="isShowOriginal" :size="12" icon-class="eye-invisible" />
- <span>{{ isShowOriginal ? '隐藏原文' : '显示原文' }}</span>
- </span>
- <span class="btn primary" @click="submitTranslation">
- <span>提交译文</span>
- </span>
- </div>
- <i class="el-icon-close" @click="closeDialog"></i>
- </div>
- <div class="content">
- <!-- eslint-disable-next-line vue/no-v-html -->
- <div v-show="isShowOriginal" class="original-text" v-html="sanitizeHTML(text)"></div>
- <el-input
- v-for="lang in selectedLangList"
- v-show="curLang === lang.code"
- :key="lang.code"
- v-model="lang.translation"
- type="textarea"
- :rows="27"
- resize="none"
- placeholder="输入译文"
- />
- </div>
- </div>
- </div>
- <UpdateLang :visible.sync="langVisible" :selected-langs="selectedLangList" @update-langs="handleUpdateLangs" />
- </el-dialog>
- </template>
- <script>
- import UpdateLang from './UpdateLang.vue';
- import { langList } from '@/views/book/courseware/data/common';
- import { sanitizeHTML } from '@/utils/common';
- export default {
- name: 'MultilingualFill',
- components: {
- UpdateLang,
- },
- props: {
- visible: {
- type: Boolean,
- required: true,
- },
- text: {
- type: String,
- default: '',
- },
- translations: {
- type: Array,
- default: () => [],
- },
- },
- data() {
- return {
- langList,
- sanitizeHTML,
- selectedLangList: [
- { code: 'en', translation: '' },
- { code: 'fr', translation: '' },
- { code: 'de', translation: '' },
- { code: 'es', translation: '' },
- { code: 'it', translation: '' },
- { code: 'pt', translation: '' },
- { code: 'ko', translation: '' },
- { code: 'ja', translation: '' },
- ],
- noSelectedLangList: ['ru', 'ar', 'tr', 'nl', 'pl', 'sv', 'el'],
- curLang: 'en',
- isShowOriginal: true, // 是否显示原文
- langVisible: false,
- };
- },
- watch: {
- translations: {
- handler(newVal) {
- if (!newVal || !Array.isArray(newVal) || newVal.length === 0) return;
- this.selectedLangList = newVal.map(({ code, translation }) => ({
- code,
- translation,
- }));
- },
- immediate: true,
- },
- },
- methods: {
- closeDialog() {
- this.$emit('update:visible', false);
- },
- showAddLang() {
- this.langVisible = true;
- },
- /**
- * 处理语言更新
- * @param {Array} langs
- */
- handleUpdateLangs(langs) {
- const newLangs = langs.filter((item) => !this.selectedLangList.map((i) => i.code).includes(item));
- const removedLangs = this.selectedLangList.map((i) => i.code).filter((item) => !langs.includes(item));
- this.selectedLangList = [
- ...this.selectedLangList.filter((item) => !removedLangs.includes(item.code)),
- ...newLangs.map((item) => ({ code: item, translation: '' })),
- ];
- },
- submitTranslation() {
- this.$emit('SubmitTranslation', this.selectedLangList);
- this.closeDialog();
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- @use 'sass:color';
- .el-dialog__wrapper {
- :deep .multilingual-fill-dialog {
- > .el-dialog__header {
- display: none;
- }
- > .el-dialog__body {
- height: 650px;
- padding: 12px 16px;
- }
- }
- }
- .multilingual-fill {
- display: flex;
- column-gap: 8px;
- .left-menu {
- width: 90px;
- .title {
- font-size: 16px;
- font-weight: bold;
- color: #333;
- }
- .lang-list {
- display: flex;
- flex-direction: column;
- row-gap: 8px;
- height: 585px;
- margin-top: 12px;
- overflow: auto;
- .lang-item {
- padding: 4px 8px;
- text-align: center;
- cursor: pointer;
- background-color: #f5f5f5;
- border-radius: 4px;
- &:hover {
- background-color: #e0e0e0;
- }
- &.active {
- color: #fff;
- background-color: $main-color;
- }
- }
- }
- }
- .right-content {
- flex: 1;
- .operator {
- display: flex;
- justify-content: space-between;
- margin-bottom: 8px;
- &-left {
- display: flex;
- column-gap: 8px;
- align-items: center;
- .btn {
- display: flex;
- column-gap: 4px;
- align-items: center;
- padding: 6px 12px;
- font-size: 12px;
- cursor: pointer;
- background-color: #f5f5f5;
- border-radius: 4px;
- &.primary {
- color: #fff;
- background-color: $main-color;
- &:hover {
- background-color: color.adjust($main-color, $lightness: -5%);
- }
- }
- }
- }
- i {
- font-weight: bold;
- cursor: pointer;
- }
- }
- .content {
- display: flex;
- column-gap: 8px;
- .original-text {
- width: 100%;
- height: 579px;
- padding: 5px 15px;
- overflow: auto;
- background-color: #f2f3f5;
- border: 1px solid #f2f3f5;
- border-radius: 4px;
- :deep p {
- margin: 0;
- }
- }
- }
- }
- }
- </style>
|