| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117 |
- <html lang="zh">
- <head>
- <title>登录</title>
- <meta charset="utf-8" />
- <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
- <script src="/jquery.min.js"></script>
- <script src="/vue.js"></script>
- <script src="/elementui.js"></script>
- <script src="/js.cookie.min.js"></script>
- <link rel="stylesheet" type="text/css" href="/elementui.css">
- <style>
- .login-card {
- width: 350px;
- margin: 20px auto 0 auto;
- }
- </style>
- </head>
- <body>
- <div id="app">
- <div>
- <el-card class="box-card login-card">
- <div slot="header">
- <span>身份验证</span>
- </div>
- <el-input :disabled="isLoading" minlength="6" maxlength="18" @keydown.native.enter="login" v-model="password" placeholder="验证码" type="password"></el-input>
- <el-button @click="login" style="margin-top:20px;display: block;margin-left: auto;margin-right: auto;" type="primary" plain :loading="isLoading">登录</el-button>
- </el-card>
- </div>
- </div>
- <script>
- var app;
- var vue = new Vue({
- el: '#app',
- data: {
- apiUrl: '/api',
- isLoading: false,
- password: ""
- },
- methods: {
- req(url, method, data) {
- data = data ? JSON.stringify(data) : "";
- return new Promise(function(resolve, reject) {
- $.ajax({
- type: method,
- url: url,
- data: data ? data : "",
- contentType: data ? "application/json" : "",
- success: function(data) {
- resolve(data);
- },
- error: function(err) {
- reject(err);
- }
- });
- });
- },
- login() {
- this.isLoading = true;
- this.req(this.apiUrl + "/admin/login", "POST", { "key": this.password }).then((data) => {
- this.isLoading = false;
- if (data["success"] === 1) {
- this.$message.closeAll();
- this.$message({
- type: 'success',
- showClose: true,
- message: "验证成功"
- });
- location.href = "/admin/home.html";
- }
- else {
- this.$message.closeAll();
- this.$message({
- type: 'error',
- showClose: true,
- message: data["msg"]
- });
- }
- }).catch((err) => {
- this.isLoading = false;
- this.$message.closeAll();
- this.$message({
- type: 'error',
- showClose: true,
- message: "服务器错误"
- });
- });
- },
- },
- mounted: function() {
- app = this;
- var token = Cookies.get("admin_token");
- if (token) {
- this.isLoading = true;
- this.req(this.apiUrl + "/admin/login/cookie", "GET", null).then((data) => {
- this.isLoading = false;
- if (data && data["success"]) {
- location.href = "/admin/home.html";
- }
- else {
- Cookies.set("admin_token", "");
- }
- }).catch(() => {
- this.isLoading = false;
- Cookies.set("admin_token", "");
- });
- }
- }
- });
- </script>
- </body>
- </html>
|