Skip to content
  • P
    Projects
  • G
    Groups
  • S
    Snippets
  • Help

杨树贤 / kefu_server

  • This project
    • Loading...
  • Sign in
Go to a project
  • Project
  • Repository
  • Issues 0
  • Merge Requests 0
  • Pipelines
  • Wiki
  • Snippets
  • Settings
  • Activity
  • Graph
  • Charts
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Files
  • Commits
  • Branches
  • Tags
  • Contributors
  • Graph
  • Compare
  • Charts
Find file
Normal viewHistoryPermalink
Switch branch/tag
  • kefu_server
  • ui
  • kefu_admin
  • src
  • views
  • knowledge
  • index.vue
index.vue 6.24 KB
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
1 2 3 4 5
<template>
  <div>
    <div class="me-head">
      <span>
        <i class="el-icon-reading"></i>
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
6
        <span slot="title">知识库管理</span>
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
7
      </span>
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
8 9 10 11 12 13
      <el-button-group>
        <template v-for="item in total">
          <el-button
            :class="{'el-button--primary': item.id + '' == tableData.platform + ''}"
            @click="onTogglePlatform(item.id)"
            :key="item.id"
keith's avatar
update code
5e3f6d21
 
keith committed 5 years ago
14 15
            size="small"
          >{{item.title}} ( {{item.count}} )</el-button>
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
16 17 18 19 20 21 22 23 24 25 26 27
        </template>
      </el-button-group>
      <el-col :span="5">
        <el-input
          @change="onRefresh"
          placeholder="请输入关键词"
          prefix-icon="el-icon-search"
          v-model="keyword"
          clearable
        ></el-input>
      </el-col>
      <el-button @click="createDialogFormVisible = true" size="mini">添 加</el-button>
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
28 29
    </div>
    <el-divider />
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
30
    <el-table :data="tableData.list" style="width: 100%" v-loading="loading">
chenxianqi's avatar
update code
b6252c89
 
chenxianqi committed 5 years ago
31
      <el-table-column type="index" :index="indexMethod" width="60" label="#序号"></el-table-column>
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
32 33
      <el-table-column prop="title" label="主标题"></el-table-column>
      <el-table-column prop="sub_title" label="子标题">
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
34 35
        <template slot-scope="scope">
          <div v-if="scope.row.sub_title != ''">
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
36 37 38 39 40
            <div
              style="font-size: 13px;"
              :key="key"
              v-for="(item, key) in scope.row.sub_title.split('|')"
            >{{key+1}}.{{item}}</div>
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
41 42 43 44
          </div>
          <div v-else>-----</div>
        </template>
      </el-table-column>
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
45
      <el-table-column prop="content" label="内容">
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
46
        <template slot-scope="scope">
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
47
          <div style="font-size: 13px;" :key="index" v-for="(item, index) in scope.row.content.split('\n')">{{item}}</div>
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
48 49
        </template>
      </el-table-column>
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
50
      <el-table-column prop="platform" align="center" label="匹配平台">
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
51 52 53 54
        <template slot-scope="scope">
          <el-tag>{{$getPlatformItem(scope.row.platform).title}}</el-tag>
        </template>
      </el-table-column>
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
55 56 57 58
      <el-table-column prop="create_at" label="创建时间">
        <template slot-scope="scope">{{$formatUnixDate(scope.row.create_at, "YYYY/MM/DD")}}</template>
      </el-table-column>
      <el-table-column prop="operating" align="center" width="150" label="操作">
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
59
        <template slot-scope="scope">
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
60 61
          <el-button size="mini" @click="edit(scope.row)">编 辑</el-button>
          <el-button size="mini" type="danger" @click="deleteKnowledge(scope.row)">删 除</el-button>
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
62 63 64
        </template>
      </el-table-column>
    </el-table>
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
65
    <el-row type="flex" style="margin-top: 20px;" justify="space-between">
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
66 67 68
      <span style="color:#666;font-size: 14px;">共找到{{tableData.total}}条数据</span>
      <el-pagination
        background
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
69 70
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
71 72 73
        layout="sizes, prev, pager, next"
        :current-page="tableData.page_on"
        :page-sizes="[5, 10, 15, 20]"
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
74 75
        :total="tableData.total"
      ></el-pagination>
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
76 77
    </el-row>
    <CreateDialog :complete="onRefresh" :dialogFormVisible.sync="createDialogFormVisible" />
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
78 79 80 81 82
    <EditDialog
      :formData="editItem"
      :complete="onRefresh"
      :dialogFormVisible.sync="editDialogFormVisible"
    />
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
83 84 85 86
  </div>
