49 lines
1.5 KiB
JavaScript
Raw Permalink Normal View History

2024-12-19 16:01:45 +08:00
import { getServerDatetimeRequest, removeBadLockRequest } from '../api'
import { Result } from '../constant'
import { getStorage, setStorage } from '../export'
/**
* 移除坏锁
* @param params
2024-12-20 17:36:14 +08:00
* @param {Number} [params.uid] 用户ID
2024-12-19 16:01:45 +08:00
* @param {List[int]} params.lockIds 锁Id列表
* @returns {Promise<Result>}
*/
export async function removeBadLock(params) {
2024-12-20 17:36:14 +08:00
const { lockIds } = params
2024-12-19 16:01:45 +08:00
// 设置执行账号
2024-12-20 17:36:14 +08:00
const result = await this.login(params.uid)
2024-12-19 16:01:45 +08:00
if (result.code !== Result.Success.code) {
return result
}
const { code, message } = await removeBadLockRequest({
lockIds: params.lockIds
})
if (code === Result.Success.code) {
const lockList = getStorage('starLockList')
2024-12-20 17:36:14 +08:00
if (lockList[this.accountInfo.uid]) {
2024-12-19 16:01:45 +08:00
lockIds.forEach(lockId => {
2024-12-20 17:36:14 +08:00
const index = lockList[this.accountInfo.uid].findIndex(item => item.lockId === lockId)
2024-12-19 16:01:45 +08:00
if (index !== -1) {
2024-12-20 17:36:14 +08:00
lockList[this.accountInfo.uid].splice(index, 1)
2024-12-19 16:01:45 +08:00
}
})
setStorage('starLockList', lockList)
}
}
return new Result(code, {}, message)
}
// 获取服务器时间
export async function getServerTimestamp() {
const { code, data, message } = await getServerDatetimeRequest({})
if (code === Result.Success.code) {
this.serverTimestamp = Math.ceil(data.date / 1000)
this.timeDifference = Math.ceil((data.date - new Date().getTime()) / 1000)
console.log('服务器时差:', this.timeDifference)
console.log('服务器时间:', data)
2024-12-19 16:01:45 +08:00
}
return new Result(code, data, message)
}