diff --git a/go/controller/category/category.go b/go/controller/category/category.go index c8ed13f7..4084451b 100644 --- a/go/controller/category/category.go +++ b/go/controller/category/category.go @@ -212,8 +212,16 @@ func List(ctx *iris.Context) { pageNo = 1 } + //默认按创建时间,降序来排序 + var orderStr = "created_at" + if ctx.FormValue("asc") == "1" { + orderStr += " asc" + } else { + orderStr += " desc" + } + offset := (pageNo - 1) * config.ServerConfig.PageSize - queryErr := db.Offset(offset).Limit(config.ServerConfig.PageSize).Find(&categories).Error + queryErr := db.Offset(offset).Limit(config.ServerConfig.PageSize).Order(orderStr).Find(&categories).Error if queryErr != nil { ctx.JSON(iris.StatusOK, iris.Map{ diff --git a/nodejs/static/javascripts/admin/actions/changeCategoryStatus.js b/nodejs/static/javascripts/admin/actions/changeCategoryStatus.js new file mode 100644 index 00000000..26c20c2e --- /dev/null +++ b/nodejs/static/javascripts/admin/actions/changeCategoryStatus.js @@ -0,0 +1,31 @@ +import { + CHANGE_CATEGORY_STATUS +} from '../constants'; + +function receiveCategoryStatus(data) { + return { + type : CHANGE_CATEGORY_STATUS, + id : data.id, + status : data.status + }; +} + +export default function(reqData) { + return dispatch => { + var url = pageConfig.apiURL + '/admin/category/status/update'; + return fetch(url, { + method: 'POST', + headers: { + 'Accept': 'application/json', + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + id : reqData.id, + status : reqData.status + }) + }) + .then(response => response.json()) + .then(json => dispatch(receiveCategoryStatus(json.data))); + }; +}; + diff --git a/nodejs/static/javascripts/admin/actions/changeProductStatus.js b/nodejs/static/javascripts/admin/actions/changeProductStatus.js new file mode 100644 index 00000000..46b6d262 --- /dev/null +++ b/nodejs/static/javascripts/admin/actions/changeProductStatus.js @@ -0,0 +1,22 @@ +import { + CHANGE_PRODUCT_STATUS +} from '../constants'; + +function receiveProductStatus(data) { + return { + type : CHANGE_PRODUCT_STATUS, + id : data.id, + status : data.status + }; +} + +export default function(reqData) { + return dispatch => { + var url = pageConfig.apiURL + '/admin/product/status/update/:id/:status'; + url = url.replace(':id', reqData.id); + url = url.replace(':status', reqData.status); + return fetch(url) + .then(response => response.json()) + .then(json => dispatch(receiveProductStatus(json.data))); + }; +} \ No newline at end of file diff --git a/nodejs/static/javascripts/admin/actions/requestCategoryList.js b/nodejs/static/javascripts/admin/actions/requestCategoryList.js new file mode 100644 index 00000000..fb872162 --- /dev/null +++ b/nodejs/static/javascripts/admin/actions/requestCategoryList.js @@ -0,0 +1,19 @@ +import { + REQUEST_CATEGORY_LIST +} from '../constants'; + +function receiveCategories(data) { + return { + type: REQUEST_CATEGORY_LIST, + categories: data.categories + }; +} + +export default function() { + return dispatch => { + var url = pageConfig.apiURL + '/admin/categories'; + return fetch(url) + .then(response => response.json()) + .then(json => dispatch(receiveCategories(json.data))) + }; +} \ No newline at end of file diff --git a/nodejs/static/javascripts/admin/components/Sidebar.js b/nodejs/static/javascripts/admin/components/Sidebar.js index eb269eff..e52e5d76 100644 --- a/nodejs/static/javascripts/admin/components/Sidebar.js +++ b/nodejs/static/javascripts/admin/components/Sidebar.js @@ -60,7 +60,6 @@ class Sidebar extends React.Component { this.setState({ current: event.key }); - hashHistory.push(url.substr(1)); } onMouseEnterSubMenu(event) { diff --git a/nodejs/static/javascripts/admin/config/index.js b/nodejs/static/javascripts/admin/config/index.js index 35860032..6991358c 100644 --- a/nodejs/static/javascripts/admin/config/index.js +++ b/nodejs/static/javascripts/admin/config/index.js @@ -64,7 +64,7 @@ var sidebarData = [ { id : getId(), title : '商品分类管理', - url : '/admin/category/list' + url : '/category/manage' }, { id : getId(), diff --git a/nodejs/static/javascripts/admin/constants/index.js b/nodejs/static/javascripts/admin/constants/index.js index 0358d809..34cd44bd 100644 --- a/nodejs/static/javascripts/admin/constants/index.js +++ b/nodejs/static/javascripts/admin/constants/index.js @@ -16,4 +16,9 @@ export const REQUEST_HOT_PRODUCT_LIST = 'requestHotProductList'; export const REQUEST_PRODUCT_LIST = 'requestProductList'; +export const CHANGE_PRODUCT_STATUS = 'changeProductStatus'; + +export const REQUEST_CATEGORY_LIST = 'requestCategoryList'; + +export const CHANGE_CATEGORY_STATUS = 'changeCategoryStatus'; diff --git a/nodejs/static/javascripts/admin/containers/CategoryManage.js b/nodejs/static/javascripts/admin/containers/CategoryManage.js new file mode 100644 index 00000000..3dc7b0f6 --- /dev/null +++ b/nodejs/static/javascripts/admin/containers/CategoryManage.js @@ -0,0 +1,146 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; +import { Link } from 'react-router'; + +import { + Icon, + Row, + Col, + Popconfirm, + Table +} from 'antd'; + +import requestCategoryList from '../actions/requestCategoryList'; +import changeCategoryStatus from '../actions/changeCategoryStatus'; +import Software from './Software'; +import analyze from '../../sdk/analyze'; +import '../../../styles/admin/categoryManage.css'; + +/* + * 管理后台,商品分类管理 + */ +class CategoryManage extends Component { + constructor(props) { + super(props); + var self = this; + this.state = { + columns: [ + { + title: '分类名称', + dataIndex: 'name' + }, + { + title: '排序', + dataIndex: 'order' + }, + { + title: '创建时间', + dataIndex: 'createdAt' + }, + { + title: '操作', + render: (text, record) => { + let openEnabled = false; + let closeEnabled = false; + //1: 已开启 + //2: 已关闭 + if (record.status == 1) { + closeEnabled = true; + } else if (record.status == 2) { + openEnabled = true; + } + return ( + + + + 查看 + + + + + 编辑 + + + { + openEnabled ? + + + + 开启 + + + : + ( + closeEnabled ? + + + + 关闭 + + + : + null + ) + } + + ); + } + } + ] + }; + } + componentDidMount() { + const { dispatch } = this.props; + dispatch(requestCategoryList()); + analyze.pv(); + } + onMenuOpen(record) { + const { dispatch } = this.props; + //1: 已开启 + //2: 已关闭 + dispatch(changeCategoryStatus({ + id : record.id, + status : 1 + })); + } + onMenuClose(record) { + const { dispatch } = this.props; + //1: 已开启 + //2: 已关闭 + dispatch(changeCategoryStatus({ + id : record.id, + status : 2 + })); + } + render() { + let { data } = this.props; + let { columns } = this.state; + let isLoading = data.categories.length > 0 ? false : true; + return ( +
+ + +
+
商品分类列表
+ + + + + + + ); + } +} + +const mapStateToProps = (state) => { + return { + data: state.category + }; +} + +export default connect(mapStateToProps)(CategoryManage); + diff --git a/nodejs/static/javascripts/admin/containers/ProductManage.js b/nodejs/static/javascripts/admin/containers/ProductManage.js index be78bb79..e26830e9 100644 --- a/nodejs/static/javascripts/admin/containers/ProductManage.js +++ b/nodejs/static/javascripts/admin/containers/ProductManage.js @@ -11,6 +11,7 @@ import { } from 'antd'; import requestProductList from '../actions/requestProductList'; +import changeProductStatus from '../actions/changeProductStatus'; import Software from './Software'; import analyze from '../../sdk/analyze'; import '../../../styles/admin/productManage.css'; @@ -36,6 +37,10 @@ class ProductManage extends Component { title: '购买量', dataIndex: 'buyCount' }, + { + title: '创建时间', + dataIndex: 'createdAt' + }, { title: '销售额', dataIndex: 'totalSale' @@ -106,10 +111,24 @@ class ProductManage extends Component { analyze.pv(); } onProductUp(record) { - console.log(11, record) + const { dispatch } = this.props; + //1: 商品已上架 + //2: 商品已下架 + //3: 商品未上架 + dispatch(changeProductStatus({ + id : record.id, + status : 1 + })); } onProductDown(record) { - console.log(11, record) + const { dispatch } = this.props; + //1: 商品已上架 + //2: 商品已下架 + //3: 商品未上架 + dispatch(changeProductStatus({ + id : record.id, + status : 2 + })); } render() { let { data } = this.props; diff --git a/nodejs/static/javascripts/admin/reducers/category.js b/nodejs/static/javascripts/admin/reducers/category.js new file mode 100644 index 00000000..aae0eabf --- /dev/null +++ b/nodejs/static/javascripts/admin/reducers/category.js @@ -0,0 +1,35 @@ +import { + REQUEST_CATEGORY_LIST, + CHANGE_CATEGORY_STATUS +} from '../constants'; + +let initState = { + categories: [] +}; + +export default (state = initState, action) => { + switch (action.type) { + case REQUEST_CATEGORY_LIST: { + return { + ...state, + categories: action.categories + }; + } + case CHANGE_CATEGORY_STATUS: { + let categories = state.categories.slice(0); + for (let i = 0; i < categories.length; i++) { + if (categories[i].id == action.id) { + categories[i].status = action.status; + break; + } + } + return { + ...state, + categories: categories + }; + } + default: { + return state + } + } +} \ No newline at end of file diff --git a/nodejs/static/javascripts/admin/reducers/index.js b/nodejs/static/javascripts/admin/reducers/index.js index d9917966..1ff28f75 100644 --- a/nodejs/static/javascripts/admin/reducers/index.js +++ b/nodejs/static/javascripts/admin/reducers/index.js @@ -3,13 +3,15 @@ import systemIndex from './systemIndex'; import userAnalyze from './userAnalyze'; import orderAnalyze from './orderAnalyze'; import productAnalyze from './productAnalyze'; +import category from './category'; const reducers = { software, systemIndex, userAnalyze, orderAnalyze, - productAnalyze + productAnalyze, + category }; export default reducers; \ No newline at end of file diff --git a/nodejs/static/javascripts/admin/reducers/productAnalyze.js b/nodejs/static/javascripts/admin/reducers/productAnalyze.js index a302b442..51a69bb2 100644 --- a/nodejs/static/javascripts/admin/reducers/productAnalyze.js +++ b/nodejs/static/javascripts/admin/reducers/productAnalyze.js @@ -1,6 +1,7 @@ import { REQUEST_HOT_PRODUCT_LIST, - REQUEST_PRODUCT_LIST + REQUEST_PRODUCT_LIST, + CHANGE_PRODUCT_STATUS } from '../constants'; let initState = { @@ -22,6 +23,19 @@ export default (state = initState, action) => { products: action.products }; } + case CHANGE_PRODUCT_STATUS: { + let products = state.products.slice(0); + for (let i = 0; i < products.length; i++) { + if (products[i].id == action.id) { + products[i].status = action.status; + break; + } + } + return { + ...state, + products: products + }; + } default: { return state } diff --git a/nodejs/static/javascripts/admin/route/index.js b/nodejs/static/javascripts/admin/route/index.js index 5634058a..4fb5e6b0 100644 --- a/nodejs/static/javascripts/admin/route/index.js +++ b/nodejs/static/javascripts/admin/route/index.js @@ -11,25 +11,31 @@ import Index from '../containers/Index'; const UserAnalyze = (location, cb) => { require.ensure([], require => { cb(null, require('../containers/UserAnalyze').default); - }, 'admin/UserAnalyze'); + }, 'admin/userAnalyze'); }; const OrderAnalyze = (location, cb) => { require.ensure([], require => { cb(null, require('../containers/OrderAnalyze').default); - }, 'admin/OrderAnalyze'); + }, 'admin/orderAnalyze'); }; const ProductAnalyze = (location, cb) => { require.ensure([], require => { cb(null, require('../containers/ProductAnalyze').default); - }, 'admin/ProductAnalyze'); + }, 'admin/productAnalyze'); }; const ProductManage = (location, cb) => { require.ensure([], require => { cb(null, require('../containers/ProductManage').default); - }, 'admin/ProductManage'); + }, 'admin/productManage'); +}; + +const CategoryManage = (location, cb) => { + require.ensure([], require => { + cb(null, require('../containers/CategoryManage').default); + }, 'admin/categoryManage'); }; const NotFound = (location, cb) => { @@ -47,6 +53,7 @@ export default (history) => { + diff --git a/nodejs/static/styles/admin/categoryManage.css b/nodejs/static/styles/admin/categoryManage.css new file mode 100644 index 00000000..86f0ed3f --- /dev/null +++ b/nodejs/static/styles/admin/categoryManage.css @@ -0,0 +1,14 @@ +.category-manage-divider { + margin-left: 10px; + margin-right: 10px; +} + +.category-list-box { + +} + +.category-list-title { + font-size: 20px; + margin-bottom: 6px; + color: #000; +} \ No newline at end of file