fix: 修改语言切换

This commit is contained in:
MTrun 2021-12-22 15:31:20 +08:00
parent 5cfdcc68b7
commit 5cbdbf137d
16 changed files with 151 additions and 140 deletions

View File

@ -2,6 +2,7 @@
<n-loading-bar-provider> <n-loading-bar-provider>
<n-dialog-provider> <n-dialog-provider>
<DialogContent /> <DialogContent />
<LoadingContent />
<n-notification-provider> <n-notification-provider>
<n-message-provider> <n-message-provider>
<MessageContent /> <MessageContent />
@ -22,4 +23,5 @@ import {
import { MessageContent } from '@/components/MessageContent' import { MessageContent } from '@/components/MessageContent'
import { DialogContent } from '@/components/DialogContent' import { DialogContent } from '@/components/DialogContent'
import { LoadingContent } from '@/components/LoadingContent'
</script> </script>

View File

@ -0,0 +1,3 @@
import LoadingContent from './index.vue';
export { LoadingContent };

View File

@ -0,0 +1,12 @@
<script lang="ts">
import { useLoadingBar } from 'naive-ui'
export default {
name: 'LoadingContent',
setup() {
// window 便js使
window['$loading'] = useLoadingBar()
window['$loading'].finish()
}
}
</script>

View File

@ -24,12 +24,11 @@ import { h, ref, reactive } from 'vue';
import { NAvatar, NText } from 'naive-ui' import { NAvatar, NText } from 'naive-ui'
import { renderIcon } from '@/utils' import { renderIcon } from '@/utils'
import { openDoc, logout } from '@/utils' import { openDoc, logout } from '@/utils'
import { useI18n } from 'vue-i18n'
import { icon } from '@/plugins' import { icon } from '@/plugins'
const { DocumentTextIcon, ChatboxEllipsesIcon, PersonIcon, LogOutOutlineIcon } = icon.ionicons5 const { DocumentTextIcon, ChatboxEllipsesIcon, PersonIcon, LogOutOutlineIcon } = icon.ionicons5
const { t } = useI18n() const t = window['$t']
const imageUrl = 'https://www.naiveui.com/assets/naivelogo.93278402.svg' const imageUrl = 'https://www.naiveui.com/assets/naivelogo.93278402.svg'

View File

@ -1,18 +1,30 @@
import login from './login' import login from './login'
import project from './project'
const global = { const global = {
doc_addr: "Document", doc_addr: 'Document',
code_addr: "Code address", code_addr: 'Code address',
form_account: "Please enter your account or email", form_account: 'Please enter your account or email',
form_password: "Please enter your password", form_password: 'Please enter your password',
// header // header
doc: 'Document', doc: 'Document',
help: 'Help', help: 'Help',
contact: 'Contact us', contact: 'Contact us',
logout: 'Logout' logout: 'Logout',
// right key
r_edit: 'Edit',
r_preview: 'Preview',
r_copy: 'Copy',
r_rename: 'Rename',
r_publish: 'Publish',
r_unpublish: 'Unpublish',
r_download: 'Download',
r_delete: 'Delete',
r_more: 'More',
} }
export default { export default {
global: global, global,
login: login login,
} project
}

15
src/i18n/en/project.ts Normal file
View File

@ -0,0 +1,15 @@
export default {
create_btn: 'Creat',
create_tip: 'Please select a content for development',
project: 'Project',
my: 'My',
new_project: 'NewProject',
all_project: 'AllProject',
my_templete: 'MyTemplete',
template_market: 'TemplateMarket',
// items
release: 'Release',
unreleased: 'Unrelease',
last_edit: 'Last edit time'
}

View File

@ -1,4 +1,5 @@
import login from './login' import login from './login'
import project from './project'
const global = { const global = {
doc_addr: '文档地址', doc_addr: '文档地址',
@ -9,10 +10,21 @@ const global = {
doc: '说明文档', doc: '说明文档',
help: '帮助中心', help: '帮助中心',
contact: '联系我们', contact: '联系我们',
logout: '退出登录' logout: '退出登录',
// 功能键
r_edit: '编辑',
r_preview: '预览',
r_copy: '复制',
r_rename: '重命名',
r_publish: '发布',
r_unpublish: '取消发布',
r_download: '下载',
r_delete: '删除',
r_more: '更多',
} }
export default { export default {
global: global, global,
login: login login,
project
} }

16
src/i18n/zh/project.ts Normal file
View File

@ -0,0 +1,16 @@
export default {
// aside
create_btn: '新建',
create_tip: '从哪里出发好呢?',
project: '项目',
my: '我的',
new_project: '新项目',
all_project: '全部项目',
my_templete: '我的模板',
template_market: '模板市场',
// items
release: '已发布',
unreleased: '未发布',
last_edit: '最后编辑'
}

View File

@ -3,85 +3,10 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { onMounted } from 'vue'
import { useLoadingBar } from 'naive-ui'
import { MainView } from '@/layout/components/Main/index' import { MainView } from '@/layout/components/Main/index'
import { useI18n } from 'vue-i18n'
const { t } = useI18n()
onMounted(() => { window['$t'] = t
// window 便js使
window['$loading'] = useLoadingBar()
window['$loading'].finish()
})
</script>
<style lang="scss" scoped> </script>
.layout {
display: flex;
flex-direction: row;
flex: auto;
&-default-background {
background: #f5f7f9;
}
.layout-sider {
min-height: 100vh;
box-shadow: 2px 0 8px 0 rgb(29 35 41 / 5%);
position: relative;
z-index: 13;
transition: all 0.2s ease-in-out;
}
.layout-sider-fix {
position: fixed;
top: 0;
left: 0;
}
.ant-layout {
overflow: hidden;
}
.layout-right-fix {
overflow-x: hidden;
padding-left: 200px;
min-height: 100vh;
transition: all 0.2s ease-in-out;
}
.layout-content {
flex: auto;
min-height: 100vh;
}
.n-layout-header.n-layout-header--absolute-positioned {
z-index: 11;
}
.n-layout-footer {
background: none;
}
}
.layout-content-main {
margin: 0 10px 10px;
position: relative;
padding-top: 64px;
}
.layout-content-main-fix {
padding-top: 64px;
}
.fluid-header {
padding-top: 0px;
}
.main-view-fix {
padding-top: 44px;
}
.noMultiTabs {
padding-top: 0;
}
</style>

View File

@ -114,7 +114,6 @@
import { reactive, ref, onMounted } from 'vue' import { reactive, ref, onMounted } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import { useMessage } from 'naive-ui' import { useMessage } from 'naive-ui'
import { useI18n } from 'vue-i18n'
import { requireUrl } from '@/utils' import { requireUrl } from '@/utils'
import { routerTurnByName } from '@/utils' import { routerTurnByName } from '@/utils'
import shuffle from 'lodash/shuffle' import shuffle from 'lodash/shuffle'
@ -142,7 +141,7 @@ const autoLogin = ref(true)
const show = ref(false) const show = ref(false)
const showBg = ref(false) const showBg = ref(false)
const designStore = useDesignStore() const designStore = useDesignStore()
const { t } = useI18n() const t = window['$t']
onMounted(() => { onMounted(() => {
setTimeout(() => { setTimeout(() => {

View File

@ -12,7 +12,7 @@
/> />
</div> </div>
<!-- 中间 --> <!-- 中间 -->
<div class="list-content-img" @click="resizeHandle"> <div class="list-content-img" @click="resizeHandle">
<n-image <n-image
object-fit="contain" object-fit="contain"
height="200" height="200"
@ -38,7 +38,11 @@
dot dot
:color="cardData.release ? '#34c749' : '#fcbc40'" :color="cardData.release ? '#34c749' : '#fcbc40'"
/> />
{{ cardData.release ? '已发布' : '未发布' }} {{
cardData.release
? $t('project.release')
: $t('project.unreleased')
}}
</n-text> </n-text>
<template v-for="item in fnBtnList" :key="item.key"> <template v-for="item in fnBtnList" :key="item.key">
@ -66,7 +70,7 @@
</template> </template>
</n-button> </n-button>
</template> </template>
<span> {{ item.label }}</span> <span> {{ item.label }} </span>
</n-tooltip> </n-tooltip>
</template> </template>
</n-space> </n-space>
@ -78,11 +82,13 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { ref } from 'vue' import { reactive, h } from 'vue'
import { renderIcon, requireUrl, requireFallbackImg } from '@/utils' import { renderIcon, requireUrl, requireFallbackImg } from '@/utils'
import { icon } from '@/plugins' import { icon } from '@/plugins'
import { AppleControlBtn } from '@/components/AppleControlBtn' import { AppleControlBtn } from '@/components/AppleControlBtn'
import { useMessage, useDialog } from 'naive-ui' import { NText } from 'naive-ui'
const t = window['$t']
const { const {
EllipsisHorizontalCircleSharpIcon, EllipsisHorizontalCircleSharpIcon,
@ -95,41 +101,40 @@ const {
SendIcon SendIcon
} = icon.ionicons5 } = icon.ionicons5
const dialog = useDialog()
const message = useMessage()
const emit = defineEmits(['delete', 'resize', 'edit']) const emit = defineEmits(['delete', 'resize', 'edit'])
const props = defineProps({ const props = defineProps({
cardData: Object cardData: Object
}) })
const renderNText = (set = {}) => {
const fnBtnList = [ return () => h(NText, set, { default: () => h('312321') })
}
const fnBtnList = reactive([
{ {
label: '编辑', label: t('global.r_edit'),
key: 'edit', key: 'edit',
icon: renderIcon(HammerIcon) icon: renderIcon(HammerIcon)
}, },
{ {
lable: '更多', lable: t('global.r_more'),
key: 'select', key: 'select',
icon: renderIcon(EllipsisHorizontalCircleSharpIcon) icon: renderIcon(EllipsisHorizontalCircleSharpIcon)
} }
] ])
const selectOptions = [ const selectOptions = reactive([
{ {
label: '预览', label: t('global.r_preview'),
key: 'preview', key: 'preview',
icon: renderIcon(ApertureSharpIcon) icon: renderIcon(ApertureSharpIcon)
}, },
{ {
label: '复制', label: t('global.r_copy'),
key: 'copy', key: 'copy',
icon: renderIcon(CopyIcon) icon: renderIcon(CopyIcon)
}, },
{ {
label: '重命名', label: t('global.r_rename'),
key: 'rename', key: 'rename',
icon: renderIcon(PencilIcon) icon: renderIcon(PencilIcon)
}, },
@ -138,12 +143,14 @@ const selectOptions = [
key: 'd1' key: 'd1'
}, },
{ {
label: props.cardData?.release ? '取消发布' : '发布', label: props.cardData?.release
? t('global.r_unpublish')
: t('global.r_publish'),
key: 'send', key: 'send',
icon: renderIcon(SendIcon) icon: renderIcon(SendIcon)
}, },
{ {
label: '下载', label: t('global.r_download'),
key: 'download', key: 'download',
icon: renderIcon(DownloadIcon) icon: renderIcon(DownloadIcon)
}, },
@ -152,11 +159,11 @@ const selectOptions = [
key: 'd2' key: 'd2'
}, },
{ {
label: '删除', label: t('global.r_delete'),
key: 'delete', key: 'delete',
icon: renderIcon(TrashIcon) icon: renderIcon(TrashIcon)
} }
] ])
const handleSelect = (key: string) => { const handleSelect = (key: string) => {
switch (key) { switch (key) {

View File

@ -36,7 +36,7 @@
<template #action> <template #action>
<n-space class="list-footer" justify="space-between"> <n-space class="list-footer" justify="space-between">
<n-text depth="3"> <n-text depth="3">
最后编辑于 {{$t('project.last_edit')}}
<n-time :time="new Date()" format="yyyy-MM-dd hh:mm" /> <n-time :time="new Date()" format="yyyy-MM-dd hh:mm" />
</n-text> </n-text>
<!-- 工具 --> <!-- 工具 -->
@ -47,7 +47,7 @@
dot dot
:color="cardData?.release ? '#34c749' : '#fcbc40'" :color="cardData?.release ? '#34c749' : '#fcbc40'"
/> />
{{ cardData?.release ? '已发布' : '未发布' }} {{ cardData?.release ? $t('project.release') : $t('project.unreleased') }}
</n-text> </n-text>
<template v-for="item in fnBtnList" :key="item.key"> <template v-for="item in fnBtnList" :key="item.key">
@ -71,14 +71,17 @@
</template> </template>
<script setup lang="ts"> <script setup lang="ts">
import { watchEffect } from 'vue' import { watchEffect, reactive } from 'vue'
import { renderIcon, requireUrl, requireFallbackImg } from '@/utils' import { renderIcon, requireUrl, requireFallbackImg } from '@/utils'
import { icon } from '@/plugins' import { icon } from '@/plugins'
import { AppleControlBtn } from '@/components/AppleControlBtn' import { AppleControlBtn } from '@/components/AppleControlBtn'
const { HammerIcon } = icon.ionicons5 const { HammerIcon } = icon.ionicons5
const emit = defineEmits(['close']) const emit = defineEmits(['close'])
const t = window['$t']
const props = defineProps({ const props = defineProps({
show: Boolean, show: Boolean,
cardData: Object cardData: Object
@ -91,13 +94,13 @@ watchEffect(() => {
} }
}) })
const fnBtnList = [ const fnBtnList = reactive([
{ {
label: '编辑', label: t('global.r_edit'),
key: 'edit', key: 'edit',
icon: renderIcon(HammerIcon) icon: renderIcon(HammerIcon)
} }
] ])
// //
const closeHandle = () => { const closeHandle = () => {

View File

@ -3,7 +3,7 @@
<n-space size="large"> <n-space size="large">
<n-card class="card-box" hoverable> <n-card class="card-box" hoverable>
<template #header> <template #header>
<n-text class="card-box-tite">从哪里出发好呢</n-text> <n-text class="card-box-tite">{{ $t('project.create_tip') }}</n-text>
</template> </template>
<template #header-extra> <template #header-extra>
<n-text @click="closeHandle"> <n-text @click="closeHandle">
@ -36,32 +36,33 @@
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { watch, ref } from 'vue' import { watch, reactive } from 'vue'
import { icon } from '@/plugins' import { icon } from '@/plugins'
import { PageEnum, ChartEnum } from '@/enums/pageEnum' import { PageEnum, ChartEnum } from '@/enums/pageEnum'
import { routerTurnByName } from '@/utils' import { routerTurnByName } from '@/utils'
const { FishIcon, LaptopOutlineIcon, BeerIcon, CloseIcon } = icon.ionicons5 const { FishIcon, LaptopOutlineIcon, BeerIcon, CloseIcon } = icon.ionicons5
const t = window['$t']
const emit = defineEmits(['close']) const emit = defineEmits(['close'])
const props = defineProps({ const props = defineProps({
show: Boolean show: Boolean
}) })
const typeList = ref([ const typeList = reactive([
{ {
title: '新项目', title: t('project.new_project'),
key: ChartEnum.CHART_HOME_NAME, key: ChartEnum.CHART_HOME_NAME,
icon: FishIcon, icon: FishIcon,
disabled: false disabled: false
}, },
{ {
title: '我的模板', title: t('project.my_templete'),
key: PageEnum.BASE_HOME_TEMPLATE_NAME, key: PageEnum.BASE_HOME_TEMPLATE_NAME,
icon: LaptopOutlineIcon, icon: LaptopOutlineIcon,
disabled: true disabled: true
}, },
{ {
title: '市场模板', title: t('project.template_market'),
key: PageEnum.BASE_HOME_TEMPLATE_MARKET_NAME, key: PageEnum.BASE_HOME_TEMPLATE_MARKET_NAME,
icon: BeerIcon, icon: BeerIcon,
disabled: true disabled: true
@ -87,13 +88,15 @@ const btnHandle = (key: string) => {
} }
</script> </script>
<style lang="scss" scoped> <style lang="scss" scoped>
$cardWidth: 570px;
@include go('create-modal') { @include go('create-modal') {
position: fixed; position: fixed;
top: 200px; top: 200px;
left: 50%; left: 50%;
transform: translateX(-50%); transform: translateX(-50%);
.card-box { .card-box {
width: 500px; width: $cardWidth;
cursor: pointer; cursor: pointer;
border: 1px solid rgba(0, 0, 0, 0); border: 1px solid rgba(0, 0, 0, 0);
@extend .go-transition; @extend .go-transition;

View File

@ -12,7 +12,7 @@
</n-button> </n-button>
</template> </template>
<span> <span>
新建 {{ $t('project.create_btn') }}
</span> </span>
</n-tooltip> </n-tooltip>
<n-button v-else ghost type="primary" size="large"> <n-button v-else ghost type="primary" size="large">
@ -23,7 +23,7 @@
</n-icon> </n-icon>
</template> </template>
<span> <span>
新建 {{ $t('project.create_btn') }}
</span> </span>
</n-button> </n-button>
</div> </div>

View File

@ -13,19 +13,22 @@ export const renderMenuLabel = (option: MenuOption | MenuGroupOption) => {
export const expandedKeys = () => ['all-project'] export const expandedKeys = () => ['all-project']
export const menuOptionsInit = () => { export const menuOptionsInit = () => {
const t = window['$t']
return reactive([ return reactive([
{ {
key: 'divider-1', key: 'divider-1',
type: 'divider' type: 'divider'
}, },
{ {
label: '项目', label: t('project.project'),
key: 'all-project', key: 'all-project',
icon: renderIcon(GridIcon), icon: renderIcon(GridIcon),
children: [ children: [
{ {
type: 'group', type: 'group',
label: '我的', label: t('project.my'),
key: 'my-project', key: 'my-project',
children: [ children: [
{ {
@ -37,7 +40,7 @@ export const menuOptionsInit = () => {
name: PageEnum.BASE_HOME_ITEMS_NAME name: PageEnum.BASE_HOME_ITEMS_NAME
} }
}, },
{ default: () => '全部项目' } { default: () => t('project.all_project') }
), ),
key: PageEnum.BASE_HOME_ITEMS_NAME, key: PageEnum.BASE_HOME_ITEMS_NAME,
icon: renderIcon(DesktopIcon) icon: renderIcon(DesktopIcon)
@ -51,7 +54,7 @@ export const menuOptionsInit = () => {
name: PageEnum.BASE_HOME_TEMPLATE_NAME name: PageEnum.BASE_HOME_TEMPLATE_NAME
} }
}, },
{ default: () => '我的物料' } { default: () => t('project.my_templete') }
), ),
key: PageEnum.BASE_HOME_TEMPLATE_NAME, key: PageEnum.BASE_HOME_TEMPLATE_NAME,
icon: renderIcon(LaptopOutlineIcon) icon: renderIcon(LaptopOutlineIcon)
@ -74,7 +77,7 @@ export const menuOptionsInit = () => {
name: PageEnum.BASE_HOME_TEMPLATE_MARKET_NAME name: PageEnum.BASE_HOME_TEMPLATE_MARKET_NAME
} }
}, },
{ default: () => '物料市场' } { default: () => t('project.template_market') }
), ),
key: PageEnum.BASE_HOME_TEMPLATE_MARKET_NAME, key: PageEnum.BASE_HOME_TEMPLATE_MARKET_NAME,
icon: renderIcon(BeerIcon) icon: renderIcon(BeerIcon)

10
types/global.d.ts vendored
View File

@ -1,7 +1,7 @@
interface Window { interface Window {
$loading: any; $loading: any
$message: any; $message: any
$dialog: any; $dialog: any
$t: any
} }
declare type Recordable<T = any> = Record<string, T>; declare type Recordable<T = any> = Record<string, T>