This commit is contained in:
牛子源 2025-05-14 13:17:13 +08:00
parent eeb3c909e3
commit c9d1e4fd28
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 => {
if (response.status != 200) {
show_error("请求失败,请稍后重试");
if (config.catch_error) {
reject("请求失败,请稍后重试");
}else{
show_error("请求失败,请稍后重试");
}
return;
}
@ -37,9 +39,11 @@ function post(path: string, data: any = {}, options: any = {}) {
return;
}
else{
show_error(data.message);
if (config.catch_error) {
reject(data.message);
}else{
show_error(data.message);
}
return;
}
@ -47,10 +51,12 @@ function post(path: string, data: any = {}, options: any = {}) {
})
.catch(error => {
// 可以在这里添加通知,例如使用 ElNotification
show_error("请求异常,请稍后重试")
console.error(error)
if(config.catch_error){
reject(error);
reject("请求异常,请稍后重试");
}else{
show_error("请求异常,请稍后重试")
}
});

View File

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