代码优化

This commit is contained in:
BianLzhaoMin 2024-08-09 13:53:32 +08:00
parent 440198e36b
commit 354f3f5ac5
4 changed files with 503 additions and 396 deletions

View File

@ -6,21 +6,15 @@
// const qrUrl = 'https://z.csgmall.com.cn/gl/qrCode/qrCodePage?qrCode='; //南网
// const qrUrl = process.env.NODE_ENV === 'production' ? 'http://192.168.0.14:18866/qrCode/qrCodePage?qrCode=' : 'http://192.168.0.14:21624/qrCode/qrCodePage?qrCode='
let qrUrl = ''
const origin = window.location.origin
if (origin == 'http://112.29.103.165:21626') {
qrUrl = 'http://112.29.103.165:21626/qrCode/qrCodePage?qrCode='
} else {
qrUrl = 'http://192.168.0.14:18866/qrCode/qrCodePage?qrCode='
const qrUrl = process.env.NODE_ENV === 'production' ? 'http://192.168.0.62:21624/sgzbgl/qrCode/qrCodePage?qrCode=' : 'http://192.168.0.14:18866/qrCode/qrCodePage?qrCode='
export default {
qrUrl,
}
// const qrUrl = process.env.NODE_ENV === 'production' ? 'https://z.csgmall.com.cn/sgzbgl/qrCode/qrCodePage?qrCode=' : 'http://192.168.0.14:18866/qrCode/qrCodePage?qrCode='
// export default {
// qrUrl,
// }

View File

@ -1,405 +1,517 @@
<template>
<div class="app-container" v-if="!isShow">
<el-form :model="queryForm" ref="queryForm" size="small" :inline="true" label-width="68px" v-show="showSearch">
<el-form-item label="关键字" prop="keyWord">
<el-input v-model="queryForm.keyWord" clearable placeholder="请输入关键字" @keyup.enter.native="handleQuery" />
</el-form-item>
<el-form-item>
<el-button type="primary" size="small" @click="handleQuery">搜索</el-button>
<el-button type="primary" size="small" @click="addIOT">添加设备</el-button>
<el-button type="primary" size="small" @click="downloadQRCord">下载二维码</el-button>
</el-form-item>
</el-form>
<el-row :gutter="10" class="mb8">
<right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
</el-row>
<el-table :data="tableData" style="width: 100%" @selection-change="selectionChange">
<el-table-column type="selection" width="55" align="center" />
<el-table-column
type="index"
label="序号"
align="center"
width="55"
:index="indexContinuation(queryParams.pageNum, queryParams.pageSize)"
/>
<el-table-column label="设备类型" prop="iotTypeName" align="center" />
<el-table-column label="设备编号" prop="iotCode" align="center" />
<el-table-column label="设备状态" prop="iotStatus" align="center">
<template v-slot="{ row }">
<el-tag v-if="row.iotStatus == 0" type="success">在线</el-tag>
<el-tag v-else type="danger">掉线</el-tag>
</template>
</el-table-column>
<el-table-column prop="prCode" label="二维码" align="center">
<template v-slot="{ row }">
<el-button type="text" size="small" @click="showQrCode(row)">查看</el-button>
</template>
</el-table-column>
<el-table-column label="状态" align="center">
<template v-slot="{ row }">
<el-tag v-if="row.bindStatus == 0" type="success">已绑定</el-tag>
<el-tag v-else type="danger">未绑定</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template v-slot="{ row }">
<el-button type="text" size="small" @click="handleCheck(row)" icon="el-icon-view">记录</el-button>
<el-button type="text" size="small" @click="handleEdit(row)" icon="el-icon-edit-outline">修改</el-button>
<el-button
type="text"
<div class="app-container" v-if="!isShow">
<el-form
:model="queryForm"
ref="queryForm"
size="small"
style="color: red"
@click="handleDelete(row)"
v-if="row.bindStatus == 1"
icon="el-icon-delete"
>
删除
</el-button>
<el-button
type="text"
size="small"
style="color: red"
@click="handleUnbind(row)"
v-if="row.bindStatus == 0"
icon="el-icon-connection"
>
解绑
</el-button>
</template>
</el-table-column>
</el-table>
:inline="true"
label-width="68px"
v-show="showSearch"
>
<el-form-item label="关键字" prop="keyWord">
<el-input
v-model="queryForm.keyWord"
clearable
placeholder="请输入关键字"
@keyup.enter.native="handleQuery"
/>
</el-form-item>
<el-form-item>
<el-button type="primary" size="small" @click="handleQuery"
>搜索</el-button
>
<el-button type="primary" size="small" @click="addIOT"
>添加设备</el-button
>
<!-- <el-button type="primary" size="small" @click="downloadQRCord"
>下载二维码</el-button
> -->
</el-form-item>
</el-form>
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<el-row :gutter="10" class="mb8">
<right-toolbar
:showSearch.sync="showSearch"
@queryTable="getList"
></right-toolbar>
</el-row>
<!-- 二维码弹框 -->
<el-dialog title="查看二维码" :visible.sync="uploadOpen" width="500px" append-to-body>
<div style="text-align: center">
<div class="qrCodeImg">
<div id="qrcode" class="qrcode" ref="codeItem"></div>
</div>
<div class="maCode">二维码编号{{ rowObj.qrCode }}</div>
</div>
<div slot="footer" class="dialog-footer" style="text-align: center"></div>
</el-dialog>
<el-table
:data="tableData"
style="width: 100%"
@selection-change="selectionChange"
>
<el-table-column type="selection" width="55" align="center" />
<el-table-column
type="index"
label="序号"
align="center"
width="55"
:index="
indexContinuation(queryParams.pageNum, queryParams.pageSize)
"
/>
<el-table-column
label="设备类型"
prop="iotTypeName"
align="center"
/>
<el-table-column label="设备编号" prop="iotCode" align="center" />
<el-table-column label="设备状态" prop="iotStatus" align="center">
<template v-slot="{ row }">
<el-tag size="mini" v-if="row.iotStatus == 0" type="success"
>在线</el-tag
>
<el-tag size="mini" v-else type="danger">下线</el-tag>
</template>
</el-table-column>
<el-table-column prop="prCode" label="二维码" align="center">
<template v-slot="{ row }">
<el-button type="text" size="small" @click="showQrCode(row)"
>查看</el-button
>
</template>
</el-table-column>
<el-table-column label="状态" align="center">
<template v-slot="{ row }">
<el-tag
v-if="row.bindStatus == 0"
type="success"
size="mini"
>已绑定</el-tag
>
<el-tag v-else type="warning" size="mini">未绑定</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" align="center">
<template v-slot="{ row }">
<el-button
type="text"
size="small"
@click="handleCheck(row)"
icon="el-icon-view"
>记录</el-button
>
<el-button
type="text"
size="small"
@click="handleEdit(row)"
icon="el-icon-edit-outline"
>修改</el-button
>
<el-button
type="text"
size="small"
style="color: red"
@click="handleDelete(row)"
v-if="row.bindStatus == 1"
icon="el-icon-delete"
>
删除
</el-button>
<el-button
type="text"
size="small"
style="color: red"
@click="handleUnbind(row)"
v-if="row.bindStatus == 0"
icon="el-icon-connection"
>
解绑
</el-button>
</template>
</el-table-column>
</el-table>
<!-- 添加/修改 设备弹框 -->
<el-dialog :title="title" :visible.sync="IOTOpen" width="500px" append-to-body>
<el-form :model="IOTForm" ref="IOTForm" label-width="120px" size="small" :rules="rules">
<el-form-item label="设备类型: " prop="iotType">
<el-select v-model="IOTForm.iotType" filterable clearable placeholder="请选择设备类型" style="width: 280px">
<el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value" />
</el-select>
</el-form-item>
<el-form-item label="设备编号: " prop="iotCode">
<el-input v-model="IOTForm.iotCode" clearable placeholder="请输入设备编号" style="width: 280px" />
</el-form-item>
<!-- 修改设备状态: 使用Switch开关 -->
<el-form-item label="设备状态: " prop="iotStatus" v-if="isEdit">
<el-switch
v-model="IOTForm.iotStatus"
active-text="在线"
inactive-text="掉线"
:active-value="0"
:inactive-value="1"
/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="IOTOpen = false"> </el-button>
<el-button type="primary" @click="submit"> </el-button>
</div>
</el-dialog>
</div>
<div v-else>
<BindDetails ref="bindDetails" :isShow="isShow" :iotId="iotId" />
</div>
<pagination
v-show="total > 0"
:total="total"
:page.sync="queryParams.pageNum"
:limit.sync="queryParams.pageSize"
@pagination="getList"
/>
<!-- 二维码弹框 -->
<el-dialog
title="查看二维码"
:visible.sync="uploadOpen"
width="500px"
append-to-body
>
<div style="text-align: center">
<div class="qrCodeImg">
<div id="qrcode" class="qrcode" ref="codeItem"></div>
</div>
<div class="maCode">二维码编号{{ rowObj.qrCode }}</div>
</div>
<div
slot="footer"
class="dialog-footer"
style="text-align: center"
></div>
</el-dialog>
<!-- 添加/修改 设备弹框 -->
<el-dialog
:title="title"
:visible.sync="IOTOpen"
width="500px"
append-to-body
>
<el-form
:model="IOTForm"
ref="IOTForm"
label-width="120px"
size="small"
:rules="rules"
>
<el-form-item label="设备类型: " prop="iotType">
<el-select
v-model="IOTForm.iotType"
filterable
clearable
placeholder="请选择设备类型"
style="width: 280px"
>
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
/>
</el-select>
</el-form-item>
<el-form-item label="设备编号: " prop="iotCode">
<el-input
v-model="IOTForm.iotCode"
clearable
placeholder="请输入设备编号"
style="width: 280px"
/>
</el-form-item>
<!-- 修改设备状态: 使用Switch开关 -->
<el-form-item label="设备状态: " prop="iotStatus" v-if="isEdit">
<el-switch
v-model="IOTForm.iotStatus"
active-text="在线"
inactive-text="下线"
:active-value="0"
:inactive-value="1"
/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="IOTOpen = false"> </el-button>
<el-button type="primary" @click="submit"> </el-button>
</div>
</el-dialog>
</div>
<div v-else>
<BindDetails ref="bindDetails" :isShow="isShow" :iotId="iotId" />
</div>
</template>
<script>
import BindDetails from './component/BindDetails'
import QRCode from 'qrcodejs2'
import { addOrUpdate, getIotList, deleteIotById, getRecordListAll, unbindIot } from '@/api/store/iotManagement.js'
import {
addOrUpdate,
getIotList,
deleteIotById,
getRecordListAll,
unbindIot,
} from '@/api/store/iotManagement.js'
export default {
name: 'IOTequipment',
components: {
BindDetails,
},
data() {
return {
isShow: false,
showSearch: true, //
uploadOpen: false, //
rowObj: {},
qrCode: '',
qrUrl: this.globalUrl.qrUrl,
queryForm: {
keyWord: '',
},
total: 0,
queryParams: {
pageNum: 1,
pageSize: 10,
},
tableData: [],
IOTForm: {
iotType: '',
iotCode: '',
iotStatus: '',
},
options: [
{
value: '125',
label: '定位设备',
},
{
value: '126',
label: '检测设备',
},
],
title: '',
IOTOpen: false,
//
rules: {
iotType: [{ required: true, message: '请选择设备类型', trigger: 'change' }],
iotCode: [
{ required: true, message: '请输入设备编号', trigger: 'blur' },
{
// 线(-) 线(_)
pattern: /^[a-zA-Z0-9_-]+$/,
message: '请输入正确的设备编码',
trigger: 'blur',
},
],
},
isEdit: false,
iotId: undefined,
}
},
created() {
this.getList()
},
methods: {
handleQuery() {
console.log('🚀 ~ handleQuery ~ 查询:', this.queryForm.keyWord)
this.getList()
name: 'IOTequipment',
components: {
BindDetails,
},
getList() {
const params = {
keyWord: this.queryForm.keyWord || '',
pageNum: this.queryParams.pageNum,
pageSize: this.queryParams.pageSize,
}
console.log('🚀 ~ getList ~ 获取列表', params)
data() {
return {
isShow: false,
showSearch: true, //
uploadOpen: false, //
rowObj: {},
qrCode: '',
qrUrl: this.globalUrl.qrUrl,
queryForm: {
keyWord: '',
},
total: 0,
queryParams: {
pageNum: 1,
pageSize: 10,
},
tableData: [],
IOTForm: {
iotType: '',
iotCode: '',
iotStatus: '',
},
options: [
// {
// value: '125',
// label: '',
// },
// {
// value: '126',
// label: '',
// },
],
title: '',
IOTOpen: false,
//
rules: {
iotType: [
{
required: true,
message: '请选择设备类型',
trigger: 'change',
},
],
iotCode: [
{
required: true,
message: '请输入设备编号',
trigger: 'blur',
},
{
// 线(-) 线(_)
pattern: /^[a-zA-Z0-9_-]+$/,
message: '请输入正确的设备编码',
trigger: 'blur',
},
],
},
isEdit: false,
iotId: undefined,
}
},
created() {
this.getList()
},
methods: {
handleQuery() {
console.log('🚀 ~ handleQuery ~ 查询:', this.queryForm.keyWord)
this.getList()
},
getList() {
const params = {
keyWord: this.queryForm.keyWord || '',
pageNum: this.queryParams.pageNum,
pageSize: this.queryParams.pageSize,
}
console.log('🚀 ~ getList ~ 获取列表', params)
getIotList(params)
.then(res => {
this.tableData = res.rows
this.total = res.total
})
.catch(err => {
console.log('🚀 ~ getList ~ err:', err)
})
},
//
getDeviceType() {
// ()
// .then(res => {
// this.options = res.data
// })
// .catch(err => {
// console.log('🚀 ~ getDeviceType ~ err:', err)
// })
},
addIOT() {
this.title = '添加设备'
this.IOTOpen = true
this.isEdit = false
this.getDeviceType()
this.$nextTick(() => {
this.IOTForm = {
iotType: '',
iotCode: '',
}
this.$refs.IOTForm.resetFields()
})
},
downloadQRCord() {
this.$confirm('是否下载二维码?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(() => {
// this.$message({
// type: 'success',
// message: '',
// })
})
},
showQrCode(row) {
console.log(row)
if (row.qrCode == null) {
this.$message.error('当前设备没有二维码')
return
}
this.rowObj = row
this.uploadOpen = true
this.qrCode = row.qrCode
let str = this.qrUrl + row.qrCode
console.log('🚀 ~ showQrCode ~ str:', str)
this.$nextTick(() => {
this.$refs.codeItem.innerHTML = ''
var qrcode = new QRCode(this.$refs.codeItem, {
text: str, //
width: 256,
height: 256,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H,
})
// console.log('🚀 ~ showQrCode ~ qrcode:', qrcode)
}, 500)
},
handleCheck(row) {
console.log('🚀 ~ handleCheck ~ 记录:', row)
this.isShow = true
this.iotId = row.iotId
},
handleEdit(row) {
console.log('🚀 ~ handleEdit ~ 修改:', row)
// IOT
this.title = '修改设备'
this.IOTOpen = true
this.isEdit = true
this.getDeviceType()
this.$nextTick(() => {
this.$refs.IOTForm.resetFields()
this.IOTForm = {
iotId: row.iotId,
iotType: row.iotType,
iotCode: row.iotCode,
iotStatus: row.iotStatus,
}
})
},
handleDelete(row) {
console.log('🚀 ~ handleDelete ~ 删除:', row)
//
this.$confirm('是否删除该设备?', '系统提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(() => {
//
deleteIotById(row.iotId).then(res => {
//
this.$message({
type: 'success',
message: '删除成功',
})
this.getList()
})
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消删除',
})
})
},
handleUnbind(row) {
try {
const params = {
id: undefined,
iotId: row.iotId,
maCode: '',
typeId: undefined,
}
console.log('🚀 ~ handleUnbind ~ 解绑', row)
this.$confirm('确定解绑设备吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(async () => {
let { data } = await getRecordListAll({ iotId: params.iotId })
console.log('🚀 ~ .then ~ res:', data)
data.forEach(item => {
if (!item.unBindTime) {
params.maCode = item.maCode
params.typeId = item.typeId
params.id = item.id
}
})
console.log('🚀 ~ .then ~ maCode:', params)
await unbindIot(params)
this.$message.success('解绑成功')
this.getList()
})
.catch((err) => {
console.log('🚀 ~ handleUnbind ~ err:', err)
this.$message.info('已取消解绑')
})
} catch (err) {
console.log('🚀 ~ handleUnbind ~ error', err)
}
},
selectionChange(val) {
console.log('🚀 ~ selectionChange ~ val:', val)
},
//
submit() {
this.$refs.IOTForm.validate(valid => {
if (valid) {
console.log('🚀 ~ submit ~ 确认提交', this.IOTForm)
let params = {}
if (this.isEdit) {
//
params = {
...this.IOTForm,
getIotList(params)
.then((res) => {
this.tableData = res.rows
this.total = res.total
})
.catch((err) => {
console.log('🚀 ~ getList ~ err:', err)
})
},
//
async getDeviceType() {
try {
const res = await selectList()
this.options = res.data
} catch (err) {
console.log('🚀 ~ getIotType ~ err:', err)
}
} else {
//
params = {
...this.IOTForm,
// ()
// .then(res => {
// this.options = res.data
// })
// .catch(err => {
// console.log('🚀 ~ getDeviceType ~ err:', err)
// })
},
addIOT() {
this.title = '添加设备'
this.IOTOpen = true
this.isEdit = false
this.getDeviceType()
this.$nextTick(() => {
this.IOTForm = {
iotType: '',
iotCode: '',
}
this.$refs.IOTForm.resetFields()
})
},
downloadQRCord() {
this.$confirm('是否下载二维码?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
}).then(() => {
// this.$message({
// type: 'success',
// message: '',
// })
})
},
showQrCode(row) {
console.log(row)
if (row.qrCode == null) {
this.$message.error('当前设备没有二维码')
return
}
}
addOrUpdate(params)
.then(res => {
this.IOTOpen = false
// isEdit ? '' : ''
this.$message({
type: 'success',
message: this.isEdit ? '修改成功' : '添加成功',
})
this.getList()
this.rowObj = row
this.uploadOpen = true
this.qrCode = row.qrCode
let str = this.qrUrl + row.qrCode
console.log('🚀 ~ showQrCode ~ str:', str)
this.$nextTick(() => {
this.$refs.codeItem.innerHTML = ''
var qrcode = new QRCode(this.$refs.codeItem, {
text: str, //
width: 256,
height: 256,
colorDark: '#000000',
colorLight: '#ffffff',
correctLevel: QRCode.CorrectLevel.H,
})
// console.log('🚀 ~ showQrCode ~ qrcode:', qrcode)
}, 500)
},
handleCheck(row) {
console.log('🚀 ~ handleCheck ~ 记录:', row)
this.isShow = true
this.iotId = row.iotId
},
handleEdit(row) {
console.log('🚀 ~ handleEdit ~ 修改:', row)
// IOT
this.title = '修改设备'
this.IOTOpen = true
this.isEdit = true
this.getDeviceType()
this.$nextTick(() => {
this.$refs.IOTForm.resetFields()
this.IOTForm = {
iotId: row.iotId,
iotType: row.iotType,
iotCode: row.iotCode,
iotStatus: row.iotStatus,
}
})
.catch(err => {
console.log('🚀 ~ submit ~ err:', err)
},
handleDelete(row) {
console.log('🚀 ~ handleDelete ~ 删除:', row)
//
this.$confirm('是否删除该设备?', '系统提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
}
})
.then(() => {
//
deleteIotById(row.iotId).then((res) => {
//
this.$message({
type: 'success',
message: '删除成功',
})
this.getList()
})
})
.catch(() => {
this.$message({
type: 'info',
message: '已取消删除',
})
})
},
handleUnbind(row) {
try {
const params = {
id: undefined,
iotId: row.iotId,
maCode: '',
typeId: undefined,
}
console.log('🚀 ~ handleUnbind ~ 解绑', row)
this.$confirm('确定解绑设备吗?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning',
})
.then(async () => {
let { data } = await getRecordListAll({
iotId: params.iotId,
})
console.log('🚀 ~ .then ~ res:', data)
data.forEach((item) => {
if (!item.unBindTime) {
params.maCode = item.maCode
params.typeId = item.typeId
params.id = item.id
}
})
console.log('🚀 ~ .then ~ maCode:', params)
await unbindIot(params)
this.$message.success('解绑成功')
this.getList()
})
.catch((err) => {
console.log('🚀 ~ handleUnbind ~ err:', err)
this.$message.info('已取消解绑')
})
} catch (err) {
console.log('🚀 ~ handleUnbind ~ error', err)
}
},
selectionChange(val) {
console.log('🚀 ~ selectionChange ~ val:', val)
},
//
submit() {
this.$refs.IOTForm.validate((valid) => {
if (valid) {
console.log('🚀 ~ submit ~ 确认提交', this.IOTForm)
let params = {}
if (this.isEdit) {
//
params = {
...this.IOTForm,
}
} else {
//
params = {
...this.IOTForm,
}
}
addOrUpdate(params)
.then((res) => {
this.IOTOpen = false
// isEdit ? '' : ''
this.$message({
type: 'success',
message: this.isEdit ? '修改成功' : '添加成功',
})
this.getList()
})
.catch((err) => {
console.log('🚀 ~ submit ~ err:', err)
})
}
})
},
},
},
}
</script>
<style lang="scss" scoped>
.qrCodeImg {
display: flex;
align-items: center;
justify-content: center;
display: flex;
align-items: center;
justify-content: center;
}
.maCode {
margin-top: 15px;
font-size: 18px;
margin-top: 15px;
font-size: 18px;
}
</style>

View File

@ -13,9 +13,7 @@
<span>({{ deviceType }})</span>
</div>
<div class="equipment">
定位设备编号: {{ equipmentNumber }}
</div>
<div class="equipment"> 定位设备编号: {{ iotCode }} </div>
<div class="equipment" v-if="false">{{ engineering }}工程</div>
<el-row :gutter="24">
<el-col :span="16">
@ -253,6 +251,10 @@ export default {
},
/** 查询按钮 */
async handleQuery() {
if (this.queryForm.date.length < 1) {
this.$message.error('请选择时间范围!')
return
}
this.tripParams.iotId = this.iotCode
const res = await getIotDeviceTripApi({ ...this.tripParams })
console.log(res, '行程信息--')

View File

@ -125,8 +125,7 @@
</el-form>
<el-row :gutter="10" class="mb8">
<el-col :span="1.5">
<!-- 推送 -->
<!-- <el-col :span="1.5">
<el-button
type="primary"
plain
@ -135,7 +134,7 @@
:disabled="ids.length == 0"
>推送租赁平台</el-button
>
</el-col>
</el-col> -->
<right-toolbar
:showSearch.sync="showSearch"
@queryTable="getList"