|
|
@ -11,7 +11,7 @@ |
|
|
|
<label for="password">密码</label> |
|
|
|
<input type="password" id="password" v-model="password" required> |
|
|
|
</div> |
|
|
|
<button type="submit">登录</button> |
|
|
|
<button type="submit" @click="loginHandler">登录</button> |
|
|
|
</form> |
|
|
|
</div> |
|
|
|
</div> |
|
|
@ -20,26 +20,34 @@ |
|
|
|
import { ref } from "vue"; |
|
|
|
import { useRouter } from "vue-router"; |
|
|
|
import { ElMessage } from 'element-plus' |
|
|
|
import { adminlogin } from '@/api/manage/login' |
|
|
|
const router = useRouter(); |
|
|
|
const username = ref(""); |
|
|
|
const password = ref(""); |
|
|
|
// username.value=='90038794' && password.value=='697522'写死的账号密码 |
|
|
|
const loginHandler = async () => { |
|
|
|
try { |
|
|
|
const response = await adminlogin({ |
|
|
|
username: username.value, |
|
|
|
password: password.value |
|
|
|
}) |
|
|
|
|
|
|
|
const login = () => { |
|
|
|
// 这里可以添加实际的登录验证逻辑 |
|
|
|
if (username.value=='homily' && password.value=='27zn') { |
|
|
|
// 登录成功后跳转到抽奖页面 |
|
|
|
ElMessage({ |
|
|
|
message: '登陆成功,欢迎您使用本系统', |
|
|
|
type: 'success', |
|
|
|
}) |
|
|
|
router.push("/zhongchou/mainimg"); |
|
|
|
}else { |
|
|
|
ElMessage({ |
|
|
|
message: '请输入正确的用户名和密码', |
|
|
|
type: 'error', |
|
|
|
}) |
|
|
|
// 假设后端返回 code == 200 表示成功 |
|
|
|
if (response.code ) { |
|
|
|
const token = response.code |
|
|
|
|
|
|
|
// ✅ 保存 token 到 localStorage |
|
|
|
localStorage.setItem('token', token) |
|
|
|
ElMessage.success('登录成功,欢迎您使用本系统') |
|
|
|
router.push('/zhongchou/mainimg') |
|
|
|
} else { |
|
|
|
ElMessage.error(response.message || '登录失败,请检查用户名或密码') |
|
|
|
} |
|
|
|
} catch (error) { |
|
|
|
ElMessage.error('登录失败,请稍后再试') |
|
|
|
console.error('登录错误:', error) |
|
|
|
} |
|
|
|
}; |
|
|
|
} |
|
|
|
</script> |
|
|
|
<style scoped> |
|
|
|
.login-container { |
|
|
|