Compare commits

...

2 Commits

Author SHA1 Message Date
牛子源 87c79ea0fc Merge remote-tracking branch 'origin/main' 2025-05-14 13:17:20 +08:00
牛子源 c9d1e4fd28 dev 2025-05-14 13:17:13 +08:00
2 changed files with 95 additions and 82 deletions

View File

@ -22,9 +22,11 @@ function post(path: string, data: any = {}, options: any = {}) {
}) })
.then(response => { .then(response => {
if (response.status != 200) { if (response.status != 200) {
show_error("请求失败,请稍后重试");
if (config.catch_error) { if (config.catch_error) {
reject("请求失败,请稍后重试"); reject("请求失败,请稍后重试");
}else{
show_error("请求失败,请稍后重试");
} }
return; return;
} }
@ -37,9 +39,11 @@ function post(path: string, data: any = {}, options: any = {}) {
return; return;
} }
else{ else{
show_error(data.message);
if (config.catch_error) { if (config.catch_error) {
reject(data.message); reject(data.message);
}else{
show_error(data.message);
} }
return; return;
} }
@ -47,10 +51,12 @@ function post(path: string, data: any = {}, options: any = {}) {
}) })
.catch(error => { .catch(error => {
// 可以在这里添加通知,例如使用 ElNotification // 可以在这里添加通知,例如使用 ElNotification
show_error("请求异常,请稍后重试")
console.error(error) console.error(error)
if(config.catch_error){ if(config.catch_error){
reject(error); reject("请求异常,请稍后重试");
}else{
show_error("请求异常,请稍后重试")
} }
}); });

View File

@ -13,6 +13,7 @@ const username = ref('')
const password = ref('') const password = ref('')
const router = useRouter(); const router = useRouter();
const loading = ref(false) const loading = ref(false)
const tip=ref<string>("正在获取本地网卡地址")
interface NetWorkType { interface NetWorkType {
ip: string, ip: string,
@ -25,32 +26,24 @@ const netWork = ref<NetWorkType>({
}) })
const handleLogin = () => { const handleLogin = async () => {
loading.value = true loading.value = true
if (netWork.value.mac == "00-00-00-00-00") { try{
// IP使IP await loginCore();
ElMessage({ }catch (e:any){
message: "获取本地IP地址失败将使用默认IP地址", error(e)
type: 'warning',
duration: 1000,
})
} }
post(apiConfig.ManagerUserLogin, {username: username.value, password: password.value},{catch_error: true}).then((token: any) => { finally {
localStorage.setItem('token', token)
// success,error
ElMessage({
message: "登录成功,正在读卡签到,请稍后...",
type: 'success',
duration: 1000,
})
post(apiConfig.signIn, {mac: netWork.value.mac, ip: netWork.value.ip}, {catch_error: true}).then((res: any) => {
success()
}).catch(() => {
error()
})
}).catch(() => {
loading.value = false loading.value = false
}) }
}
const loginCore=async ()=>{
let token:any=await post(apiConfig.ManagerUserLogin, {username: username.value, password: password.value},{catch_error: true})
localStorage.setItem('token', token)
await post(apiConfig.signIn, {mac: netWork.value.mac, ip: netWork.value.ip}, {catch_error: true})
success()
} }
@ -64,19 +57,12 @@ const success = () => {
}, },
}) })
} }
const error = () => { const error = (message:any) => {
loading.value = false ElMessageBox.alert(message)
ElMessageBox.alert('读卡签到失败,我们将以非签到模式启动系统', '签到提示', {
confirmButtonText: '确定',
type:'error',
showClose: false,
callback: (action: Action) => {
router.push("/home/index")
},
})
} }
const wsStore = useWsStore(); const wsStore = useWsStore();
const reciceMessage = (response: Response) => { const reciceMessage = (response: Response) => {
tip.value="将以IP:"+response.Data[0].IPAddress+"登录签到"
netWork.value = { netWork.value = {
ip: response.Data[0].IPAddress, ip: response.Data[0].IPAddress,
mac: response.Data[0].MACAddress mac: response.Data[0].MACAddress
@ -94,10 +80,15 @@ const getNetwork = () => {
onMounted(async () => { onMounted(async () => {
wsStore.setMessageCallback(reciceMessage) wsStore.setMessageCallback(reciceMessage)
wsStore.setErrorCallback(errorCallback)
getNetwork() getNetwork()
}); });
const errorCallback = () => {
tip.value="获取本地IP失败将以默认IP进行登录"
}
onUnmounted(() => { onUnmounted(() => {
wsStore.removeAllMessageCallback() wsStore.removeAllMessageCallback()
wsStore.removeAllErrorCallback()
}) })
const isShowAuth = ref(false) const isShowAuth = ref(false)
const showAuth = () => { const showAuth = () => {
@ -138,11 +129,13 @@ const showAuth = () => {
class="input-field" class="input-field"
> >
</div> </div>
<div class="button"> <div class="button-group">
<button type="submit" class="login-button" @click="handleLogin">登录</button> <button type="submit" class="login-button" @click="handleLogin">登录</button>
<button class="auth-button" @click="showAuth">授权</button> <button class="auth-button" @click="showAuth">授权</button>
</div> </div>
<div class="tip" >{{tip}}</div>
</div> </div>
</div> </div>
<Mask :is-show="isShowAuth" @close="isShowAuth=false" :width="600" :height="500" title="授权"> <Mask :is-show="isShowAuth" @close="isShowAuth=false" :width="600" :height="500" title="授权">
<Auth></Auth> <Auth></Auth>
@ -357,53 +350,67 @@ const showAuth = () => {
} }
} }
.button { .button-group {
display: flex; display: flex;
.login-button {
flex: 1;
padding: 1rem;
background: linear-gradient(135deg, #3498db, #2980b9);
border: none;
border-radius: 8px;
color: white;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s ease;
&:hover {
transform: translateY(-2px);
}
&:active {
transform: translateY(0);
}
}
.auth-button {
flex: 1;
margin-left: 10px;
padding: 1rem;
background: linear-gradient(135deg, #3498db, #2980b9);
border: none;
border-radius: 8px;
color: white;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s ease;
&:hover {
transform: translateY(-2px);
}
&:active {
transform: translateY(0);
}
}
} }
.tip{
.login-button { position: relative;
flex: 1; width: 100%;
padding: 1rem; height: 30px;
background: linear-gradient(135deg, #3498db, #2980b9); line-height: 30px;
border: none; font-size: 14px;
border-radius: 8px; color: #999;
color: white; text-align: left;
font-size: 1.1rem; box-sizing: border-box;
font-weight: 600; padding-left: 10px;
cursor: pointer; padding-right: 10px;
transition: transform 0.2s ease; overflow: hidden;
margin-top: 10px;
&:hover {
transform: translateY(-2px);
}
&:active {
transform: translateY(0);
}
} }
.auth-button {
flex: 1;
margin-left: 10px;
padding: 1rem;
background: linear-gradient(135deg, #3498db, #2980b9);
border: none;
border-radius: 8px;
color: white;
font-size: 1.1rem;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s ease;
&:hover {
transform: translateY(-2px);
}
&:active {
transform: translateY(0);
}
}
.register-link { .register-link {
text-align: center; text-align: center;
margin-top: 1.5rem; margin-top: 1.5rem;