From 5621f56c0de1717e86c3a3ef9e7c31ef39c5ed52 Mon Sep 17 00:00:00 2001 From: shen100 Date: Sat, 13 May 2017 10:08:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=BF=E6=8E=89go=E9=BB=98=E8=AE=A4=E7=9A=84?= =?UTF-8?q?gopath,=20=E4=BF=AE=E6=94=B9=E5=8C=85=E7=9A=84=E5=BC=95?= =?UTF-8?q?=E5=85=A5=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 7 +- go/config/config.go | 2 +- go/controller/category/category.go | 4 +- go/controller/order/order.go | 2 +- go/controller/product/product.go | 4 +- go/controller/user/user.go | 2 +- go/controller/visit/visit.go | 4 +- go/model/order.go | 2 +- go/model/user.go | 2 +- go/model/uservisit.go | 2 +- main.go | 16 +-- .../admin/actions/product/requestProduct.js | 25 +++++ .../admin/containers/product/EditProduct.js | 102 ++++++++++++++++++ .../javascripts/admin/reducers/index.js | 2 +- .../{productAnalyze.js => product.js} | 15 ++- .../styles/admin/product/editProduct.css | 15 +++ 16 files changed, 181 insertions(+), 25 deletions(-) create mode 100644 nodejs/static/javascripts/admin/actions/product/requestProduct.js create mode 100644 nodejs/static/javascripts/admin/containers/product/EditProduct.js rename nodejs/static/javascripts/admin/reducers/{productAnalyze.js => product.js} (73%) create mode 100644 nodejs/static/styles/admin/product/editProduct.css diff --git a/README.md b/README.md index 20f138a4..21e11a0a 100755 --- a/README.md +++ b/README.md @@ -71,8 +71,8 @@ go run main.go * 数据库: mysql ## 项目结构 -| 目录或文件 |目录或文件| 说明 | -|:--------|:--------|:-------:| +| 目录或文件 | 目录或文件 | 说明 | +|:---------|:-----------------------|:-------:| | docs | | 文档| | go | | 后台代码目录| | | config | 配置| @@ -86,5 +86,6 @@ go run main.go | configuration.json | | 项目配置文件 | | main.go | | go主程序入口| - +## 最后 +求star,star就是继续下去的动力 diff --git a/go/config/config.go b/go/config/config.go index 36cdbdbc..44e29397 100644 --- a/go/config/config.go +++ b/go/config/config.go @@ -5,7 +5,7 @@ import ( "encoding/json" "fmt" "io/ioutil" - "../utils" + "wemall/go/utils" ) var jsonData map[string]interface{} diff --git a/go/controller/category/category.go b/go/controller/category/category.go index 4084451b..d0fb23c3 100644 --- a/go/controller/category/category.go +++ b/go/controller/category/category.go @@ -4,10 +4,10 @@ import ( "unicode/utf8" "strings" "strconv" - "../../config" - "../../model" "github.com/jinzhu/gorm" "gopkg.in/kataras/iris.v6" + "wemall/go/config" + "wemall/go/model" ) // Save 保存分类(创建或更新) diff --git a/go/controller/order/order.go b/go/controller/order/order.go index 27688095..ba59d8ef 100644 --- a/go/controller/order/order.go +++ b/go/controller/order/order.go @@ -1,9 +1,9 @@ package order import ( - "../../model" "gopkg.in/kataras/iris.v6" "time" + "wemall/go/model" ) // TodayCount 今日总订单数 diff --git a/go/controller/product/product.go b/go/controller/product/product.go index 0e7604a0..5b84cd6f 100644 --- a/go/controller/product/product.go +++ b/go/controller/product/product.go @@ -1,13 +1,13 @@ package product import ( - "../../config" - "../../model" "strconv" "strings" "unicode/utf8" "github.com/jinzhu/gorm" "gopkg.in/kataras/iris.v6" + "wemall/go/config" + "wemall/go/model" ) // List 产品列表 diff --git a/go/controller/user/user.go b/go/controller/user/user.go index e67e2a15..b4931dcc 100644 --- a/go/controller/user/user.go +++ b/go/controller/user/user.go @@ -1,9 +1,9 @@ package user import ( - "../../model" "time" "gopkg.in/kataras/iris.v6" + "wemall/go/model" ) // YesterdayRegisterUser 昨日注册的用户数 diff --git a/go/controller/visit/visit.go b/go/controller/visit/visit.go index 8d34d290..ff58214f 100644 --- a/go/controller/visit/visit.go +++ b/go/controller/visit/visit.go @@ -1,12 +1,12 @@ package visit import ( - "../../config" - "../../model" "strconv" "time" "gopkg.in/kataras/iris.v6" "github.com/jinzhu/gorm" + "wemall/go/config" + "wemall/go/model" ) // Latest30Day 近30天,每天的PV diff --git a/go/model/order.go b/go/model/order.go index 55a9c374..99237910 100644 --- a/go/model/order.go +++ b/go/model/order.go @@ -3,8 +3,8 @@ package model import ( "strings" "time" - "../config" "github.com/jinzhu/gorm" + "wemall/go/config" ) // Order 订单 diff --git a/go/model/user.go b/go/model/user.go index cef175fc..a03c7bf5 100644 --- a/go/model/user.go +++ b/go/model/user.go @@ -3,8 +3,8 @@ package model import ( "strings" "time" - "../config" "github.com/jinzhu/gorm" + "wemall/go/config" ) // User 用户 diff --git a/go/model/uservisit.go b/go/model/uservisit.go index fa786999..70a073c2 100644 --- a/go/model/uservisit.go +++ b/go/model/uservisit.go @@ -2,9 +2,9 @@ package model import ( "time" - "../config" "strings" "github.com/jinzhu/gorm" + "wemall/go/config" ) // UserVisit 访客记录 diff --git a/main.go b/main.go index 97bcd6ac..3c6a95a9 100644 --- a/main.go +++ b/main.go @@ -1,18 +1,18 @@ package main import ( - "./go/config" - "./go/model" - "./go/controller/admin" - "./go/controller/category" - "./go/controller/product" - "./go/controller/order" - "./go/controller/user" - "./go/controller/visit" _ "github.com/jinzhu/gorm/dialects/mysql" "gopkg.in/kataras/iris.v6" "gopkg.in/kataras/iris.v6/adaptors/httprouter" "strconv" + "wemall/go/config" + "wemall/go/model" + "wemall/go/controller/admin" + "wemall/go/controller/category" + "wemall/go/controller/product" + "wemall/go/controller/order" + "wemall/go/controller/user" + "wemall/go/controller/visit" ) func main() { diff --git a/nodejs/static/javascripts/admin/actions/product/requestProduct.js b/nodejs/static/javascripts/admin/actions/product/requestProduct.js new file mode 100644 index 00000000..df4a9259 --- /dev/null +++ b/nodejs/static/javascripts/admin/actions/product/requestProduct.js @@ -0,0 +1,25 @@ +import { + REQUEST_PRODUCT, + REQUEST_PRODUCT_SUCCESS +} from '../../constants'; + +function receive(data) { + return { + type : REQUEST_PRODUCT_SUCCESS, + product : data + }; +} + +export default function(id) { + return dispatch => { + dispatch({ + type: REQUEST_PRODUCT, + }); + var url = pageConfig.apiURL + '/admin/product/:id'; + url = url.replace(':id', id); + return fetch(url) + .then(response => response.json()) + .then(json => dispatch(receive(json.data))); + }; +}; + diff --git a/nodejs/static/javascripts/admin/containers/product/EditProduct.js b/nodejs/static/javascripts/admin/containers/product/EditProduct.js new file mode 100644 index 00000000..1a30ab6f --- /dev/null +++ b/nodejs/static/javascripts/admin/containers/product/EditProduct.js @@ -0,0 +1,102 @@ +import React, { Component } from 'react'; +import { connect } from 'react-redux'; + +import { + Row, + Col, + Form, + Input, + TreeSelect +} from 'antd'; + +import requestProduct from '../actions/product/requestProduct'; +import requestCategoryList from '../actions/category/requestCategoryList'; +import Software from './Software'; +import utils from '../utils'; +import analyze from '../../sdk/analyze'; +import '../../../styles/admin/editProduct.css'; + +/* + * 管理后台,新建或编辑商品 + */ +class EditProduct extends Component { + constructor(props) { + super(props); + this.state = { + productId : this.props.routeParams.id, + parents : [] //父分类 + }; + } + componentDidMount() { + analyze.pv(); + const { dispatch } = this.props; + if (this.state.productId) { + dispatch(requestProduct(this.state.productId)); + } + dispatch(requestCategoryList()); + } + onParentsChange(value) { + console.log('onChange ', value, arguments); + this.setState({ value }); + } + render() { + let { data } = this.props; + let isLoading = this.state.productId && !data.category ? true : false; + let editLabel = this.state.productId ? '编辑' : '添加'; + + const FormItem = Form.Item; + const formItemLayout = { + labelCol: { + xs: { span: 24 }, + sm: { span: 3 }, + }, + wrapperCol: { + xs: { span: 24 }, + sm: { span: 12 }, + } + }; + + let treeData = utils.parseCategoryTree(data.categories); + + const treeProps = { + treeData, + value : this.state.value, + onChange : this.onParentsChange.bind(this), + multiple : true, + treeCheckable: true, + showCheckedStrategy: TreeSelect.SHOW_PARENT, + searchPlaceholder: '选择父分类', + style: { + width: '100%', + } + }; + + return ( +
+ + +
+
{editLabel}商品
+
+ + + +
+ +
+ +
+ +
+ ); + } +} + +const mapStateToProps = (state) => { + return { + data: state.category + }; +} + +export default connect(mapStateToProps)(EditProduct); + diff --git a/nodejs/static/javascripts/admin/reducers/index.js b/nodejs/static/javascripts/admin/reducers/index.js index 1ff28f75..8ade9e6a 100644 --- a/nodejs/static/javascripts/admin/reducers/index.js +++ b/nodejs/static/javascripts/admin/reducers/index.js @@ -2,7 +2,7 @@ import software from './software'; import systemIndex from './systemIndex'; import userAnalyze from './userAnalyze'; import orderAnalyze from './orderAnalyze'; -import productAnalyze from './productAnalyze'; +import product from './product'; import category from './category'; const reducers = { diff --git a/nodejs/static/javascripts/admin/reducers/productAnalyze.js b/nodejs/static/javascripts/admin/reducers/product.js similarity index 73% rename from nodejs/static/javascripts/admin/reducers/productAnalyze.js rename to nodejs/static/javascripts/admin/reducers/product.js index 51a69bb2..73971738 100644 --- a/nodejs/static/javascripts/admin/reducers/productAnalyze.js +++ b/nodejs/static/javascripts/admin/reducers/product.js @@ -6,7 +6,8 @@ import { let initState = { hotProducts: [], - products: [] + products : [], //产品列表 + category : null //当前查询出的产品 }; export default (state = initState, action) => { @@ -36,6 +37,18 @@ export default (state = initState, action) => { products: products }; } + case REQUEST_CATEGORY: { + return { + ...state, + product: null + }; + } + case REQUEST_CATEGORY_SUCCESS: { + return { + ...state, + product: action.product + }; + } default: { return state } diff --git a/nodejs/static/styles/admin/product/editProduct.css b/nodejs/static/styles/admin/product/editProduct.css new file mode 100644 index 00000000..1c184030 --- /dev/null +++ b/nodejs/static/styles/admin/product/editProduct.css @@ -0,0 +1,15 @@ +.product-box { + +} + +.product-title { + font-size: 20px; + margin-bottom: 6px; + color: #000; +} + +.ant-select-tree-noline_close:after { + -webkit-transform: rotate(270deg) scale(.59) !important; + -ms-transform: rotate(270deg) scale(.59) !important; + transform: rotate(270deg) scale(.59) !important; +} \ No newline at end of file