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

1.页面

 

2.品类列表展示

  1. let listBody = this.state.list.map((category, index) => {
  2.             return (
  3.                 <tr key={index}>
  4.                     <td>{category.id}</td>
  5.                     <td>{category.name}</td>
  6.                     <td>
  7.                         <a className="opear"
  8.                             onClick={(e) => this.onUpdateName(category.id, category.name)}>修改名称</a>
  9.                         {
  10.                             category.parentId === 0
  11.                             ? <Link to={`/product-category/index/${category.id}`}>查看子品类</Link>
  12.                             : null
  13.                         }
  14.                     </td>
  15.                 </tr>
  16.             );
  17.         });
  18.         return (
  19.             <div id="page-wrapper">
  20.                 <PageTitle title="品类列表">
  21.                     <div className="page-header-right">
  22.                         <Link to="/product-category/add" className="btn btn-primary">
  23.                             <i className="fa fa-plus"></i>
  24.                             <span>添加品类</span>
  25.                         </Link>
  26.                     </div>
  27.                 </PageTitle>
  28.                 <div className="row">
  29.                     <div className="col-md-12">
  30.                         <p>父品类ID: {this.state.parentCategoryId}</p>
  31.                     </div>
  32.                 </div>
  33.                 <TableList tableHeads={['品类ID', '品类名称', '操作']}>
  34.                     {listBody}
  35.                 </TableList>
  36.             </div>
  37.         );
  38.     }

 

3.加载品类列表

  1. // 加载品类列表
  2.     loadCategoryList(){
  3.        _product.getCategoryList(this.state.parentCategoryId).then(res => {
  4.            this.setState({
  5.                list : res
  6.            });
  7.        }, errMsg => {
  8.            this.setState({
  9.                list : []
  10.            });
  11.            _mm.errorTips(errMsg);
  12.        });
  13.    }

 

4.修改品类名称

  1. // 更新品类的名字
  2.     onUpdateName(categoryId, categoryName){
  3.        let newName = window.prompt('请输入新的品类名称', categoryName);
  4.        if(newName){
  5.            _product.updateCategoryName({
  6.                categoryId: categoryId,
  7.                categoryName : newName
  8.            }).then(res => {
  9.                _mm.successTips(res);
  10.                this.loadCategoryList();
  11.            }, errMsg => {
  12.                _mm.errorTips(errMsg);
  13.            });
  14.        }
  15.    }

 

5.添加品类

  1. import React from 'react';
  2. import MUtil from 'util/mm.jsx'
  3. import Product from 'service/product-service.jsx'
  4. import PageTitle from 'component/page-title/index.jsx';
  5. const _mm = new MUtil();
  6. const _product = new Product();
  7. class CategoryAdd extends React.Component{
  8.     constructor(props){
  9.         super(props);
  10.         this.state = {
  11.             categoryList : [],
  12.             parentId : 0,
  13.             categoryName : ''
  14.         };
  15.     }
  16.     componentDidMount(){
  17.         this.loadCategoryList();
  18.     }
  19.     // 加载品类列表,显示父品类列表
  20.     loadCategoryList(){
  21.         _product.getCategoryList().then(res => {
  22.             this.setState({
  23.                 categoryList : res
  24.             });
  25.         }, errMsg => {
  26.             _mm.errorTips(errMsg);
  27.         });
  28.     }
  29.     // 表单的值发生变化
  30.     onValueChange(e){
  31.         let name = e.target.name,
  32.             value = e.target.value;
  33.         this.setState({
  34.             [name] : value
  35.         });
  36.     }
  37.     // 提交
  38.     onSubmit(e){
  39.         let categoryName = this.state.categoryName.trim();
  40.         // 品类名称不为空,提交数据
  41.         if(categoryName){
  42.             _product.saveCategory({
  43.                 parentId : this.state.parentId,
  44.                 categoryName : categoryName
  45.             }).then((res) => {
  46.                 _mm.successTips(res);
  47.                 this.props.history.push('/product-category/index');
  48.             }, (errMsg) => {
  49.                 _mm.errorTips(errMsg);
  50.             });
  51.         }
  52.         // 否则,提示错误
  53.         else{
  54.             _mm.errorTips('请输入品类名称');
  55.         }
  56.     }
  57.     render(){
  58.         return (
  59.             <div id="page-wrapper">
  60.                 <PageTitle title="品类列表"/>
  61.                 <div className="row">
  62.                     <div className="col-md-12">
  63.                         <div className="form-horizontal">
  64.                             <div className="form-group">
  65.                                 <label className="col-md-2 control-label">所属品类</label>
  66.                                 <div className="col-md-5">
  67.                                     <select name="parentId"
  68.                                         className="form-control"
  69.                                         onChange={(e) => this.onValueChange(e)}>
  70.                                         <option value="0">根品类/</option>
  71.                                         {
  72.                                             this.state.categoryList.map((category, index) => {
  73.                                                 return <option value={category.id} key={index}>根品类/{category.name}</option>
  74.                                             })
  75.                                         }
  76.                                     </select>
  77.                                 </div>
  78.                             </div>
  79.                             <div className="form-group">
  80.                                 <label className="col-md-2 control-label">品类名称</label>
  81.                                 <div className="col-md-5">
  82.                                     <input type="text" className="form-control"
  83.                                         placeholder="请输入品类名称"
  84.                                         name="categoryName"
  85.                                         value={this.state.name}
  86.                                         onChange={(e) => this.onValueChange(e)}/>
  87.                                 </div>
  88.                             </div>
  89.                             <div className="form-group">
  90.                                 <div className="col-md-offset-2 col-md-10">
  91.                                     <button type="submit" className="btn btn-primary"
  92.                                         onClick={(e) => {this.onSubmit(e)}}>提交</button>
  93.                                 </div>
  94.                             </div>
  95.                         </div>
  96.                     </div>
  97.                 </div>
  98.             </div>
  99.         );
  100.     }
  101. }
  102. export default CategoryAdd;

