Skip to content

Commit

Permalink
perf: šŸ› Fix the problem of frequently trigger preservation of prefereā€¦
Browse files Browse the repository at this point in the history
ā€¦nces
  • Loading branch information
viarotel committed Jul 12, 2024
1 parent 677f30c commit 8261916
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default {
for (let index = 0; index < this.devices.length; index++) {
const item = this.devices[index]
await this.$refs.applicationProxyRef.invoke(item)
await sleep(2 * 1000)
await sleep(1 * 1000)
}
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default {
for (let index = 0; index < this.devices.length; index++) {
const item = this.devices[index]
await this.$refs.screenshotProxyRef.invoke(item)
await sleep(2 * 1000)
await sleep(1 * 1000)
}
},
},
Expand Down
16 changes: 2 additions & 14 deletions src/components/Preference/components/PreferenceForm/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ const preferenceData = defineModel('modelValue', {
const preferenceStore = usePreferenceStore()
const collapseValue = ref([])
const preferenceModel = computed(() =>
omit(preferenceStore.model, props.excludes),
)
const preferenceModelKeys = Object.keys(preferenceModel.value ?? {})
const collapseValue = ref([])
if (preferenceModelKeys.length) {
if (props.collapseProps.accordion) {
collapseValue.value = preferenceModelKeys[0]
Expand All @@ -136,18 +136,6 @@ if (preferenceModelKeys.length) {
}
}
watch(
() => props.deviceScope,
(value) => {
if (!value) {
return false
}
preferenceData.value = preferenceStore.getData(value)
},
{ immediate: true },
)
function subModel(item) {
const children = item?.children || {}
Expand Down
70 changes: 70 additions & 0 deletions src/components/Preference/components/ScopeSelect/index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<template>
<el-select
:placeholder="$t('preferences.scope.placeholder')"
:no-data-text="$t('preferences.scope.no-data')"
filterable
class="!w-90"
>
<template #prefix>
<el-tooltip class="" effect="dark" placement="bottom-start">
<el-icon class="text-primary-300 hover:text-primary-500">
<QuestionFilled />
</el-icon>
<template #content>
<div class="space-y-1">
<div class="pb-1">
{{ $t('preferences.scope.details[0]') }}
</div>
<div class="">
{{ $t('preferences.scope.details[1]') }}
</div>
<div class="">
{{ $t('preferences.scope.details[2]') }}
</div>
</div>
</template>
</el-tooltip>
</template>
<el-option
v-for="item in options"
:key="item.id"
:label="item.label"
:value="item.value"
>
</el-option>
</el-select>
</template>

<script setup>
import { useDeviceStore } from '$/store/index.js'
const emit = defineEmits(['device-change'])
const deviceStore = useDeviceStore()
const options = computed(() => {
const value = deviceStore.list.map(item => ({
...item,
label: `${item.id}ļ¼ˆ${item.$name}${
item.$remark ? `ļ¼Œ${item.$remark}` : ''
}ļ¼‰`,
value: item.id,
}))
value.unshift({
label: `Globalļ¼ˆ${window.t('preferences.scope.global')}ļ¼‰`,
value: 'global',
})
return value
})
watch(
() => deviceStore.list.length,
() => {
emit('device-change', options.value)
},
)
</script>

<style></style>
127 changes: 29 additions & 98 deletions src/components/Preference/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,11 @@
class="mr-4 pb-4 flex items-center justify-between flex-none border-b border-gray-200 dark:border-gray-700"
>
<div class="">
<el-select
<ScopeSelect
v-model="deviceScope"
value-key=""
:placeholder="$t('preferences.scope.placeholder')"
filterable
:no-data-text="$t('preferences.scope.no-data')"
class="!w-90"
@change="onScopeChange"
>
<template #prefix>
<el-tooltip class="" effect="dark" placement="bottom-start">
<el-icon class="text-primary-300 hover:text-primary-500">
<QuestionFilled />
</el-icon>
<template #content>
<div class="space-y-1">
<div class="pb-1">
{{ $t('preferences.scope.details[0]') }}
</div>
<div class="">
{{ $t('preferences.scope.details[1]') }}
</div>
<div class="">
{{ $t('preferences.scope.details[2]') }}
</div>
</div>
</template>
</el-tooltip>
</template>
<el-option
v-for="item in scopeList"
:key="item.id"
:label="item.label"
:value="item.value"
>
</el-option>
</el-select>
@device-change="onDeviceChange"
/>
</div>
<div class="">
<el-button type="" icon="Upload" plain @click="handleImport">
Expand All @@ -52,7 +20,7 @@
<el-button type="" icon="Edit" plain @click="handleEdit">
{{ $t('preferences.config.edit.name') }}
</el-button>
<el-button type="" icon="RefreshRight" plain @click="handleResetAll">
<el-button type="" icon="RefreshRight" plain @click="handleReset">
{{ $t('preferences.config.reset.name') }}
</el-button>
</div>
Expand All @@ -73,47 +41,32 @@
<script>
import { debounce } from 'lodash-es'
import ScopeSelect from './components/ScopeSelect/index.vue'
import PreferenceForm from './components/PreferenceForm/index.vue'
import { usePreferenceStore } from '$/store/index.js'
export default {
components: {
ScopeSelect,
PreferenceForm,
},
setup() {
const preferenceStore = usePreferenceStore()
const preferenceData = ref(preferenceStore.data)
const deviceScope = ref(preferenceStore.deviceScope)
return {
preferenceStore,
preferenceData,
deviceScope,
}
},
computed: {
commonPreferenceModel() {
return this.$store.preference.model?.common || {}
},
preferenceModel() {
return this.$store.preference.model || {}
},
scopeList() {
const value = this.$store.device.list.map(item => ({
...item,
label: `${item.id}ļ¼ˆ${item.$name}${
item.$remark ? `ļ¼Œ${item.$remark}` : ''
}ļ¼‰`,
value: item.id,
}))
value.unshift({
label: `Globalļ¼ˆ${this.$t('preferences.scope.global')}ļ¼‰`,
value: 'global',
})
return value
return this.preferenceStore.model || {}
},
},
watch: {
Expand All @@ -133,50 +86,36 @@ export default {
this.handleDevices()
},
},
// 列č”Øč®¾å¤‡å‘ē”Ÿå˜åŒ–åŽå¦‚ęžœę²”ęœ‰åŒ¹é…åˆ°åˆ™é»˜č®¤é€‰äø­ global
'scopeList': {
handler(value) {
const someValue = value.some(
item => this.$replaceIP(item.value) === this.deviceScope,
)
if (someValue) {
return
}
this.deviceScope = 'global'
this.$store.preference.setScope(this.deviceScope)
this.preferenceData = this.$store.preference.data
},
immediate: true,
},
},
created() {
this.handleSave = debounce(this.handleSave, 1000)
this.handleDevices = debounce(this.handleDevices, 1000)
},
methods: {
onDeviceChange(options) {
const device = options.some(
item => this.$replaceIP(item.value) === this.deviceScope,
)
if (device) {
return false
}
this.deviceScope = 'global'
this.preferenceStore.setScope(this.deviceScope)
this.preferenceData = this.preferenceStore.data
},
handleDevices() {
this.$root.reRenderPost()
},
subModel(item) {
const children = item?.children || {}
const value = {}
Object.entries(children).forEach(([key, data]) => {
if (!data.hidden) {
value[key] = data
}
})
return value
},
handleResetAll() {
this.$store.preference.reset(this.deviceScope)
this.preferenceData = this.$store.preference.data
handleReset() {
this.preferenceStore.reset(this.deviceScope)
this.preferenceData = this.preferenceStore.data
},
onScopeChange(value) {
this.$store.preference.setScope(value)
this.preferenceData = this.$store.preference.data
this.preferenceStore.setScope(value)
this.preferenceData = this.preferenceStore.data
},
async handleImport() {
Expand All @@ -194,7 +133,7 @@ export default {
this.$message.success(this.$t('preferences.config.import.success'))
this.preferenceData = this.$store.preference.init()
this.preferenceData = this.preferenceStore.init()
}
catch (error) {
if (error.message) {
Expand Down Expand Up @@ -237,17 +176,9 @@ export default {
},
handleSave() {
this.$store.preference.setData(this.preferenceData)
this.preferenceStore.setData(this.preferenceData)
this.$message.success(this.$t('preferences.config.save.placeholder'))
},
handleReset(type) {
this.preferenceData = {
...this.preferenceData,
...this.$store.preference.getDefaultData(type),
}
this.$store.preference.setData(this.preferenceData)
},
},
}
</script>
Expand Down

0 comments on commit 8261916

Please sign in to comment.