123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435 |
- <!-- 硬件分类 -->
- <template>
- <div class="app-container hardwareClassification">
- <div class="page-container hardwareClassificationPage" v-if="pageType === 1">
- <div class="page-form-title-box">
- <el-form :model="queryParams" class="form-box" ref="queryForm"
- :inline="true" style="width:100%;">
- <el-form-item label="" prop="searchValue">
- <el-input
- maxLength="30"
- v-model="queryParams.searchValue"
- placeholder="请输入名称/标识"
- style="width: 200px"
- />
- </el-form-item>
- <el-form-item label="" prop="state">
- <el-select v-model="queryParams.state" placeholder="请选择状态" style="width: 200px">
- <el-option
- v-for="dict in optionList"
- :key="dict.value"
- :label="dict.label"
- :value="dict.value"
- />
- </el-select>
- </el-form-item>
- <p class="page-inquire-common-style-button" @click="handleQuery">查询</p>
- <p class="page-reset-common-style-button" @click="resetQuery">重置</p>
- <p class="page-add-common-style-button"
- style="float: right;"
- @click="dialogFormReset"
- v-hasPermiRouter="['iot:hardwareType:add']"
- >新增</p>
- </el-form>
- </div>
- <div class="page-content-box">
- <el-table class="table-box" v-loading="loading" border :data="dataList">
- <el-table-column label="名称" prop="hardwareTypeName" show-overflow-tooltip/>
- <el-table-column label="硬件标识" prop="hardwareTypeKey" width="200" show-overflow-tooltip/>
- <el-table-column label="物联分类" prop="deviceTypeName" width="200" show-overflow-tooltip/>
- <el-table-column label="物联标识" prop="deviceTypeKey" width="200" show-overflow-tooltip/>
- <el-table-column label="状态" prop="state" width="100" show-overflow-tooltip
- v-hasPermiRouter="['iot:hardwareType:edit']">
- <template slot-scope="scope">
- <el-switch
- @click.native="tableButton(5,scope.row)"
- class="switch captcha-img"
- :active-value="true"
- :inactive-value="false"
- active-color="#0183FA"
- inactive-color="#999"
- v-model="scope.row.state"
- active-text="启用"
- inactive-text="停用"
- disabled
- ></el-switch>
- </template>
- </el-table-column>
- <el-table-column label="创建时间" prop="createTime" width="200" show-overflow-tooltip>
- <template slot-scope="scope">
- <span>{{ parseTime(scope.row.createTime,"{y}-{m}-{d} {h}:{i}") }}</span>
- </template>
- </el-table-column>
- <el-table-column label="操作" width="200" show-overflow-tooltip v-if="tableButtonType">
- <template slot-scope="scope">
- <div class="table-button-box">
- <p class="table-button-null"></p>
- <p class="table-button-p"
- @click="tableButton(2,scope.row)"
- v-hasPermiRouter="['iot:hardwareType:detail']"
- >详情</p>
- <p class="table-button-p"
- @click="tableButton(3,scope.row)"
- v-hasPermiRouter="['iot:hardwareType:edit']"
- >编辑</p>
- <p class="table-button-p"
- @click="tableButton(4,scope.row)"
- v-hasPermiRouter="['iot:hardwareType:del']"
- >删除</p>
- <p class="table-button-null"></p>
- </div>
- </template>
- </el-table-column>
- </el-table>
- <pagination :page-sizes="[20, 30, 40, 50]"
- v-show="total>0"
- :total="total"
- :page.sync="queryParams.page"
- :limit.sync="queryParams.pageSize"
- @pagination="getList"
- />
- </div>
- </div>
- <infoPage v-if="pageType == 2" :propsData="propsData"></infoPage>
- <!--新增弹窗-->
- <el-dialog class="iotClassification-dialog" :title='dialogTitle' width="540px" append-to-body
- :visible.sync="dialogType" v-if="dialogType" @close="dialogOff()"
- :close-on-click-modal="false" :close-on-press-escape="false">
- <el-form :model="dialogForm" ref="dialogForm" :inline="true"
- :rules="dialogRules" class="addCheckPage-min" label-width="120px">
- <!--<el-form-item label="名称" prop="hardwareTypeName">-->
- <!--<el-input v-model="dialogForm.hardwareTypeName" disabled-->
- <!--placeholder="请输入名称" maxLength="10" style="width:320px;"/>-->
- <!--</el-form-item>-->
- <el-form-item label="硬件标识" prop="hardwareTypeKey">
- <el-select v-model="dialogForm.hardwareTypeKey" @change="hardwareChange" placeholder="请选择硬件标识" style="width: 320px">
- <el-option
- v-for="dict in keyOptionList"
- :key="dict.code"
- :label="dict.name"
- :value="dict.code"
- />
- </el-select>
- </el-form-item>
- <el-form-item label="状态" prop="state">
- <el-radio-group v-model="dialogForm.state">
- <el-radio :label="true" style="margin-left:20px;">启用</el-radio>
- <el-radio :label="false">禁用</el-radio>
- </el-radio-group>
- </el-form-item>
- <el-form-item label="物联标识" prop="deviceTypeKey">
- <el-select v-model="dialogForm.deviceTypeKey" clearable @change="deviceChange" placeholder="请选择物联标识" style="width: 320px">
- <el-option
- v-for="dict in iotTypeOptions"
- :key="dict.typeKey"
- :label="dict.typeName"
- :value="dict.typeKey"
- />
- </el-select>
- </el-form-item>
- <el-form-item label="小图标:" prop="icon">
- <el-upload
- style="width:100px;"
- class="iotClassification-dialog-upload"
- :action="uploadImgUrl"
- :show-file-list="false"
- :on-success="(res)=>handleAvatarSuccess(res,'icon')"
- :headers="headers"
- :before-upload="(file)=>beforeAvatarUpload(file)">
- <div class="center-img" style="margin-left:20px;">
- <img v-if="dialogForm.icon" :src="dialogForm.icon" style="max-width:40px;max-height:40px;">
- <p v-if="!dialogForm.icon" class="el-icon-upload" style="text-align: center;line-height:40px;font-size:30px;color:#0183FA;"></p>
- </div>
- </el-upload>
- </el-form-item>
- <el-form-item label="大图标:" prop="exceptionIcon">
- <el-upload
- style="width:100px;"
- class="iotClassification-dialog-upload"
- :action="uploadImgUrl"
- :show-file-list="false"
- :on-success="(res)=>handleAvatarSuccess(res,'exceptionIcon')"
- :headers="headers"
- :before-upload="(file)=>beforeAvatarUpload(file)">
- <div class="center-img" style="margin-left:20px;">
- <img v-if="dialogForm.exceptionIcon" :src="dialogForm.exceptionIcon" style="max-width:40px;max-height:40px;">
- <p v-if="!dialogForm.exceptionIcon" class="el-icon-upload" style="text-align: center;line-height:40px;font-size:30px;color:#E65D6E;"></p>
- </div>
- </el-upload>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer dialog-footer-box">
- <p class="dialog-footer-button-null"></p>
- <p class="dialog-footer-button-info" @click="dialogOff()">取消</p>
- <p class="dialog-footer-button-primary" @click="dialogSubmit">提交</p>
- <p class="dialog-footer-button-null"></p>
- </div>
- </el-dialog>
- <!--<add-page :propsData="propsData" v-if="pageType === 2"></add-page>-->
- </div>
- </template>
- <script>
- import { getToken } from "@/utils/auth";
- import {
- iotHardwareTypeAdd,
- iotHardwareTypeUpdate,
- iotHardwareTypeList,
- iotHardwareTypeDelete,
- iotHardwareTypeGetTypeKey,
- iotTypeGetAllTypes
- } from '@/api/iotDevice/index'
- import infoPage from "./infoPage.vue"
- export default {
- name: 'index',
- components: {
- infoPage
- },
- data () {
- return {
- //上传相关
- uploadImgUrl: this.uploadUrl(), // 上传的图片服务器地址
- headers: {
- Authorization:getToken(),
- },
- tableButtonType:this.hasPermiDom(['iot:hardwareType:edit','iot:hardwareType:del',]),
- //页面状态
- pageType:1,
- //页面遮罩
- loading:false,
- //下拉列表数据
- optionList:[{value:true,label:'启用'},{value:false,label:'停用'}],
- keyOptionList:[],
- //查询条件
- queryParams:{
- page:1,
- pageSize:20,
- searchValue:"",
- state :null,
- },
- //列表数据
- dataList:[],
- //数据数量
- total:0,
- //组件传参
- propsData:{},
- //弹窗相关
- dialogTitle:'',
- dialogType:false,
- dialogForm:{},
- dialogRules:{
- hardwareTypeName: [
- { required: true, message: "请输入名称", trigger: "blur" },
- { required: true, message: "请输入名称", validator: this.spaceJudgment, trigger: "blur" }
- ],
- hardwareTypeKey: [
- { required: true, message: "请输入标识", trigger: "blur" },
- { required: true, message: "请输入标识", validator: this.spaceJudgment, trigger: "blur" }
- ],
- state: [
- { required: true, message: "请选择状态", trigger: "blur" },
- { required: true, message: "请选择状态", validator: this.spaceJudgment, trigger: "blur" }
- ],
- },
- //物联分类下拉列表
- iotTypeOptions:[],
- }
- },
- created () {
- },
- mounted () {
- this.iotTypeGetAllTypes();
- this.iotHardwareTypeGetTypeKey();
- this.getList();
- },
- methods: {
- //硬件选中
- hardwareChange(val){
- let self = this;
- this.keyOptionList.forEach((item) => {
- if(val == item.code){
- self.$set(self.dialogForm,'hardwareTypeKey',item.code);
- self.$set(self.dialogForm,'hardwareTypeName',item.name);
- }
- });
- },
- //物联选中
- deviceChange(val){
- let self = this;
- if(val){
- this.iotTypeOptions.forEach((item) => {
- if(val == item.typeKey){
- self.$set(self.dialogForm,'deviceTypeId',item.typeId);
- self.$set(self.dialogForm,'deviceTypeKey',item.typeKey);
- self.$set(self.dialogForm,'deviceTypeName',item.typeName);
- }
- });
- }else{
- this.$set(this.dialogForm,'deviceTypeId','');
- this.$set(this.dialogForm,'deviceTypeKey','');
- this.$set(this.dialogForm,'deviceTypeName','');
- }
- },
- //获取物联分类下拉列表
- iotTypeGetAllTypes(){
- iotTypeGetAllTypes({}).then(response => {
- this.$set(this,'iotTypeOptions',response.data);
- });
- },
- //查询按钮
- handleQuery(){
- this.$set(this.queryParams,'page',1);
- this.getList();
- },
- //重置按钮
- resetQuery(){
- this.$set(this,'queryParams',{
- page:1,
- pageSize:20,
- searchValue:"",
- state :null,
- });
- this.getList();
- },
- //获取数据列表
- getList(){
- this.$set(this,'loading',true);
- let obj = JSON.parse(JSON.stringify(this.queryParams))
- iotHardwareTypeList(obj).then(response => {
- this.$set(this,'loading',false);
- this.$set(this,'dataList',response.data.records);
- this.$set(this,'total',response.data.total);
- });
- },
- //操作按钮
- tableButton(type,row){
- let self = this;
- if(type == 2){
- //详情
- this.$set(this,'propsData',JSON.parse(JSON.stringify(row)));
- this.$set(this,'pageType',2);
- }if(type == 3){
- //编辑
- this.$set(this, 'dialogTitle', '编辑')
- let obj = JSON.parse(JSON.stringify(row))
- this.$set(this,'dialogForm',obj);
- this.$set(this,'dialogType',true);
- }else if(type == 4){
- //删除
- this.$confirm('是否确认删除?', "警告", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- }).then(function() {
- }).then(() => {
- iotHardwareTypeDelete({hardwareTypeId:row.hardwareTypeId}).then(response => {
- self.msgSuccess(response.message)
- self.getList();
- });
- }).catch(() => {});
- }else if(type == 5){
- //启用&停用
- let text = row.state ? "停用" : "启用";
- this.$confirm('是否确认' + text + '?', "警告", {
- confirmButtonText: "确定",
- cancelButtonText: "取消",
- type: "warning"
- }).then(function() {
- }).then(() => {
- iotHardwareTypeUpdate({hardwareTypeId:row.hardwareTypeId,state:!row.state,}).then(response => {
- self.msgSuccess(response.message)
- self.getList();
- });
- }).catch(() => {});
- }else if(type == 6){
- //返回并刷新
- this.$set(this,'pageType',1);
- this.getList();
- }
- },
- //获取分类标识
- iotHardwareTypeGetTypeKey(){
- iotHardwareTypeGetTypeKey({}).then(response => {
- this.$set(this,'keyOptionList',response.data);
- });
- },
- //**************************弹窗相关**************************
- //弹层关闭
- dialogOff(){
- this.$set(this,'dialogType',false);
- },
- //弹层新增
- dialogFormReset(){
- this.$set(this,'dialogTitle','新增');
- this.$set(this,'dialogForm',{
- hardwareTypeName:"",
- hardwareTypeKey:"",
- deviceTypeId:"",
- deviceTypeName:"",
- deviceTypeKey:"",
- state:"",
- icon:"",
- exceptionIcon:"",
- });
- this.$set(this,'dialogType',true);
- },
- //dialog提交按钮
- dialogSubmit(){
- this.$refs["dialogForm"].validate(valid => {
- if (valid) {
- let obj = {
- hardwareTypeName:this.dialogForm.hardwareTypeName,
- hardwareTypeKey:this.dialogForm.hardwareTypeKey,
- deviceTypeId:this.dialogForm.deviceTypeId,
- deviceTypeName:this.dialogForm.deviceTypeName,
- deviceTypeKey:this.dialogForm.deviceTypeKey,
- state:this.dialogForm.state,
- icon:this.dialogForm.icon,
- exceptionIcon:this.dialogForm.icon,
- }
- if(this.dialogForm.hardwareTypeId){
- obj.hardwareTypeId = this.dialogForm.hardwareTypeId;
- iotHardwareTypeUpdate(obj).then(response => {
- this.msgSuccess(response.message)
- this.dialogOff();
- this.getList();
- });
- }else{
- iotHardwareTypeAdd(obj).then(response => {
- this.msgSuccess(response.message)
- this.dialogOff();
- this.getList();
- });
- }
- }
- })
- },
- //图片上传相关
- handleAvatarSuccess(res,type) {
- if(type == 'icon'){
- this.$set(this.dialogForm,'icon',res.data.url);
- }else if(type == 'exceptionIcon'){
- this.$set(this.dialogForm,'exceptionIcon',res.data.url);
- }
- },
- beforeAvatarUpload(file) {
- return new Promise((resolve, reject) => {
- if (file.type == 'image/svg+xml') {
- resolve()
- }else{
- this.$message.error('只能上传svg格式图片');
- reject();
- }
- })
- },
- },
- }
- </script>
- <style scoped lang="scss">
- .hardwareClassification{
- .hardwareClassificationPage{
- }
- }
- </style>
|