Prechádzať zdrojové kódy

1、获取租户id
2、登录接口调通
3、post加入headers租户id

liyanbo 9 mesiacov pred
rodič
commit
5751e0acc6

+ 17 - 2
package-lock.json

@@ -8,14 +8,17 @@
       "name": "vite-project",
       "version": "0.0.0",
       "dependencies": {
+        "@element-plus/icons-vue": "^2.3.1",
         "@microsoft/fetch-event-source": "^2.0.1",
         "axios": "^1.10.0",
         "element-plus": "^2.10.2",
         "highlight.js": "^11.11.1",
+        "jsencrypt": "^3.3.2",
         "markdown-it": "^14.1.0",
         "router": "^2.2.0",
         "vue": "^3.5.17",
-        "vue-router": "^4.5.1"
+        "vue-router": "^4.5.1",
+        "web-storage-cache": "^1.1.1"
       },
       "devDependencies": {
         "@types/markdown-it": "^14.1.2",
@@ -83,7 +86,7 @@
     },
     "node_modules/@element-plus/icons-vue": {
       "version": "2.3.1",
-      "resolved": "https://registry.npmmirror.com/@element-plus/icons-vue/-/icons-vue-2.3.1.tgz",
+      "resolved": "https://registry.npmjs.org/@element-plus/icons-vue/-/icons-vue-2.3.1.tgz",
       "integrity": "sha512-XxVUZv48RZAd87ucGS48jPf6pKu0yV5UCg9f4FFwtrYxXOwWuVJo6wOvSLKEoMQKjv8GsX/mhP6UsC1lRwbUWg==",
       "license": "MIT",
       "peerDependencies": {
@@ -1971,6 +1974,12 @@
       "integrity": "sha512-hvpoI6korhJMnej285dSg6nu1+e6uxs7zG3BYAm5byqDsgJNWwxzM6z6iZiAgQR4TJ30JmBTOwqZUw3WlyH3AQ==",
       "license": "MIT"
     },
+    "node_modules/jsencrypt": {
+      "version": "3.3.2",
+      "resolved": "https://registry.npmjs.org/jsencrypt/-/jsencrypt-3.3.2.tgz",
+      "integrity": "sha512-arQR1R1ESGdAxY7ZheWr12wCaF2yF47v5qpB76TtV64H1pyGudk9Hvw8Y9tb/FiTIaaTRUyaSnm5T/Y53Ghm/A==",
+      "license": "MIT"
+    },
     "node_modules/linkify-it": {
       "version": "5.0.0",
       "resolved": "https://registry.npmjs.org/linkify-it/-/linkify-it-5.0.0.tgz",
@@ -2503,6 +2512,12 @@
       "peerDependencies": {
         "vue": "^3.2.0"
       }
+    },
+    "node_modules/web-storage-cache": {
+      "version": "1.1.1",
+      "resolved": "https://registry.npmjs.org/web-storage-cache/-/web-storage-cache-1.1.1.tgz",
+      "integrity": "sha512-D0MieGooOs8RpsrK+vnejXnvh4OOv/+lTFB35JRkJJQt+uOjPE08XpaE0QBLMTRu47B1KGT/Nq3Gbag3Orinzw==",
+      "license": "MIT"
     }
   }
 }

+ 4 - 1
package.json