更多专业前端知识,请上 【猿2048】www.mk2048.com

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/363091.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

hdu5111 树链剖分,主席树

hdu5111 链接 hdu 思路 先考虑序列上如何解决。 1 3 2 5 4 1 2 4 5 3 这个序列变成 1 2 3 4 5 1 3 5 5 2 是对答案没有影响的(显然)。 然后查询操作\(l,r,L,R\)就是&#xff0c; 一段连续的区间\([L,R]\)内包含几个值在\([l,r]\)的数字个数. 主席树就可以做了。\(query(rt[L-1]…

使用log4j监视和筛选应用程序日志到邮件

在今天的帖子中&#xff0c;我将向您展示如何将日志语句过滤为警告电子邮件。 这是出于监视我正在处理的一个应用程序的一些关键点的需要。 您可以使用一些工具来执行应用程序监视。 我不会详细介绍这些工具&#xff0c;但有时让应用程序发送警告电子邮件会更容易。 我主要将l…

FF

ietab :IE 内核tab mix plus &#xff1a;管理TABfirebug live http headersminimizeToTray安装插件方法&#xff1a;file-open file - select "*.xpi"https://addons.mozilla.org/en-US/firefox/https://addons.mozilla.org/en-US/firefox/addon/1419http://l…

Vue node.js商城-购物车模块

