forked from YMFE/yapi
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProjectCard.js
More file actions
executable file
·179 lines (167 loc) · 5.31 KB
/
ProjectCard.js
File metadata and controls
executable file
·179 lines (167 loc) · 5.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import './ProjectCard.scss';
import React, { PureComponent as Component } from 'react';
import { Card, Icon, Tooltip, Modal, Alert, Input, message } from 'antd';
import { connect } from 'react-redux';
import { delFollow, addFollow } from '../../reducer/modules/follow';
import PropTypes from 'prop-types';
import { withRouter } from 'react-router';
import { debounce } from '../../common';
import constants from '../../constants/variable.js';
import produce from 'immer';
import { getProject, checkProjectName, copyProjectMsg } from '../../reducer/modules/project';
import { trim } from '../../common.js';
const confirm = Modal.confirm;
@connect(
state => {
return {
uid: state.user.uid,
currPage: state.project.currPage
};
},
{
delFollow,
addFollow,
getProject,
checkProjectName,
copyProjectMsg
}
)
@withRouter
class ProjectCard extends Component {
constructor(props) {
super(props);
this.add = debounce(this.add, 400);
this.del = debounce(this.del, 400);
}
static propTypes = {
projectData: PropTypes.object,
uid: PropTypes.number,
inFollowPage: PropTypes.bool,
callbackResult: PropTypes.func,
history: PropTypes.object,
delFollow: PropTypes.func,
addFollow: PropTypes.func,
isShow: PropTypes.bool,
getProject: PropTypes.func,
checkProjectName: PropTypes.func,
copyProjectMsg: PropTypes.func,
currPage: PropTypes.number
};
copy = async projectName => {
const id = this.props.projectData._id;
let projectData = await this.props.getProject(id);
let data = projectData.payload.data.data;
let newData = produce(data, draftData => {
draftData.preName = draftData.name;
draftData.name = projectName;
});
await this.props.copyProjectMsg(newData);
message.success('项目复制成功');
this.props.callbackResult();
};
// 复制项目的二次确认
showConfirm = () => {
const that = this;
confirm({
title: '确认复制 ' + that.props.projectData.name + ' 项目吗?',
okText: '确认',
cancelText: '取消',
content: (
<div style={{ marginTop: '10px', fontSize: '13px', lineHeight: '25px' }}>
<Alert
message={`该操作将会复制 ${
that.props.projectData.name
} 下的所有接口集合,但不包括测试集合中的接口`}
type="info"
/>
<div style={{ marginTop: '16px' }}>
<p>
<b>项目名称:</b>
</p>
<Input id="project_name" placeholder="项目名称" />
</div>
</div>
),
async onOk() {
const projectName = trim(document.getElementById('project_name').value);
// 查询项目名称是否重复
const group_id = that.props.projectData.group_id;
await that.props.checkProjectName(projectName, group_id);
that.copy(projectName);
},
iconType: 'copy',
onCancel() {}
});
};
del = () => {
const id = this.props.projectData.projectid || this.props.projectData._id;
this.props.delFollow(id).then(res => {
if (res.payload.data.errcode === 0) {
this.props.callbackResult();
// message.success('已取消关注!'); // 星号已做出反馈 无需重复提醒用户
}
});
};
add = () => {
const { uid, projectData } = this.props;
const param = {
uid,
projectid: projectData._id,
projectname: projectData.name,
icon: projectData.icon || constants.PROJECT_ICON[0],
color: projectData.color || constants.PROJECT_COLOR.blue
};
this.props.addFollow(param).then(res => {
if (res.payload.data.errcode === 0) {
this.props.callbackResult();
// message.success('已添加关注!'); // 星号已做出反馈 无需重复提醒用户
}
});
};
render() {
const { projectData, inFollowPage, isShow } = this.props;
return (
<div className="card-container">
<Card
bordered={false}
className="m-card"
onClick={() =>
this.props.history.push('/project/' + (projectData.projectid || projectData._id))
}
>
<Icon
type={projectData.icon || 'star-o'}
className="ui-logo"
style={{
backgroundColor:
constants.PROJECT_COLOR[projectData.color] || constants.PROJECT_COLOR.blue
}}
/>
<h4 className="ui-title">{projectData.name || projectData.projectname}</h4>
</Card>
<div
className="card-btns"
onClick={projectData.follow || inFollowPage ? this.del : this.add}
>
<Tooltip
placement="rightTop"
title={projectData.follow || inFollowPage ? '取消关注' : '添加关注'}
>
<Icon
type={projectData.follow || inFollowPage ? 'star' : 'star-o'}
className={'icon ' + (projectData.follow || inFollowPage ? 'active' : '')}
/>
</Tooltip>
</div>
{isShow && (
<div className="copy-btns" onClick={this.showConfirm}>
<Tooltip placement="rightTop" title="复制项目">
<Icon type="copy" className="icon" />
</Tooltip>
</div>
)}
</div>
);
}
}
export default ProjectCard;