React后台管理系统-后台接口封装
1新建文件夹 service ,里边建4个文件,分别是statistic-service.jsx 首页数据统计接口, user-service.jsx用户接口, product-service.jsx产品接口,order-service.jx订单接口

2.首页数据统计接口statistic-service
mm.jsx是封装的ajax请求,在上一边博客里边有讲到
- import MUtil from 'util/mm.jsx'
- const _mm = new MUtil();
- class Statistic{
- // 首页数据统计
- getHomeCount(){
- return _mm.request({
- url: '/manage/statistic/base_count.do'
- });
- }
- }
- export default Statistic;
3. 用户接口user-service
- import MUtil from 'util/mm.jsx'
- const _mm = new MUtil();
- class User{
- // 用户登录
- login(loginInfo){
- return _mm.request({
- type: 'post',
- url: '/manage/user/login.do',
- data: loginInfo
- });
- }
- // 检查登录接口的数据是不是合法
- checkLoginInfo(loginInfo){
- let username = $.trim(loginInfo.username),
- password = $.trim(loginInfo.password);
- // 判断用户名为空
- if(typeof username !== 'string' || username.length ===0){
- return {
- status: false,
- msg: '用户名不能为空!'
- }
- }
- // 判断密码为空
- if(typeof password !== 'string' || password.length ===0){
- return {
- status: false,
- msg: '密码不能为空!'
- }
- }
- return {
- status : true,
- msg : '验证通过'
- }
- }
- // 退出登录
- logout(){
- return _mm.request({
- type : 'post',
- url : '/user/logout.do'
- });
- }
- getUserList(pageNum){
- return _mm.request({
- type : 'post',
- url : '/manage/user/list.do',
- data : {
- pageNum : pageNum
- }
- });
- }
- }
- export default User;
4.产品接口product-service
- import MUtil from 'util/mm.jsx'
- const _mm = new MUtil();
- class Product{
- // 获取商品列表
- getProductList(listParam){
- let url = '',
- data = {};
- if(listParam.listType === 'list'){
- url = '/manage/product/list.do';
- data.pageNum = listParam.pageNum;
- }else if(listParam.listType === 'search'){
- url = '/manage/product/search.do';
- data.pageNum = listParam.pageNum;
- data[listParam.searchType] = listParam.keyword;
- }
- return _mm.request({
- type : 'post',
- url : url,
- data : data
- });
- }
- // 获取商品详情
- getProduct(productId){
- return _mm.request({
- type : 'post',
- url : '/manage/product/detail.do',
- data : {
- productId : productId || 0
- }
- });
- }
- // 检查保存商品的表单数据
- checkProduct(product){
- let result = {
- status: true,
- msg: '验证通过'
- };
- // 判断用户名为空
- if(typeof product.name !== 'string' || product.name.length ===0){
- return {
- status: false,
- msg: '商品名称不能为空!'
- }
- }
- // 判断描述不能为空
- if(typeof product.subtitle !== 'string' || product.subtitle.length ===0){
- return {
- status: false,
- msg: '商品描述不能为空!'
- }
- }
- // 验证品类ID
- if(typeof product.categoryId !== 'number' || !(product.categoryId > 0)){
- return {
- status: false,
- msg: '请选择商品品类!'
- }
- }
- // 判断商品价格为数字,且大于0
- if(typeof product.price !== 'number' || !(product.price >= 0)){
- return {
- status: false,
- msg: '请输入正确的商品价格!'
- }
- }
- // 判断库存为数字,且大于或等于0
- if(typeof product.stock !== 'number' || !(product.stock >= 0)){
- return {
- status: false,
- msg: '请输入正确的库存数量!'
- }
- }
- return result;
- }
- // 保存商品
- saveProduct(product){
- return _mm.request({
- type : 'post',
- url : '/manage/product/save.do',
- data : product
- });
- }
- // 变更商品销售状态
- setProductStatus(productInfo){
- return _mm.request({
- type : 'post',
- url : '/manage/product/set_sale_status.do',
- data : productInfo
- });
- }
- //查找一级品类列表
- getCategoryList(parentCategoryId){
- return _mm.request({
- type : 'post',
- url : '/manage/category/get_category.do',
- data : {
- //没有传的话默认值就是0
- categoryId : parentCategoryId || 0
- }
- });
- }
- // 新增品类
- saveCategory(category){
- return _mm.request({
- type : 'post',
- url : '/manage/category/add_category.do',
- data : category
- });
- }
- // 修改品类名称
- updateCategoryName(category){
- return _mm.request({
- type : 'post',
- url : '/manage/category/set_category_name.do',
- data : category
- });
- }
- }
- export default Product;
5.订单接口order-service.jx
- import MUtil from 'util/mm.jsx'
- const _mm = new MUtil();
- class Order{
- // 获取订单列表
- getOrderList(listParam){
- let url = '',
- data = {};
- if(listParam.listType === 'list'){
- url = '/manage/order/list.do';
- data.pageNum = listParam.pageNum;
- }else if(listParam.listType === 'search'){
- url = '/manage/order/search.do';
- data.pageNum = listParam.pageNum;
- data.orderNo = listParam.orderNo;
- }
- return _mm.request({
- type : 'post',
- url : url,
- data : data
- });
- }
- // 获取订单详情
- getOrderDetail(orderNumber){
- return _mm.request({
- type : 'post',
- url : '/manage/order/detail.do',
- data : {
- orderNo : orderNumber
- }
- });
- }
- sendGoods(orderNumber){
- return _mm.request({
- type : 'post',
- url : '/manage/order/send_goods.do',
- data : {
- orderNo : orderNumber
- }
- });
- }
- }
- export default Order;
6.解决跨域问题
在webpack.config里边 devserverr 里边的proxy配置即可解决

