完成url获取用户账号功能

This commit is contained in:
2023-03-01 17:31:20 +08:00
parent 83b256a832
commit 2a226831dc
10 changed files with 4787 additions and 4701 deletions

View File

@@ -0,0 +1,4 @@
$color-bg-01: #ba1800;
$color-bg-02: #f27620;
$color-bg-03: #fecb96;

View File

@@ -1,4 +0,0 @@
$bg-color-01: #ba1800;
$bg-color-02: #f27620;
$bg-color-03: #fecb96;

View File

@@ -11,9 +11,10 @@ body {
/* background-color: #8796a6; */
width: 100vw;
height: 100vh;
/* border: 1px solid red; */
border: 1px solid green;
/* overflow: hidden; */
padding: 0px;
margin: 0px;
overflow: hidden;
}

View File

@@ -2,8 +2,8 @@
* @Author: Kane
* @Date: 2023-02-28 19:30:40
* @LastEditors: Kane
* @FilePath: /task_schedule/src/utils/api/account.ts
* @Description:
* @FilePath: /deskop_task_schedule/code/web/task_schedule/src/utils/api/url.ts
* @Description: 对URL的操作
*
* Copyright (c) ${2022} by Kane, All Rights Reserved.
*/
@@ -11,17 +11,17 @@
/**
* 将url的参数拆分成对象
* @param url 访问的url
* @returns
* @returns
*/
function getURL(url: string)
function getURLParams(url: string)
{
const arr = url.split('?');
const params = arr[1].split('&');
const arr = url.split("?");
const params = arr[1].split("&");
const obj = {};
for (let i = 0; i < params.length; i++)
{
const param = params[i].split('=');
const param = params[i].split("=");
obj[param[0]] = param[1];
}
@@ -29,4 +29,54 @@ function getURL(url: string)
return obj;
}
export { getURL };
/**
* 对URL中的参数进行拆分拆分的参数名称和值作为一个对象属性的键值对。
* @param url url字符串
* @returns 返回包含url中参数作为key值作为value的对象。
*/
function getParamsFromURL(url: string): any
{
const indexOfQuestionMark: number = url.indexOf("?");
const indexOfSharp: number = url.indexOf("#");
const paramObj = {};
let paramString;
//url中没有问号说明没有参数
if (indexOfQuestionMark < 0)
{
return paramObj;
}
//检查是否有#号
if (indexOfSharp < 0)
{
//没有#号,可以直接截取参数字符串
paramString = url.substring(indexOfQuestionMark);
}
else
{
//有#号,截取?和#之间的字符串
const end: number = indexOfQuestionMark < indexOfSharp ? indexOfSharp : url.length;
paramString = url.substring(indexOfQuestionMark + 1, end);
}
//拆分属性
const paramArray: string[] = paramString.split("&");
paramArray.forEach((item) =>
{
if (item.length == 0)
{
return;
}
const param = item.split("=");
paramObj[param[0]] = param[1] || "";
});
return paramObj;
}
export { getURLParams, getParamsFromURL };

View File

@@ -2,7 +2,7 @@
* @Author: Kane
* @Date: 2023-02-28 00:57:21
* @LastEditors: Kane
* @FilePath: /deskop_task_schedule/code/web/task_schedule/src/components/login/Login.vue
* @FilePath: /deskop_task_schedule/code/web/task_schedule/src/views/Login.vue
* @Description:
* 登录页面路由默认指向这个页面
* 1判断url中的参数取得用户信息根据用户的部门改变路由
@@ -10,15 +10,16 @@
* Copyright (c) ${2022} by Kane, All Rights Reserved.
-->
<template>
<span>{{ ui.p13uid }}</span>
<br>
<span>存储的P13:{{ ui.savedP13uid }}
</span>
<div class="page-wrap">
<span v-show="ui.showNeedAccountTip">请在链接中提供用户的P13账号或P09工号</span>
</div>
</template>
<script lang="ts">
import { reactive } from "vue";
import { service as instance } from "@/utils/api/request";
import { getParamsFromURL } from "@/utils/api/url";
const URL = "http://222.76.244.118:11001/admin-system/account/p13_account_check";
@@ -29,40 +30,39 @@ export default {
const ui = reactive({
p13uid: "",
savedP13uid: "",
showNeedAccountTip: false,
});
//根据url获取用户账号
const urlParams = getParamsFromURL(window.location.href);
console.log(window.location.href);
console.log(urlParams);
const userInfo = {
p13account: "wangwei-202",
password: "Kane@1983",
};
instance.request(
{
method: "post",
url: URL,
data: userInfo,
}
)
.then((response) =>
{
// debugger;
const data = response.data;
if (data.success === true)
{
ui.savedP13uid = data.staff_info;
}
})
.catch((error) =>
{
ui.savedP13uid = error;
});
if (urlParams.account == undefined)
{
ui.showNeedAccountTip = true;
}
return { ui, };
},
};
</script>
<style scoped lang="scss"></style>
<style scoped>
.page-wrap {
box-sizing: border-box;
height: calc(100vh - 100px);
width: calc(100vw - 100px);
margin: 50px;
border: 1px solid red;
display: flex;
justify-content: center;
align-items: center;
}
span {
font-size: 30px;
color: red;
}
</style>