1404/10/28-base
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
import {loading} from '@/utils/index'
|
||||
import {getLastPrice, getPrice} from '@/api/home'
|
||||
import {ref} from 'vue'
|
||||
import type {Price} from '@/models/home'
|
||||
|
||||
let interval: any
|
||||
export const price = ref<Price>()
|
||||
export const lastPrice = ref<Price>()
|
||||
export const olderPrice = ref<number| undefined>(0)
|
||||
|
||||
export async function setIntervalGetAllPrice() {
|
||||
// console.log('salam')
|
||||
try {
|
||||
interval = setInterval(async () => {
|
||||
await getLastPrices()
|
||||
await getUpPrice()
|
||||
}, 10000)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export async function setIntervalGetLastPrice() {
|
||||
// console.log('salam')
|
||||
try {
|
||||
interval = setInterval(async () => {
|
||||
await getLastPrices()
|
||||
// await getUpPrice()
|
||||
}, 10000)
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export async function getUpPrice() {
|
||||
try {
|
||||
// loading.value = true
|
||||
const data = await getPrice()
|
||||
// const dataLast = await getLastPrice()
|
||||
// if (lastPrice.value?.price_last != dataLast.price_last) {
|
||||
// olderPrice.value = lastPrice.value?.price_last
|
||||
// }
|
||||
price.value = data
|
||||
// lastPrice.value = dataLast
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
} finally {
|
||||
// loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
export async function getLastPrices() {
|
||||
try {
|
||||
// loading.value = true
|
||||
// const data = await getPrice()
|
||||
const dataLast = await getLastPrice()
|
||||
if (lastPrice.value?.price_last != dataLast.price_last) {
|
||||
olderPrice.value = lastPrice.value?.price_last
|
||||
}
|
||||
// price.value = data
|
||||
lastPrice.value = dataLast
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
} finally {
|
||||
// loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
export function stopPriceInterval() {
|
||||
// console.log('stop')
|
||||
clearInterval(interval);
|
||||
}
|
||||
|
||||
export function percentPriceChanged() {
|
||||
// console.log(olderPrice.value)
|
||||
// console.log(lastPrice.value?.price_last)
|
||||
if (!olderPrice.value)
|
||||
return 0
|
||||
return ((lastPrice.value?.price_last-olderPrice.value) *100)/olderPrice.value
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user