根据公司项目使用的配置对应着官网做一个总结,下面复制部分公司项目用作学习及参考
app: {
rootId: 'ice-container',
addProvider: ({
children
}) => ( <LocaleProvider locale = {locale} > {children} < /LocaleProvider>),
getInitialData: async () => {
try {
const data = await authService.getUserPermission()
return {
auth: data
}
} catch (e) {
return {auth: {}}
}
},
},
"publicPath": "./",
"plugins": [
[
"build-plugin-fusion",
{
"themePackage": [{
"name": "@alifd/theme-1"
},
{
"name": "@alifd/theme-2",
"default": true
}
]
}
],
[
"build-plugin-moment-locales",
{
"locales": [
"zh-cn"
]
}
],
"build-plugin-fusion-material",
"build-plugin-ice-auth"
]
import React from 'react';
import BasicLayout from '@/layouts/BasicLayout';
import UserLayout from '@/layouts/UserLayout';
import { lazy } from 'ice'
const FeedbackServerError = React.lazy(() => import('@/pages/Feedback/FeedbackServerError'));
const FeedbackNotFound = React.lazy(() => import('@/pages/Feedback/FeedbackServerError')) ;
const FeedbackForbidden = React.lazy(() => import('@/pages/Feedback/FeedbackForbidden'));
const SystemView = React.lazy(() => import('@/pages/IndexPage/SystemIndex'));
const routerConfig = [
{
path: '/user',
component: UserLayout,
children: [
{
path: '/login',
component: Login,
},
{
path: '/',
redirect: '/user/login',
},
],
},
{
path: '/',
component: BasicLayout,
children: [
{
path: '/index/dashborad',
component: SystemView,
},
{
path: '/index/tenantview',
component: TenantView,
},
],
},
];
export default routerConfig;
官网demo,通常使用 Link
组件或者 history
API 进行路由的跳转:
import { Link, useHistory } from 'ice';
function Home() {
const history = useHistory();
return (
<>
<Link to="/about">去 about 页面</Link>
<span
onClick={() => {
history.push('/about');
}}
>
去 about 页面
</span>
</>
);
}
项目demo
import { Route, Link, Switch, HashRouter, Redirect } from 'react-router-dom';
<HashRouter>
<Nav className="basic-nav" direction="hoz" type="normal" onSelect={changeNav} triggerType="hover" style={{ marginBottom: '15px' }} selectedKeys={projectType}>
{getNavMenuItems(data)}
</Nav>
<Switch>
<Route exact path="/system/applacation/table/:projecttype" component={ApplacationTable} />
<Route exact path="/system/applacation/menu/:projectid" component={AllocationMenu} />
<Redirect from="/system/applacation" to="/system/applacation/table/SYSTEM_PROJECT" exact />
</Switch>
</HashRouter>
项目有用。global.scss配置全局样式(不用自己引入,框架默认引入),局部用CSS module(和react原生一样)项目demo部分:
// 引入默认全局样式
@import '@alifd/next/reset.scss';
body {
-webkit-font-smoothing: antialiased;
}
.next-breadcrumb {
margin-top: 15px;
margin-left: 34px;
}
.jifrog-filter-table {
table {
table-layout: fixed;
width: 100%;
}
table tr td {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
-moz-text-overflow: ellipsis;
-webkit-text-overflow: ellipsis;
}
}
可以看看前面css专栏css初始化
文章
公司项目配置了个globalServices.tsx文件,一部分请求如下:
app.tsx里还需要配置request(如配置token等
,身份失效等),具体去官网查看官网详细配置
import { request } from 'ice';
export default {
async getUserTree() {
return await request({
url: 'url',
method: 'GET',
})
},
async queryRoleMenuById(roleId: any) {
return await request(`url${roleId}`)
}
}
项目用到了权限配置
import React from 'react'
import AreaTable from './components'
const Area = () => {
return (
<AreaTable />
)
}
Area.pageConfig = {
auth: ['p.platform.system.area']
}
export default Area
应该是配合app.tsx的appConfig中的auth配置相对应,做权限管理
Pro
模板布局,需要配置src/layouts/BasicLayout/menuConfig.ts
中。headerMenuConfig和asideMenuConfig项目中有用到
"scripts": {
"start": "icejs start",
"build:test": "icejs build",
"build:dev": "icejs build --mode dev",
"build:prod": "icejs build --mode prod",
"lint": "npm run eslint && npm run stylelint",
"eslint": "eslint --cache --ext .js,.jsx ./",
"stylelint": "stylelint ./**/*.scss"
},
然后和app.tsx同级目录下config.ts配置,项目中注释掉了这一块,有待研究
后期跟进查看配置