一、渲染购物车列表页面 新建src/views/Cart.vue获取cartList购物车列表数据就可以在页面中渲染出该用户的购物车列表数据 data(){ return { cartList:[] // 购物车商品列表 } }, mounted:function(){ this.init(); }, methods:{ init(){ // 初始化商品数据 axios.get(/users/…

RxJava + Java8 + Java EE 7 + Arquillian =幸福

微服务是一种体系结构样式&#xff0c;其中每个服务都实现为一个独立的系统。 他们可以使用自己的持久性系统&#xff08;尽管不是强制性的&#xff09;&#xff0c;部署&#xff0c;语言等。 由于系统由一个以上的服务组成&#xff0c;因此每个服务将与其他服务通信&#xff…

C# -- RSA加密与解密

1. RSA加密与解密 -- 使用公钥加密、私钥解密 public class RSATool{public string Encrypt(string strText, string strPublicKey){RSACryptoServiceProvider rsa new RSACryptoServiceProvider();rsa.FromXmlString(strPublicKey);byte[] byteText Encoding.UTF8.GetByt…

React后台管理系统-file-uploader组件

1.React文件上传组件github地址: https://github.com/SoAanyip/React-FileUpload 2.Util里边新建file-uploader文件夹&#xff0c;里边新建index.jsx import React from react; import FileUpload from ./react-fileupload.jsx; class FileUploader extends React.Component{…

经典代码收藏

1. οncοntextmenu"window.event.returnvaluefalse" 将彻底屏蔽鼠标右键 <table border οncοntextmenureturn(false)><td>no</table> 可用于Table 2. <body onselectstart"return false"> 取…

js 实现文件导出、文件下载

1、通过创建a标签&#xff0c;实现下载功能 function downLoad(content,fileName){var aEle document.createElement("a");// 创建a标签// blob new Blob([content]); aEle.download fileName;// 设置下载文件的文件名//aEle.href URL.createObjectUrl(blob);aEl…

VMware Station NAT上网模式配置

转载于:https://www.cnblogs.com/MimiSnowing/p/10718235.html

JavaFX技巧10:自定义复合控件

用JavaFX编写自定义控件是一个简单直接的过程。 需要一个控件类来控制控件的状态&#xff08;因此命名&#xff09;。 外观需要控件的外观。 而且通常不是用于自定义外观CSS文件。 控件的常用方法是将其使用的节点隐藏在其外观类中。 例如&#xff0c; TextField控件使用javaf…

dell服务器安装系统注意之二.(2003/xp 的sn)

刚找回笔记,以前写的东西记了下来,是关于dell服务器上安装系统的.列表如下1、开机看画面提示&#xff0c;提示有“ctrm”--->当然入到去就要看提示“clean”磁盘的资料啦。&#xff08;除非你不清除&#xff09;---》根据提示进入-》easy setup----》提示f10保存---》ok了。…

React后台管理系统-首页Home组件

1.Home组件要显示用户总数、商品总数和订单总数&#xff0c;数据请求后端的 /manage/statistic/base_count.do接口&#xff0c;返回的是 this.state { userCount : -, productCount : -, orderCount : - } //页面挂载之后请求数据componentDidMount(){ this.loadCount(); } lo…

js 实现简单的轮询

在实际开发中&#xff0c;经常会有轮询的效果。 1、js实现轮询效果》使用setTimeout&#xff0c;clearTimeout方法 function setTimer () {let timeraxios.post(url, params).then(function (res) {if(res){console.log(res);timer setTimeout(() > {this.setTimer()}, 500…

MyBatis第一天课上笔记

[今日课程大纲]高级软件介绍(部分)MySql 数据库建库建表语句强调命名规范强调基于MVC 开发模式完成单表查询和新增Eclipse 中项目默认发布路径高级课程大纲介绍框架是什么MyBatis 简介MyBatis 搭建流程数据库连接池和JNDI 复习搭建流程详解( 全局配置文件,resultType 原理及Aut…

JAX-RS 2.0的新功能– @BeanParam批注

至少可以说JAX-RS很棒&#xff0c;也是我的最爱之一&#xff01; 为什么&#xff1f; 功能丰富 直观&#xff08;因此学习曲线不那么陡峭&#xff09; 易于使用和开发 具有出色的RI – Jersey &#xff0c; RestEasy等 有足够的JAX-RS粉丝可以添加此内容&#xff01; JAX…

js操作json方法总结

相对于前端的老铁来说JSon并不陌生&#xff0c;JSON JavaScript Object Notation 是一种轻量级的数据交换格式&#xff0c;采用完全独立于语言的文本格式&#xff0c;是一种理想的数据交换格式。 json可以以对象的传递数据&#xff0c;也可以以字符串的形式传递数据&#xff0c…

反编译工具Reflector下载(集成FileGenerator和FileDisassembler)

Reflector是一款比较强大的反编译工具,相信很多朋友都用过它,但reflector本身有很多局限性,比如只能一个一个的查看方法等,但幸好 reflector支持插件功能目前网上有很多reflector的插件,本人找取了两个应用范围很广,并且广受好评的插 件:Reflector.FileDisassembler和Reflector…

带有自定义模块的JBoss EAP上的骆驼

Apache Camel —最好的开源集成库 Apache Camel是一个很棒的开放源代码集成库&#xff0c;可以用作ESB的主干或在独立的应用程序中进行系统的路由&#xff0c;转换或中介&#xff08;请参阅&#xff1a;集成多个系统&#xff09;。 Camel非常通用&#xff0c;不会迫使用户部署到…

Java中的读写锁

一、读写锁 1、初识读写锁 a&#xff09;Java中的锁——Lock和synchronized中介绍的ReentrantLock和synchronized基本上都是排它锁&#xff0c;意味着这些锁在同一时刻只允许一个线程进行访问&#xff0c;而读写锁在同一时刻可以允许多个读线程访问&#xff0c;在写线程访问的时…