|
|
@ -1,11 +1,12 @@
|
|
|
|
import { isUrl } from "@/microhost/util"
|
|
|
|
import { isUrl } from "@/microhost/util"
|
|
|
|
import { CastMode, CacheUserData } from "../params"
|
|
|
|
import { CastMode, CacheUserData } from "../params"
|
|
|
|
import {defaultSetting as cfg} from "@/config/default"
|
|
|
|
import { defaultSetting as cfg } from "@/config/default"
|
|
|
|
import util from "@/microhost/common"
|
|
|
|
import util from "@/microhost/common"
|
|
|
|
import { SystemData } from "@/microhost/models/system"
|
|
|
|
import { SystemData } from "@/microhost/models/system"
|
|
|
|
import MicroApps from "../apps"
|
|
|
|
import MicroApps from "../apps"
|
|
|
|
import { Log } from "./logger"
|
|
|
|
import { Log } from "./logger"
|
|
|
|
import {history} from "umi"
|
|
|
|
import { history } from "umi"
|
|
|
|
|
|
|
|
import requestaxios from 'axios';
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* 运行时用户
|
|
|
|
* 运行时用户
|
|
|
@ -22,7 +23,7 @@ export default class RuntimeUser {
|
|
|
|
return this.timeoutHours
|
|
|
|
return this.timeoutHours
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set timeout(hours: number){
|
|
|
|
set timeout(hours: number) {
|
|
|
|
this.timeoutHours = hours < 1 ? 1 : hours
|
|
|
|
this.timeoutHours = hours < 1 ? 1 : hours
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -31,19 +32,19 @@ export default class RuntimeUser {
|
|
|
|
return this.userData
|
|
|
|
return this.userData
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
set data(d: CacheUserData | undefined){
|
|
|
|
set data(d: CacheUserData | undefined) {
|
|
|
|
if(d){
|
|
|
|
if (d) {
|
|
|
|
d.touchTime = new Date().getTime()
|
|
|
|
d.touchTime = new Date().getTime()
|
|
|
|
util.saveCache(cfg.userInfo, d)
|
|
|
|
util.saveCache(cfg.userInfo, d)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else {
|
|
|
|
util.removeCache(cfg.userInfo)
|
|
|
|
util.removeCache(cfg.userInfo)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
this.userData = d
|
|
|
|
this.userData = d
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
get loginId(){
|
|
|
|
get loginId() {
|
|
|
|
return this.data ? this.data.loginId : undefined
|
|
|
|
return this.data ? this.data.loginId : undefined
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -53,23 +54,23 @@ export default class RuntimeUser {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public isTimeout = () => {
|
|
|
|
public isTimeout = () => {
|
|
|
|
if(!this.data) return true
|
|
|
|
if (!this.data) return true
|
|
|
|
let touchTime = this.data.touchTime
|
|
|
|
let touchTime = this.data.touchTime
|
|
|
|
if(!touchTime) return true
|
|
|
|
if (!touchTime) return true
|
|
|
|
if(new Date().getTime() - touchTime >= this.timeout * 3600 * 1000) return true
|
|
|
|
if (new Date().getTime() - touchTime >= this.timeout * 3600 * 1000) return true
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public checkAllowed = async (redirect?: string) => {
|
|
|
|
public checkAllowed = async (redirect?: string) => {
|
|
|
|
if(!this.isAllowed() || !this.isLogin()){
|
|
|
|
if (!this.isAllowed() || !this.isLogin()) {
|
|
|
|
let quick = await this.quickLogin()
|
|
|
|
let quick = await this.quickLogin()
|
|
|
|
if(!quick){
|
|
|
|
if (!quick) {
|
|
|
|
this.logout(false)
|
|
|
|
this.logout(false)
|
|
|
|
let url = `${cfg.url.login}${redirect && isUrl(redirect) && !redirect?.includes(cfg.url.login) ? ("?redirect=" + encodeURIComponent(redirect)) : ""}`
|
|
|
|
let url = `${cfg.url.login}${redirect && isUrl(redirect) && !redirect?.includes(cfg.url.login) ? ("?redirect=" + encodeURIComponent(redirect)) : ""}`
|
|
|
|
location.href = url
|
|
|
|
location.href = url
|
|
|
|
return false
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else {
|
|
|
|
location.reload()
|
|
|
|
location.reload()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -82,7 +83,7 @@ export default class RuntimeUser {
|
|
|
|
let password: any = pass || history.location.query?.password
|
|
|
|
let password: any = pass || history.location.query?.password
|
|
|
|
// console.log("querys", history.location.query, loginId, password)
|
|
|
|
// console.log("querys", history.location.query, loginId, password)
|
|
|
|
// debugger
|
|
|
|
// debugger
|
|
|
|
if(loginId){
|
|
|
|
if (loginId) {
|
|
|
|
password = password || cfg.quickLogin.defpass
|
|
|
|
password = password || cfg.quickLogin.defpass
|
|
|
|
let result = await this.doLogin(loginId, password)
|
|
|
|
let result = await this.doLogin(loginId, password)
|
|
|
|
return result === true
|
|
|
|
return result === true
|
|
|
@ -97,17 +98,17 @@ export default class RuntimeUser {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public setAllowed = (allowed: boolean) => {
|
|
|
|
public setAllowed = (allowed: boolean) => {
|
|
|
|
if(allowed){
|
|
|
|
if (allowed) {
|
|
|
|
util.saveCookie(cfg.allowKey, 1, 0)
|
|
|
|
util.saveCookie(cfg.allowKey, 1, 0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
else {
|
|
|
|
util.removeCookie(cfg.allowKey)
|
|
|
|
util.removeCookie(cfg.allowKey)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public isLogin = () => {
|
|
|
|
public isLogin = () => {
|
|
|
|
this.reload()
|
|
|
|
this.reload()
|
|
|
|
if(!this.userData) return false
|
|
|
|
if (!this.userData) return false
|
|
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -131,21 +132,21 @@ export default class RuntimeUser {
|
|
|
|
util.removeCache(this.cacheName)
|
|
|
|
util.removeCache(this.cacheName)
|
|
|
|
this.setAllowed(false)
|
|
|
|
this.setAllowed(false)
|
|
|
|
|
|
|
|
|
|
|
|
if(jump){
|
|
|
|
if (jump) {
|
|
|
|
location.href = cfg.url.login
|
|
|
|
location.href = cfg.url.login
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public doLogin = async (loginId: string, password: any) : Promise<string | true> => {
|
|
|
|
public doLogin = async (loginId: string, password: any): Promise<string | true> => {
|
|
|
|
//debugger
|
|
|
|
//debugger
|
|
|
|
let result: any = await this.model.login(loginId, password)
|
|
|
|
let result: any = await this.model.login(loginId, password)
|
|
|
|
|
|
|
|
|
|
|
|
if(!result){
|
|
|
|
if (!result) {
|
|
|
|
await MicroApps.GetRuntimeLogger().failed(Log.Login)
|
|
|
|
await MicroApps.GetRuntimeLogger().failed(Log.Login)
|
|
|
|
return "登录出现错误"
|
|
|
|
return "登录出现错误"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!result.success || result.success == 500){
|
|
|
|
if (!result.success || result.success == 500) {
|
|
|
|
await MicroApps.GetRuntimeLogger().failed(Log.Login)
|
|
|
|
await MicroApps.GetRuntimeLogger().failed(Log.Login)
|
|
|
|
return result.error ? result.error : (result.msg ? result.msg : "登陆失败!")
|
|
|
|
return result.error ? result.error : (result.msg ? result.msg : "登陆失败!")
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -158,7 +159,11 @@ export default class RuntimeUser {
|
|
|
|
, userData?.Name
|
|
|
|
, userData?.Name
|
|
|
|
, userData?.OrganName)
|
|
|
|
, userData?.OrganName)
|
|
|
|
await MicroApps.GetRuntimeLogger().success(Log.Login, loginId)
|
|
|
|
await MicroApps.GetRuntimeLogger().success(Log.Login, loginId)
|
|
|
|
|
|
|
|
let obj = {
|
|
|
|
|
|
|
|
OperateUser: loginId || "未登录",
|
|
|
|
|
|
|
|
Operate: `${loginId}登陆了工艺数据管理子系统`
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await requestaxios.post('/Personnel/Personnelapi/LogRecording', obj)
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|