瀏覽代碼

feat(liveroomList): 商品跳转记录

web 1 年之前
父節點
當前提交
5c98332e4e

+ 198 - 0
src/components/base-table/base-table.vue

@@ -0,0 +1,198 @@
+<template>
+  <div class="table-wrap" v-loading='loading'>
+    <div class="table-page-search-wrapper" v-if="condition.length">
+      <el-form :inline="true" class="demo-form-inline" label-width='80px' size="small">
+        <el-row :gutter='10'>
+          <el-col :span='span' v-for='v in condition' :key='v.dataIndex'>
+            <el-form-item :label="layout === 'include' ? '' : v.title" style="display: flex">
+              <el-input v-model='queryParam[v.dataIndex]' :placeholder="layout === 'include' ? v.title : '请输入'"
+                v-if="v.type === 'input'" clearable />
+              <el-date-picker v-model='queryParam[v.dataIndex]' valueFormat="YYYY-MM-DD"
+                v-else-if="v.type === 'time-range'" :placeholder="layout === 'include' ? v.title : '请选择'" />
+              <el-select v-model='queryParam[v.dataIndex]' :placeholder="layout === 'include' ? v.title : '请选择'"
+                :default-value='v.defaultValue' v-else-if="v.type === 'select'" clearable>
+                <el-option :value='v1.value' :label="v1.label" v-for='v1 in v.options' :key='v1.value'></el-option>
+              </el-select>
+            </el-form-item>
+          </el-col>
+          <el-col :span='24 - condition.length % (24 / span) * span'>
+            <span class="table-page-search-submitButtons">
+              <el-button type="primary" @click='onQueryClick' size="small">
+                查询
+              </el-button>
+              <el-button style="margin-left: 8px" @click='reset' size="small">
+                重置
+              </el-button>
+              <slot name='append-btn'></slot>
+            </span>
+          </el-col>
+        </el-row>
+      </el-form>
+    </div>
+    <el-table :data='tableData' style="margin: 6px 0;" v-bind="$attrs" v-on='$listeners' ref='table'>
+      <el-table-column type="selection" width="55" v-if="isSelection">
+      </el-table-column>
+      <el-table-column v-bind='v' :prop='v.dataIndex' :label='v.title' v-for="(v, i) in columns" :key='i'>
+        <template slot-scope="scope">
+          <!-- 格式化函数 -->
+          <span
+            v-if="v.scopedSlots && v.scopedSlots.customRender && Object.prototype.toString.call(v.scopedSlots.customRender) === '[object Function]'">
+            {{ v.scopedSlots.customRender(scope.row[v.dataIndex], scope.row, scope.$index) }}
+          </span>
+          <!-- 格式化插槽 -->
+          <slot v-else-if="v.scopedSlots && v.scopedSlots.customRender" v-bind='scope' :name="v.scopedSlots.customRender">
+          </slot>
+          <span v-else>{{ scope.row[v.dataIndex] }}</span>
+        </template>
+      </el-table-column>
+    </el-table>
+    <el-pagination :layout="paginationSize === 'mini' ? 'prev, pager, next' : 'total, sizes, prev, pager, next, jumper'"
+      :currentPage.sync='localPagination.currentPage' :pageCount.sync='localPagination.totalPage'
+      :style="paginationSize === 'mini' ? 'display: flex;justify-content: center;' : 'display: flex;justify-content: flex-end;'"
+      :page-sizes="[5, 10, 20, 30, 50]" @size-change="queryTable" @current-change="queryTable" v-if='showPagination'>
+    </el-pagination>
+  </div>
+</template>
+
+<script>
+export default {
+  name: 'BaseTable',
+  props: {
+    columns: {
+      default: () => [],
+      required: true,
+    },
+    condition: {
+      default: () => [],
+      required: false
+    },
+    queryFunction: {
+      required: false
+    },
+    pagination: {
+      required: false,
+      default: () => ({
+        pageSize: 10,
+      }),
+    },
+    paginationText: {
+      required: false,
+      default: () => ({
+        currentPage: 'currentPage', total: 'total', totalPage: 'totalPage', data: 'data'
+      }),
+    },
+    span: {
+      required: false,
+      default: 6
+    },
+    paginationSize: {
+      required: false,
+      default: 'small'
+    },
+    layout: {
+      required: false,
+      default: 'normal'
+    },
+    // 无需查询的静态数据
+    injectData: {
+      required: false,
+      default: null
+    },
+    isSelection: {
+      required: false,
+      default: false
+    },
+    rowKey: {
+      required: false,
+      default: 'id'
+    },
+  },
+  data() {
+    return {
+      tableData: [],
+      queryParam: {}, // 暂存
+      confirmParam: {}, // 点击查询键后赋值
+
+      localPagination: Object.assign({
+        currentPage: 1,
+        total: 10
+      }, this.pagination),
+      loading: false,
+
+      selectedRows: [],
+      selectedRowKeys: [],
+
+      showPagination: true
+    };
+  },
+  async created() {
+    this.condition.forEach(v => {
+      v.defaultValue && this.$set(this.queryParam, v.dataIndex, v.defaultValue)
+    })
+    if (this.injectData) {
+      this.tableData = this.injectData
+      this.showPagination = false
+    } else {
+      this.queryTable()
+    }
+  },
+  watch: {
+    injectData: {
+      handler(v) {
+        this.tableData = v
+      },
+      deep: true
+    }
+  },
+  methods: {
+    async submit() {
+    },
+    onQueryClick() {
+      this.confirmParam = JSON.parse(JSON.stringify(this.queryParam))
+      this.localPagination.currentPage = 1
+      this.queryTable()
+    },
+    async queryTable() {
+      this.loading = true
+      try {
+        const { confirmParam, paginationText, localPagination } = this
+        const queryParamFilter = {}
+        Object.keys(confirmParam).forEach(key => confirmParam[key] && (queryParamFilter[key] = confirmParam[key]))
+        const queryResult = await this.queryFunction(
+          {
+            [paginationText.currentPage]: localPagination.currentPage,
+            query: queryParamFilter
+          }
+        )
+        this.tableData = queryResult[paginationText.data]
+        this.localPagination = {
+          currentPage: queryResult[paginationText.currentPage],
+          total: queryResult[paginationText.total],
+          totalPage: queryResult[paginationText.totalPage]
+        }
+      } finally {
+        this.loading = false
+      }
+    },
+    reset() {
+      this.queryParam = {}
+      this.confirmParam = {}
+      this.queryTable()
+    },
+    /**
+     * 表格重新加载方法
+     * 如果参数为 true, 则强制刷新到第一页
+     * @param Boolean bool
+     */
+    refresh(bool = false) {
+      bool && (this.localPagination.currentPage = 1)
+      this.queryTable()
+    },
+    test(v) {
+      console.log(v)
+    }
+  },
+};
+</script>
+
+<style lang="scss" scoped></style>

