Skip to content

Commit

Permalink
代码优化
Browse files Browse the repository at this point in the history
  • Loading branch information
xianyunleo committed Oct 31, 2024
1 parent 42a1e63 commit f24913d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 53 deletions.
5 changes: 3 additions & 2 deletions src/main/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ export const isDev = process.resourcesPath.includes(`${sep}node_modules${sep}`)
export const isWindows = OS.isWindows()
export const isMacOS = OS.isMacOS()

export function devConsoleLog(...str) {
export function devConsoleLog(...inputArr) {
if (isDev) {
console.log(...str)
const outputArr = inputArr.map((input) => (typeof input === 'function' ? input() : input))
console.log(...outputArr)
}
}

Expand Down
27 changes: 12 additions & 15 deletions src/renderer/components/Settings/Server.vue
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
<template>
<a-card size="small" :title="t('Server')" class="settings-card">
<a-card size="small" :title="`${t('Server')} & ${t('OneClick')}`" class="settings-card">
<div class="settings-card-row flex-vertical-center">
<a-tooltip>
<template #title>{{ t('OneClick') }}</template>
<span>{{ mt('Server', 'ws', 'List') }}:</span>
</a-tooltip>
<span>{{ mt('Server', 'ws', 'List') }}:</span>

<a-select
v-model:value="store.settings.OneClickServerList"
:options="oneClickServerOptions" @change="oneClickServerChange"
mode="multiple" placeholder="请选择" style="flex: 1"
mode="multiple" :placeholder="t('pleaseChoose')" style="flex: 1"
></a-select>
</div>

<div class="settings-card-row flex-vertical-center">
<a-switch v-model:checked="store.settings.AutoStartAndRestartServer" class="settings-switch"
@change="changeAutoStartAndRestartServer" />
<span>{{ t('websiteAutoRestartText') }}</span>
:disabled="emptyOneClickServerList()" @change="changeAutoStartAndRestartServer" />
<span :class="disabledTextClass()">{{ t('websiteAutoRestartText') }}</span>
</div>

<div class="settings-card-row flex-vertical-center">
<a-switch v-model:checked="store.settings.AfterOpenAppStartServer" class="settings-switch"
@change="changeAfterOpenAppStartServer" />
<span>{{ t('afterOpenAppStartServer') }}</span>
:disabled="emptyOneClickServerList()" @change="changeAfterOpenAppStartServer" />
<span :class="disabledTextClass()">{{ t('afterOpenAppStartServer')
}}</span>
</div>
</a-card>
</template>
Expand All @@ -40,11 +38,7 @@ const { serverList } = storeToRefs(store)
const oneClickServerOptions = computed(() => {
const options = serverList.value.map((item) => {
const name = item.Name
const obj = { value: name, label: item.ServerName ? item.ServerName : name }
if (name === 'Nginx') {
obj.disabled = true
}
return obj
return { value: name, label: item.ServerName ? item.ServerName : name }
})
options.unshift({ label: t('Website') + ' PHP-FPM', value: 'PHP-FPM' })
return options
Expand All @@ -59,6 +53,9 @@ const changeAutoStartAndRestartServer = () => {
const changeAfterOpenAppStartServer = () => {
store.setSettings('AfterOpenAppStartServer')
}
const emptyOneClickServerList = () => store.settings.OneClickServerList.length === 0
const disabledTextClass = () => emptyOneClickServerList() ? 'disabled-text' : ''
</script>

<style scoped></style>
44 changes: 18 additions & 26 deletions src/renderer/components/Settings/Timer.vue
Original file line number Diff line number Diff line change
@@ -1,33 +1,27 @@
<template>
<a-card size="small" :title="t('Timer')" class="settings-card">
<div class="settings-card-row flex-vertical-center">
<a-tooltip>
<template #title>{{ t('TimerServerList') }}</template>
<span>{{ mt('Server', 'ws', 'List') }}</span>
</a-tooltip>

<a-switch v-model:checked="store.settings.AutoTimerRestartServer" class="settings-switch"
@change="changeAutoTimerRestartServer" />
<span>{{ t('ServerAutoRestartText') }}</span>
</div>
<div class="settings-card-row flex-vertical-center">
<span :class="disabledTextClass()">{{ mt('Server', 'ws', 'List') }}:</span>
<a-select
v-model:value="store.settings.AutoTimerServerList"
:options="TimerServerOptions"
mode="multiple"
style="flex: 1"
placeholder="请选择"
:options="timerServerOptions" :disabled="!store.settings.AutoTimerRestartServer"
mode="multiple" style="flex: 1" :placeholder="t('pleaseChoose')"
@change="AutoTimerServerChange"
></a-select>
</div>

<div class="interval-card-row flex-vertical-center">
<a-tooltip>
<template #title>{{ t('RestartIntervalText') }}</template>
<span>{{ t('RestartIntervalText') }}:</span>
</a-tooltip>

<a-select v-model:value="store.settings.AutoTimerInterval" :options="intervalOptions" placeholder="选择重启间隔" style="flex: 1" @change="changeAutoTimerInterval"></a-select>
</div>

<div class="settings-card-row flex-vertical-center">
<a-switch v-model:checked="store.settings.AutoTimerRestartServer" class="settings-switch" @change="changeAutoTimerRestartServer" />
<span>{{ t('ServerAutoRestartText') }}</span>
<span :class="disabledTextClass()">{{ t('RestartIntervalText') }}:</span>
<a-select v-model:value="store.settings.AutoTimerInterval"
:options="intervalOptions" :placeholder="t('pleaseChoose')" style="flex: 1"
:disabled="!store.settings.AutoTimerRestartServer"
@change="changeAutoTimerInterval"
></a-select>
</div>
</a-card>
</template>
Expand Down Expand Up @@ -68,14 +62,10 @@ const ACard = createAsyncComponent(import('ant-design-vue'), 'Card')
const store = useMainStore()
const { serverList } = storeToRefs(store)
const { serverReactive } = inject('GlobalProvide')
const TimerServerOptions = computed(() => {
const timerServerOptions = computed(() => {
const options = serverList.value.map((item) => {
const name = item.Name
const obj = { value: name, label: item.ServerName ? item.ServerName : name }
if (name === 'Nginx') {
obj.disabled = true
}
return obj
return { value: name, label: item.ServerName ? item.ServerName : name }
})
options.unshift({ label: t('Website') + ' PHP-FPM', value: 'PHP-FPM' })
return options
Expand Down Expand Up @@ -128,6 +118,8 @@ const changeAutoTimerRestartServer = () => {
store.setSettings('AutoTimerRestartServer')
setRestartTimer()
}
const disabledTextClass = () => !store.settings.AutoTimerRestartServer ? 'disabled-text' : ''
</script>
<style scoped></style>
6 changes: 3 additions & 3 deletions src/renderer/store/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ export const useMainStore = defineStore('main', {
return { ...item, Installed }
}))
},
async setSettings(key, callback = null) {
async setSettings(key, beforeFunc = null) {
const originVal = Settings.get(key)
try {
if (callback) {
const res = await callback(originVal)
if (beforeFunc) {
const res = await beforeFunc(originVal)
if (res === false) {
return
}
Expand Down
12 changes: 5 additions & 7 deletions src/renderer/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@
</template>

<script setup>
import { EnumSoftwareType } from '@/shared/utils/enum'
import { inject, onMounted, ref, watch} from 'vue'
import { useMainStore } from '@/renderer/store'
import GetPath from '@/shared/utils/GetPath'
Expand All @@ -91,17 +90,17 @@ import MessageBox from '@/renderer/utils/MessageBox'
import { storeToRefs } from 'pinia/dist/pinia'
import { APP_NAME } from '@/shared/utils/constant'
import Native from '@/main/utils/Native'
import { enumGetName, sleep } from '@/shared/utils/utils'
import { sleep } from '@/shared/utils/utils'
import Path from '@/main/utils/Path'
import ProcessExtend from '@/main/utils/ProcessExtend'
import Settings from '@/main/Settings'
import SoftwareExtend from '@/main/core/software/SoftwareExtend'
import TcpProcess from '@/main/utils/TcpProcess'
import { isWindows } from '@/main/utils/utils'
import { devConsoleLog,isWindows } from '@/main/utils/utils'
import { createAsyncComponent } from '@/renderer/utils/utils'
import { mt, t } from '@/renderer/utils/i18n'
var timestamp = new Date().getTime()
const timestamp = new Date().getTime()
const serverTableLoading = ref(false)
const { serverReactive } = inject('GlobalProvide')
Expand Down Expand Up @@ -138,8 +137,7 @@ const store = useMainStore()
const { serverList, afterOpenAppStartServerMark } = storeToRefs(store)
onMounted(async () => {
var timestamp2 = new Date().getTime()
console.log('home onMounted', timestamp2 - timestamp)
devConsoleLog('Home onMounted ms:', () => (new Date().getTime()) - timestamp)
if (serverList?.value?.length > 0) {
serverTableLoading.value = { tip: `${t('RefreshingServer')}...` }
Expand Down Expand Up @@ -282,7 +280,7 @@ const startServerClick = async (item) => {
item.btnLoading = false
}
async function restartServerClick(item) {
async function restartServerClick(item, callback = null) {
item.btnLoading = true
try {
await ServerControl.stop(item)
Expand Down

0 comments on commit f24913d

Please sign in to comment.