Browse Source

登录接口调试成功

Michael Wang 4 years ago
parent
commit
f735d4305b
7 changed files with 289 additions and 27 deletions
  1. 1 0
      package.json
  2. 269 0
      src/features/Login/Login.vue
  3. 3 2
      src/plugins/axiosApp.js
  4. 6 19
      src/router/index.js
  5. 3 0
      src/store/modules/user.js
  6. 2 6
      vue.config.js
  7. 5 0
      yarn.lock

+ 1 - 0
package.json

@@ -21,6 +21,7 @@
     "axios-retry": "^3.1.8",
     "bootstrap": "^4.5.0",
     "core-js": "^3.6.5",
+    "crypto-js": "^4.0.0",
     "element-ui": "^2.13.2",
     "js-cookie": "^2.2.1",
     "lodash-es": "^4.17.15",

+ 269 - 0
src/features/Login/Login.vue

@@ -0,0 +1,269 @@
+<template>
+  <div class="user-login">
+    <div
+      class="user-login-bg"
+      :style="{ 'background-image': `url(${backgroundImage})` }"
+    ></div>
+    <div class="content-wrapper">
+      <h2 class="slogan">
+        欢迎使用 <br />
+        ICE 内容管理系统
+      </h2>
+      <div class="form-container">
+        <h4 class="form-title">登录</h4>
+        <el-form ref="form" :model="user" label-width="0">
+          <div class="form-items">
+            <el-row class="form-item">
+              <el-col>
+                <el-form-item
+                  prop="username"
+                  :rules="[
+                    { required: true, message: '会员名/邮箱/手机号不能为空' },
+                  ]"
+                >
+                  <div class="form-line">
+                    <i class="el-icon-user input-icon"></i>
+                    <el-input
+                      placeholder="会员名/邮箱/手机号"
+                      v-model="user.username"
+                    ></el-input>
+                  </div>
+                </el-form-item>
+              </el-col>
+            </el-row>
+            <el-row class="form-item">
+              <el-col>
+                <el-form-item
+                  prop="password"
+                  :rules="[{ required: true, message: '密码不能为空' }]"
+                >
+                  <div class="form-line">
+                    <i class="el-icon-lock input-icon"></i>
+                    <el-input
+                      type="password"
+                      placeholder="密码"
+                      v-model="user.password"
+                    ></el-input>
+                  </div>
+                </el-form-item>
+              </el-col>
+            </el-row>
+            <el-row class="form-item">
+              <el-col>
+                <el-form-item>
+                  <el-checkbox class="checkbox">记住账号</el-checkbox>
+                </el-form-item>
+              </el-col>
+            </el-row>
+            <el-row class="form-item">
+              <el-button
+                type="primary"
+                class="submit-btn"
+                size="small"
+                @click="submitBtn"
+              >
+                登 录
+              </el-button>
+            </el-row>
+          </div>
+          <el-row class="tips">
+            <a href="/" class="link">
+              立即注册
+            </a>
+            <span class="line">|</span>
+            <a href="/" class="link">
+              忘记密码
+            </a>
+          </el-row>
+        </el-form>
+      </div>
+    </div>
+  </div>
+</template>
+
+<script>
+// import BasicContainer from "@/samples/BasicContainer/BasicContainer";
+const backgroundImage =
+  "https://img.alicdn.com/tfs/TB1zsNhXTtYBeNjy1XdXXXXyVXa-2252-1500.png";
+export default {
+  // components: { BasicContainer },
+  name: "Login",
+  data() {
+    return {
+      backgroundImage: backgroundImage,
+      user: {
+        username: "",
+        password: "",
+      },
+    };
+  },
+  created() {},
+  methods: {
+    async submitBtn() {
+      const CryptoJS = require("crypto-js");
+
+      const AES = (content) => {
+        const KEY = "1234567890123456";
+        const IV = "1234567890123456";
+        // const key = CryptoJS.enc.Utf8.parse("1234567890123456");
+        // console.log(key);
+        // const key = "1234567890123456";
+        console.log(content);
+
+        var key = CryptoJS.enc.Utf8.parse(KEY);
+        var iv = CryptoJS.enc.Utf8.parse(IV);
+        var encrypted = CryptoJS.AES.encrypt(content, key, { iv: iv });
+        return encrypted.toString();
+
+        // const enstr = CryptoJS.AES.encrypt(content + "", key, {
+        //   // mode: CryptoJS.mode.ECB,
+        //   // padding: CryptoJS.pad.Pkcs7,
+        // }).toString();
+
+        // return enstr;
+      };
+
+      this.$refs["form"].validate(async (valid) => {
+        if (valid) {
+          const res = await this.$http.post("/api/admin/user/login/account", {
+            loginName: this.user.username,
+            password: AES(this.user.password),
+          });
+          console.log(res);
+          this.$message({
+            message: "登录成功",
+            type: "success",
+          });
+        }
+      });
+    },
+  },
+};
+</script>
+
+<style lang="scss" scoped>
+.user-login {
+  .user-login-bg {
+    position: absolute;
+    top: 0;
+    left: 0;
+    right: 0;
+    bottom: 0;
+    background-size: cover;
+  }
+  .el-checkbox__label {
+    color: #999;
+    font-size: 13px;
+  }
+  .content-wrapper {
+    position: absolute;
+    top: -100px;
+    left: 0;
+    right: 0;
+    bottom: 0;
+    max-width: 1080px;
+    margin: 0 auto;
+    display: flex;
+    justify-content: space-around;
+    align-items: center;
+    .slogan {
+      text-align: center;
+      color: blue;
+      font-size: 36px;
+      letter-spacing: 2px;
+      line-height: 48px;
+    }
+  }
+  .form-container {
+    display: flex;
+    justify-content: center;
+    flex-direction: column;
+    padding: 30px 40px;
+    background-color: #fff;
+    border-radius: 6px;
+    box-shadow: 1px 1px 2px #eee;
+  }
+  .el-form-item {
+    margin-bottom: 15px;
+  }
+  .form-Item {
+    position: relative;
+    flex-direction: column;
+  }
+  .form-line {
+    position: relative;
+    display: flex;
+    align-items: center;
+    &:after {
+      content: "";
+      position: absolute;
+      bottom: 3px;
+      left: 0;
+      width: 100%;
+      box-sizing: border-box;
+      border-width: 1px;
+      border-style: solid;
+      border-top: 0;
+      border-left: 0;
+      border-right: 0;
+      border-color: #dcdcdc;
+      border-radius: 0;
+    }
+  }
+  .el-input {
+    width: 240px;
+    // FIXME: 此处css没有生效
+    input {
+      border: none;
+      margin: 0;
+      padding-left: 10px;
+      font-size: 13px;
+    }
+  }
+  .form-title {
+    margin: 0 0 20px;
+    text-align: center;
+    color: #3080fe;
+    letter-spacing: 12px;
+  }
+  .input-icon {
+    color: #999;
+  }
+  .checkbox {
+    margin-left: 5px;
+  }
+  .submit-btn {
+    margin-bottom: 25px;
+    width: 100%;
+    background: #3080fe;
+    border-radius: 28px;
+  }
+  .tips {
+  }
+  .link {
+    color: #999;
+    text-decoration: none;
+    font-size: 13px;
+  }
+  .line {
+    color: #dcd6d6;
+    margin: 0 8px;
+  }
+}
+
+@media screen and (max-width: 720px) {
+  .user-login {
+    .content-wrapper {
+      margin: 20px auto;
+      top: 40px;
+      max-width: 300px;
+      display: block;
+      .slogan {
+        color: #666;
+        font-size: 22px;
+        line-height: 30px;
+      }
+    }
+  }
+}
+</style>

