mirror of
https://github.com/YMFE/yapi.git
synced 2025-03-01 14:05:44 +08:00
Merge branch 'dev' of http://gitlab.corp.qunar.com/mfe/yapi into dev
This commit is contained in:
commit
6e665d0beb
@ -12,23 +12,23 @@ const plugin = require('client/plugin.js');
|
||||
let importDataModule = {};
|
||||
|
||||
@connect(
|
||||
state=>{
|
||||
state => {
|
||||
// console.log(state);
|
||||
return {
|
||||
curCatid: -(-state.inter.curdata.catid),
|
||||
basePath: state.project.currProject.basepath
|
||||
}
|
||||
},{
|
||||
}, {
|
||||
|
||||
}
|
||||
)
|
||||
|
||||
class ProjectData extends Component {
|
||||
constructor(props){
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
selectCatid:"",
|
||||
menuList:[],
|
||||
selectCatid: "",
|
||||
menuList: [],
|
||||
curImportType: null
|
||||
}
|
||||
}
|
||||
@ -38,8 +38,8 @@ class ProjectData extends Component {
|
||||
basePath: PropTypes.string
|
||||
}
|
||||
|
||||
componentWillMount(){
|
||||
axios.get(`/api/interface/getCatMenu?project_id=${this.props.match.params.id}`).then((data)=>{
|
||||
componentWillMount() {
|
||||
axios.get(`/api/interface/getCatMenu?project_id=${this.props.match.params.id}`).then((data) => {
|
||||
let menuList = data.data.data;
|
||||
this.setState({
|
||||
menuList: menuList
|
||||
@ -47,15 +47,15 @@ class ProjectData extends Component {
|
||||
});
|
||||
plugin.emitHook('import_data', importDataModule, this.props);
|
||||
}
|
||||
selectChange(value){
|
||||
selectChange(value) {
|
||||
this.setState({
|
||||
selectCatid: +value
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
|
||||
uploadChnange(info){
|
||||
|
||||
uploadChnange(info) {
|
||||
const status = info.file.status;
|
||||
if (status !== 'uploading') {
|
||||
console.log(info.file, info.fileList);
|
||||
@ -67,43 +67,50 @@ class ProjectData extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
handleAddInterface(info){
|
||||
if(this.state.selectCatid){
|
||||
handleAddInterface(info) {
|
||||
if (!this.state.curImportType) {
|
||||
return message.error('请选择导入数据的方式');
|
||||
}
|
||||
if (this.state.selectCatid) {
|
||||
// let filename = info.file.name;
|
||||
// let filetype = filename.substr(filename.lastIndexOf(".")).toLowerCase();
|
||||
// console.log(filename,filetype);
|
||||
//if(filetype != ".json") return message.error("文件格式只能为json");
|
||||
let reader = new FileReader();
|
||||
reader.readAsText(info.file);
|
||||
reader.onload = (res)=>{
|
||||
reader.onload = (res) => {
|
||||
res = importDataModule[this.state.curImportType].run(res.target.result);
|
||||
res = res.apis;
|
||||
let len = res.length;
|
||||
let count = 0;
|
||||
let successNum = len;
|
||||
res.forEach(async (item)=>{
|
||||
res.forEach(async (item) => {
|
||||
let data = {
|
||||
...item,
|
||||
project_id: this.props.match.params.id,
|
||||
catid: this.state.selectCatid
|
||||
}
|
||||
let result = await axios.post('/api/interface/add',data);
|
||||
if (this.props.basePath) {
|
||||
data.path = data.path.indexOf(this.props.basePath) === 0 ? data.path.substr(this.props.basePath.length) : data.path;
|
||||
}
|
||||
|
||||
let result = await axios.post('/api/interface/add', data);
|
||||
count++;
|
||||
if(result.data.errcode){
|
||||
if (result.data.errcode) {
|
||||
successNum--;
|
||||
}
|
||||
if(count === len){
|
||||
if (count === len) {
|
||||
message.success(`成功导入接口 ${successNum} 个`);
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
message.error("请选择上传的分类");
|
||||
}
|
||||
}
|
||||
|
||||
handleImportType=(val) =>{
|
||||
handleImportType = (val) => {
|
||||
this.setState({
|
||||
curImportType: val
|
||||
})
|
||||
@ -125,16 +132,16 @@ class ProjectData extends Component {
|
||||
onChange: this.uploadChnange.bind(this)
|
||||
}
|
||||
return (
|
||||
<div className="m-panel g-row" style={{paddingTop: '15px'}}>
|
||||
<div className="m-panel g-row" style={{ paddingTop: '15px' }}>
|
||||
<div className="postman-dataImport">
|
||||
<h2>数据导入</h2>
|
||||
<div className="dataImportCon">
|
||||
<div ><h3>数据导入</h3></div>
|
||||
<div className="dataImportTile">
|
||||
<Select placeholder="请选择导入数据的方式" onChange={this.handleImportType}>
|
||||
{Object.keys(importDataModule).map((name)=>{
|
||||
<Select placeholder="请选择导入数据的方式" onChange={this.handleImportType}>
|
||||
{Object.keys(importDataModule).map((name) => {
|
||||
return <Option key={name} value={name}>{importDataModule[name].name}</Option>
|
||||
})}
|
||||
|
||||
|
||||
|
||||
</Select>
|
||||
</div>
|
||||
@ -147,10 +154,10 @@ class ProjectData extends Component {
|
||||
onChange={this.selectChange.bind(this)}
|
||||
filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
|
||||
>
|
||||
{this.state.menuList.map((item,key)=>{
|
||||
return <Option key = {key} value={item._id+""}>{item.name}</Option>;
|
||||
{this.state.menuList.map((item, key) => {
|
||||
return <Option key={key} value={item._id + ""}>{item.name}</Option>;
|
||||
})}
|
||||
|
||||
|
||||
</Select>
|
||||
</div>
|
||||
<div style={{ marginTop: 16, height: 180 }}>
|
||||
@ -159,7 +166,7 @@ class ProjectData extends Component {
|
||||
<Icon type="inbox" />
|
||||
</p>
|
||||
<p className="ant-upload-text">点击或者拖拽文件到上传区域</p>
|
||||
<p className="ant-upload-hint">{this.state.curImportType?importDataModule[this.state.curImportType].desc: null}</p>
|
||||
<p className="ant-upload-hint">{this.state.curImportType ? importDataModule[this.state.curImportType].desc : null}</p>
|
||||
</Dragger>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { Component } from 'react'
|
||||
import { formatTime } from '../../common.js'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { setBreadcrumb } from '../../reducer/modules/user';
|
||||
import { setBreadcrumb } from '../../reducer/modules/user';
|
||||
//import PropTypes from 'prop-types'
|
||||
import { connect } from 'react-redux'
|
||||
import PropTypes from 'prop-types'
|
||||
@ -12,13 +12,13 @@ import {
|
||||
} from 'antd'
|
||||
import axios from 'axios';
|
||||
|
||||
const limit = 10;
|
||||
const limit = 20;
|
||||
@connect(
|
||||
state => {
|
||||
return {
|
||||
curUserRole: state.user.role
|
||||
}
|
||||
},{
|
||||
}, {
|
||||
setBreadcrumb
|
||||
}
|
||||
)
|
||||
@ -36,19 +36,19 @@ class List extends Component {
|
||||
setBreadcrumb: PropTypes.func,
|
||||
curUserRole: PropTypes.string
|
||||
}
|
||||
changePage =(current)=>{
|
||||
changePage = (current) => {
|
||||
this.setState({
|
||||
current: current
|
||||
}, this.getUserList)
|
||||
}
|
||||
|
||||
getUserList() {
|
||||
axios.get('/api/user/list?page=' + this.state.current).then((res) => {
|
||||
axios.get('/api/user/list?page=' + this.state.current + '&limit=' + limit).then((res) => {
|
||||
let result = res.data;
|
||||
|
||||
if (result.errcode === 0) {
|
||||
let list = result.data.list;
|
||||
let total = result.data.total * limit;
|
||||
let total = result.data.count;
|
||||
list.map((item, index) => {
|
||||
item.key = index;
|
||||
item.up_time = formatTime(item.up_time)
|
||||
@ -65,35 +65,35 @@ class List extends Component {
|
||||
this.getUserList()
|
||||
}
|
||||
|
||||
confirm = (uid) =>{
|
||||
confirm = (uid) => {
|
||||
axios.post('/api/user/del', {
|
||||
id: uid
|
||||
}).then( (res)=>{
|
||||
if(res.data.errcode === 0){
|
||||
}).then((res) => {
|
||||
if (res.data.errcode === 0) {
|
||||
message.success('已删除此用户');
|
||||
let userlist = this.state.data;
|
||||
userlist = userlist.filter( (item)=>{
|
||||
userlist = userlist.filter((item) => {
|
||||
return item._id != uid
|
||||
} )
|
||||
})
|
||||
this.setState({
|
||||
data: userlist
|
||||
})
|
||||
}else{
|
||||
} else {
|
||||
message.error(res.data.errmsg);
|
||||
}
|
||||
}, (err) => {
|
||||
message.error(err.message);
|
||||
} )
|
||||
})
|
||||
}
|
||||
|
||||
async componentWillMount() {
|
||||
this.props.setBreadcrumb([{name: '用户管理'}]);
|
||||
this.props.setBreadcrumb([{ name: '用户管理' }]);
|
||||
}
|
||||
|
||||
render() {
|
||||
const role = this.props.curUserRole;
|
||||
let data = [];
|
||||
if(role === 'admin'){
|
||||
if (role === 'admin') {
|
||||
data = this.state.data;
|
||||
}
|
||||
let columns = [{
|
||||
@ -114,7 +114,7 @@ class List extends Component {
|
||||
title: '用户角色',
|
||||
dataIndex: 'role',
|
||||
key: 'role',
|
||||
width:150
|
||||
width: 150
|
||||
}, {
|
||||
title: '更新日期',
|
||||
dataIndex: 'up_time',
|
||||
@ -123,13 +123,13 @@ class List extends Component {
|
||||
}, {
|
||||
title: '功能',
|
||||
key: 'action',
|
||||
width:"90px",
|
||||
width: "90px",
|
||||
render: (item) => {
|
||||
return (
|
||||
<span>
|
||||
<Link to={"/user/profile/" + item._id} >查看</Link>
|
||||
<span className="ant-divider" />
|
||||
<Popconfirm title="确认删除此用户?" onConfirm={() => {this.confirm(item._id)}} okText="确定" cancelText="取消">
|
||||
<Popconfirm title="确认删除此用户?" onConfirm={() => { this.confirm(item._id) }} okText="确定" cancelText="取消">
|
||||
<a href="#">删除</a>
|
||||
</Popconfirm>
|
||||
</span>
|
||||
@ -137,12 +137,12 @@ class List extends Component {
|
||||
}
|
||||
}]
|
||||
|
||||
columns = columns.filter( (item)=>{
|
||||
if(item.key === 'action' && role !== 'admin'){
|
||||
columns = columns.filter((item) => {
|
||||
if (item.key === 'action' && role !== 'admin') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
} )
|
||||
})
|
||||
|
||||
const pageConfig = {
|
||||
total: this.state.total,
|
||||
@ -153,7 +153,7 @@ class List extends Component {
|
||||
|
||||
return (
|
||||
<section className="user-table">
|
||||
|
||||
<h2 style={{marginBottom:'10px'}} >用户总数:{this.state.total}位</h2>
|
||||
<Table bordered={true} columns={columns} pagination={pageConfig} dataSource={data} />
|
||||
|
||||
</section>
|
||||
|
@ -317,6 +317,7 @@ class userController extends baseController {
|
||||
let user = await userInst.listWithPaging(page, limit);
|
||||
let count = await userInst.listCount();
|
||||
return ctx.body = yapi.commons.resReturn({
|
||||
count: count,
|
||||
total: Math.ceil(count / limit),
|
||||
list: user
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user