7.页面引入和使用
- import Statistic from 'service/statistic-service.jsx'
- const _statistic = new Statistic();
- _statistic.getHomeCount().then(res => {
- this.setState(res);
- }, errMsg => {
- _mm.errorTips(errMsg);
- });
React后台管理系统-后台接口封装的更多相关文章
- React后台管理系统-ajax请求封装
1.新建文件夹 util , 在util里边新建 mm.jsx文件 2.使用jquery里边的ajax发送请求,回调用promise,返回一个promise对象 request(param){ ...
- 使用react全家桶制作博客后台管理系统
前面的话 笔者在做一个完整的博客上线项目,包括前台.后台.后端接口和服务器配置.本文将详细介绍使用react全家桶制作的博客后台管理系统 概述 该项目是基于react全家桶(React.React-r ...
- 使用React全家桶搭建一个后台管理系统
引子 学生时代为了掌握某个知识点会不断地做习题,做总结,步入岗位之后何尝不是一样呢?做业务就如同做习题,如果‘课后’适当地进行总结,必然更快地提升自己的水平. 由于公司采用的react+node的技术 ...
- 使用react全家桶制作博客后台管理系统 网站PWA升级 移动端常见问题处理 循序渐进学.Net Core Web Api开发系列【4】:前端访问WebApi [Abp 源码分析]四、模块配置 [Abp 源码分析]三、依赖注入
使用react全家桶制作博客后台管理系统 前面的话 笔者在做一个完整的博客上线项目,包括前台.后台.后端接口和服务器配置.本文将详细介绍使用react全家桶制作的博客后台管理系统 概述 该项目是基 ...
- 《React后台管理系统实战 :一》:目录结构、引入antd、引入路由、写login页面、使用antd的form登录组件、form前台验证、高阶函数/组件
实战 上接,笔记:https://blog.csdn.net/u010132177/article/details/104150177 https://gitee.com/pasaulis/react ...
- React版/Vue版都齐了,开源一套【特别】的后台管理系统...
本项目主要基于Elux+Antd构建,包含React版本和Vue版本,旨在提供给大家一个简单基础.开箱即用的后台管理系统通用模版,主要包含运行环境.脚手架.代码风格.基本Layout.状态管理.路由管 ...
- react后台管理系统路由方案及react-router原理解析
最近做了一个后台管理系统主体框架是基于React进行开发的,因此系统的路由管理,选用了react-router(4.3.1)插件进行路由页面的管理配置. 实现原理剖析 1.hash的方式 ...
- 【共享单车】—— React后台管理系统开发手记:主页面架构设计
前言:以下内容基于React全家桶+AntD实战课程的学习实践过程记录.最终成果github地址:https://github.com/66Web/react-antd-manager,欢迎star. ...
- Vue + Element-ui实现后台管理系统(4)---封装一个ECharts组件的一点思路
封装一个ECharts组件的一点思路 有关后台管理系统之前写过三遍博客,看这篇之前最好先看下这三篇博客.另外这里只展示关键部分代码,项目代码放在github上: mall-manage-system ...
随机推荐
- kubectl 命令
Kubectl 命令表 kubectl run kubectl expose kubectl annotate kubectl autoscale kubectl convert kubectl cr ...
- 洛谷P2846 光开关Light Switching
题目描述 灯是由高科技--外星人鼠标操控的.你只要左击两个灯所连的鼠标, 这两个灯,以及之间的灯都会由暗变亮,或由亮变暗.右击两个灯所连的鼠 标,你就可以知道这两个灯,以及之间的灯有多少灯是亮的.起初 ...
- promise封装小程序的蓝牙类
// pages/bluetooth/bluetooth.js import { BluetoothMode } from '../../models/bluetooth.js' import {Sy ...
- 虚拟机上安装Cell节点(12.1.2.3.3)
安装介质下载 打开firefox,输入:https://edelivery.oracle.com 点击"Sign In",输入帐号.密码,登陆edelivery网站. ...
- htmlunit最具有参考意义项目
### HtmlUnit What? - 项目1 https://gitee.com/dgwcode/spiderTmallTradeInfo - 项目2 https://gitee.com/dgwc ...
- Spring学习(二)Spring的bean管理(XML)
Bean的实例化方式 1.在Spring里面通过配置文件创建对象 2.bean实例化的三种方式第一种:使用类的无参数构造函数创建(最常用的方式,第2种和第3种方法一般不用) 如果类里面没有无参的构造函 ...
- 036 Valid Sudoku 有效的数独
详见:https://leetcode.com/problems/valid-sudoku/description/ class Solution { public: bool isValidSudo ...
- .net中Response.End() 和Response.Redirect("http://dotnet.aspx.cc");
问:什么情况下需要Response.End()语句,加这句有什么好处 答: 首先你要理解Response.End()的意思,它的意思是终止执行下面的语句!但有时不加和加上都一样,但还要加上好,为什么呢 ...
- .bak文件数据还原
.bak文件还原(见下图) 1.连接上数据库,右键数据库,选择新建数据库,输入你要还原数据库的名称 2.数据库右键-->任务-->还原-->数据库,弹出窗口选择[源设备],选择.ba ...
- 《C#高效编程》读书笔记11-理解短小方法的优势
我们最好尽可能的编写最清晰的代码,将优化交给JIT编译器完成.一个常见的错误优化是,将大量逻辑放在一个函数中,以期减少额外的方法调用开销.这种将函数逻辑直接写在循环内部的常见优化做法却会降低.NET应 ...