wxy 4 yıl önce
ebeveyn
işleme
8f0ff5d7f0

+ 5 - 0
src/components/common/Sidebar.vue

@@ -79,6 +79,11 @@ export default {
           index: 'index',
           title: '公司测试',
         },
+        {
+          icon: 'el-icon-s-home',
+          index: 'productIndex',
+          title: '产品测试',
+        },
       ],
     };
   },

+ 10 - 0
src/router/index.js

@@ -51,6 +51,16 @@ export default new Router({
           component: () => import('../views/company/indexDetail.vue'),
           meta: { title: '公司页面跳转' },
         },
+        {
+          path: '/productIndex',
+          component: () => import('../views/product/productIndex.vue'),
+          meta: { title: '产品' },
+        },
+        {
+          path: '/productDetail',
+          component: () => import('../views/product/productDetail.vue'),
+          meta: { title: '产品信息' },
+        },
       ],
     },
     {

+ 2 - 0
src/store/index.js

@@ -6,6 +6,7 @@ import login from './login';
 //第二步引入自己创建的文件
 import lunbo from './lunbo';
 import company from './company';
+import product from './product';
 
 Vue.use(Vuex);
 
@@ -18,5 +19,6 @@ export default new Vuex.Store({
     //声明引用文件
     lunbo,
     company,
+    product,
   },
 });

+ 54 - 0
src/store/product.js

@@ -0,0 +1,54 @@
+//第一步
+import Vue from 'vue';
+import Vuex from 'vuex';
+import _ from 'lodash';
+Vue.use(Vuex);
+const api = {
+  //接口地址
+  productInfo: `/api/huanqi/product`,
+};
+const state = () => ({});
+const mutations = {};
+
+const actions = {
+  //查询列表 skip:第一页,limit:第一页显示的数据,info:其余查询参数
+  async query({ commit }, { skip = 0, limit, ...info } = {}) {
+    //连接接口。。。。
+    const res = await this.$axios.$get(`${api.productInfo}`, {
+      skip,
+      limit,
+      ...info,
+    });
+    //把数据集合res返回
+    return res;
+  },
+  //创建数据  payload是添加form表单中的数据集合  创建数据的时候需要拿到form表单里面的数据
+  async create({ commit }, payload) {
+    //通过$axios提交post请求????
+    const res = await this.$axios.$post(`${api.productInfo}`, payload);
+    return res;
+  },
+  //查询详情,payload:参数位,一般传当前数据id
+  async fetch({ commit }, payload) {
+    //有/一般都是路径
+    const res = await this.$axios.$get(`${api.productInfo}/${payload}`);
+    return res;
+  },
+  //修改:id: 当前数据id, data: 当前修改数据的新form表单
+  async update({ commit }, { id, ...data }) {
+    const res = await this.$axios.$post(`${api.productInfo}/update/${id}`, data);
+    return res;
+  },
+  //删除:payload:参数位,一般传当前数据id
+  async delete({ commit }, payload) {
+    const res = await this.$axios.$delete(`${api.productInfo}/${payload}`);
+    return res;
+  },
+};
+
+export default {
+  namespaced: true,
+  state,
+  mutations,
+  actions,
+};

+ 3 - 3
src/views/company/indexDetail.vue

@@ -3,10 +3,10 @@
     <el-row>
       <el-col :span="24">
         <breadcrumb :breadcrumbTitle="this.$route.meta.title"></breadcrumb>
-        <el-col :span="24" style="margin:0 0 15px 0;text-align:right;">
-          <el-button type="primary" size="mini" @click="back()">返回</el-button>
-        </el-col>
         <el-col :span="24" class="container">
+          <el-col :span="24" style="margin:0 0 15px 0;text-align:right;">
+            <el-button type="primary" size="mini" @click="back()">返回</el-button>
+          </el-col>
           <el-form :model="form" :rules="rules" ref="form" label-width="100px" class="demo-ruleForm">
             <el-form-item label="企业名称" prop="company">
               <el-input v-model="form.company"></el-input>

+ 122 - 0
src/views/product/productDetail.vue