@@ -9,14 +9,17 @@
     "preview": "vite preview"
   },
   "dependencies": {
+    "@element-plus/icons-vue": "^2.3.1",
     "@microsoft/fetch-event-source": "^2.0.1",
     "axios": "^1.10.0",
     "element-plus": "^2.10.2",
     "highlight.js": "^11.11.1",
+    "jsencrypt": "^3.3.2",
     "markdown-it": "^14.1.0",
     "router": "^2.2.0",
     "vue": "^3.5.17",
-    "vue-router": "^4.5.1"
+    "vue-router": "^4.5.1",
+    "web-storage-cache": "^1.1.1"
   },
   "devDependencies": {
     "@types/markdown-it": "^14.1.2",

+ 20 - 0
src/api/login/login.js

@@ -0,0 +1,20 @@
+import axios from "@/utils/request";
+
+// 登录
+export function login (headers,data){
+    return axios({
+        url: "bjdxWeb/web/login",
+        method: 'post',
+        data: data,
+        headers: headers,
+    })
+}
+
+
+// 使用租户名,获得租户编号
+export function getTenantIdByName (name){
+    return axios({
+        url: "bjdxWeb/web/getTenantIdByName?name=" + name,
+        method: 'get'
+    })
+}

+ 1 - 1
src/router/index.js

@@ -3,7 +3,7 @@ import App from '../App.vue'
 // import HomePage from '../components/HomePage.vue'
 
 const routes = [
-  { path: '/login', component: () => import('../views/AILogin.vue') },
+  { path: '/login', component: () => import('../views/Login.vue') },
   // 首页
   {
     path: '/home',

+ 5 - 1
src/utils/request.js

@@ -85,8 +85,12 @@ export default function ajax (config) {
         }
         return request.post(url, obj, { headers })
       }
+      console.log(headers['Tenant-Id'],"====")
+      const obj = new FormData()
+      obj.append('Tenant-Id', headers['Tenant-Id'])
+      return request.post(url, obj, { headers })
       // 3. json 数据
-      return request.post(url, data)
+      // return request.post(url, data)
     case 'PUT':
       // 通常用来修改数据用的 --- 数据更新
       return request.put(url, data)

+ 0 - 111
src/views/AILogin.vue

@@ -1,111 +0,0 @@
-<template>
-  <!-- 登录页面 -->
-  <div class="login-content">
-    <!-- 登录输入框 -->
-    <div class="login-input">
-      <div class="input-item">
-        <el-input v-model="tenant" :prefix-icon="HomeFilled" placeholder="租户" />
-        <el-input v-model="account" :prefix-icon="Avatar" placeholder="账号" />
-        <el-input
-          v-model="password"
-          type="password"
-          :prefix-icon="Lock"
-          placeholder="密码"
-          show-password
-        />
-        <!-- 多选框 -->
-        <div class="check-box">
-          <el-checkbox v-model="checked" label="记住我" size="large" />
-          <a href="javascript:;" class="forgot-password">忘记密码?</a>
-        </div>
-
-        <!-- 登录按钮 -->
-        <el-button type="primary">登录</el-button>
-
-      </div>
-    </div>
-  </div>
-</template>
-
-<script setup>
-import { ref, onMounted, computed } from 'vue'
-import { useRouter } from 'vue-router'
-import { HomeFilled, Avatar, Lock } from '@element-plus/icons-vue'
-
-// 租户
-const tenant = ref('')
-// 账号
-const account = ref('')
-// 密码
-const password = ref('')
-// 选框
-const checked = ref()
-</script>
-
-<style scoped lang="scss">
-@use 'sass:math';
-// 定义rpx转换函数
-@function rpx($px) {
-  @return math.div($px, 750) * 100vw;
-}
-.login-content {
-  position: fixed;
-  top: 0;
-  left: 0;
-  right: 0;
-  bottom: 0;
-  background: linear-gradient(to bottom, #001169, #8a78d0);
-  display: flex;
-  flex-direction: column;
-  gap: rpx(0);
-}
-.login-input {
-  width: rpx(210);
-  height: rpx(240);
-  margin:  auto;
-  display: flex;
-  border-radius: rpx(10);
-  background-color: rgb(255, 255, 255, 0.3);
-  border: 1px white solid;
-  box-shadow: 0 8px 8px rgb(0, 0, 0, 0.3);
-}
-.input-item {
-  margin: auto;
-  // margin-top: rpx(20);
-  // color: white;
-  // letter-spacing: rpx(5);
-}
-.input-item .el-input {
-  width: rpx(180);
-  height: rpx(18);
-  margin-bottom: rpx(15);
-}
-.input-item .el-button {
-  width: rpx(180);
-  height: rpx(18);
-  color: black;
-  font-size: rpx(8);
-  letter-spacing: rpx(10);
-  border-radius: rpx(3);
-  margin: auto;
-  border: none;
-  background: linear-gradient(to bottom, #fee78a, #ffce1b);
-  box-shadow: 0 8px 8px rgb(0, 0, 0, 0.2);
-}
-.check-box {
-  width: rpx(180);
-  height: rpx(18);
-  margin: auto;
-  display: flex;
-  justify-content: space-between;
-  align-items: center;
-}
-.check-box .el-checkbox{
-  color: white;
-}
-.check-box .forgot-password {
-  color: white;
-  font-size: rpx(6);
-  text-decoration: none;
-}
-</style>

+ 168 - 0
src/views/Login.vue

@@ -0,0 +1,168 @@
+<template>
+  <!-- 登录页面 -->
+  <div class="login-content">
+    <!-- 登录输入框 -->
+    <div class="login-input">
+      <div class="input-item">
+        <el-input v-model="loginData.loginForm.tenantName" :prefix-icon="HomeFilled" placeholder="租户" />
+        <el-input v-model="loginData.loginForm.username" :prefix-icon="Avatar" placeholder="账号" />
+        <el-input
+          v-model="loginData.loginForm.password"
+          type="password"
+          :prefix-icon="Lock"
+          placeholder="密码"
+          show-password
+        />
+        <!-- 多选框 -->
+        <div class="check-box">
+          <el-checkbox v-model="loginData.loginForm.rememberMe" label="记住我" size="large" />
+          <a href="javascript:;" class="forgot-password">忘记密码?</a>
+        </div>
+
+        <!-- 登录按钮 -->
+        <el-button type="primary"
+                   @click="handleLogin">登录</el-button>
+
+      </div>
+    </div>
+  </div>
+</template>
+
+<script setup>
+import { ref, onMounted, computed } from 'vue'
+import { useRouter } from 'vue-router'
+import { HomeFilled, Avatar, Lock } from '@element-plus/icons-vue'
+import { ElLoading } from 'element-plus'
+import {getTenantIdByName, login} from "@/api/login/login.js";
+const router = useRouter()
+
+const loginData = ref({
+  tenantEnable: true,
+  loginForm: {
+    tenantName: '博雅智算',
+    username: 'admin',
+    password: '',
+    captchaVerification: '',
+    rememberMe: true // 默认记录我。如果不需要,可手动修改
+  }
+})
+
+const loginLoading = ref(false)
+
+const loading = ref() // ElLoading.service 返回的实例
+
+const tenantId = ref('')
+
+// 获取租户 ID
+const getTenantId = async () => {
+  if (loginData.value.tenantEnable === true) {
+    const res = await getTenantIdByName(loginData.value.loginForm.tenantName)
+    //记录租户id
+    tenantId.value = res.data
+  }
+}
+// 登录
+const handleLogin = async (params) => {
+  loginLoading.value = true
+  try {
+
+    await getTenantId()
+
+    //【补充】缺少form表单校验(登录框要改成form表单,并加入必填项,用什么div啊???换掉)
+
+    const loginDataLoginForm = { ...loginData.value.loginForm }
+    loginDataLoginForm.captchaVerification = params.captchaVerification
+    // 构建包含 headers 的请求参数
+    const res = await login({
+      'Tenant-Id': tenantId.value
+    },loginDataLoginForm);
+    if (!res) {
+      return
+    }
+
+    //【补充】校验登录状态
+    //成功-失败-提示文字
+
+    loading.value = ElLoading.service({
+      lock: true,
+      text: '正在加载系统中...',
+      background: 'rgba(0, 0, 0, 0.7)'
+    })
+
+    //登录成功后,跳转到指定的页面
+    router.push('/home')
+
+  } finally {
+    loginLoading.value = false
+    loading.value.close()
+  }
+}
+</script>
+
+<style scoped lang="scss">
+@use 'sass:math';
+// 定义rpx转换函数
+@function rpx($px) {
+  @return math.div($px, 750) * 100vw;
+}
+.login-content {
+  position: fixed;
+  top: 0;
+  left: 0;
+  right: 0;
+  bottom: 0;
+  background: linear-gradient(to bottom, #001169, #8a78d0);
+  display: flex;
+  flex-direction: column;
+  gap: rpx(0);
+}
+.login-input {
+  width: rpx(210);
+  height: rpx(240);
+  margin:  auto;
+  display: flex;
+  border-radius: rpx(10);
+  background-color: rgb(255, 255, 255, 0.3);
+  border: 1px white solid;
+  box-shadow: 0 8px 8px rgb(0, 0, 0, 0.3);
+}
+.input-item {
+  margin: auto;
+  // margin-top: rpx(20);
+  // color: white;
+  // letter-spacing: rpx(5);
+}
+.input-item .el-input {
+  width: rpx(180);
+  height: rpx(18);
+  margin-bottom: rpx(15);
+}
+.input-item .el-button {
+  width: rpx(180);
+  height: rpx(18);
+  color: black;
+  font-size: rpx(8);
+  letter-spacing: rpx(10);
+  border-radius: rpx(3);
+  margin: auto;
+  border: none;
+  background: linear-gradient(to bottom, #fee78a, #ffce1b);
+  box-shadow: 0 8px 8px rgb(0, 0, 0, 0.2);
+}
+.check-box {
+  width: rpx(180);
+  height: rpx(18);
+  margin: auto;
+  display: flex;
+  justify-content: space-between;
+  align-items: center;
+}
+.check-box .el-checkbox{
+  color: white;
+}
+.check-box .forgot-password {
+  color: white;
+  font-size: rpx(6);
+  text-decoration: none;
+}
+</style>

+ 1 - 1
vite.config.js

@@ -15,7 +15,7 @@ export default defineConfig({
   server: {
     host: "0.0.0.0",
     proxy: {
-      '/api': {
+      '/admin-api': {
         target: 'https://192.168.110.8:8080',
         changeOrigin: true
       }