From e845691edaab14a026a3938108caed8a5262c743 Mon Sep 17 00:00:00 2001 From: vapao Date: Sun, 12 Jan 2020 00:57:05 +0800 Subject: [PATCH] U web update --- spug_web/src/pages/config/app/store.js | 2 +- spug_web/src/pages/system/role/DeployPerm.js | 96 +++++++++++++++++++ .../role/{Permission.js => PagePerm.js} | 6 +- spug_web/src/pages/system/role/Table.js | 10 +- spug_web/src/pages/system/role/index.js | 6 +- spug_web/src/pages/system/role/store.js | 13 ++- 6 files changed, 118 insertions(+), 15 deletions(-) create mode 100644 spug_web/src/pages/system/role/DeployPerm.js rename spug_web/src/pages/system/role/{Permission.js => PagePerm.js} (96%) diff --git a/spug_web/src/pages/config/app/store.js b/spug_web/src/pages/config/app/store.js index 16c9d4c..c2926d6 100644 --- a/spug_web/src/pages/config/app/store.js +++ b/spug_web/src/pages/config/app/store.js @@ -13,7 +13,7 @@ class Store { fetchRecords = () => { this.isFetching = true; - http.get('/api/app/') + return http.get('/api/app/') .then(res => this.records = res) .finally(() => this.isFetching = false) }; diff --git a/spug_web/src/pages/system/role/DeployPerm.js b/spug_web/src/pages/system/role/DeployPerm.js new file mode 100644 index 0000000..f47436f --- /dev/null +++ b/spug_web/src/pages/system/role/DeployPerm.js @@ -0,0 +1,96 @@ +import React from 'react'; +import {observer} from 'mobx-react'; +import {Modal, Form, Transfer, message, Tabs, Alert} from 'antd'; +import http from 'libs/http'; +import envStore from 'pages/config/environment/store'; +import appStore from 'pages/config/app/store'; +import store from './store'; + +@observer +class DeployPerm extends React.Component { + constructor(props) { + super(props); + this.state = { + loading: false, + envs: [], + apps: [] + } + } + + componentDidMount() { + if (envStore.records.length === 0) { + envStore.fetchRecords().then( + () => this._updateRecords(envStore.records, 'envs') + ) + } else { + this._updateRecords(envStore.records, 'envs') + } + if (appStore.records.length === 0) { + appStore.fetchRecords().then( + () => this._updateRecords(appStore.records, 'apps') + ) + } else { + this._updateRecords(appStore.records, 'apps') + } + } + + _updateRecords = (records, key) => { + const data = records.map(x => { + return {...x, key: x.id, _key: x.key} + }); + this.setState({[key]: data}) + }; + + handleSubmit = () => { + this.setState({loading: true}); + const {app, service} = store.confRel; + http.patch('/api/app/', {id: store.record.id, rel_apps: app, rel_services: service}) + .then(res => { + message.success('操作成功'); + store.relVisible = false; + store.fetchRecords() + }, () => this.setState({loading: false})) + }; + + render() { + return ( + store.deployPermVisible = false} + confirmLoading={this.state.loading} + onOk={this.handleSubmit}> + + + + + store.deployRel.envs = keys} + render={item => `${item.name}(${item._key})`}/> + + + + + store.deployRel.apps = keys} + render={item => `${item.name}(${item._key})`}/> + + + + + ) + } +} + +export default DeployPerm \ No newline at end of file diff --git a/spug_web/src/pages/system/role/Permission.js b/spug_web/src/pages/system/role/PagePerm.js similarity index 96% rename from spug_web/src/pages/system/role/Permission.js rename to spug_web/src/pages/system/role/PagePerm.js index 88691d7..1e51fb1 100644 --- a/spug_web/src/pages/system/role/Permission.js +++ b/spug_web/src/pages/system/role/PagePerm.js @@ -8,7 +8,7 @@ import styles from './index.module.css'; import lds from 'lodash'; @observer -class Permission extends React.Component { +class PagePerm extends React.Component { constructor(props) { super(props); this.state = { @@ -66,7 +66,7 @@ class Permission extends React.Component { maskClosable={false} title="功能权限设置" className={styles.container} - onCancel={() => store.permVisible = false} + onCancel={() => store.pagePermVisible = false} confirmLoading={this.state.loading} onOk={this.handleSubmit}> index + 1, - width: 80, - }, { title: '角色名称', dataIndex: 'name', }, { @@ -28,11 +23,14 @@ class ComTable extends React.Component { ellipsis: true }, { title: '操作', + width: 300, render: info => ( store.showForm(info)}>编辑 - store.showPerm(info)}>权限 + store.showPagePerm(info)}>功能权限 + + store.showDeployPerm(info)}>发布权限 this.handleDelete(info)}>删除 diff --git a/spug_web/src/pages/system/role/index.js b/spug_web/src/pages/system/role/index.js index 7943325..20f1828 100644 --- a/spug_web/src/pages/system/role/index.js +++ b/spug_web/src/pages/system/role/index.js @@ -4,7 +4,8 @@ import { Card, Input, Button } from 'antd'; import { SearchForm } from 'components'; import ComTable from './Table'; import ComForm from './Form'; -import Permission from './Permission'; +import PagePerm from './PagePerm'; +import DeployPerm from './DeployPerm'; import store from './store'; export default observer(function () { @@ -23,7 +24,8 @@ export default observer(function () { {store.formVisible && } - {store.permVisible && } + {store.pagePermVisible && } + {store.deployPermVisible && } ) }) \ No newline at end of file diff --git a/spug_web/src/pages/system/role/store.js b/spug_web/src/pages/system/role/store.js index 248d601..50e305d 100644 --- a/spug_web/src/pages/system/role/store.js +++ b/spug_web/src/pages/system/role/store.js @@ -8,9 +8,11 @@ class Store { @observable records = []; @observable record = {}; @observable permissions = lds.cloneDeep(codes); + @observable deployRel = {} @observable isFetching = false; @observable formVisible = false; - @observable permVisible = true; + @observable pagePermVisible = false; + @observable deployPermVisible = true; @observable f_name; @@ -42,9 +44,14 @@ class Store { this.record = info }; - showPerm = (info) => { + showPagePerm = (info) => { this.record = info; - this.permVisible = true; + this.pagePermVisible = true; + }; + + showDeployPerm = (info) => { + this.record = info; + this.deployPermVisible = true; } }