2023-03-21 20:24:04 +08:00
|
|
|
|
<template>
|
|
|
|
|
|
<div class="app-container">
|
|
|
|
|
|
<!--工具栏-->
|
|
|
|
|
|
<div class="head-container">
|
|
|
|
|
|
<!--如果想在工具栏加入更多按钮,可以使用插槽方式, slot = 'left' or 'right'-->
|
|
|
|
|
|
<crudOperation :permission="permission" />
|
|
|
|
|
|
<!--表单组件-->
|
|
|
|
|
|
<el-dialog
|
|
|
|
|
|
:close-on-click-modal="false"
|
|
|
|
|
|
:before-close="crud.cancelCU"
|
|
|
|
|
|
:visible.sync="crud.status.cu > 0"
|
|
|
|
|
|
:title="crud.status.title"
|
|
|
|
|
|
width="500px"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
|
|
|
|
|
|
<el-form-item label="编码" prop="code">
|
|
|
|
|
|
<el-input v-model="form.code" style="width: 370px;" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="名字" prop="name">
|
|
|
|
|
|
<el-input v-model="form.name" style="width: 370px;" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="值" prop="value">
|
|
|
|
|
|
<el-input v-model="form.value" style="width: 370px;" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="启用" prop="is_active">
|
|
|
|
|
|
<el-radio-group v-model="form.is_active" size="mini">
|
|
|
|
|
|
<el-radio-button label="1">是</el-radio-button>
|
|
|
|
|
|
<el-radio-button label="0">否</el-radio-button>
|
|
|
|
|
|
</el-radio-group>
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
<el-form-item label="备注" prop="description">
|
|
|
|
|
|
<el-input v-model="form.remark" style="width: 380px;" rows="5" type="textarea" />
|
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
</el-form>
|
|
|
|
|
|
<div slot="footer" class="dialog-footer">
|
|
|
|
|
|
<el-button type="text" @click="crud.cancelCU">取消</el-button>
|
|
|
|
|
|
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</el-dialog>
|
|
|
|
|
|
<!--表格渲染-->
|
|
|
|
|
|
<el-table
|
|
|
|
|
|
ref="table"
|
|
|
|
|
|
v-loading="crud.loading"
|
|
|
|
|
|
:data="crud.data"
|
|
|
|
|
|
size="small"
|
|
|
|
|
|
style="width: 100%;"
|
|
|
|
|
|
@selection-change="crud.selectionChangeHandler"
|
|
|
|
|
|
>
|
|
|
|
|
|
<el-table-column type="selection" width="55" />
|
|
|
|
|
|
<el-table-column v-if="false" prop="id" label="id" />
|
|
|
|
|
|
<el-table-column prop="code" label="编码" />
|
|
|
|
|
|
<el-table-column prop="name" label="名称" />
|
|
|
|
|
|
<el-table-column prop="value" label="值" />
|
|
|
|
|
|
<el-table-column prop="remark" label="备注" />
|
|
|
|
|
|
<el-table-column prop="is_active" label="启用" width="75px">
|
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
|
<span v-if="scope.row.is_active==0">否</span>
|
|
|
|
|
|
<span v-else>是</span>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
<el-table-column prop="create_by" label="创建者" />
|
|
|
|
|
|
<el-table-column v-permission="['admin','param:edit','param:del']" label="操作" width="150px" align="center">
|
|
|
|
|
|
<template slot-scope="scope">
|
|
|
|
|
|
<udOperation
|
|
|
|
|
|
:data="scope.row"
|
|
|
|
|
|
:permission="permission"
|
|
|
|
|
|
/>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
</el-table-column>
|
|
|
|
|
|
</el-table>
|
|
|
|
|
|
<!--分页组件-->
|
|
|
|
|
|
<pagination />
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
import crudParam from '@/api/system/param'
|
|
|
|
|
|
import CRUD, { presenter, header, form, crud } from '@crud/crud'
|
|
|
|
|
|
import crudOperation from '@crud/CRUD.operation'
|
|
|
|
|
|
import udOperation from '@crud/UD.operation'
|
|
|
|
|
|
import pagination from '@crud/Pagination'
|
|
|
|
|
|
|
|
|
|
|
|
const defaultForm = {
|
|
|
|
|
|
id: null,
|
|
|
|
|
|
code: null,
|
|
|
|
|
|
name: null,
|
|
|
|
|
|
value: null,
|
|
|
|
|
|
remark: null,
|
|
|
|
|
|
is_active: 1,
|
|
|
|
|
|
create_by: null,
|
|
|
|
|
|
create_time: null,
|
|
|
|
|
|
update_by: null,
|
|
|
|
|
|
update_time: null
|
|
|
|
|
|
}
|
|
|
|
|
|
export default {
|
|
|
|
|
|
name: 'Param',
|
|
|
|
|
|
components: { pagination, crudOperation, udOperation },
|
|
|
|
|
|
mixins: [presenter(), header(), form(defaultForm), crud()],
|
|
|
|
|
|
cruds() {
|
|
|
|
|
|
return CRUD({ title: '系统参数', url: 'api/param', idField: 'id', sort: 'id,desc', crudMethod: { ...crudParam }})
|
|
|
|
|
|
},
|
|
|
|
|
|
data() {
|
|
|
|
|
|
return {
|
|
|
|
|
|
permission: {
|
|
|
|
|
|
add: ['admin', 'param:add'],
|
|
|
|
|
|
edit: ['admin', 'param:edit'],
|
|
|
|
|
|
del: ['admin', 'param:del']
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
rules: {
|
|
|
|
|
|
id: [
|
|
|
|
|
|
{ required: true, message: '不能为空', trigger: 'blur' }
|
|
|
|
|
|
],
|
|
|
|
|
|
code: [
|
|
|
|
|
|
{ required: true, message: '不能为空', trigger: 'blur' }
|
|
|
|
|
|
],
|
|
|
|
|
|
name: [
|
|
|
|
|
|
{ required: true, message: '不能为空', trigger: 'blur' }
|
|
|
|
|
|
],
|
|
|
|
|
|
value: [
|
|
|
|
|
|
{ required: true, message: '不能为空', trigger: 'blur' }
|
|
|
|
|
|
],
|
|
|
|
|
|
create_time: [
|
|
|
|
|
|
{ required: true, message: '不能为空', trigger: 'blur' }
|
|
|
|
|
|
]
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
},
|
|
|
|
|
|
created() {
|
|
|
|
|
|
this.webSocket()
|
|
|
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
|
|
|
|
// 钩子:在获取表格数据之前执行,false 则代表不获取数据
|
|
|
|
|
|
[CRUD.HOOK.beforeRefresh]() {
|
|
|
|
|
|
return true
|
|
|
|
|
|
},
|
|
|
|
|
|
webSocket() {
|
|
|
|
|
|
const that = this
|
|
|
|
|
|
if (typeof (WebSocket) === 'undefined') {
|
|
|
|
|
|
this.$notify({
|
|
|
|
|
|
title: '提示',
|
|
|
|
|
|
message: '当前浏览器无法接收实时报警信息,请使用谷歌浏览器!',
|
|
|
|
|
|
type: 'warning',
|
|
|
|
|
|
duration: 0
|
|
|
|
|
|
})
|
|
|
|
|
|
} else {
|
2023-09-01 10:16:13 +08:00
|
|
|
|
const id = '123'
|
2023-03-21 20:24:04 +08:00
|
|
|
|
// 获取token保存到vuex中的用户信息,此处仅适用于本项目,注意删除或修改
|
|
|
|
|
|
// 实例化socket,这里我把用户名传给了后台,使后台能判断要把消息发给哪个用户,其实也可以后台直接获取用户IP来判断并推送
|
|
|
|
|
|
const wsUri = process.env.VUE_APP_WS_API + id
|
|
|
|
|
|
this.socket = new WebSocket(wsUri)
|
|
|
|
|
|
// 监听socket打开
|
|
|
|
|
|
this.socket.onopen = function() {
|
|
|
|
|
|
console.log('浏览器WebSocket已打开')
|
|
|
|
|
|
that.socket.send('测试客户端发送消息')
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 监听socket消息接收
|
|
|
|
|
|
|
|
|
|
|
|
this.socket.onmessage = function(msg) {
|
|
|
|
|
|
// 转换为json对象
|
|
|
|
|
|
/* const data = JSON.parse(msg.data);*/
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 监听socket错误
|
|
|
|
|
|
this.socket.onerror = function() {
|
|
|
|
|
|
that.$notify({
|
|
|
|
|
|
title: '错误',
|
|
|
|
|
|
message: '服务器错误,无法接收实时报警信息',
|
|
|
|
|
|
type: 'error',
|
|
|
|
|
|
duration: 0
|
|
|
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
// 监听socket关闭
|
|
|
|
|
|
this.socket.onclose = function() {
|
|
|
|
|
|
console.log('WebSocket已关闭')
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
|
|
|
|
</style>
|