优化代码&删除多余的请求

This commit is contained in:
wu
2022-08-24 14:10:27 +08:00
parent f845494607
commit 2a86558335
5 changed files with 478 additions and 590 deletions

View File

@@ -8,7 +8,7 @@ export default ({ service, request, serviceForMock, requestForMock, mock, faker,
VERIFY_SERVER (url) { VERIFY_SERVER (url) {
return request({ return request({
auth: { auth: {
username: 'admin', username: 'admin',
password: process.env.VUE_APP_HSLSERVER_PASSWORD password: process.env.VUE_APP_HSLSERVER_PASSWORD
}, },
method: 'post', method: 'post',
@@ -19,7 +19,7 @@ export default ({ service, request, serviceForMock, requestForMock, mock, faker,
MODIFY_SERVER (url, data) { MODIFY_SERVER (url, data) {
return request({ return request({
auth: { auth: {
username: 'admin', username: 'admin',
password: process.env.VUE_APP_HSLSERVER_PASSWORD password: process.env.VUE_APP_HSLSERVER_PASSWORD
}, },
data: data, data: data,
@@ -50,7 +50,7 @@ export default ({ service, request, serviceForMock, requestForMock, mock, faker,
GET_HSLSERVER_CONFIGURE (url) { GET_HSLSERVER_CONFIGURE (url) {
return request({ return request({
auth: { auth: {
username: 'admin', username: 'admin',
password: process.env.VUE_APP_HSLSERVER_PASSWORD password: process.env.VUE_APP_HSLSERVER_PASSWORD
}, },
method: 'post', method: 'post',
@@ -60,7 +60,7 @@ export default ({ service, request, serviceForMock, requestForMock, mock, faker,
SET_HSLSERVER_CONFIGURE (url, data) { SET_HSLSERVER_CONFIGURE (url, data) {
return request({ return request({
auth: { auth: {
username: 'admin', username: 'admin',
password: process.env.VUE_APP_HSLSERVER_PASSWORD password: process.env.VUE_APP_HSLSERVER_PASSWORD
}, },
data: data, data: data,
@@ -75,7 +75,7 @@ export default ({ service, request, serviceForMock, requestForMock, mock, faker,
GET_SERVE_DEVICE_MONITORING (url) { GET_SERVE_DEVICE_MONITORING (url) {
return request({ return request({
auth: { auth: {
username: 'admin', username: 'admin',
password: process.env.VUE_APP_HSLSERVER_PASSWORD password: process.env.VUE_APP_HSLSERVER_PASSWORD
}, },
url: url + '/Edge/DeviceData?data=/' url: url + '/Edge/DeviceData?data=/'
@@ -88,37 +88,40 @@ export default ({ service, request, serviceForMock, requestForMock, mock, faker,
GET_SERVER_DEVICE_STATUS (url) { GET_SERVER_DEVICE_STATUS (url) {
return request({ return request({
auth: { auth: {
username: 'admin', username: 'admin',
password: process.env.VUE_APP_HSLSERVER_PASSWORD password: process.env.VUE_APP_HSLSERVER_PASSWORD
}, },
url: url + '/Edge/DeviceData?data=__status' url: url + '/Edge/DeviceData?data=__status'
}) })
}, },
GET_DEVICE_POINT_VALUE(url, deviceName, data, type){ GET_DEVICE_POINT_VALUE (url, deviceName, data, type) {
return request({ return request({
validateStatus: (status) => {
return status === 404 ? 200 : status
},
auth: { auth: {
username: 'admin', username: 'admin',
password: process.env.VUE_APP_HSLSERVER_PASSWORD password: process.env.VUE_APP_HSLSERVER_PASSWORD
}, },
data: { data: {
'address':data address: data
}, },
method: 'post', method: 'post',
url: url + '/'+ deviceName +'/Read'+ type +'32' url: url + '/' + deviceName + '/Read' + type + '32'
}) })
}, },
SET_DEVICE_POINT_VALUE(url, deviceName, data, type, value){ SET_DEVICE_POINT_VALUE (url, deviceName, data, type, value) {
return request({ return request({
auth: { auth: {
username: 'admin', username: 'admin',
password: process.env.VUE_APP_HSLSERVER_PASSWORD password: process.env.VUE_APP_HSLSERVER_PASSWORD
}, },
data: { data: {
address:data, address: data,
value:value value: value
}, },
method: 'post', method: 'post',
url: url + '/'+ deviceName +'/Write'+ type +'32' url: url + '/' + deviceName + '/Write' + type + '32'
}) })
} }
}) })

File diff suppressed because it is too large Load Diff

View File

@@ -3,7 +3,7 @@
<el-form :inline="true" size="mini" :model="deviceConfigureModelValue" ref="form" :rules="rules" <el-form :inline="true" size="mini" :model="deviceConfigureModelValue" ref="form" :rules="rules"
label-position="right" class="demo-form-inline"> label-position="right" class="demo-form-inline">
<el-form-item label="设备"> <el-form-item label="设备">
<el-select @change="deviceChange" v-model="defaultDeviceTypeNameValue" placeholder="请选择"> <el-select @change="deviceChange" filterable v-model="defaultDeviceTypeNameValue" placeholder="请选择">
<el-option v-for="item in deviceTypeData" :key="item" :label="item" :value="item"> <el-option v-for="item in deviceTypeData" :key="item" :label="item" :value="item">
</el-option> </el-option>
</el-select> </el-select>
@@ -116,7 +116,7 @@ export default {
}) })
this.rules = rules this.rules = rules
this.deviceConfigureModelValue = assign(deviceConfigureModelValue, { '@ParentDeviceCode': '' }) this.deviceConfigureModelValue = assign(deviceConfigureModelValue, { '@ParentDeviceCode': '' })
//this.deviceConfigureModelValue = this.choosable === 'true' ? assign(deviceConfigureModelValue, { parent_device_code: '' }) : deviceConfigureModelValue // this.deviceConfigureModelValue = this.choosable === 'true' ? assign(deviceConfigureModelValue, { parent_device_code: '' }) : deviceConfigureModelValue
this.deviceConfigureFormItem = deviceConfigureFormItemData[e] this.deviceConfigureFormItem = deviceConfigureFormItemData[e]
}, },
setDeviceDefaultFormItemValue (val) { setDeviceDefaultFormItemValue (val) {
@@ -124,7 +124,7 @@ export default {
// if (this.choosable === 'true') { // if (this.choosable === 'true') {
// deviceConfigureModelValue["@ParentDeviceCode"] = val["@ParentDeviceCode"] // deviceConfigureModelValue["@ParentDeviceCode"] = val["@ParentDeviceCode"]
// } // }
deviceConfigureModelValue["@ParentDeviceCode"] = val["@ParentDeviceCode"] || '' deviceConfigureModelValue['@ParentDeviceCode'] = val['@ParentDeviceCode'] || ''
each(deviceConfigureFormItemData[this.defaultDeviceTypeNameValue], (item) => { each(deviceConfigureFormItemData[this.defaultDeviceTypeNameValue], (item) => {
if (item.type === 'time') { if (item.type === 'time') {
deviceConfigureModelValue[item.key] = val[item.key] ? val[item.key] : new Date() deviceConfigureModelValue[item.key] = val[item.key] ? val[item.key] : new Date()

View File

@@ -195,7 +195,7 @@ export default {
labelPosition: 'left', labelPosition: 'left',
saveLoading: false, saveLoading: false,
saveButtonText: '测试', saveButtonText: '测试',
saveButtonType: 'text', saveButtonType: 'text'
}, },
addRules: { addRules: {
deviceName: [{ required: true, type: 'string', message: '服务名称不可为空', trigger: 'blur' }], deviceName: [{ required: true, type: 'string', message: '服务名称不可为空', trigger: 'blur' }],
@@ -222,10 +222,10 @@ export default {
} }
}, },
handleDialogOpen ({ mode }) { handleDialogOpen ({ mode }) {
if(mode === 'edit'){ if (mode === 'edit') {
this.formOptions.saveButtonText = '确定' this.formOptions.saveButtonText = '确定'
this.formOptions.saveButtonType = 'text' this.formOptions.saveButtonType = 'text'
} }
}, },
// 普通的新增 // 普通的新增
addRow () { addRow () {
@@ -239,7 +239,7 @@ export default {
// 定义测试动作 // 定义测试动作
if (this.formOptions.saveButtonText === '测试') { if (this.formOptions.saveButtonText === '测试') {
this.serverSettings = await this.$api.VERIFY_SERVER( this.serverSettings = await this.$api.VERIFY_SERVER(
'http://' + row.url + ':' + row.port, 'http://' + row.url + ':' + row.port
) )
if (this.serverSettings) { if (this.serverSettings) {
this.$message({ this.$message({
@@ -289,8 +289,8 @@ export default {
}, },
async handleRowEdit ({ index, row }, done) { async handleRowEdit ({ index, row }, done) {
this.formOptions.saveLoading = true this.formOptions.saveLoading = true
let serverSettings = await this.$api.VERIFY_SERVER( const serverSettings = await this.$api.VERIFY_SERVER(
'http://' + row.url + ':' + row.port 'http://' + row.url + ':' + row.port
) )
serverSettings.Content.ServerInfoConfig.CaptureURL = row.address serverSettings.Content.ServerInfoConfig.CaptureURL = row.address
this.$api.MODIFY_SERVER( this.$api.MODIFY_SERVER(
@@ -321,33 +321,31 @@ export default {
done() done()
}, },
setServerExec ({ row }) { setServerExec ({ row }) {
this.$confirm('是否要重启动该服务', '提示', { this.$confirm('是否要重启动该服务', '提示', {
confirmButtonText: '确定', confirmButtonText: '确定',
cancelButtonText: '取消', cancelButtonText: '取消',
type: 'warning' type: 'warning'
}).then(async () => { }).then(async () => {
try { try {
await this.$api.SET_SERVER_EXEC({ await this.$api.SET_SERVER_EXEC({
action: 'exec', action: 'exec',
server_id: row.id, server_id: row.id,
command: 'server_restart' command: 'server_restart'
}) })
this.$message({
message: '服务应用请求成功,请求动作已添加至请求队列中,请从服务监控页面查看结果',
type: 'success'
})
this.getServers()
} catch (e) {
console.log(e)
}
}).catch(() => {
this.$message({ this.$message({
type: 'info', message: '服务应用请求成功,请求动作已添加至请求队列中,请从服务监控页面查看结果',
message: '已重启动该服务' type: 'success'
}); })
}); this.getServers()
} catch (e) {
console.log(e)
}
}).catch(() => {
this.$message({
type: 'info',
message: '已重启动该服务'
})
})
}, },
handleDialogCancel (done) { handleDialogCancel (done) {
this.$message({ this.$message({
@@ -369,7 +367,7 @@ export default {
}, },
closeDrawer () { closeDrawer () {
this.server = { id: 0, url: '', port: '' } this.server = { id: 0, url: '', port: '' }
if(this.$refs.deviceTemplate.timing){ if (this.$refs.deviceTemplate.timing) {
this.$refs.deviceTemplate.clearTime() this.$refs.deviceTemplate.clearTime()
} }
}, },

View File

@@ -211,7 +211,7 @@ export default {
}, },
mounted () { mounted () {
this.getServe() this.getServe()
setInterval(()=>{ setInterval(() => {
this.getServe() this.getServe()
}, 30000) }, 30000)
} }