import React from 'react';
import { Table, Button, Input, Spin, Message, Select, Modal, Tag, Icon } from 'antd';
import ajax from 'jquery/src/ajax/xhr.js'
import $ from 'jquery/src/ajax';
const Role = React.createClass({
getInitialState() {
return {
visible: false,
disabled: false,
name: '',
selectOption: [],
data: [],
selectedRowKeys: [],
selectedRows: [],
loading: false,
permissions: {
},
modelRecord: {
id: '',
name: '',
permissions: []
}
}
},
componentWillMount() {
this.loadData();
},
loadData() {
let _me = this;
this.setState({
loading: true
});
$.when($.ajax({
url: globalConfig.context + '/api/roles',
method: 'get',
cache: false
}), $.ajax({
url: globalConfig.context + '/api/permissions',
method: 'get',
cache: false
})).done((roles, permissions) => {
if (!roles[0].error.length && roles[0].data) {
this.state.data = [];
for (let i = 0; i < roles[0].data.length; i++) {
let thisdata = roles[0].data[i];
this.state.data.push({
key: i,
id: thisdata.id,
roleName: thisdata.roleName,
permissions: thisdata.permissions.map((p) => { return String(p.id) }) || []
});
};
}
if (!permissions[0].error.length && permissions[0].data) {
_me.state.selectOption = [];
permissions[0].data.map(function (item) {
_me.state.selectOption.push(