React后台管理系统-品类的增加、修改和查看
1.页面

2.品类列表展示
- let listBody = this.state.list.map((category, index) => {
- return (
- <tr key={index}>
- <td>{category.id}</td>
- <td>{category.name}</td>
- <td>
- <a className="opear"
- onClick={(e) => this.onUpdateName(category.id, category.name)}>修改名称</a>
- {
- category.parentId === 0
- ? <Link to={`/product-category/index/${category.id}`}>查看子品类</Link>
- : null
- }
- </td>
- </tr>
- );
- });
- return (
- <div id="page-wrapper">
- <PageTitle title="品类列表">
- <div className="page-header-right">
- <Link to="/product-category/add" className="btn btn-primary">
- <i className="fa fa-plus"></i>
- <span>添加品类</span>
- </Link>
- </div>
- </PageTitle>
- <div className="row">
- <div className="col-md-12">
- <p>父品类ID: {this.state.parentCategoryId}</p>
- </div>
- </div>
- <TableList tableHeads={['品类ID', '品类名称', '操作']}>
- {listBody}
- </TableList>
- </div>
- );
- }
3.加载品类列表
- // 加载品类列表
- loadCategoryList(){
- _product.getCategoryList(this.state.parentCategoryId).then(res => {
- this.setState({
- list : res
- });
- }, errMsg => {
- this.setState({
- list : []
- });
- _mm.errorTips(errMsg);
- });
- }
4.修改品类名称
- // 更新品类的名字
- onUpdateName(categoryId, categoryName){
- let newName = window.prompt('请输入新的品类名称', categoryName);
- if(newName){
- _product.updateCategoryName({
- categoryId: categoryId,
- categoryName : newName
- }).then(res => {
- _mm.successTips(res);
- this.loadCategoryList();
- }, errMsg => {
- _mm.errorTips(errMsg);
- });
- }
- }
5.添加品类
- import React from 'react';
- import MUtil from 'util/mm.jsx'
- import Product from 'service/product-service.jsx'
- import PageTitle from 'component/page-title/index.jsx';
- const _mm = new MUtil();
- const _product = new Product();
- class CategoryAdd extends React.Component{
- constructor(props){
- super(props);
- this.state = {
- categoryList : [],
- parentId : 0,
- categoryName : ''
- };
- }
- componentDidMount(){
- this.loadCategoryList();
- }
- // 加载品类列表,显示父品类列表
- loadCategoryList(){
- _product.getCategoryList().then(res => {
- this.setState({
- categoryList : res
- });
- }, errMsg => {
- _mm.errorTips(errMsg);
- });
- }
- // 表单的值发生变化
- onValueChange(e){
- let name = e.target.name,
- value = e.target.value;
- this.setState({
- [name] : value
- });
- }
- // 提交
- onSubmit(e){
- let categoryName = this.state.categoryName.trim();
- // 品类名称不为空,提交数据
- if(categoryName){
- _product.saveCategory({
- parentId : this.state.parentId,
- categoryName : categoryName
- }).then((res) => {
- _mm.successTips(res);
- this.props.history.push('/product-category/index');
- }, (errMsg) => {
- _mm.errorTips(errMsg);
- });
- }
- // 否则,提示错误
- else{
- _mm.errorTips('请输入品类名称');
- }
- }
- render(){
- return (
- <div id="page-wrapper">
- <PageTitle title="品类列表"/>
- <div className="row">
- <div className="col-md-12">
- <div className="form-horizontal">
- <div className="form-group">
- <label className="col-md-2 control-label">所属品类</label>
- <div className="col-md-5">
- <select name="parentId"
- className="form-control"
- onChange={(e) => this.onValueChange(e)}>
- <option value="">根品类/</option>
- {
- this.state.categoryList.map((category, index) => {
- return <option value={category.id} key={index}>根品类/{category.name}</option>
- })
- }
- </select>
- </div>
- </div>
- <div className="form-group">
- <label className="col-md-2 control-label">品类名称</label>
- <div className="col-md-5">
- <input type="text" className="form-control"
- placeholder="请输入品类名称"
- name="categoryName"
- value={this.state.name}
- onChange={(e) => this.onValueChange(e)}/>
- </div>
- </div>
- <div className="form-group">
- <div className="col-md-offset-2 col-md-10">
- <button type="submit" className="btn btn-primary"
- onClick={(e) => {this.onSubmit(e)}}>提交</button>
- </div>
- </div>
- </div>
- </div>
- </div>
- </div>
- );
- }
- }
- export default CategoryAdd;
React后台管理系统-品类的增加、修改和查看的更多相关文章
- React后台管理系统-品类选择器二级联动组件
1.页面大致是这个样子 2.页面结构 <div className="col-md-10"> <select name="&quo ...
- 《React后台管理系统实战 :四》产品分类管理页:添加产品分类、修改(更新)产品分类
一.静态页面 目录结构 F:\Test\react-demo\admin-client\src\pages\admin\category add-cate-form.jsx index.jsx ind ...
- react后台管理系统路由方案及react-router原理解析
最近做了一个后台管理系统主体框架是基于React进行开发的,因此系统的路由管理,选用了react-router(4.3.1)插件进行路由页面的管理配置. 实现原理剖析 1.hash的方式 ...
- 《React后台管理系统实战 :一》:目录结构、引入antd、引入路由、写login页面、使用antd的form登录组件、form前台验证、高阶函数/组件
实战 上接,笔记:https://blog.csdn.net/u010132177/article/details/104150177 https://gitee.com/pasaulis/react ...
- 【共享单车】—— React后台管理系统开发手记:主页面架构设计
前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...
- 《React后台管理系统实战 :二》antd左导航:cmd批量创建子/目录、用antd进行页面布局、分离左导航为单独组件、子路由、动态写左导航、css样式相对陷阱
一.admin页面布局及路由创建 0)cmd批量创建目录及子目录 //创建各个目录,及charts和子目录bar md home category product role user charts\b ...
- 【共享单车】—— React后台管理系统开发手记:UI菜单各个组件使用(Andt UI组件)
前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...
- 《React后台管理系统实战 零》:基础笔记
day01 1. 项目开发准备 1). 描述项目 2). 技术选型 3). API接口/接口文档/测试接口 2. 启动项目开发 1). 使用react脚手架创建项目 2). 开发环境运行: npm s ...
- React后台管理系统-添加商品组件
引入了CategorySelector 二级联动组件.FileUploader图片上传组件和RichEditor富文本编辑组件 import React from 'react'; import MU ...
随机推荐
- Unity 在Inspector面板,脚本前面的激活对勾
写个脚本,把它挂在一个游戏对象上: using System.Collections; using System.Collections.Generic; using UnityEngine; pub ...
- windows 7下安装MySQL5.6
一. 软件下载 从MySql官网上下载响应的版本,我的是5.6.17. 二.安装过程 以管理员权限运行安装程序,收集信息. 选择安装MySql产品,如果之前有安装过,那么就选择更新了. 同意Licen ...
- hduoj 2602Bone Collector
Bone Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- 网站启用GZip压缩后,速度快了3倍!
GZip压缩,是一种网站速度优化技术,也是一把SEO优化利器,许多网站都采用了这种技术,以达到提升网页打开速度.缩短网页打开时间的目的. 本文是一篇研究性文章,将通过某个案例来给大家显示网站采用GZi ...
- 浅入分析Linux
Linux 操作系统必须完成的两个主要目的 与硬件部分交互, 为包含在硬件平台上的所有底层可编程部件提供服务 为运行在计算机系统上的应用程序(即所谓的用户空间)提供执行环境 一些操作系统运行所有的用户 ...
- ajax多次请求的一个效果思路
首先页面加载时候显示遮罩层 jQuery(function() { show_dialog(); //tianxie(); }); 定义一个全局数组,用于存放问题id var qar = []; 循环 ...
- MSSql中profiler工具介绍,
第一次使用profiler感觉真的是很方便. 他的作用可能有很多,但是我只是简单其中一点,就是查看某一时刻数据库执行了哪些操作,执行了哪些语句,执行语句所花费的时间.都可以很方便的查到,这对于我们优化 ...
- vue将数据绑定到属性中
*必须使用[] <tr v-for="(p,index) in prodects"> @*v-bind:class="styleType(index)&quo ...
- C++中的虚函数表
(感谢http://blog.csdn.net/haoel/article/details/1948051/) C++中的虚函数的作用主要是实现了多态的机制. 多态,简而言之就是用父类型别的指针指向其 ...
- ORACLE:毫秒与日期的相互转换,获取某天的信息
毫秒转换为日期 SELECT TO_CHAR(1406538765000 / (1000 * 60 * 60 * 24) + TO_DATE('1970-01-01 08:00:00', 'YYYY- ...