</template>

<script>
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
87 88 89
import CreateDialog from "./create";
import EditDialog from "./edit";
import axios from "axios";
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
export default {
  name: "knowledge",
  components: {
    CreateDialog,
    EditDialog
  },
  data() {
    return {
      keyword: "",
      tableData: {
        list: [],
        page_on: 1,
        page_size: 10,
        total: 0,
        keyword: "",
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
105
        platform: 1
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
106 107 108 109 110 111
      },
      total: [],
      createDialogFormVisible: false,
      editDialogFormVisible: false,
      loading: true,
      editItem: null
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
112
    };
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
113 114
  },
  computed: {
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
115 116
    platformConfig() {
      return this.$store.state.platformConfig || [];
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
117 118
    }
  },
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
119 120 121 122 123
  created() {
    setTimeout(() => {
      this.getKnowledgeList();
      this.getTotal();
    }, 500);
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
124 125
  },
  methods: {
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
126 127 128
    onRefresh() {
      this.getTotal();
      this.getKnowledgeList();
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
129 130 131
    },
    // 行号
    indexMethod(index) {
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
132 133 134
      return (
        (this.tableData.page_on - 1) * this.tableData.page_size + index + 1
      );
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
135 136
    },
    // 删除
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
137 138 139 140
    deleteKnowledge(item) {
      this.$confirm("您确定要删除该知识库吗? 删除后不可恢复!", "温馨提示!", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
141
        center: true,
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
142
        type: "warning"
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
143
      }).then(() => {
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
144 145 146 147 148 149 150 151 152 153 154
        axios
          .delete("/knowledge/" + item.id)
          .then(response => {
            console.log(response.data);
            this.$message.success("删除成功");
            this.getKnowledgeList(1);
          })
          .catch(error => {
            this.$message.error(error.response.data.message);
          });
      });
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
155 156
    },
    // 切换显示平台
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
157 158 159
    onTogglePlatform(pid) {
      this.tableData.platform = parseInt(pid);
      this.getKnowledgeList(1);
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
160 161
    },
    // 编辑
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
162 163 164
    edit(item) {
      this.editItem = item;
      this.editDialogFormVisible = true;
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
165 166 167
    },
    // 改变每页条数
    handleSizeChange(val) {
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
168 169
      this.tableData.page_size = val;
      this.getKnowledgeList();
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
170 171 172
    },
    // 分页
    handleCurrentChange(val) {
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
173 174
      this.tableData.page_on = val;
      this.getKnowledgeList();
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
175 176
    },
    // 获取数据
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
177 178 179 180 181 182 183 184 185 186 187 188 189 190
    getKnowledgeList(index) {
      if (index) this.tableData.page_on = index;
      const { page_on, page_size, platform } = this.tableData;
      const keyword = this.keyword;
      axios
        .post("/knowledge/list", { page_on, page_size, platform, keyword })
        .then(response => {
          this.loading = false;
          this.tableData = response.data.data;
        })
        .catch(error => {
          this.loading = false;
          this.$message.error(error.response.data.message);
        });
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
191 192
    },
    // 获取统计数据
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
193 194 195 196 197 198
    getTotal() {
      axios.get("/knowledge/total").then(response => {
        this.total = response.data.data;
      });
    }
  }
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
199 200 201
};
</script>
<style lang="stylus" scoped>
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
202 203 204 205 206 207 208 209 210 211
.me-head {
  height: 30px;
  display: flex;
  align-items: center;
  font-size: 20px;
  justify-content: space-between;
  color: #666;

  i {
    margin-right: 5px;
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
212
  }
keith's avatar
update code
db2b66d4
 
keith committed 5 years ago
213
}
keith's avatar
into client,admin public
f958b975
 
keith committed 5 years ago
214
</style>