Compare commits

..

No commits in common. "87c79ea0fcb62e527c6b04e8e6f88828c648ee1b" and "188f98c5909d88a4127bdc82324301e25f80a2fb" have entirely different histories.

2 changed files with 75 additions and 88 deletions

View File

@ -22,11 +22,9 @@ 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;
} }
@ -39,11 +37,9 @@ 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;
} }
@ -51,12 +47,10 @@ 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("请求异常,请稍后重试"); reject(error);
}else{
show_error("请求异常,请稍后重试")
} }
}); });

View File

@ -13,7 +13,6 @@ 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,
@ -26,24 +25,32 @@ const netWork = ref<NetWorkType>({
}) })
const handleLogin = async () => { const handleLogin = () => {
loading.value = true loading.value = true
try{ if (netWork.value.mac == "00-00-00-00-00") {
await loginCore(); // IP使IP
}catch (e:any){ ElMessage({
error(e) message: "获取本地IP地址失败将使用默认IP地址",
type: 'warning',
duration: 1000,
})
} }
finally { post(apiConfig.ManagerUserLogin, {username: username.value, password: password.value},{catch_error: true}).then((token: any) => {
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) localStorage.setItem('token', token)
await post(apiConfig.signIn, {mac: netWork.value.mac, ip: netWork.value.ip}, {catch_error: true}) // 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() success()
}).catch(() => {
error()
})
}).catch(() => {
loading.value = false
})
} }
@ -57,12 +64,19 @@ const success = () => {
}, },
}) })
} }
const error = (message:any) => { const error = () => {
ElMessageBox.alert(message) loading.value = false
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
@ -80,15 +94,10 @@ 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 = () => {
@ -129,13 +138,11 @@ const showAuth = () => {
class="input-field" class="input-field"
> >
</div> </div>
<div class="button-group"> <div class="button">
<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>
@ -350,10 +357,11 @@ const showAuth = () => {
} }
} }
.button-group { .button {
display: flex; display: flex;
}
.login-button { .login-button {
flex: 1; flex: 1;
padding: 1rem; padding: 1rem;
background: linear-gradient(135deg, #3498db, #2980b9); background: linear-gradient(135deg, #3498db, #2980b9);
@ -372,9 +380,9 @@ const showAuth = () => {
&:active { &:active {
transform: translateY(0); transform: translateY(0);
} }
} }
.auth-button { .auth-button {
flex: 1; flex: 1;
margin-left: 10px; margin-left: 10px;
padding: 1rem; padding: 1rem;
@ -394,23 +402,8 @@ const showAuth = () => {
&:active { &:active {
transform: translateY(0); 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 { .register-link {
text-align: center; text-align: center;
margin-top: 1.5rem; margin-top: 1.5rem;