Skip to content

Commit

Permalink
Merge branch 'master' of github.com:WeBankFinTech/TractionWidget into…
Browse files Browse the repository at this point in the history
… branch_joy
  • Loading branch information
nancyzhan committed Mar 18, 2024
2 parents 6bd76a6 + 8382ba6 commit 95de6ae
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 16 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fesjs/traction-widget",
"version": "1.8.7",
"version": "1.8.9",
"description": "集合大型中台项目使用到的通用组件和工具函数",
"scripts": {
"docs:dev": "npm run build && vitepress dev docs",
Expand All @@ -11,10 +11,11 @@
"build:esm": "node scripts/build-esm.js",
"build:umd": "node scripts/build-umd.js",
"build:type": "node scripts/build-types.js",
"build.unix": "rm -rf packages/traction-widget/dist packages/traction-widget/es && npm run build:esm && npm run build:type && npm run build:umd",
"build:style": "node scripts/build-style.js",
"build.unix": "rm -rf packages/traction-widget/dist packages/traction-widget/es && npm run build:esm && npm run build:type && npm run build:style && npm run build:umd",
"release": "npm run build && node scripts/release.js",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s",
"build.win": "npm run build:esm && npm run build:type && npm run build:umd",
"build.win": "npm run build:esm && npm run build:type && npm run build:style && npm run build:umd",
"build": "node scripts/build.js"
},
"files": [
Expand Down Expand Up @@ -74,6 +75,7 @@
"lodash-es": "4.17.21",
"prettier": "2.8.4",
"rollup": "3.17.2",
"rollup-plugin-copy": "^3.5.0",
"rollup-plugin-postcss": "4.0.2",
"rollup-plugin-vue": "6.0.0",
"shiki": "0.12.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,20 +91,35 @@ interface MenuItem {
children?: MenuItem[];
}
function findParentPath (tree: MenuItem[], target: string): string[] | null {
for (const node of tree) {
if (node.value === target) {
return [node.value];
function findParentPath (menus: MenuItem[], targetPath: string): string[] {
for (const menu of menus) {
if (menu.value === targetPath) {
return [menu.value]; // 找到目标路径,返回包含目标路径的数组
}
if (node.children && node.children.length > 0) {
const childPath = findParentPath(node.children, target);
if (childPath !== null) {
return [node.value, ...childPath];
if (menu.children) {
const parentPath = findParentPath(menu.children, targetPath);
if (parentPath.length > 0) {
return [menu.value, ...parentPath]; // 找到目标路径的父路径,返回包含父路径和目标路径的数组
}
}
}
return null;
// 没有找到匹配的路径,尝试匹配父路径
for (const menu of menus) {
if (targetPath.startsWith(menu.value)) {
const parentPath = findParentPath(menu.children || [], targetPath);
if (parentPath.length > 0) {
return [menu.value, ...parentPath]; // 找到目标路径的父路径,返回包含父路径和目标路径的数组
} else {
if (menu.value !== targetPath) {
return [menu.value]; // 没有找到目标路径的父路径,返回当前路径
}
}
}
}
return []; // 没有找到匹配的路径,返回空数组
}
watchEffect(() => {
if (curPath.value) {
Expand Down
10 changes: 10 additions & 0 deletions packages/traction-widget/components/_style.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import './HorizontalLayout/style';
import './NavBar/style';
import './NavHeader/style';
import './PageLoading/style';
import './Search/style';
import './TableHeaderConfig/style';
import './TablePage/style';
import './TagSelector/style';
import './VerticalLayout/style';
import './TagsPanel/style';
2 changes: 1 addition & 1 deletion packages/traction-widget/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fesjs/traction-widget",
"version": "1.8.7",
"version": "1.8.9",
"description": "集合大型中台项目使用到的通用组件和工具函数",
"main": "dist/traction-widget.min.js",
"module": "es/components/index.js",
Expand Down
12 changes: 9 additions & 3 deletions scripts/build-shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ const { nodeResolve } = require('@rollup/plugin-node-resolve');
const vuePlugin = require('rollup-plugin-vue');
const commonjs = require('@rollup/plugin-commonjs');
const babel = require('@rollup/plugin-babel');

const copy = require('rollup-plugin-copy');
const postcss = require('rollup-plugin-postcss');

const SOURCE_PATH = path.join(__dirname, '../packages/traction-widget/components/index.ts');
const OUTPUT_DIR = path.join(__dirname, '../packages/traction-widget/dist');

const ASSEETS_DIR = path.join(__dirname, '../packages/traction-widget/components/assets');
const extensions = ['.js', '.jsx', '.ts', '.tsx', '.vue', '.json'];

const getRollupConfig = (config = {}) => ({
Expand Down Expand Up @@ -62,7 +62,13 @@ const getRollupConfig = (config = {}) => ({
]
}),
postcss({
extract: true
extract: false
}),
// asserts目录拷贝到产物
copy({
targets: [
{ src: ASSEETS_DIR, dest: OUTPUT_DIR }
]
})
],
...config
Expand Down
37 changes: 37 additions & 0 deletions scripts/build-style.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const path = require('path');
const fse = require('fs-extra');
const csso = require('csso');
const { compilerCss } = require('./compilerCss.js');
const { OUTPUT_DIR } = require('./build-shard');

function getProjectRootDir () {
return process.cwd();
}
const rootDir = getProjectRootDir();
const STYLE_SOURCE = path.join(rootDir, './packages/traction-widget/components/_style.ts');

fse.mkdirsSync(OUTPUT_DIR);

async function main () {
const tempFilePath = path.join(OUTPUT_DIR, 'temp.css');
await compilerCss(STYLE_SOURCE, tempFilePath);

let cssContent = fse.readFileSync(tempFilePath, 'utf-8');

// 替换路径
cssContent = cssContent.replace(/(\.\.\/\.\.\/assets\/)/g, './assets/');

fse.outputFileSync(tempFilePath, cssContent);

const outputFilePath = path.join(OUTPUT_DIR, 'traction-widget.css');
fse.moveSync(tempFilePath, outputFilePath, { overwrite: true });

const compressResult = csso.minify(cssContent);

fse.outputFileSync(
path.join(OUTPUT_DIR, 'traction-widget.min.css'),
compressResult.css
);
}

main();

0 comments on commit 95de6ae

Please sign in to comment.