Compare commits
2 Commits
188f98c590
...
87c79ea0fc
| Author | SHA1 | Date |
|---|---|---|
|
|
87c79ea0fc | |
|
|
c9d1e4fd28 |
|
|
@ -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("请求异常,请稍后重试")
|
||||
}
|
||||
|
||||
});
|
||||
|
|
|
|||
|
|
@ -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,53 +350,67 @@ const showAuth = () => {
|
|||
}
|
||||
}
|
||||
|
||||
.button {
|
||||
.button-group {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
.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);
|
||||
}
|
||||
.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;
|
||||
}
|
||||
|
||||
.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 {
|
||||
text-align: center;
|
||||
margin-top: 1.5rem;
|
||||
|
|
|
|||
Loading…
Reference in New Issue