mirror of
https://github.com/Physton/sd-webui-prompt-all-in-one.git
synced 2026-01-26 11:19:55 +00:00
refactor: try avoid request api at same time
This commit is contained in:
@@ -173,6 +173,7 @@ import jsYaml from "js-yaml";
|
||||
import {ref} from "vue";
|
||||
import Hotkey from "@/components/hotkey.vue";
|
||||
import ExtraNetworksPopup from "@/components/extraNetworksPopup.vue";
|
||||
import waitTick from "@/utils/waitTick";
|
||||
|
||||
export default {
|
||||
name: 'App',
|
||||
@@ -370,7 +371,7 @@ export default {
|
||||
this.gradioAPI.setData('languageCode', val).then(data => {
|
||||
}).catch(err => {
|
||||
})
|
||||
this.loadGroupTags()
|
||||
waitTick.addWaitTick(() => this.loadGroupTags())
|
||||
},
|
||||
immediate: false,
|
||||
},
|
||||
@@ -782,7 +783,7 @@ export default {
|
||||
}
|
||||
if (data.tagCompleteFile !== null) {
|
||||
this.tagCompleteFile = data.tagCompleteFile
|
||||
this.$nextTick(() => {
|
||||
waitTick.addWaitTick(() => {
|
||||
this.$refs.translateSetting.getCSV(this.tagCompleteFile)
|
||||
})
|
||||
} else {
|
||||
@@ -870,7 +871,8 @@ export default {
|
||||
})
|
||||
|
||||
this.handlePaste()
|
||||
this.loadGroupTags()
|
||||
|
||||
waitTick.addWaitTick(() => this.loadGroupTags())
|
||||
|
||||
/*this.gradioAPI.getVersion().then(res => {
|
||||
this.version = res.version
|
||||
@@ -905,7 +907,7 @@ export default {
|
||||
})
|
||||
},
|
||||
loadGroupTags() {
|
||||
this.gradioAPI.getGroupTags(this.languageCode).then(data => {
|
||||
return this.gradioAPI.getGroupTags(this.languageCode).then(data => {
|
||||
if (!data || data === '') {
|
||||
this.groupTags = []
|
||||
} else {
|
||||
|
||||
@@ -120,10 +120,10 @@ export default {
|
||||
}
|
||||
},
|
||||
emits: ['use'],
|
||||
async mounted() {
|
||||
for (const item of this.favorites) {
|
||||
await this.getFavorites(item.key)
|
||||
}
|
||||
mounted() {
|
||||
this.favorites.forEach(item => {
|
||||
waitTick.addWaitTick(() => this.getFavorites(item.key))
|
||||
})
|
||||
},
|
||||
methods: {
|
||||
formatTime(time) {
|
||||
|
||||
41
src/src/utils/waitTick.js
Normal file
41
src/src/utils/waitTick.js
Normal file
@@ -0,0 +1,41 @@
|
||||
import { nextTick } from 'vue'
|
||||
|
||||
export default {
|
||||
/**
|
||||
* @types Function[]
|
||||
*/
|
||||
waitTickList: [],
|
||||
startingTick: false,
|
||||
/**
|
||||
*
|
||||
* @param cb Function
|
||||
*/
|
||||
addWaitTick(cb) {
|
||||
this.waitTickList.push(cb)
|
||||
return this.startWaitTick()
|
||||
},
|
||||
|
||||
async execatueWaitTick()
|
||||
{
|
||||
if (this.startingTick) return
|
||||
|
||||
this.startingTick = true
|
||||
|
||||
while (this.waitTickList.length) {
|
||||
const cb = this.waitTickList.shift()
|
||||
await nextTick().then(cb)
|
||||
}
|
||||
|
||||
this.startingTick = false
|
||||
},
|
||||
|
||||
async startWaitTick() {
|
||||
if (!this.startingTick)
|
||||
{
|
||||
return nextTick(() => this.execatueWaitTick().catch(e => {
|
||||
this.startingTick = false
|
||||
return this.startWaitTick()
|
||||
}))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user