优化样式

This commit is contained in:
黄心宇 2024-05-08 09:59:48 +08:00
parent 62f699c61f
commit a2f7376285
8 changed files with 42 additions and 30 deletions

1
public/css/detail.css Normal file

File diff suppressed because one or more lines are too long

View File

@ -13,6 +13,7 @@ import { setDefaultMeta } from '../src/common/UrlTool'
import Logger from "./log";
import { changeHead } from './setHead'
// 目前只用项目详情页的,不需要动态添加
const css = new Set() // 这个必须在路由函数里面在外面的话就会累加出现之前的css
const insertCss = (...styles) => styles.forEach(style => css.add(style._getCss()));
@ -105,19 +106,22 @@ export const render = async (req,res)=>{
script.textContent = `window.__initState__ = ${ JSON.stringify(store.getState()) }`
const styleNode = domObj.window.document.createElement('style')
styleNode.type = 'text/css'
styleNode.innerHTML = `${ [...css].join('') }`
// styleNode.innerHTML = `${ [...css].join('') }`
styleNode.innerHTML = detailCss
domObj.window.document.head.appendChild(script);
domObj.window.document.head.appendChild(styleNode);
}
if (_route && !specialRoute.includes(_match.url && _match.url.replace('/', ''))) {
Logger.info(`matchRoot: ${ _match.url }`)
await changeHead(_route, _match.params)
// 匹配上的并且只修改head的页面
if (_route.onlyHead) {
Logger.info(`matchRoot: ${ _match.url }`)
await changeHead(_route, _match.params)
}
} else {
return false
}
let html = domObj.serialize()
const prepHTML=(data,rootString)=>{

View File

@ -1,11 +1,12 @@
const jsdom = require("jsdom");
import fs from 'fs'
import path from 'path';
import axios from "axios";
import { getSetting } from '../src/services/project'
const { JSDOM } = jsdom;
const html = fs.readFileSync(path.join(path.resolve('./build'),'index.html'),'utf-8');
// 压缩的项目详情页需要的css
const css = fs.readFileSync(path.join(path.resolve('./build/css'),'detail.css'),'utf-8');
const { window } = new JSDOM(html);
const $ = require( "jquery" )( window )
@ -13,20 +14,20 @@ const $ = require( "jquery" )( window )
global.window = window;
global.document = window.document;
global.navigator = window.navigator;
global.localStorage = {}
global.localStorage = {};
global.defaultSetting = {}
// 全局缓存css
global.detailCss = css
const setGlobalSetting = async () => {
const setting = await getSetting()
if (setting.data) {
global.defaultSetting = setting.data.setting
}
}
setGlobalSetting()
export const getDomObj = () => {
return new JSDOM(html)
}
// axios.get('https://gw.alipayobjects.com/os/lib/alipay/alex/2.0.19/bundle/alex.all.global.min.js')
// .then(response => {
// // 处理响应
// if (response) {
// // 这里你可以直接使用response.data而不是eval
// eval(response);
// }
// })
// .catch(error => {
// console.error('Error fetching data:', error);
// });

View File

@ -2,11 +2,11 @@ import React, { useEffect , useState } from 'react';
import './header.scss';
function Footer(){
const [ value , setValue ] = useState(undefined);
const [ value , setValue ] = useState(__CLIENT__ ? undefined : defaultSetting && defaultSetting.footer);
useEffect(()=>{
try {
var chromesettingArray = JSON.parse(localStorage.getItem('chromesetting'));
let chromesettingArray = JSON.parse(localStorage.getItem('chromesetting'));
setValue(chromesettingArray.footer);
} catch (e) {
}

View File

@ -15,9 +15,9 @@ import types from '../../redux/actions/actionTypes'
import { getProjectFunc, getProjectDetailFunc } from '../../services/project'
import '../css/index.scss'
import './list.scss';
import styles from './list.scss'
import styles1 from '../css/index.scss'
import withStyles from 'isomorphic-style-loader/withStyles';
// import styles from './list.scss'
// import styles1 from '../css/index.scss'
// import withStyles from 'isomorphic-style-loader/withStyles';
import Loadable from 'react-loadable';
@ -983,7 +983,7 @@ Detail.preFetch = ({ store, match, query }) => {
});
};
export default withRouter(withStyles(styles, styles1)(connect(
export default withRouter(connect(
mapStateToProps,
mapDispatchToProps
)(Detail)));
)(Detail));

View File

@ -7,7 +7,7 @@ import datasetImg from '../img/dataset.jpg';
import axios from 'axios';
function DetailBanner({ history,list , owner , projectsId ,showNotification , url , pathname , state , urlFlag , projectDetail , platform ,open_devops ,current_user, showNpsModal }){
const [ menuName , setMenuName ] = useState(undefined);
const [ menuName , setMenuName ] = useState(list);
const [ visible , setVisible ] = useState(false);
useEffect(()=>{

View File

@ -61,12 +61,13 @@ export function TPMIndexHOC(WrappedComponent) {
window.removeEventListener('keyup', this.keyupListener)
}
componentWillMount() {
this.setState({
current_user: {}
})
if (!__SERVER__) {
this.fetchUsers();
} else {
this.setState({
current_user: {}
})
}
}

View File

@ -80,3 +80,8 @@ export async function getNewsDetail (id) {
}
return axiosInstance.get(url);
}
export async function getSetting () {
const url = `${baseUrl}/setting.json`;
return axiosInstance.get(url);
}