+ 5 - 0
src/router/index.ts

@@ -71,6 +71,11 @@ export const pages = [
     component: _import("modules/liveroom/liveroomEdit"),
     name: "liveroomEdit",
     meta: { title: "直播间信息", sidebar: false, icon: "", isTab: false }
+  },{
+    path: "/liveroom/liveroom-product-jump-record/:id",
+    component: _import("modules/liveroom/liveroomProductJumpRecord"),
+    name: "liveroomProductJumpRecord",
+    meta: { title: "商品跳转记录", sidebar: false, icon: "", isTab: false }
   },
 ]
 

+ 1 - 1
src/views/modules/liveroom/liveroomList-opbar.vue

@@ -14,7 +14,7 @@
         <el-button type="primary" size="small" disabled><icon-svg name="question" /></el-button>
       </el-tooltip>
       <el-tooltip effect="dark" content="商品跳转记录" placement="top" :enterable="false">
-        <el-button type="info" size="small" disabled><icon-svg name="record" /></el-button>
+        <el-button type="info" size="small" @click="$router.push(`/liveroom/liveroom-product-jump-record/${id}`)"><icon-svg name="record" /></el-button>
       </el-tooltip>
       <el-tooltip effect="dark" content="邀约码统计" placement="top" :enterable="false">
         <el-button type="info" size="small" disabled><icon-svg name="share" /></el-button>

+ 44 - 0
src/views/modules/liveroom/liveroomProductJumpRecord.vue

@@ -0,0 +1,44 @@
+<template>
+  <div>sss</div>
+</template>
+
+<script>
+import BaseTable from "@/components/base-table/base-table.vue"
+export default {
+    data() {
+    return {
+      columns: [],
+      condition: [],
+      queryParam: {},
+      queryFunction: params => new Promise((resolve, reject) => {
+        const formatParams = {
+          page: params.pageCurrent, ...params.query
+        }
+        return this.$http({
+          url: '/order/index',
+          method: 'post',
+          data: formatParams,
+          params: formatParams
+        }).then(
+          ({ data }) => {
+            resolve(data)
+          }
+        ).catch(e => reject(e))
+      }),
+    }
+  },
+  components: { BaseTable,  },
+  mounted() {
+    console.log(this.$route.params.id);
+  },
+  methods: {
+    show(scope) {
+      this.$refs.dialog.show(scope.row)
+    },
+  }
+}
+</script>
+
+<style>
+
+</style>