Skip to content

Commit

Permalink
feat(版本区分): 区分各版本菜单
Browse files Browse the repository at this point in the history
根据不同系统版本显示不同的菜单

fix jetlink/jetlinks-pro#71
  • Loading branch information
Lind-pro committed Jun 24, 2020
1 parent ec1cbea commit 18814ac
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 16 deletions.
18 changes: 13 additions & 5 deletions config/config.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import {IConfig, IPlugin} from 'umi-types';
import { IConfig, IPlugin } from 'umi-types';
import defaultSettings from './defaultSettings'; // https://umijs.org/config/
import slash from 'slash2';
import themePluginConfig from './themePluginConfig';
import proxy from './proxy';
import webpackPlugin from './plugin.config';

const {pwa} = defaultSettings;
const { pwa } = defaultSettings;

// preview.pro.ant.design only do not use in your production ;
// preview.pro.ant.design 专用环境变量,请不要在你的项目中使用它。
const {ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, REACT_APP_ENV} = process.env;
const { ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION, REACT_APP_ENV } = process.env;
const isAntDesignProPreview = ANT_DESIGN_PRO_ONLY_DO_NOT_USE_IN_YOUR_PRODUCTION === 'site';

const plugins: IPlugin[] = [
Expand Down Expand Up @@ -133,6 +133,7 @@ export default {
path: '/system/open-api',
name: 'OpenApi客户端',
authority: ['open-api', 'admin'],
version: 'pro',
component: './system/open-api',
},
{
Expand All @@ -156,14 +157,16 @@ export default {
{
path: 'system/tenant',
name: '租户管理',
// authority: ['tenant', 'admin'],
authority: ['tenant', 'admin'],
version: 'pro',
component: './system/tenant'
},
{
hideInMenu: true,
path: '/system/tenant/detail/:id',
name: '租户详情',
// authority: ['device-product'],
authority: ['device-product'],
version: 'pro',
component: './system/tenant/detail',
},
],
Expand Down Expand Up @@ -216,6 +219,7 @@ export default {
path: '/device/group',
name: '设备分组',
authority: ['device-group', 'admin'],
version: 'pro',
component: './device/group',
},
{
Expand All @@ -234,11 +238,13 @@ export default {
path: '/device/location',
name: '地理位置',
authority: ['geo-manager', 'admin'],
version: 'pro',
component: './device/location',
}, {
path: '/device/firmware',
name: '固件升级',
authority: ['firmware-manager', 'admin'],
version: 'pro',
component: './device/firmware',
}, {
hideInMenu: true,
Expand Down Expand Up @@ -310,13 +316,15 @@ export default {
name: '规则模型',
icon: 'appstore',
authority: ['rule-model', 'admin'],
version: 'pro',
component: './rule-engine/model',
},
{
path: '/rule-engine/instance',
name: '规则实例',
icon: 'control',
authority: ['rule-instance', 'admin'],
version: 'pro',
component: './rule-engine/instance',
},
{
Expand Down
4 changes: 2 additions & 2 deletions config/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
export default {
dev: {
'/jetlinks': {
target: 'http://192.168.3.25:8844/',
ws: 'ws://192.168.3.25:8844/',
target: 'http://192.168.3.146:8844/',
ws: 'ws://192.168.3.146:8844/',
// target: 'http://water.zlkjhb.com:9000/jetlinks',
// ws: 'http://water.zlkjhb.com:9000/jetlinks',
// ws: 'ws://demo.jetlinks.cn/jetlinks',
Expand Down
12 changes: 8 additions & 4 deletions src/layouts/BasicLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,15 @@ export type BasicLayoutContext = { [K in 'location']: BasicLayoutProps[K] } & {
* use Authorized check all menu item
*/

const menuDataRender = (menuList: MenuDataItem[]): MenuDataItem[] =>
menuList.map(item => {
const localItem = { ...item, children: item.children ? menuDataRender(item.children) : [] };
return Authorized.check(item.authority, localItem, null) as MenuDataItem;
const menuDataRender = (menuList: MenuDataItem[]): MenuDataItem[] => {
const version = localStorage.getItem('system-version');

return menuList.map(item => {
const localItem: any = { ...item, children: item.children ? menuDataRender(item.children) : [] };

return localItem?.version && version === 'community' ? [] : Authorized.check(item.authority, localItem, null) as MenuDataItem;
});
}

const defaultFooterDom = <div />;

Expand Down
5 changes: 5 additions & 0 deletions src/models/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { setAuthority, clearAutz, setAccessToken, setAutz } from '@/utils/author
import { getPageQuery } from '@/utils/utils';
import apis from '@/services';
import { reloadAuthorized } from '@/utils/Authorized';
import { systemVersion } from '@/services/user';

export interface StateType {
status?: 200 | 400 | undefined;
Expand Down Expand Up @@ -45,6 +46,10 @@ const Model: LoginModelType = {
setAccessToken(response.result.token);
setAutz(response.result);
reloadAuthorized();
const version = yield call(systemVersion);
if (version) {
localStorage.setItem('system-version', version?.result?.edition);
}
const urlParams = new URL(window.location.href);
const params = getPageQuery();
let { redirect } = params as { redirect: string };
Expand Down
3 changes: 3 additions & 0 deletions src/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Effect } from 'dva';
import { Reducer } from 'redux';

import { queryCurrent, query as queryUsers } from '@/services/user';
import { router } from 'umi';

export interface CurrentUser {
avatar?: string;
Expand Down Expand Up @@ -56,6 +57,8 @@ const UserModel: UserModelType = {
type: 'saveCurrentUser',
payload: response.result.user,
});
} else {
router.push('/user/login');
}
},
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/system/tenant/service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import BaseService from "@/services/crud";
import { TenantItem } from "./data";
import { defer, from } from "rxjs";
import request from "@/utils/request";
import { map, filter } from "rxjs/operators";
import { TenantItem } from "./data";

class Service extends BaseService<TenantItem>{
public create = (params: any) => defer(() => from(request(`/jetlinks/tenant/_create`, {
Expand Down
2 changes: 1 addition & 1 deletion src/pages/user/login2/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import React, { useState, useEffect } from 'react';
import style from './index.less';
import { connect } from 'dva';
import { Dispatch, ConnectState } from '@/models/connect';
import { Settings } from '@ant-design/pro-layout';
import { Spin } from 'antd';
import style from './index.less';

interface Props {
dispatch: Dispatch;
Expand Down
6 changes: 3 additions & 3 deletions src/services/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ export async function queryCurrent(): Promise<any> {
});
}

export async function queryNotices(): Promise<any> {
return request('/api/notices');
}
export async function systemVersion(): Promise<any> {
return request(`/jetlinks/system/version`);
}

0 comments on commit 18814ac

Please sign in to comment.