商品分类管理系统实现(Vue + ElementUI)

Posted 有时间指导毕业设计SmallMonkey

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了商品分类管理系统实现(Vue + ElementUI)相关的知识,希望对你有一定的参考价值。

文章目录

前端代码使用el-tree

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>分类管理</title>
  <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/semantic-ui@2.4.2/dist/semantic.min.css">

  <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
  <!-- 引入样式 -->
  <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
  <!-- 引入组件库 -->
  <script src="https://unpkg.com/element-ui/lib/index.js">

  </script>

  <script src="static/js/base.js"></script>
  <script src="static/js/axios.min.js"></script>
  <style>
    .custom-tree-node 
      flex: 1;
      display: flex;
      align-items: center;
      justify-content: space-between;
      font-size: 14px;
      padding-right: 8px;
    
  </style>
</head>

<body>


  <div id="app">
    <el-alert title="商品分类管理页面" description="对商品的分类进行管理" type="success" description="对商品的多级分类进行管理" show-icon>
    </el-alert>
    <h2 class="ui teal header" style="color: teawl;margin-top: 30px;text-align: center;">欢迎来到分类管理页面</h2>


    <!-- this.categories -->

    <!-- 通过一个li遍历多个 -->

    <div class="category">
      <h3 class="ui teal header">商品多级分类名称:</h3>

      <!-- 树形控件实现商品分类 -->
      <el-input placeholder="输入关键字进行商品分类的过滤" v-model="filterText"
        style="width: 800px;background: transparent;border: none; background-color: rgba(255, 255, 255, 0.247);">
      </el-input>
   <el-switch
  style="display: inline-block;"
  v-model="value2"
  active-color="#13ce66"
  inactive-color="#ff4949"
  active-text="开启拖拽"
  >
</el-switch>
<el-button type="danger" size="small" @click="batchDelete" style="padding-right: 30px">批量删除</el-button>
   
      <!-- <el-button type="primary" icon="search">搜索</el-button> -->
<!-- 
      //注意这一组一定要写对,通过categoryId唯一标识,expandedkeys定义需要展开的结点
      node-key="categoryId" 
      :default-expanded-keys="expandedkeys"  -->
      <el-tree show-checkbox class="filter-tree" :data="data1" 
      node-key="categoryId" 
      :default-expanded-keys="expandedkeys" 

       :props="defaultProps"
        :filter-node-method="filterNode"
       ref="menusTree" :expand-on-click-node="false" >
        <span class="custom-tree-node" slot-scope=" node, data ">
          <span> node.label </span>
          <span>
            <el-button v-if="node.level <= 2" type="text" size="mini" @click="() => append(data)">
              增加
            </el-button>
            <el-button  type="text" size="mini" @click="() => edit(data)">
              修改
            </el-button>
            <el-button v-if="node.childNodes.length == 0" type="text" size="mini" @click="() => remove(node, data)">
              删除
            </el-button>
          </span>
        </span>
      </el-tree>