+ 3 - 2
src/plugins/axiosApp.js

@@ -7,7 +7,7 @@ import { notifyInvalidTokenThrottled } from "./axiosNotice";
 import { getToken, removeToken } from "../auth/auth";
 import axiosRetry from "axios-retry";
 
-const PLATFORM = "Wap";
+const PLATFORM = "web";
 
 // Full config:  https://github.com/axios/axios#request-config
 // axios.defaults.baseURL = process.env.BASE_URL || process.env.apiUrl || '';
@@ -47,8 +47,9 @@ _axiosApp.interceptors.request.use(
       config.headers.common["Authorization"] = gToken(config.url, wk_token);
       config.headers.common["deviceId"] = Store.state.user.deviceId;
       config.headers.common["domain"] = Store.state.user.domain;
-      config.headers.common["platform"] = PLATFORM;
     }
+    config.headers.common["platform"] = PLATFORM;
+    config.headers.common["deviceId"] = Store.state.user.deviceId;
     return config;
   },
   function (error) {

+ 6 - 19
src/router/index.js

@@ -29,24 +29,6 @@ Vue.use(VueRouter);
 //   });
 //   return props;
 // }
-const sampleRoutes = [
-  {
-    path: "/samples/Login_01",
-    name: "Login_01",
-    component: () =>
-      import(
-        /* webpackChunkName: "about" */ "../samples/Login_01/Login_01.vue"
-      ),
-  },
-  {
-    path: "/samples/Layout_01",
-    name: "Layout_01",
-    component: () =>
-      import(
-        /* webpackChunkName: "about" */ "../samples/Layout_01/Layout_01.vue"
-      ),
-  },
-];
 
 const routes = [
   {
@@ -63,7 +45,12 @@ const routes = [
     component: () =>
       import(/* webpackChunkName: "about" */ "../views/About.vue"),
   },
-  ...sampleRoutes,
+  {
+    path: "/login",
+    name: "Login",
+    component: () =>
+      import(/* webpackChunkName: "about" */ "../features/Login/Login.vue"),
+  },
   // {
   //   path: "/xxx/:id",
   //   component: XXX,

+ 3 - 0
src/store/modules/user.js

@@ -3,6 +3,8 @@ import { loginByUsername, loginByPhone, sendSMS, logout } from "@/api/login";
 import { omit } from "lodash-es";
 import { LOGIN_BY_USERNAME, LOGIN_BY_PHONE, SEND_SMS } from "../action-types";
 
+const DEVICE_ID = Math.random() + "-" + Date.now();
+
 const user = {
   state: {
     accountType: "LOGIN_NAME",
@@ -12,6 +14,7 @@ const user = {
     partitionId: null,
     roleList: null,
     smsSendDate: null,
+    deviceId: DEVICE_ID,
   },
 
   mutations: {

+ 2 - 6
vue.config.js

@@ -1,10 +1,6 @@
 let proxy = {
-  "/ocean/api": {
-    target: "http://192.168.10.30:10060",
-    changeOrigin: true,
-  },
-  "/skynet/api": {
-    target: "http://192.168.10.39:8030",
+  "/api": {
+    target: "http://192.168.10.36:6001/backend",
     changeOrigin: true,
   },
 };

+ 5 - 0
yarn.lock

@@ -3796,6 +3796,11 @@ crypto-browserify@^3.11.0:
     randombytes "^2.0.0"
     randomfill "^1.0.3"
 
+crypto-js@^4.0.0:
+  version "4.0.0"
+  resolved "https://registry.npm.taobao.org/crypto-js/download/crypto-js-4.0.0.tgz?cache=0&sync_timestamp=1581509454262&other_urls=https%3A%2F%2Fregistry.npm.taobao.org%2Fcrypto-js%2Fdownload%2Fcrypto-js-4.0.0.tgz#2904ab2677a9d042856a2ea2ef80de92e4a36dcc"
+  integrity sha1-KQSrJnep0EKFai6i74DekuSjbcw=
+
 css-color-names@0.0.4, css-color-names@^0.0.4:
   version "0.0.4"
   resolved "https://registry.yarnpkg.com/css-color-names/-/css-color-names-0.0.4.tgz#808adc2e79cf84738069b646cb20ec27beb629e0"