// Login 管理员登录页
export default {
template: `
`,
data() {
return {
password: '',
loading: false,
error: ''
};
},
methods: {
async submit() {
if (!this.password || this.loading) return;
this.loading = true;
this.error = '';
try {
const res = await fetch('/admin/login', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ password: this.password })
});
const data = await res.json();
if (data.code === 0) {
// Cookie 已由服务端写入,跳回原本要访问的页面
window.location.href = window.location.pathname === '/admin/login'
? '/admin/'
: window.location.pathname;
} else {
this.error = data.msg || '登录失败';
}
} catch (e) {
this.error = '网络错误,请重试';
} finally {
this.loading = false;
}
}
}
};