Authored by yyq

save

... ... @@ -559,7 +559,7 @@ r.get('/add', async (ctx) => {
r.post('/add', async (ctx) => {
let mysql = new Mysql();
let keyword = ctx.request.body.keywords || '';
let keyword = ctx.request.body.keywords;
let brand = ctx.request.body.brand || 0;
let msort = ctx.request.body.msort || 0;
let misort = ctx.request.body.misort || 0;
... ... @@ -571,8 +571,8 @@ r.post('/add', async (ctx) => {
let result = {code: 400, message: ''};
if (_.isEmpty(keyword)) {
selectSql.message = '关键词必填';
if (!keyword) {
result.message = '关键词必填';
return ctx.response.body = result;
}
... ... @@ -583,7 +583,7 @@ r.post('/add', async (ctx) => {
return ctx.response.body = result;
}
await mysql.query(`insert into seo_keywords (keyword, brand_id, msort, misort, sort_id, add_time, describe, goods_img, is_hot) values ('${keyword}', ${brand}, ${msort}, ${misort}, ${sort}, ${addTime}, '${describe}', '${goods_img}', ${is_hot})`);
await mysql.query(`insert into seo_keywords (keyword, brand_id, msort, misort, sort_id, add_time, \`describe\`, goods_img, is_hot) values ('${keyword}', ${brand}, ${msort}, ${misort}, ${sort}, ${addTime}, '${describe}', '${goods_img}', ${is_hot})`);
result.code = 200;
return ctx.response.body = result;
... ...
... ... @@ -35,6 +35,8 @@ const columns = [{
key: 'add_time',
}];
let globalSort = [];
function ActionButton(props) {
function editClick() {
... ... @@ -45,8 +47,6 @@ function ActionButton(props) {
}
return (
<span>
<a href="javascript:;" onClick={editClick}>编辑</a>
<Divider type="vertical" />
<a href="javascript:;" onClick={deleteClick}>删除</a>
</span>
);
... ... @@ -58,43 +58,74 @@ class OptionModal extends React.Component {
this.props = props;
this.state = {
showModal: false,
sorts: []
sorts: globalSort || []
};
this.renderData = Object.assign({}, props.record || {});
this.hotApi = new HotApi();
this.handleOk = this.handleOk.bind(this);
this.loadHotList = props.loadHotList;
this.hideOptionModal = props.hideOptionModal;
this.handleKeywordChange = this.handleKeywordChange.bind(this);
this.handleDescChange = this.handleDescChange.bind(this);
this.handleSortChange = this.handleSortChange.bind(this);
this.handleImageChange = this.handleImageChange.bind(this);
this.loadSortData = this.loadSortData.bind(this);
this.loadSortDataAsync().then(result => {
this.setState({sorts: result});
switch (this.renderData.type) {
case 'edit':
this.modalTitle = '编辑关键词';
this.handleOk = this.handleSave.bind(this);
break;
case 'delete':
this.modalTitle = '删除关键词';
this.handleOk = this.handleDelete.bind(this);
break;
default:
this.modalTitle = '新建关键词';
this.handleOk = this.handleSave.bind(this);
break;
}
if (!globalSort.length) {
this.loadSortDataAsync().then(result => {
this.setState({sorts: result});
globalSort = result;
});
}
}
handleDelete() {
return this.hotApi.delHotKeywords([this.renderData.id]).then(result => {
if (result.code === 200) {
this.loadHotList && this.loadHotList();
this.hideOptionModal && this.hideOptionModal();
} else {
message.error(result.message);
}
});
}
handleOk() {
this.hotApi.saveHotKeywords(this.renderData).then(result => {
handleSave() {
return this.hotApi.saveHotKeywords(this.renderData).then(result => {
if (result.code === 200) {
this.props.loadHotList && this.props.loadHotList();
this.loadHotList && this.loadHotList();
this.hideOptionModal && this.hideOptionModal();
} else {
message.error(result.message);
}
})
this.props.hideOptionModal && this.props.hideOptionModal();
});
}
handleKeywordChange(e) {
this.renderData.keyword = e.target.value;
console.log(this.renderData);
}
handleDescChange(e) {
this.renderData.describe = e.target.value;
console.log(this.renderData);
}
handleSortChange(select) {
this.renderData.msort = select[0];
this.renderData.misort = select[1];
this.renderData.sort_id = select[2];
console.log(this.renderData);
}
handleImageChange() {
// this.renderData.goods_img = select[2];
... ... @@ -119,6 +150,7 @@ class OptionModal extends React.Component {
this.loadSortDataAsync(targetOption.value).then(result => {
targetOption.loading = false;
targetOption.children = result;
globalSort = this.state.sorts;
this.setState({sorts: this.state.sorts});
});
}
... ... @@ -148,45 +180,29 @@ class OptionModal extends React.Component {
return result;
});
}
uploadButton(loading) {
return (
<div>
<Icon type={loading ? 'loading' : 'plus'} />
<div className="ant-upload-text">Upload</div>
</div>);
}
render() {
const {showModal, hideOptionModal, record} = this.props;
const record = this.renderData;
let title = '';
this.renderData = Object.assign({}, record || {});
if (record) {
switch (record.type) {
case 'edit':
title = '编辑关键词';
break;
case 'delete':
title = '删除关键词';
break;
default:
title = '新建关键词';
break;
}
}
if (record && record.type === 'delete') {
return (
<Modal title={title} visible={showModal} onOk={this.handleOk} onCancel={hideOptionModal}>
<Modal title={this.modalTitle} visible={true} onOk={this.handleOk} onCancel={this.hideOptionModal}>
<p>确认删除该关键词?</p>
</Modal>
)
} else {
const uploadButton = (
<div>
<Icon type={this.state.loading ? 'loading' : 'plus'} />
<div className="ant-upload-text">Upload</div>
</div>
);
const imageUrl = '';
return (
<Modal title={title} visible={showModal} onOk={this.handleOk} onCancel={hideOptionModal}>
<Modal title={this.modalTitle} visible={true} onOk={this.handleOk} onCancel={this.hideOptionModal}>
<div style={{ paddingBottom: 10 }}>
<span>关键词:</span>
<Input onChange={this.handleKeywordChange} />
... ... @@ -206,7 +222,7 @@ class OptionModal extends React.Component {
beforeUpload={this.beforeUpload}
onChange={this.handleImageChange}
style={{ width: 600 }}>
{imageUrl ? <img src={imageUrl} alt="" /> : uploadButton}
{imageUrl ? <img src={imageUrl} alt="" /> : this.uploadButton(this.state.loading)}
</Upload>
</div>
<div style={{ paddingBottom: 10 }}>
... ... @@ -249,6 +265,13 @@ class HotKeywords extends React.Component {
};
this.hotApi = new HotApi();
this.loadHotList = this.loadHotList.bind(this);
this.handleTableChange = this.handleTableChange.bind(this);
this.deleteTableRow = this.deleteTableRow.bind(this);
this.hideOptionModal = this.hideOptionModal.bind(this);
this.addTableRow = this.addTableRow.bind(this);
this.loadHotList();
}
loadHotList(params = {}) {
... ... @@ -304,16 +327,17 @@ class HotKeywords extends React.Component {
this.modelRecord = null;
this.setState({showModal: false});
}
optionModal(showModal) {
if (showModal) {
return <OptionModal hideOptionModal={this.hideOptionModal} record={this.modelRecord} loadHotList={this.loadHotList}/>
} else {
return <div></div>;
}
}
render() {
const { showModal, dataSource, columns, selectedRowKeys, pagination, loading } = this.state;
const hasSelected = selectedRowKeys.length > 0;
const loadHotList = this.loadHotList.bind(this);
const handleTableChange = this.handleTableChange.bind(this);
const deleteTableRow = this.deleteTableRow.bind(this);
const hideOptionModal = this.hideOptionModal.bind(this);
const addTableRow = this.addTableRow.bind(this);
const rowSelection = {
selectedRowKeys,
onChange: this.onSelectChange.bind(this)
... ... @@ -327,14 +351,14 @@ class HotKeywords extends React.Component {
return (
<div>
<div style={{ paddingBottom: 10 }}>
<Button type="primary" onClick={deleteTableRow} disabled={!hasSelected} loading={loading}>删除</Button>
<Button type="primary" style={{ marginLeft: 10 }} onClick={addTableRow}>添加</Button>
<Button type="primary" onClick={this.deleteTableRow} disabled={!hasSelected} loading={loading}>删除</Button>
<Button type="primary" style={{ marginLeft: 10 }} onClick={this.addTableRow}>添加</Button>
<Button type="primary" style={{ marginLeft: 10 }} onClick={this.sendToBaidu}>推送百度</Button>
<OptionModal showModal={showModal} hideOptionModal={hideOptionModal} record={this.modelRecord} loadHotList={loadHotList}/>
{this.optionModal(showModal)}
</div>
<Table rowSelection={rowSelection} dataSource={dataSource} columns={columns}
rowKey={rowKey} pagination={pagination} onChange={handleTableChange}/>
rowKey={rowKey} pagination={pagination} onChange={this.handleTableChange}/>
</div>
);
}
... ...