suerprisePlus
2024-07-04 121b2ce562afa4fe69de89853f549687f11b7d1f
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
<template>
    <div v-loading="loading" class="modelLibiraryBox">
        <el-card>
            <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px"
                style="margin-bottom: -20px">
                <el-form-item label="服务名称" prop="name">
                    <el-input v-model="queryParams.name" placeholder="请输入模型名称" clearable size="small"
                        @keyup.enter.native="setQueryParamsQuery" />
                </el-form-item>
                <el-form-item label="服务类别" prop="type">
                    <el-select v-model="queryParams.type" @change="getList" placeholder="请选择模型类别" clearable
                        size="small">
                        <el-option v-for="dict in dict.type.iot_model_library_type" :key="dict.value"
                            :label="dict.label" :value="dict.value" />
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" icon="el-icon-search" size="mini"
                        @click="setQueryParamsQuery">搜索</el-button>
                    <el-button icon="el-icon-refresh" size="mini" @click="setQueryParamsRest">重置</el-button>
                </el-form-item>
 
            </el-form>
        </el-card>
        <el-card class="modelLibiraryContent">
            <el-tabs v-model="activeName" @tab-click="setQueryParamsRest">
                <el-tab-pane label="未发布模型数据" name="first"></el-tab-pane>
                <el-tab-pane label="已发布模型数据" name="second"></el-tab-pane>
            </el-tabs>
            <div class="modelLibiraryTable">
 
                <div class="modelLibiraryTable">
                    <el-table :data="templateList" border>
                        <!-- <el-table-column type="selection" width="55" /> -->
                        <el-table-column label="模型名称" align="center" prop="name" />
                        <el-table-column label="模型类型" align="center" prop="type" />
                        <el-table-column label="模型大小" align="center" prop="sizes" :formatter="formatterSize" />
                        <el-table-column label="发布状态" align="center">
                            <template slot-scope="scope">
                                <span v-if="scope.row.url">已发布</span>
                                <span v-else>未发布</span>
                            </template>
                        </el-table-column>
                        <el-table-column label="发布地址" align="center" prop="url" />
 
                        <el-table-column label="创建时间" align="center" prop="createTime" :formatter="formatterTime" />
                        <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="240">
                            <template slot-scope="scope">
 
                                <el-button v-show="activeName == 'first' && !scope.row.url" type="success" size="small"
                                    @click="setModelLibraryExport(scope.row)" icon="el-icon-position">发布</el-button>
                                <el-button v-show="activeName == 'second'" size="small"
                                    @click="setModelLibraryDelete(scope.row)" type="warning"
                                    icon="el-icon-delete">移除</el-button>
                            </template>
                        </el-table-column>
                    </el-table>
                    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageIndex"
                        :limit.sync="queryParams.pageSize" @pagination="getList" />
                </div>
            </div>
        </el-card>
 
    </div>
</template>
 
<script>
 
import configTools from '../../../assets/js/configTools';
import { getToken } from "@/utils/auth";
import {
    modelSelectMetasByPage,
    modelSelectPublishByPage,
    modelPubMetas,
    modelDeletePublishes
} from '@/api/iot/modelServer';
 
export default {
    name: 'modelserver',
    dicts: ['iot_model_library_type'],
    data() {
        return {
            loading: false,
            queryParams: {
                pageIndex: 1,
                pageSize: 10,
                name: null,
                type: null,
            },
            // 是否为租户
            isTenant: false,
            templateList: [
 
            ],
            // 总条数
            total: 0,
            title: '',
            // 是否显示弹出层
            open: false,
            modelFrom: {
                name: '',
                type: '',
                path: '',
                bak: '',
                ids: '',
            },
            selectPath: null,
            selectMappers: null,
            //表单验证
            rules: {
                name: [
                    {
                        required: true,
                        message: '模型名称不能为空',
                        trigger: 'blur',
                    },
                ],
                type: [{ required: true, message: '请选择模型类别', trigger: 'change' }],
                path: [{ required: true, message: '请选择需要上传的模型文件', trigger: 'change' }],
            },
            multipleSelection: [],
            headers: { Authorization: "Bearer " + getToken() },
            activeName: 'first'
        };
    },
    created() {
        this.init();
    },
    methods: {
 
        handleClick() {
            if (this.activeName == 'first') {
                this.getList()
            } else {
                this.getListSource();
            }
        },
        init() {
            if (this.$store.state.user.roles.indexOf('tenant') !== -1) {
                this.isTenant = true;
            }
 
            this.handleClick();
        },
        getSelectPath() {
            modelSelectPath().then((response) => {
                if (response.code == 200 && response.msg) {
                    this.selectPath = response.msg;
                } else {
                    this.$message('模型上传路径获取失败: ' + response.msg);
                }
            });
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        //查询
        setQueryParamsQuery() {
            this.queryParams.pageIndex = 1;
            this.handleClick();
        },
        // 重置
        setQueryParamsRest() {
            this.queryParams = {
                pageIndex: 1,
                pageSize: 10,
                name: null,
                type: null,
            }
            this.handleClick();
        },
        // 搜索
        getList() {
            modelSelectMetasByPage(this.queryParams).then((response) => {
                if (response.code == 200) {
 
                    if (response.data) {
                        this.total = response.data.length;
                        this.templateList = response.data;
                    } else {
                        this.total = 0;
                        this.templateList = [];
                    }
 
                } else {
                    this.$message('模型数据列表获取失败。');
                }
            })
        },
        getListSource() {
            modelSelectPublishByPage(this.queryParams).then((response) => {
                if (response.code == 200) {
                    if (response.data) {
                        this.total = response.data.length;
                        this.templateList = response.data;
                    } else {
                        this.total = 0;
                        this.templateList = [];
                    }
                } else {
                    this.$message('模型数据列表获取失败。');
                }
            })
        },
        setModelLibraryExport(res) {
            modelPubMetas({
                ids: [res.id]
            }).then(response => {
                if (response.code == 200) {
                    this.$message({
                        message: '模型数据发布成功。',
                        type: 'success'
                    });
                    this.handleClick();
                } else {
                    this.$message('模型数据发布失败。');
                }
 
            })
        },
        setModelLibraryDelete(res) {
            modelDeletePublishes({
                ids: [res.id].toString()
            }).then(response => {
                if (response.code == 200) {
                    this.$message({
                        message: '模型服务移除成功。',
                        type: 'success'
                    });
                    this.handleClick();
                } else {
                    this.$message('模型服务移除失败。');
                }
 
            })
        },
        formatterTime(row, column, cellValue, index) {
            if (cellValue) {
                return configTools.formatterTime(cellValue);
            } else {
                return null
            }
 
        },
        formatterSize(row, column, cellValue, index) {
 
            if (cellValue) {
                return configTools.formatterSize(cellValue);
            } else {
                return null
            }
        },
    },
};
</script>
 
<style lang="scss" scoped>
.modelLibiraryBox {
    padding: 6px;
    width: 100%;
    height: 100%;
    position: absolute;
    display: flex;
    flex-direction: column;
 
    .modelLibiraryContent {
        margin: 6px 0px;
        flex: 1;
        position: relative;
 
        ::v-deep .el-card__body {
            padding: 15px !important;
        }
 
        .modelLibiraryTable {
            width: calc(100% - 30px);
            height: calc(100% - 36px);
            position: absolute;
            display: flex;
            flex-direction: column;
        }
    }
}
</style>