🐛 Fix: i18n bug

This commit is contained in:
PiEgg 2023-01-07 20:45:01 +08:00
parent 66d8d714db
commit 911e34e98d
9 changed files with 36 additions and 17 deletions

View File

@ -32,6 +32,7 @@ app.config.globalProperties.$builtInPicBed = [
'aliyun', 'aliyun',
'github' 'github'
] ]
app.config.unwrapInjectedRef = true
app.config.globalProperties.$$db = db app.config.globalProperties.$$db = db
app.config.globalProperties.$http = axios app.config.globalProperties.$http = axios

View File

@ -6,9 +6,11 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useStore } from '@/hooks/useStore' import { useStore } from '@/hooks/useStore'
import { onBeforeMount } from 'vue' import { onBeforeMount, onMounted, onUnmounted } from 'vue'
import { getConfig } from './utils/dataSender' import { getConfig } from './utils/dataSender'
import type { IConfig } from 'picgo' import type { IConfig } from 'picgo'
import bus from './utils/bus'
import { FORCE_UPDATE } from '~/universal/events/constants'
const store = useStore() const store = useStore()
onBeforeMount(async () => { onBeforeMount(async () => {
@ -18,6 +20,16 @@ onBeforeMount(async () => {
} }
}) })
onMounted(() => {
bus.on(FORCE_UPDATE, () => {
store?.updateForceUpdateTime()
})
})
onUnmounted(() => {
bus.off(FORCE_UPDATE)
})
</script> </script>
<script lang="ts"> <script lang="ts">

View File

@ -73,7 +73,7 @@
</div> </div>
</template> </template>
<script lang="ts" setup> <script lang="ts" setup>
import { reactive, ref, watch, defineExpose, toRefs } from 'vue' import { reactive, ref, watch, toRefs } from 'vue'
import { cloneDeep, union } from 'lodash' import { cloneDeep, union } from 'lodash'
import { getConfig } from '@/utils/dataSender' import { getConfig } from '@/utils/dataSender'
import { useRoute } from 'vue-router' import { useRoute } from 'vue-router'

View File

@ -549,7 +549,6 @@ async function handlePasteStyleChange (val: string) {
} }
onBeforeUnmount(() => { onBeforeUnmount(() => {
console.log('unmounted')
ipcRenderer.removeAllListeners('updateGallery') ipcRenderer.removeAllListeners('updateGallery')
ipcRenderer.removeListener(GET_PICBEDS, getPicBeds) ipcRenderer.removeListener(GET_PICBEDS, getPicBeds)
}) })

View File