@@ -0,0 +1,122 @@
+<template>
+  <div id="productDetail">
+    <el-row>
+      <el-col :span="24">
+        <breadcrumb :breadcrumb="this.$route.meta.title"></breadcrumb>
+      </el-col>
+      <el-col :span="24" class="container">
+        <el-col :span="24" style="margin:15px 0;text-align:right">
+          <el-button type="primary" size="mini" @click="back()">返回</el-button>
+        </el-col>
+        <el-form :model="form" :rules="rules" ref="form" label-width="100px">
+          <el-form-item label="名称" prop="name">
+            <el-input v-model="form.name"></el-input>
+          </el-form-item>
+          <el-form-item label="简介" prop="brief">
+            <el-input type="textarea" v-model="form.brief"></el-input>
+          </el-form-item>
+          <el-form-item label="内容" prop="content">
+            <el-input type="textarea" v-model="form.content"></el-input>
+          </el-form-item>
+          <el-form-item label="图片">
+            <upload :limit="1" :data="form.filepath" type="filepath" :url="'/files/filepath/upload'" @upload="uploadSuccess"></upload>
+          </el-form-item>
+          <el-form-item label="发布时间" prop="create_time">
+            <el-date-picker type="date" placeholder="选择日期" v-model="form.create_time" value-format="yyyy-MM-dd" format="yyyy-MM-dd"></el-date-picker>
+          </el-form-item>
+          <el-form-item>
+            <el-button type="primary" @click="submitForm('form')">保存</el-button>
+          </el-form-item>
+        </el-form>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import upload from '@/components/frame/uploadone.vue';
+import breadcrumb from '@c/common/breadcrumb.vue';
+import { mapState, createNamespacedHelpers } from 'vuex';
+const { mapActions: product } = createNamespacedHelpers('product');
+export default {
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+  name: 'productDetail',
+  props: {},
+  components: {
+    upload,
+    breadcrumb,
+  },
+  data: function() {
+    return {
+      form: {},
+      rules: {
+        name: [{ required: true, message: '请输入名称', trigger: 'blur' }],
+        brief: [{ required: true, message: '请输简介', trigger: 'blur' }],
+        content: [{ required: true, message: '请输入内容', trigger: 'blur' }],
+        create_time: [{ required: true, message: '请选择日期', trigger: 'change' }],
+      },
+    };
+  },
+  created() {
+    this.search();
+  },
+  methods: {
+    ...product(['query', 'fetch', 'create', 'update', 'delete']),
+    //查询列表
+    async search() {
+      if (this.id) {
+        let res = await this.fetch(this.id);
+        if (this.$checkRes(res)) {
+          this.$set(this, `form`, res.data);
+        }
+      }
+    },
+    back() {
+      this.$set(this, `form`, {});
+      this.$router.push({ path: '/productIndex' });
+    },
+    //保存数据
+    submitForm(formName) {
+      // element表单验证
+      this.$refs[formName].validate(async valid => {
+        if (valid) {
+          let data = this.form;
+          console.log(data);
+          if (data.id) {
+            let res = await this.update(data);
+            if (this.$checkRes(res)) {
+              this.$message({
+                message: '修改成功',
+                type: 'success',
+              });
+              this.back();
+            }
+          } else {
+            let res = await this.create(data);
+            if (this.$checkRes(res)) {
+              this.$message({
+                message: '创建成功',
+                type: 'success',
+              });
+              this.back();
+            }
+          }
+        } else {
+          console.log('error submit!!');
+          return false;
+        }
+      });
+    },
+    uploadSuccess({ type, data }) {
+      this.$set(this.form, `${type}`, data.uri);
+    },
+  },
+  computed: {
+    ...mapState(['user']),
+  },
+};
+</script>
+
+<style lang="less" scoped></style>

+ 120 - 0
src/views/product/productIndex.vue

@@ -0,0 +1,120 @@
+<template>
+  <div id="productIndex">
+    <el-row>
+      <el-col :span="24">
+        <el-col :span="24">
+          <breadcrumb :breadcrumb="this.$route.meta.title"></breadcrumb>
+        </el-col>
+        <el-col :span="24" class="container">
+          <el-col :span="24" style="margin:15px 0;text-align:right">
+            <el-button type="primary" size="mini" @click="add()">添加</el-button>
+          </el-col>
+
+          <el-table :data="list">
+            <el-table-column prop="name" label="产品名称" width="120" show-overflow-tooltip> </el-table-column>
+            <el-table-column prop="brief" label="简介" width="150" show-overflow-tooltip> </el-table-column>
+            <el-table-column prop="content" label="内容" width="150" show-overflow-tooltip> </el-table-column>
+            <el-table-column prop="create_time" label="发布时间" width="120" show-overflow-tooltip> </el-table-column>
+            <el-table-column label="操作">
+              <template slot-scope="scope">
+                <el-button size="mini" @click="handleEdit(scope.row)">编辑</el-button>
+                <el-button size="mini" type="danger" @click="handleDelete(scope.row)">删除</el-button>
+              </template>
+            </el-table-column>
+          </el-table>
+          <el-col :span="24" class="page">
+            <!-- current-page:当前页数 current-change触发当前页  page-size:每页显示条目个数 -->
+            <el-pagination
+              background
+              @current-change="handleCurrentChange"
+              :current-page="currentPage"
+              layout="total, prev, pager, next, jumper"
+              :total="total"
+              :page-size="pageSize"
+            >
+            </el-pagination>
+          </el-col>
+        </el-col>
+      </el-col>
+    </el-row>
+  </div>
+</template>
+
+<script>
+import { mapState, createNamespacedHelpers } from 'vuex';
+import breadcrumb from '@c/common/breadcrumb.vue';
+const { mapActions: product } = createNamespacedHelpers('product');
+export default {
+  metaInfo() {
+    return { title: this.$route.meta.title };
+  },
+  name: 'productIndex',
+  props: {},
+  components: {
+    breadcrumb,
+  },
+  data: function() {
+    return {
+      list: [],
+      total: 0,
+      form: {},
+      currentPage: 0,
+      pageSize: 10,
+      skip: 0,
+    };
+  },
+  created() {
+    this.search();
+  },
+  methods: {
+    ...product(['query', 'fetch', 'create', 'update', 'delete']),
+    // 查询列表
+    async search({ skip = 0, limit = 10, ...info } = {}) {
+      skip = this.skip;
+      let res = await this.query({ skip, limit, ...info });
+      if (this.$checkRes(res)) {
+        this.$set(this, `list`, res.data);
+        this.$set(this, `total`, res.total);
+      }
+    },
+    //添加跳转
+    add() {
+      this.$router.push({ path: '/productDetail' });
+    },
+    //编辑
+    handleEdit() {
+      this.$router.push({
+        path: '/productDetail',
+        query: {
+          id: data.id,
+        },
+      });
+    },
+    //删除数据
+    async handleDelete(data) {
+      let res = await this.delete(data.id);
+      if (this.$checkRes(res)) {
+        this.$message({
+          message: '删除成功',
+          type: 'success',
+        });
+        this.search();
+      }
+    },
+    handleCurrentChange(currentPage) {
+      this.$set(this, `skip`, (currentPage - 1) * this.pageSize);
+      this.search();
+    },
+  },
+  computed: {
+    ...mapState(['user']),
+  },
+};
+</script>
+
+<style lang="less" scoped>
+.page {
+  text-align: center;
+  margin: 15px 0;
+}
+</style>