smart-power-ui/src/views/iot/modelScries/index.vue

653 lines
18 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div class="app-container iot-model-series">
<el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" class="main-search-card" label-width="68px">
<el-form-item label="系列名称" prop="seriesName">
<el-input
v-model="queryParams.seriesName"
clearable
placeholder="请输入系列名称"
size="mini"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item label="产品PK" prop="prodKey">
<el-input
v-model="queryParams.prodKey"
clearable
placeholder="产品PK"
size="small"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
</el-form-item>
</el-form>
<div class="main-content-card">
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<el-button
v-hasPermi="['model:modelSeries:add']"
icon="el-icon-plus"
plain
size="mini"
type="primary"
@click="handleAdd"
>新增</el-button>
</el-col>
<el-col :span="1.5">
<el-button
v-hasPermi="['model:modelSeries:edit']"
:disabled="single"
icon="el-icon-edit"
plain
size="mini"
type="success"
@click="handleUpdate"
>修改</el-button>
</el-col>
<el-col :span="1.5">
<el-button
v-hasPermi="['model:modelSeries:remove']"
:disabled="multiple"
icon="el-icon-delete"
plain
size="mini"
type="danger"
@click="handleDelete"
>删除</el-button>
</el-col>
<el-col :span="1.5">
<el-button
v-hasPermi="['model:modelSeries:export']"
icon="el-icon-download"
plain
size="mini"
type="warning"
@click="handleExport"
>导出</el-button>
</el-col>
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table
v-loading="loading"
:data="modelSeriesList"
:default-sort="{ prop: 'createTime', order: 'descending' }"
@sort-change="sortChange">
<el-table-column
:index="indexFormatter"
align="center"
label="序号"
type="index"
width="80px"
></el-table-column>
<el-table-column
align="left"
label="系列名称"
prop="seriesName"
/>
<el-table-column
align="left"
label="产品PK"
prop="prodKey"
/>
<el-table-column
align="center"
label="设备类型"
prop="deviceType"
width="150px"
>
<template slot-scope="scope">
<span v-text="deviceTypeList[scope.row.deviceType]"></span>
</template>
</el-table-column>
<el-table-column
align="center"
label="启用状态"
prop="seriesStatus"
width="100px"
>
<template slot-scope="scope">
<el-tag v-if="scope.row.seriesStatus === '0'" type="success"
>启用</el-tag
>
<el-tag v-else type="danger">禁用</el-tag>
</template>
</el-table-column>
<el-table-column
align="center"
label=" 创建时间"
prop="createTime"
sortable="custom"
width="160px"
/>
<el-table-column
align="center"
class-name="small-padding fixed-width"
label="操作"
width="160px"
>
<template slot-scope="scope">
<el-button
v-hasPermi="['model:modelSeries:edit']"
icon="el-icon-edit"
size="mini"
type="text"
@click="handleUpdate(scope.row)"
>修改</el-button
>
<el-button
v-hasPermi="['model:modelSeries:remove']"
icon="el-icon-delete"
size="mini"
type="text"
@click="handleDelete(scope.row)"
>删除</el-button
>
</template>
</el-table-column>
</el-table>
<pagination
v-show="total>0"
:limit.sync="queryParams.pageSize"
:page.sync="queryParams.pageNum"
:total="total"
@pagination="getList"
/>
</div>
<dialog-template :title="title" :visible="open" width="1000px" @close="open = false" >
<el-form ref="form" slot="dialog-center" :model="form" :rules="rules" label-width="100px">
<el-row>
<el-col :span="12">
<el-form-item label="系列名称:" prop="seriesName">
<el-input v-model="form.seriesName" placeholder="请输入系列名称" />
</el-form-item>
</el-col>
<el-col :span="12">
<el-form-item label="产品PK" prop="prodKey">
<el-input
v-model="form.prodKey"
:disabled="form.seriesId || form.seriesId === 0"
placeholder="请填写产品PK"
></el-input>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item
label="产品json"
prop="prodJson"
>
<attribute-view
v-if="open"
ref="attributeref"
:arttributeList="form.prodJson"
:groupList="form.remark"
@handleEvent="handleViewEvent"
></attribute-view>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item label="设备类型:" prop="deviceType">
<el-select
v-model="form.deviceType"
clearable
placeholder="请选择设备类型"
size="small"
style="width: 100%"
>
<el-option
v-for="(keys, vals) in deviceTypeList"
:key="vals"
:label="keys"
:value="vals"
/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="24">
<el-form-item v-show="form.deviceType" label="参数设置:">
<span style="color: red; font-size: 12px"
>*注意:锁定即参数不可修改;未锁则可以修改。</span
>
<div class="form-params-wrap">
<param-wrap
ref="paramWrap"
:typeKeys="form.deviceType"
></param-wrap>
</div>
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="dialog-footer" class="dialog-footer">
<el-button size="mini" type="primary" @click="submitForm">确 定</el-button>
<el-button size="mini" @click="cancel">取 消</el-button>
</div>
</dialog-template>
<dialog-template
:title="componentTitle"
:visible="AttributeViewShow"
width="750px"
@close="
() => {
AttributeViewShow = false;
}
"
>
<component
:is="componectVal"
v-if="AttributeViewShow"
ref="componentref"
slot="dialog-center"
:other="{
action: '',
prodPK: form.prodKey,
cmdKey: '',
}"
:paramIdx="childOpt.paramIdx"
:paramsList="functionList"
:tempType="childOpt.type"
@ok="compEventOk"
></component>
<div slot="dialog-footer">
<el-button size="mini" type="primary" @click="submitAttribute"
>确 定</el-button
>
<el-button
size="mini"
@click="
() => {
AttributeViewShow = false;
}
"
>取 消</el-button
>
</div>
</dialog-template>
</div>
</template>
<script>
import { listDeviceTypeList } from "@/api/iot/device";
import { listModelSeries, getModelSeries, delModelSeries, addModelSeries, updateModelSeries, exportModelSeries } from "@/api/iot/modelSeries";
import DialogTemplate from "@/components/DialogTemplate";
import attributeForm from "@/views/profile/attribute/attributeForm";
import groupForm from "@/views/profile/attribute/groupForm";
import paramsJson from "@/views/profile/attribute/paramsJson";
import ParamWrap from "@/components/ParamWrap/deviceParam";
import AttributeView from "@/views/profile/attribute/index";
export default {
name: "ModelSeries",
components: {
DialogTemplate,
attributeForm,
groupForm,
paramsJson,
AttributeView,
ParamWrap,
},
data() {
return {
// 遮罩层
loading: true,
// 选中数组
ids: [],
// 非单个禁用
single: true,
// 非多个禁用
multiple: true,
// 显示搜索条件
showSearch: true,
// 总条数
total: 0,
// 型号系列表格数据
modelSeriesList: [],
// 弹出层标题
title: "",
// 执行状态字典
statusOptions: [],
// 是否显示弹出层
open: false,
// 查询参数
queryParams: {
pageNum: 1,
pageSize: 10,
seriesName: null,
prodKey: null,
deviceType: null,
seriesStatus: null,
createId: null,
updateId: null,
prodJson: null,
paramJson: null
},
// 表单参数
form: {},
// 表单校验
rules: {
vendorId: [
{ required: true, message: "厂商不能为空", trigger: "change" },
],
prodKey: [
{ required: true, message: "产品PK不能为空", trigger: "change" },
],
modelName: [
{ required: true, message: "型号名称不能为空", trigger: "blur" },
],
deviceType: [
{ required: true, message: "设备类型不能为空", trigger: "blur" },
],
},
///////
childOpt: {
type: "add",
paramIdx: 0,
},
componentTitle: "",
AttributeViewShow: false,
functionList: [],
componectVal: "attributeForm",
deviceTypeList: {},
};
},
created() {
this.getDicts("sys_status").then(response => {
this.statusOptions = response.data;
});
this.getDeviceTypeList();
this.getList();
},
methods: {
indexFormatter(val) {
return (
val + 1 + (this.queryParams.pageNum - 1) * this.queryParams.pageSize
);
},
handleViewEvent(data) {
console.log(data);
this.componentTitle = data.title;
(this.childOpt.type = data.type),
(this.childOpt.paramIdx = data.paramIdx);
this.AttributeViewShow = true;
this.functionList = JSON.parse(
JSON.stringify(this.$store.getters.attributeList)
);
this.componectVal = data.component;
},
submitAttribute() {
if (this.childOpt.type === "param") {
this.AttributeViewShow = false;
return;
}
if (this.$refs.componentref) {
this.$refs.componentref.submitForm();
}
},
compEventOk() {
//执行
this.AttributeViewShow = false;
this.$forceUpdate();
this.$refs.attributeref.forceUpdate(this.componectVal);
},
// 查询设备类型列表
getDeviceTypeList() {
listDeviceTypeList().then((response) => {
this.deviceTypeList = response.data;
});
},
sortChange(column) {
const sort = {
isAsc: column.order === "descending" ? "desc" : "asc",
orderByColumn: column.prop,
};
this.queryParams = Object.assign(this.queryParams, sort);
this.handleQuery();
},
// 执行状态字典翻译
statusFormat(row, column) {
return this.selectDictLabel(this.statusOptions, row.status);
},
/** 查询型号系列列表 */
getList() {
this.loading = true;
listModelSeries(this.queryParams).then(response => {
this.modelSeriesList = response.rows;
this.total = response.total;
this.loading = false;
});
},
// 取消按钮
cancel() {
this.open = false;
this.reset();
},
// 表单重置
reset() {
this.form = {
seriesId: null,
seriesName: '',
prodKey: '',
deviceType: '',
seriesStatus: "0",
prodJson: '[]',
paramJson: '[]'
};
this.resetForm("form");
},
/** 搜索按钮操作 */
handleQuery() {
this.queryParams.pageNum = 1;
this.getList();
},
/** 重置按钮操作 */
resetQuery() {
this.resetForm("queryForm");
this.handleQuery();
},
// 多选框选中数据
handleSelectionChange(selection) {
this.ids = selection.map(item => item.seriesId)
this.single = selection.length!==1
this.multiple = !selection.length
},
/** 新增按钮操作 */
handleAdd() {
this.reset();
this.form.prodJson = '';
this.open = true;
this.title = "添加型号系列";
},
/** 修改按钮操作 */
handleUpdate(row) {
this.reset();
const seriesId = row.seriesId || this.ids;
const _this = this;
getModelSeries(seriesId).then((response) => {
_this.form = response.data;
_this.open = true;
_this.title = "修改型号系列";
setTimeout(() => {
_this.$refs.paramWrap.setList(JSON.parse(response.data.paramJson) || []);
}, 100);
});
},
/** 提交按钮 */
submitForm() {
this.$refs["form"].validate((valid) => {
if (valid) {
// if (this.form.protocolType === "OFFICIAL") {
let attrList = [];
if (
this.$store.getters.attributeList &&
this.$store.getters.attributeList.length > 0
) {
attrList = this.$store.getters.attributeList.map((v) => {
v["sourceId"] = this.form.prodKey;
return v;
});
attrList.sort((a, b) => a.sort - b.sort);
}
let groupList = [];
if (
this.$store.getters.groupList &&
this.$store.getters.groupList.length > 0
) {
groupList = this.$store.getters.groupList.map((v) => {
v["sourceId"] = this.form.prodKey;
return v;
});
groupList.sort((a, b) => a.sort - b.sort);
}
let functionList = [];
if (
this.$store.getters.functionList &&
this.$store.getters.functionList.length > 0
) {
functionList = this.$store.getters.functionList;
}
this.form.prodJson = JSON.stringify({
properties:attrList,
functions:functionList,
events:[]
}) || null;
this.form.remark = JSON.stringify(groupList) || null;
// }
try {
this.form.paramJson = JSON.stringify(this.$refs.paramWrap.getResult());
} catch (error) {
this.form.paramJson = "";
}
if (this.form.seriesId != null) {
updateModelSeries(this.form).then((response) => {
this.msgSuccess("修改成功");
this.open = false;
this.getList();
});
} else {
addModelSeries(this.form).then((response) => {
this.msgSuccess("新增成功");
this.open = false;
this.getList();
});
}
}
});
},
/** 删除按钮操作 */
handleDelete(row) {
const seriesIds = row.seriesId || this.ids;
this.$confirm("是否删除该选项?", "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return delModelSeries(seriesIds);
}).then(() => {
this.getList();
this.msgSuccess("删除成功");
})
},
/** 导出按钮操作 */
handleExport() {
const queryParams = this.queryParams;
this.$confirm('是否确认导出所有数据项?', "警告", {
confirmButtonText: "确定",
cancelButtonText: "取消",
type: "warning"
}).then(function() {
return exportModelSeries(queryParams);
}).then(response => {
this.download(response.msg);
})
}
}
};
</script>
<style lang="scss">
.iot-model-series {
.eldialog-wrap {
.el-dialog__header {
}
.el-dialog__body {
padding: 0px;
}
.el-form {
padding: 20px;
padding-right: 40px;
}
.el-dialog__footer {
height: 60px;
text-align: right;
width: 100%;
padding: 0px;
padding-top: 15px;
.el-button + .el-button {
margin-right: 10px;
}
.el-button {
padding-top: 8px;
}
}
.form-params-wrap {
height: 100%;
width: calc(100% + 110px);
position: relative;
top: 15px;
left: -90px;
max-height: 250px;
overflow: auto;
padding: 10px;
border: 1px solid #009688;
border-radius: 5px;
}
}
}
.form-params-wrap::-webkit-scrollbar {
/*滚动条整体样式*/
width: 8px; /*高宽分别对应横竖滚动条的尺寸*/
height: 5px;
}
.form-params-wrap::-webkit-scrollbar-thumb {
/*滚动条里面小方块*/
border-radius: 10px;
box-shadow: inset 0 0 5px #c4c4c4;
background: #dededea6;
}
.form-params-wrap::-webkit-scrollbar-track {
/*滚动条里面轨道*/
box-shadow: inset 0 0 5px #f6f6f6;
border-radius: 10px;
background: #ffffff;
}
</style>