| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- const n = `<template>
- <div
- class="s-toggle-language"
- :class="blockType === 'button' ? 'flex-right' : ''"
- v-if="$utils.env.VITE_APP_LANG_ENABLE"
- >
- <a-dropdown :trigger="['click']" @openChange="openChange" v-if="blockType === 'dropdown'">
- <div class="locale-select">
- <div class="label">{{ lang === 'zh' ? '中文' : 'English' }}</div>
- <img src="@p/static/svg/login/map-icon.svg" class="icon" v-if="!isOpen" />
- <img src="@p/static/svg/login/map-icon-s.svg" class="icon" v-else />
- <s-icon
- name="CaretDownOutlined"
- style="color: var(--s-text-color); font-size: 12px"
- v-if="!isOpen"
- />
- <s-icon name="CaretUpOutlined" class="s-theme-color" style="font-size: 12px" v-else />
- </div>
- <template #overlay>
- <a-menu>
- <a-menu-item v-for="item in locales" :key="item.key" @click="toggleLang(item)">
- {{ item.name }}
- </a-menu-item>
- </a-menu>
- </template>
- </a-dropdown>
- <a-button v-else class="custom-btn" @click="toggleChange">{{
- lang === 'zh' ? '中' : 'EN'
- }}</a-button>
- </div>
- </template>
- <script setup>
- import { onMounted, ref } from 'vue'
- defineOptions({ name: 'SToggleLanguage' })
- defineProps({
- // 展示形态:button 按钮 / dropdown 下拉 / 其它为块状
- blockType: {
- type: String,
- default: 'button'
- }
- })
- const lang = ref('')
- const isOpen = ref(false)
- const locales = [
- {
- key: 'zh',
- name: window.$l('中文')
- },
- {
- key: 'en',
- name: 'English'
- }
- ]
- function openChange(e) {
- isOpen.value = e
- }
- function toggleLang(item) {
- lang.value = item.key
- window.$utils.ls.set('lang', item.key)
- window.location.reload()
- }
- function toggleChange() {
- if (lang.value === 'zh') {
- lang.value = 'en'
- window.$utils.ls.set('lang', 'en')
- } else {
- lang.value = 'zh'
- window.$utils.ls.set('lang', 'zh')
- }
- window.location.reload()
- }
- function init() {
- // 默认中文
- const saved = window.$utils.ls.get('lang')
- if (!saved || saved === 'undefined') {
- window.$utils.ls.set('lang', window.$utils.env.VITE_APP_LANG)
- }
- lang.value = window.$utils.env.VITE_APP_LANG_ENABLE ? window.$utils.ls.get('lang') : 'zh'
- }
- onMounted(() => {
- init()
- })
- <\/script>
- <style lang="less" scoped>
- .s-toggle-language {
- width: 100px;
- height: 42px;
- display: flex;
- justify-content: center;
- align-items: center;
- // user-select: none;
- }
- .locale-select {
- width: 100px;
- height: 42px;
- display: flex;
- justify-content: center;
- align-items: center;
- border-radius: 4px;
- cursor: pointer;
- }
- .label {
- width: 58px;
- text-align: right;
- }
- .icon {
- width: 16px;
- height: 16px;
- margin: 0 5px;
- }
- .custom-btn {
- padding: 0;
- width: 24px;
- height: 24px;
- color: var(--s-text-color-inverse);
- outline: none;
- box-shadow: none;
- border: none;
- background-color: var(--s-text-color);
- border-radius: 5px;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .custom-btn:hover {
- color: var(--s-text-color-inverse);
- outline: none;
- box-shadow: none;
- border: none;
- }
- .flex-right {
- justify-content: flex-end;
- }
- </style>
- `;
- export {
- n as default
- };
|