<!-- 添加商品分类的对话框 -->
      <el-dialog title="添加分类" :visible.sync="dialogFormVisible">
        <el-form :model="category">
          <el-form-item label="分类名称">
            <el-input v-model="category.categoryName" autocomplete="off"></el-input>
          </el-form-item>
      
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button @click="dialogFormVisible = false">取 消</el-button>
          <el-button type="primary" @click="addCategory">确 定</el-button>
        </div>
      </el-dialog>


    </div>




  </div>
  <script src="static/js/cookie_utils.js"></script>

  <script src="static/js/base.js"></script>

  <script>
    new Vue(
      el: '#app',
      data: 
        expandedkeys:[],
        dialogFormVisible:false,
        value2:false,//开启拖拽
        category:
          categoryId:"",
          categoryName:"",
          categoryLevel:0,
          parentId:0,

        ,
        data1: [],
        message: "hello",
        dataList: [],
        categories: [],
        inputCategoryLevel1: true,
        token: "",
        userId: "",
        disabled: true,
        filterText: "",
        data: [
          id: 1,
          label: '一级 1',
          children: [
            id: 4,
            label: '二级 1-1',
            children: [
              id: 9,
              label: '三级 1-1-1'
            , 
              id: 10,
              label: '三级 1-1-2'
            ]
          ]
        , 
          id: 2,
          label: '一级 2',
          children: [
            id: 5,
            label: '二级 2-1'
          , 
            id: 6,
            label: '二级 2-2'
          ]
        , 
          id: 3,
          label: '一级 3',
          children: [
            id: 7,
            label: '二级 3-1'
          , 
            id: 8,
            label: '二级 3-2'
          ]
        ],
        defaultProps: 
          children: 'categories',
          label: 'categoryName',
        

      ,
      watch: 
        filterText(val) 
          this.$refs.menusTree.filter(val);
        
      ,
      created() 
        //  商品分类相关参数
        this.showCategorires();
      ,
      methods: 
        filterNode(value, data) 
          console.log(value);
          if (!value) return true;
          return data.categoryName.indexOf(value) !== -1;
        ,

        // ---------------商品分类查询实现

        showCategorires() 
          let token = getCookieValue("token");
          console.log(token);
          this.token = token;
          let userId = getCookieValue("userId");
          console.log(userId, "UserId");
          this.userId = userId;
          var url22 = baseUrl + "index/categorylist";
          axios(
            url: url22,
            method: "post",
            headers: 
              token: this.token
            ,
            data: this.userId
          ).then(res => 
            console.log(res.data.data);
            this.categories = res.data.data;
            this.data1 = res.data.data;
            this.dataList = this.categories.filter(function (type) 
              return type.parentId == "1";
            );
            console.log(this.categories, "categoryList")
            this.categories.forEach(element => 


            );


          )
        ,

        // -------------商品分类添加和删除方法

        append(data) 
          console.log("分类添加", data);
          this.category = ;
          this.dialogFormVisible = true;
          this.category.parentId = data.categoryId;
          this.category.categoryLevel = data.categoryLevel*1 +1;
        ,
        addCategory()
          console.log("提交的分类数据",this.category);
          var url5 = baseUrl + "category/addOrUpdate";
          axios(
            url: url5,
            method: "post",
            headers: 
              token: this.token
            ,
            data: this.category
          ).then(res => 
            if(res.data.code == 1)
              //添加成功重新查询分类
              this.showCategorires();
              this.dialogFormVisible = false;
              ELEMENT.Message.success("商品分类添加成功");
              //设置默认展开的key
              this.expandedkeys = [this.category.parentId]
            
            else if(res.data.code == 2)
              console.log("商品分类修改数据----",res.data);
              //添加成功重新查询分类
              this.showCategorires();
              this.dialogFormVisible = false;
              ELEMENT.Message.success("商品分类修改成功");
              //设置默认展开的key
              this.expandedkeys = [this.category.categoryId]
            
         

        )
      ,

        remove(node, data) 
          console.log("分类参数",node,data);
          var cids = [data.categoryId];
          console.log("分类id-------",cids);
          var url3 = baseUrl + "category/delete";
          this.$confirm(`此操作将永久,删除【$data.categoryName】 是否继续?`, '提示', 
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        ).then(() => 
       
          axios(
            url: url3,
            method: "post",
            headers: 
              token: this.token
            ,
            data: cids

以上是关于商品分类管理系统实现(Vue + ElementUI)的主要内容,如果未能解决你的问题,请参考以下文章

VUE项目实战38实现商品分类的树形表格

VUE项目实战40添加商品分类功能

vue电商后台管理系统保姆级教程——商品分类

Java网络商城项目 SpringBoot+SpringCloud+Vue 网络商城(SSM前后端分离项目)六(商品分类功能实现)

VUE项目实战39商品分类树形表格渲染和分页

Vue电商管理系统-商品分类