@ -112,26 +112,22 @@ onBeforeRouteUpdate((to, from, next) => {
if (to.params.type && (to.name === UPLOADER_CONFIG_PAGE)) { if (to.params.type && (to.name === UPLOADER_CONFIG_PAGE)) {
type.value = to.params.type as string type.value = to.params.type as string
getCurrentConfigList() getCurrentConfigList()
console.log(type.value)
} }
next() next()
}) })
onBeforeMount(() => { onBeforeMount(() => {
type.value = $route.params.type as string type.value = $route.params.type as string
console.log(type.value)
getCurrentConfigList() getCurrentConfigList()
}) })
async function getCurrentConfigList () { async function getCurrentConfigList () {
const configList = await triggerRPC<IUploaderConfigItem>(IRPCActionType.GET_PICBED_CONFIG_LIST, type.value) const configList = await triggerRPC<IUploaderConfigItem>(IRPCActionType.GET_PICBED_CONFIG_LIST, type.value)
console.log(configList)
curConfigList.value = configList?.configList ?? [] curConfigList.value = configList?.configList ?? []
defaultConfigId.value = configList?.defaultId ?? '' defaultConfigId.value = configList?.defaultId ?? ''
} }
function openEditPage (configId: string) { function openEditPage (configId: string) {
console.log(configId, type.value, defaultConfigId.value)
$router.push({ $router.push({
name: PICBEDS_PAGE, name: PICBEDS_PAGE,
params: { params: {

View File

@ -60,7 +60,6 @@ const $route = useRoute()
const $router = useRouter() const $router = useRouter()
const $configForm = ref<InstanceType<typeof ConfigForm> | null>(null) const $configForm = ref<InstanceType<typeof ConfigForm> | null>(null)
type.value = $route.params.type as string type.value = $route.params.type as string
console.log('picbed type', $route.params.type)
onBeforeMount(() => { onBeforeMount(() => {
sendToMain('getPicBedConfig', $route.params.type) sendToMain('getPicBedConfig', $route.params.type)
@ -69,7 +68,6 @@ onBeforeMount(() => {
const handleConfirm = async () => { const handleConfirm = async () => {
const result = (await $configForm.value?.validate()) || false const result = (await $configForm.value?.validate()) || false
console.log(result)
if (result !== false) { if (result !== false) {
await triggerRPC<void>(IRPCActionType.UPDATE_UPLOADER_CONFIG, type.value, result?._id, result) await triggerRPC<void>(IRPCActionType.UPDATE_UPLOADER_CONFIG, type.value, result?._id, result)
const successNotification = new Notification($T('SETTINGS_RESULT'), { const successNotification = new Notification($T('SETTINGS_RESULT'), {

View File

@ -1,4 +1,4 @@
import { reactive, InjectionKey, readonly, App, UnwrapRef } from 'vue' import { reactive, InjectionKey, readonly, App, UnwrapRef, ref } from 'vue'
import { saveConfig } from '@/utils/dataSender' import { saveConfig } from '@/utils/dataSender'
export interface IState { export interface IState {
@ -8,6 +8,7 @@ export interface IState {
export interface IStore { export interface IStore {
state: UnwrapRef<IState> state: UnwrapRef<IState>
setDefaultPicBed: (type: string) => void; setDefaultPicBed: (type: string) => void;
updateForceUpdateTime: () => void;
} }
export const storeKey: InjectionKey<IStore> = Symbol('store') export const storeKey: InjectionKey<IStore> = Symbol('store')
@ -17,6 +18,8 @@ const state: IState = reactive({
defaultPicBed: 'smms' defaultPicBed: 'smms'
}) })
const forceUpdateTime = ref<number>(Date.now())
// methods // methods
const setDefaultPicBed = (type: string) => { const setDefaultPicBed = (type: string) => {
saveConfig({ saveConfig({
@ -24,14 +27,19 @@ const setDefaultPicBed = (type: string) => {
'picBed.uploader': type 'picBed.uploader': type
}) })
state.defaultPicBed = type state.defaultPicBed = type
console.log(state) }
const updateForceUpdateTime = () => {
forceUpdateTime.value = Date.now()
} }
export const store = { export const store = {
install (app: App) { install (app: App) {
app.provide(storeKey, { app.provide(storeKey, {
state: readonly(state), state: readonly(state),
setDefaultPicBed setDefaultPicBed,
updateForceUpdateTime
}) })
app.provide('forceUpdateTime', forceUpdateTime)
} }
} }

View File

@ -22,7 +22,7 @@ export const trimValues = (obj: IStringKeyMap) => {
/** /**
* get raw data from reactive or ref * get raw data from reactive or ref
*/ */
export const getRawData = (args: any) => { export const getRawData = (args: any): any => {
if (Array.isArray(args)) { if (Array.isArray(args)) {
const data = args.map((item: any) => { const data = args.map((item: any) => {
if (isRef(item)) { if (isRef(item)) {
@ -31,7 +31,7 @@ export const getRawData = (args: any) => {
if (isReactive(item)) { if (isReactive(item)) {
return toRaw(item) return toRaw(item)
} }
return item return getRawData(item)
}) })
return data return data
} }

View File

@ -1,11 +1,16 @@
import { ComponentOptions, getCurrentInstance } from 'vue' import { ComponentOptions } from 'vue'
import { FORCE_UPDATE, GET_PICBEDS } from '~/universal/events/constants' import { FORCE_UPDATE, GET_PICBEDS } from '~/universal/events/constants'
import bus from '~/renderer/utils/bus' import bus from '~/renderer/utils/bus'
import { ipcRenderer } from 'electron' import { ipcRenderer } from 'electron'
export const mainMixin: ComponentOptions = { export const mainMixin: ComponentOptions = {
inject: ['forceUpdateTime'],
created () { created () {
bus.on(FORCE_UPDATE, () => { // FIXME: may be memory leak
getCurrentInstance()?.proxy?.$forceUpdate() this?.$watch('forceUpdateTime', (newVal: number, oldVal: number) => {
if (oldVal !== newVal) {
this?.$forceUpdate()
}
}) })
}, },