Skip to content

Commit

Permalink
编辑商品分类前端页面已完成
Browse files Browse the repository at this point in the history
  • Loading branch information
shen100 committed May 17, 2017
1 parent 2cfa502 commit cc9d906
Show file tree
Hide file tree
Showing 11 changed files with 287 additions and 65 deletions.
2 changes: 1 addition & 1 deletion go/controller/category/category.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func Save(ctx *iris.Context) {
return
}

var categoryJSON model.Category = category
var categoryJSON = category
if createOrUpdate == "update" {
categoryJSON = updatedCategory
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
/* 前后端通信相关的配置,注释只允许使用多行方式 */
{
package ueditor

// UEditor 前后端通信相关的配置,注释只允许使用多行方式
var UEditor = map[string]interface{}{
/* 上传图片配置项 */
"imageActionName": "uploadImage", /* 执行上传图片的action名称 */
"imageFieldName": "upFile", /* 提交的图片表单名称 */
"imageMaxSize": 2048000, /* 上传大小限制,单位B */
"imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */
"imageAllowFiles": []string{".png", ".jpg", ".jpeg", ".gif", ".bmp"}, /* 上传图片格式显示 */
"imageCompressEnable": true, /* 是否压缩图片,默认是true */
"imageCompressBorder": 1600, /* 图片压缩最长边限制 */
"imageInsertAlign": "none", /* 插入的图片浮动方式 */
Expand Down Expand Up @@ -38,57 +40,56 @@
"snapscreenInsertAlign": "none", /* 插入的图片浮动方式 */

/* 抓取远程图片配置 */
"catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"],
"catcherLocalDomain": []string{"127.0.0.1", "localhost", "img.baidu.com"},
"catcherActionName": "catchimage", /* 执行抓取远程图片的action名称 */
"catcherFieldName": "source", /* 提交的图片列表表单名称 */
"catcherPathFormat": "/ueditor/php/upload/image/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"catcherUrlPrefix": "", /* 图片访问路径前缀 */
"catcherMaxSize": 2048000, /* 上传大小限制,单位B */
"catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 抓取图片格式显示 */
"catcherAllowFiles": []string{".png", ".jpg", ".jpeg", ".gif", ".bmp"}, /* 抓取图片格式显示 */

/* 上传视频配置 */
"videoActionName": "uploadvideo", /* 执行上传视频的action名称 */
"videoFieldName": "upfile", /* 提交的视频表单名称 */
"videoPathFormat": "/ueditor/php/upload/video/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"videoUrlPrefix": "", /* 视频访问路径前缀 */
"videoMaxSize": 102400000, /* 上传大小限制,单位B,默认100MB */
"videoAllowFiles": [
"videoAllowFiles": []string{
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"], /* 上传视频格式显示 */
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid"}, /* 上传视频格式显示 */

/* 上传文件配置 */
"fileActionName": "uploadfile", /* controller里,执行上传视频的action名称 */
"fileFieldName": "upfile", /* 提交的文件表单名称 */
"filePathFormat": "/ueditor/php/upload/file/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
"fileUrlPrefix": "", /* 文件访问路径前缀 */
"fileMaxSize": 51200000, /* 上传大小限制,单位B,默认50MB */
"fileAllowFiles": [
"fileAllowFiles": []string{
".png", ".jpg", ".jpeg", ".gif", ".bmp",
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
], /* 上传文件格式显示 */
".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml",
}, /* 上传文件格式显示 */

/* 列出指定目录下的图片 */
"imageManagerActionName": "listimage", /* 执行图片管理的action名称 */
"imageManagerListPath": "/ueditor/php/upload/image/", /* 指定要列出图片的目录 */
"imageManagerListSize": 20, /* 每次列出文件数量 */
"imageManagerUrlPrefix": "", /* 图片访问路径前缀 */
"imageManagerInsertAlign": "none", /* 插入的图片浮动方式 */
"imageManagerAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 列出的文件类型 */
"imageManagerAllowFiles": []string{".png", ".jpg", ".jpeg", ".gif", ".bmp"}, /* 列出的文件类型 */

/* 列出指定目录下的文件 */
"fileManagerActionName": "listfile", /* 执行文件管理的action名称 */
"fileManagerListPath": "/ueditor/php/upload/file/", /* 指定要列出文件的目录 */
"fileManagerUrlPrefix": "", /* 文件访问路径前缀 */
"fileManagerListSize": 20, /* 每次列出文件数量 */
"fileManagerAllowFiles": [
"fileManagerAllowFiles": []string{
".png", ".jpg", ".jpeg", ".gif", ".bmp",
".flv", ".swf", ".mkv", ".avi", ".rm", ".rmvb", ".mpeg", ".mpg",
".ogg", ".ogv", ".mov", ".wmv", ".mp4", ".webm", ".mp3", ".wav", ".mid",
".rar", ".zip", ".tar", ".gz", ".7z", ".bz2", ".cab", ".iso",
".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml"
] /* 列出的文件类型 */

".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".pdf", ".txt", ".md", ".xml",
}, /* 列出的文件类型 */
}
33 changes: 1 addition & 32 deletions go/controller/ueditor/ueditor.go
Original file line number Diff line number Diff line change
@@ -1,43 +1,18 @@
package ueditor

import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"mime"
"os"
"time"
"strconv"
"strings"
"regexp"
"gopkg.in/kataras/iris.v6"
"github.com/satori/go.uuid"
"wemall/go/config"
"wemall/go/utils"
)

func readConfig(filename string) (map[string]interface{}, error) {
bytes, err := ioutil.ReadFile(filename)
if err != nil {
fmt.Println("ReadFile: ", err.Error())
return nil, err
}

configStr := string(bytes[:])
reg := regexp.MustCompile(`/\*.*\*/`)

configStr = reg.ReplaceAllString(configStr, "")
bytes = []byte(configStr)

var result map[string]interface{}

if err := json.Unmarshal(bytes, &result); err != nil {
fmt.Println("Unmarshal: ", err.Error())
return nil, err
}
return result, nil
}

func upload(ctx *iris.Context) {
errResData := iris.Map{
Expand Down Expand Up @@ -141,13 +116,7 @@ func Handler(ctx *iris.Context) {
action := ctx.FormValue("action")
switch action {
case "config": {
var result map[string]interface{}
var err error
if result, err = readConfig("./go/controller/ueditor/config.json"); err != nil {
ctx.JSON(iris.StatusOK, iris.Map{})
return
}
ctx.JSON(iris.StatusOK, result)
ctx.JSON(iris.StatusOK, UEditor)
break
}
case "uploadImage": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
REQUEST_SAVE_CATEGORY,
REQUEST_SAVE_CATEGORY_SUCCESS,
} from '../../constants';

function receive(data) {
return {
type : REQUEST_SAVE_CATEGORY_SUCCESS,
category : data.category
};
}

export default function(category) {
return dispatch => {
var url = pageConfig.apiPath + '/admin/category/update';
return fetch(url, {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(category)
})
.then(response => response.json())
.then(json => dispatch(receive(json.data)));
};
};

Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export default function(product) {
var url = pageConfig.apiPath + '/admin/product/update';
var categories = [];
for (var i = 0; i < product.categories.length; i++) {
var idArr = product.categories[i].split('-');
categories.push({
id: parseInt(product.categories[i].split('-')[1])
id: parseInt(idArr[idArr.length - 1])
});
}
var reqData ={
Expand Down
160 changes: 160 additions & 0 deletions nodejs/static/javascripts/admin/containers/category/EditCategory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';

import {
Button,
Row,
Col,
Form,
Input,
InputNumber,
TreeSelect
} from 'antd';

import requestCategory from '../../actions/category/requestCategory';
import requestSaveCategory from '../../actions/category/requestSaveCategory';
import requestCategoryList from '../../actions/category/requestCategoryList';
import Software from '../Software';
import utils from '../../utils';
import analyze from '../../../sdk/analyze';
import '../../../../styles/admin/category/editCategory.css';

/*
* 管理后台,新建或编辑商品分类
*/
class EitCategory extends Component {
constructor(props) {
super(props);
this.onNameBlur = this.onNameBlur.bind(this);
this.onCategoryChange = this.onCategoryChange.bind(this);
this.onRemarkBlur = this.onRemarkBlur.bind(this);
this.onSubmit = this.onSubmit.bind(this);

this.state = {
categoryId : this.props.routeParams.id,
parentId : '',
parentKey : [], //父分类, 初始为数组是为了让树形控件显示placeholder
name : '',
remark : '',
treeData : []
};
}
componentDidMount() {
analyze.pv();
const { dispatch } = this.props;
if (this.state.categoryId) {
dispatch(requestCategory(this.state.categoryId));
}
dispatch(requestCategoryList());
}
componentWillReceiveProps(nextProps) {
var category = nextProps.data.category;
var categories = nextProps.data.categories;
if (category && categories && categories.length > 0) {
this.setState({
categoryId : category.id,
parentId : category.parentId,
parentKey : utils.parseTreeNodeKey(categories, category.parentId),
name : category.name,
remark : category.remark,
treeData : utils.parseTree(categories, {
withRoot: true
})
});
}
}
onNameBlur(event) {
this.setState({ name: event.target.value });
}
onCategoryChange(value) {
var arr = value.split('-');
this.setState({
parentId : arr[arr.length - 1],
parentKey : value
});
}
onRemarkBlur(event) {
this.setState({ remark: event.target.value });
}
onSubmit() {
const { dispatch } = this.props;
dispatch(requestSaveCategory({
id : this.state.categoryId,
name : this.state.name,
parentId : this.state.parentId,
remark : this.state.remark
}));
}
render() {
let { data } = this.props;
let editLabel = this.state.categoryId ? '编辑' : '添加';
let isLoading = this.state.categoryId
&& (!data.category || !data.categories || data.categories.length <= 0)
? true : false;

let name = this.state.name;
let remark = this.state.remark;
let treeData = this.state.treeData;

const FormItem = Form.Item;
const formItemLayout = {
labelCol: {
xs: { span: 24 },
sm: { span: 3 },
},
wrapperCol: {
xs: { span: 24 },
sm: { span: 12 },
}
};

return (
<div>
<Row gutter={24}>
<Col span={24}>
<div className="category-box">
<div className="category-title">{editLabel}商品分类</div>
{
isLoading ? null :
<Form>
<FormItem {...formItemLayout} label="名称">
<Input defaultValue={name} onBlur={this.onNameBlur}/>
</FormItem>
<FormItem {...formItemLayout} label="父分类">
<TreeSelect
style={{ width: '100%' }}
value={this.state.parentKey}
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
treeData={treeData}
placeholder="请选择父分类"
treeDefaultExpandAll
onChange={this.onCategoryChange} />
</FormItem>
<FormItem {...formItemLayout} label="备注">
<Input type="textarea" defaultValue={remark} rows={4} onBlur={this.onRemarkBlur}/>
</FormItem>
</Form>
}
</div>
</Col>
<Col span={24}>
<Col span={15} className="submit-box">
<Button onClick={this.onSubmit} type="primary" size="large">保存</Button>
<Button className="submit-cancel-btn" size="large">取消</Button>
</Col>
</Col>
</Row>
<Software />
</div>
);
}
}

const mapStateToProps = (state) => {
return {
data: state.category
};
}

export default connect(mapStateToProps)(EitCategory);

Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,14 @@ class EditProduct extends Component {
});
}
componentWillReceiveProps(nextProps) {
var product = nextProps.data.product;
if (product) {
var product = nextProps.data.product;
var allCategories = nextProps.data.categories;
if (product && allCategories && allCategories.length > 0) {
var categories = [];
for (var i = 0; i < product.categories.length; i++) {
var parentId = product.categories[i].parentId;
var id = product.categories[i].id;
categories.push(parentId + '-' + id);
categories.push(utils.parseTreeNodeKey(allCategories, id));
}
this.setState({
productId : product.id,
Expand Down Expand Up @@ -186,7 +187,7 @@ class EditProduct extends Component {
}
};

let treeData = utils.parseCategoryTree(data.categories);
let treeData = utils.parseTree(data.categories);

const treeProps = {
treeData,
Expand Down
4 changes: 2 additions & 2 deletions nodejs/static/javascripts/admin/reducers/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from '../constants';

let initState = {
category : null,
categories : []
category : null,
categories : []
};

export default (state = initState, action) => {
Expand Down
Loading

0 comments on commit cc9d906

Please sign in to comment.