heyujie
2022-07-29 90427ad7b5e73aaee2eb376080547787d25dc2bb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
<template>
  <div class="right-main">
    <div class="top-title">
      <p>基础算法列表</p>
    </div>
 
    <div class="control-bar">
      <div class="line-one">
        <div class="right-fixed">
          <el-button type="primary" size="small" @click="createBaseAlg"
            >添加</el-button
          >
        </div>
      </div>
    </div>
    <div class="table-area">
      <el-table
        id="multipleTable"
        ref="multipleTable"
        :data="baseSdkData"
        tooltip-effect="dark"
        :fit="true"
      >
        <!-- <el-table-column type="selection" width="30"></el-table-column> -->
        <el-table-column label="序号" width="68">
          <template slot-scope="scope">{{
            scope.$index + 1 + (page - 1) * size
          }}</template>
        </el-table-column>
        <el-table-column
          prop="name"
          label="基础算法名称"
          min-width="200"
          show-overflow-tooltip
          sortable
        >
          <template slot-scope="scope">
            <div v-if="isBaseAlgEdit && curEditIndex == scope.$index">
              <el-input size="small" v-model="baseSdkItem.sdk_type"></el-input>
            </div>
            <div v-else>{{ scope.row.sdk_type }}</div>
          </template>
        </el-table-column>
        <el-table-column label="更新时间" width="200">
          <template slot-scope="scope">
            <div>{{ getTime(scope.row.update_time) }}</div>
          </template>
        </el-table-column>
        <el-table-column
          prop="version"
          label="最新版本号"
          width="200"
          sortable
        ></el-table-column>
        <!-- <el-table-column
          prop="source"
          label="基础算法组件"
          min-width="130"
          show-overflow-tooltip
          sortable
        >
          <template slot-scope="scope">
            <div v-if="isBaseAlgEdit && curEditIndex == scope.$index">
              <file-uploader
                single
                uploadPlaceholder="上传算法组件"
                url="/data/api-f/file/upload"
                @complete="onFileUpload"
                @file-added="onFileAdded"
              />
            </div>
            <div v-else>{{scope.row.component_name}}</div>
          </template>
        </el-table-column>-->
        <el-table-column label="操作" width="200">
          <template slot-scope="scope">
            <!-- <div v-if="isBaseAlgEdit && curEditIndex == scope.$index">
              <span class="cursor-pointer" @click="cancle(scope.row)">取消</span>
              <span class="cursor-pointer" @click="saveRowSdk(scope.row)">保存</span>
            </div>-->
            <div>
              <span
                class="cursor-pointer"
                @click="editBaseAlg(scope.row, scope.$index)"
                >编辑</span
              >
              <span class="cursor-pointer" @click="delSdk(scope.row)"
                >删除</span
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div>
        <el-pagination
          @current-change="refresh"
          @size-change="handleSizeChange"
          :current-page="page"
          :page-sizes="[8, 10, 15, 20, 25]"
          :page-size="size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
 
<script>
import request from "@/api/index";
// import { findAllBaseAlg, deleteBaseAlg } from "@/api/algorithm";
import { getFilePath } from "@/api/utils";
export default {
  data() {
    return {
      size: 10,
      page: 1,
      total: 0,
      baseSdkData: [],
      baseSdkItem: {
        sdk_type: "",
        component_name: "",
        component_path: "",
      },
      //baseSdkItem:{},
      curEditRow: {},
      isBaseAlgEdit: false,
      curEditIndex: 0,
    };
  },
  methods: {
    newBaseSdk() {
      return {
        sdk_type: "",
        component_name: "",
        component_path: "",
      };
    },
    async renderTableList() {
      let data = await findAllBaseAlg({ page: this.page, size: this.size });
      if (data.code == 200) {
        this.total = data.data.total;
        this.baseSdkData = data.data.list;
      }
    },
    saveRowSdk(row) {
      this.isBaseAlgEdit = false;
      let params = {
        id: this.baseSdkItem.id,
        component_name: this.curEditRow.component_name,
        component_path: this.curEditRow.component_path,
        sdk_type: this.baseSdkItem.sdk_type,
      };
 
      saveBaseAlg(params)
        .then((res) => {
          this.$notify({
            type: "success",
            message: "保存成功!",
            duration: 2500,
            offset: 57,
          });
          this.renderTableList();
        })
        .catch((e) => {
          console.log(e);
        });
    },
    cancle(row) {
      if (!row.id) {
        this.baseSdkData.splice(this.baseSdkData.length - 1, 1);
        this.isBaseAlgEdit = false;
        return;
      }
      this.isBaseAlgEdit = false;
    },
    editBaseAlg(row, index) {
      this.$router.push({ path: `/Layout/BaseAlgorithmEdit/edit/${row.id}` });
      // if (this.isBaseAlgEdit) return;
      // this.isBaseAlgEdit = true;
      // this.curEditIndex = index;
      // this.baseSdkItem = JSON.parse(JSON.stringify(row));
    },
    delSdk(row) {
      this.$confirm("确定删除该项吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
        center: true,
      })
        .then(() => {
          deleteBaseAlg(row.id).then((res) => {
            this.$message({
              type: "success",
              message: "删除成功!",
            });
            this.renderTableList();
          });
        })
        .catch((e) => {
          console.log(e);
        });
    },
    createBaseAlg() {
      this.$router.push({ path: "/Layout/BaseAlgorithmEdit/create/alg" });
      // if (this.isBaseAlgEdit) return;
      // this.baseSdkItem = this.newBaseSdk();
      // this.baseSdkData.push(this.baseSdkItem);
      // this.isBaseAlgEdit = true;
      // this.curEditIndex = this.baseSdkData.length - 1;
    },
 
    refresh(page) {
      this.page = page;
      this.renderTableList();
    },
    handleSizeChange(size) {
      this.size = size;
      this.renderTableList();
    },
 
    getTime(time) {
      return (
        time.substring(0, 4) +
        "-" +
        time.substring(4, 6) +
        "-" +
        time.substring(6, 8)
      );
    },
 
    // rowClick(row, column, ev){
    //   this.curEditRow = JSON.parse(JSON.stringify(row));
    // }
  },
  mounted() {
    this.renderTableList();
  },
};
</script>