|
|
@@ -48,6 +48,7 @@ import { inject, ref } from 'vue'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
import router from '@/router/index'
|
|
|
import { store } from '@/stores/store'
|
|
|
+import { isBefore, parse, format, isAfter } from 'date-fns'
|
|
|
const loginForm = ref({
|
|
|
username: localStorage.getItem('username') || import.meta.env.VITE_USERNAME || '',
|
|
|
password: localStorage.getItem('password') || import.meta.env.VITE_PASSWORD || '',
|
|
|
@@ -65,8 +66,27 @@ const login = async () => {
|
|
|
try {
|
|
|
await form.value.validate()
|
|
|
loading.value = true
|
|
|
- await http.login(loginForm.value.username, loginForm.value.password)
|
|
|
- store.userInfo = await http.get('/user/my')
|
|
|
+ let { user, account, token } = await http.login(
|
|
|
+ loginForm.value.username,
|
|
|
+ loginForm.value.password,
|
|
|
+ loginForm.value.tradeCode
|
|
|
+ )
|
|
|
+ if (account.startTime) {
|
|
|
+ let startTime = parse(account.startTime, 'yyyy-MM-dd HH:mm:ss', new Date())
|
|
|
+ if (isBefore(new Date(), startTime)) {
|
|
|
+ throw new Error('账户未到开通时间')
|
|
|
+ return
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (account.expireTime) {
|
|
|
+ let expireTime = parse(account.expireTime, 'yyyy-MM-dd HH:mm:ss', new Date())
|
|
|
+ if (isAfter(new Date(), expireTime)) {
|
|
|
+ throw new Error('账号已过期')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ http.setToken(token)
|
|
|
+ store.userInfo = user
|
|
|
+ store.account = account
|
|
|
loading.value = false
|
|
|
sessionStorage.setItem('tradeCode', loginForm.value.tradeCode)
|
|
|
localStorage.setItem('tradeCode', loginForm.value.tradeCode)
|