Skip to content

Commit

Permalink
feat: 企业版动态配置图片埋点
Browse files Browse the repository at this point in the history
  • Loading branch information
youngster-yj committed Sep 23, 2024
1 parent 8e28165 commit 0655a84
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 23 deletions.
31 changes: 31 additions & 0 deletions app/main/handlers/staticEE.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const {ipcMain} = require("electron")
const fs = require("fs")
const customPath = require("path")
module.exports = {
register: (win, getClient) => {
const sorcePath = {
loginImg: "../../../bins/staticEE/yakit.jpg",
miniProject:"../../../bins/staticEE/yakitFontEE.jpg",
project:"../../../bins/staticEE/yakitEE.jpg",
}

const asyncGetStaticImgEEByType = (data) => {
return new Promise((resolve, reject) => {
try {
const {type} = data
const path = customPath.join(__dirname, sorcePath[type])
const img = fs.readFileSync(path)
const base64 = `data:image/jpeg;base64,${img.toString('base64')}`
resolve(base64)
} catch (error) {
reject(error)
}
})
}

// 通过类型 读取静态资源
ipcMain.handle("GetStaticImgEEByType", async (e, data) => {
return await asyncGetStaticImgEEByType(data)
})
}
}
3 changes: 3 additions & 0 deletions app/main/ipc.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,9 @@ module.exports = {
// reverse logger
require("./handlers/reverse-connlogger").register(win, getClient)

// 读取企业版静态资源
require("./handlers/staticEE").register(win, getClient)

// 接口注册
const api = fs.readdirSync(path.join(__dirname, "./api"))
api.forEach((item) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {loginOut, aboutLoginUpload, loginHTTPFlowsToOnline} from "@/utils/login"
import {useDebounceFn, useMemoizedFn, useGetState} from "ahooks"
import {getRemoteValue, setRemoteValue} from "@/utils/kv"
import {useStore} from "@/store"
import yakitImg from "@/assets/yakit.jpg"
import {API} from "@/services/swagger/resposeType"
import {YakitButton} from "../yakitUI/YakitButton/YakitButton"
import {YakitAutoComplete, defYakitAutoCompleteRef} from "../yakitUI/YakitAutoComplete/YakitAutoComplete"
Expand Down Expand Up @@ -93,7 +92,7 @@ export const ConfigPrivateDomain: React.FC<ConfigPrivateDomainProps> = React.mem
companyHeadImg: res.from_platform === "company" ? res.head_img : null,
role: res.role,
user_id: res.user_id,
token: res.token,
token: res.token
}
setStoreUserInfo(user)
if (data?.next) {
Expand Down Expand Up @@ -230,12 +229,21 @@ export const ConfigPrivateDomain: React.FC<ConfigPrivateDomainProps> = React.mem
}
}
]

const [yakitEEImg, setyYakitEEImg] = useState<string>()
useEffect(() => {
if (enterpriseLogin) {
ipcRenderer.invoke("GetStaticImgEEByType", {type: "loginImg"}).then((res) => {
setyYakitEEImg(res)
})
}
}, [])
return (
<div className='private-domain'>
{enterpriseLogin && (
<div className='login-title-show'>
<div className='icon-box'>
<img src={yakitImg} className='type-icon-img' />
<img src={yakitEEImg} className='type-icon-img' />
</div>
<div className='title-box'>企业登录</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {memo, ReactNode, Suspense, useEffect, useState} from "react"
import React, {memo, ReactNode, Suspense, useEffect, useMemo, useState} from "react"
import {YakitButton} from "@/components/yakitUI/YakitButton/YakitButton"
import {DesktopComputerSvgIcon, YakitLogoSvgIcon} from "@/assets/newIcon"
import {Typography} from "antd"
Expand All @@ -9,11 +9,11 @@ import {ProjectManageProp} from "./ProjectManage"

import classNames from "classnames"
import styles from "./SoftwareSettings.module.scss"
import { isEnpriTrace, isEnpriTraceAgent } from "@/utils/envfile"
import yakitEEProject from "@/assets/yakitFontEE.png";
import yakitSEProject from "@/assets/yakitFontSE.png";
import yakitEEMiniProject from "@/assets/yakitEE.png";
import yakitSEMiniProject from "@/assets/yakitSE.png";
import {isEnpriTrace, isEnpriTraceAgent} from "@/utils/envfile"
// import yakitEEProject from "@/assets/yakitFontEE.png"
import yakitSEProject from "@/assets/yakitFontSE.png"
// import yakitEEMiniProject from "@/assets/yakitEE.png";
import yakitSEMiniProject from "@/assets/yakitSE.png"

const ProjectManage = React.lazy(() => import("./ProjectManage"))

Expand All @@ -26,17 +26,7 @@ interface SettingsMenuProp {
name: string
icon: ReactNode
}
const ProjectLogo = (showMini:boolean) => {
if(isEnpriTrace()){
return <img style={{height:"100%"}} src={showMini?yakitEEMiniProject:yakitEEProject} alt="暂无图片" />
}
else if(isEnpriTraceAgent()){
return <img style={{height:"100%"}} src={showMini?yakitSEMiniProject:yakitSEProject} alt="暂无图片" />
}
else{
return <YakitLogoSvgIcon />
}
}

const SettingsMenu: SettingsMenuProp[] = [
{
key: "project",
Expand Down Expand Up @@ -100,6 +90,39 @@ export const SoftwareSettings: React.FC<SoftwareSettingsProp> = memo((props) =>
}
}, [])

const [yakitEEMiniProject, setYakitEEMiniProject] = useState<string>()
const [yakitEEProject, setYakitEEProject] = useState<string>()

useEffect(() => {
if (isEnpriTrace()) {
ipcRenderer.invoke("GetStaticImgEEByType", {type: "miniProject"}).then((res) => {
setYakitEEMiniProject(res)
})
ipcRenderer.invoke("GetStaticImgEEByType", {type: "project"}).then((res) => {
setYakitEEProject(res)
})
}
}, [])

const ProjectLogo = useMemoizedFn((showMini: boolean) => {
if (isEnpriTrace()) {
return (
<img
style={
showMini
? {height: 35, width: 35, objectFit: "scale-down"}
: {height: "100%", width: "100%", objectFit: "cover"}
}
src={showMini ? yakitEEMiniProject : yakitEEProject}
alt='暂无图片'
/>
)
} else if (isEnpriTraceAgent()) {
return <img style={{height: "100%"}} src={showMini ? yakitSEMiniProject : yakitSEProject} alt='暂无图片' />
} else {
return <YakitLogoSvgIcon />
}
})
return (
<div className={styles["software-settings-wrapper"]}>
<div className={styles["software-settings-container"]}>
Expand All @@ -109,9 +132,7 @@ export const SoftwareSettings: React.FC<SoftwareSettingsProp> = memo((props) =>
[styles["left-mini-body"]]: showMini
})}
>
<div className={styles["navbar-logo"]}>
{ProjectLogo(showMini)}
</div>
<div className={styles["navbar-logo"]}>{ProjectLogo(showMini)}</div>

<div className={styles["navbar-list-wrapper"]}>
<div className={styles["list-body"]}>
Expand Down
Binary file added bins/staticEE/yakit.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bins/staticEE/yakitEE.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added bins/staticEE/yakitFontEE.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0655a84

Please sign in to comment.