index.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. <template>
  2. <a-form-model ref="form" :model="model" :rules="validatorRules">
  3. <a-form-model-item label="设备参数名" :labelCol="labelCol" :wrapperCol="wrapperCol">
  4. <a-input v-model="tagname" style="width: 20%" />
  5. <a-button @click="get" icon="reload" type="primary" style="margin-left: 10px">获取参数值</a-button>
  6. <a-button @click="getdirect" icon="reload" type="warning" style="margin-left: 10px">直接获取</a-button>
  7. </a-form-model-item>
  8. <a-form-model-item label="设备参数值" :labelCol="labelCol" :wrapperCol="wrapperCol">
  9. <a-input v-model="tagvalue" style="width: 20%" />
  10. <a-button type="info" icon="reload" @click="set" style="margin-left: 10px">设置参数值</a-button>
  11. </a-form-model-item>
  12. <a-form-model-item label="获取历史数据" :labelCol="labelCol" :wrapperCol="wrapperCol">
  13. <a-button type="info" icon="reload" @click="getlog">获取历史数据</a-button>
  14. <a-button type="info" icon="reload" @click="loginwa">登录WA</a-button>
  15. </a-form-model-item>
  16. <a-form-model-item label="返回内容" :labelCol="labelCol" :wrapperCol="wrapperCol">
  17. <a-textarea v-model="message" rows="9" />
  18. </a-form-model-item>
  19. </a-form-model>
  20. </template>
  21. <script>
  22. import { getWATagNameValues, setWATagNameValues, getWADataLog } from '@/api/datacoll/webaccess.js'
  23. import axios from 'axios'
  24. export default {
  25. name: 'Index',
  26. data() {
  27. return {
  28. model: {},
  29. labelCol: {
  30. xs: { span: 24 },
  31. sm: { span: 5 },
  32. },
  33. wrapperCol: {
  34. xs: { span: 24 },
  35. sm: { span: 16 },
  36. },
  37. tagname: '设备状态',
  38. tagvalue: 2,
  39. message: '',
  40. confirmLoading: false,
  41. }
  42. },
  43. methods: {
  44. loginwa() {
  45. const instance = axios.create({
  46. baseURL: 'https://192.168.2.246/WaWebService', // 目标服务器的URL
  47. timeout: 20000, // 请求超时时间
  48. headers: {
  49. 'Content-Type': 'application/json',
  50. Authorization: 'Basic YWRtaW46',
  51. },
  52. })
  53. instance
  54. .get('/Json/Logon')
  55. .then((response) => {
  56. console.log("登录", response);
  57. console.log(response.header);
  58. })
  59. .catch((error) => {
  60. // 处理错误
  61. console.error(error)
  62. })
  63. },
  64. get() {
  65. console.log('获取参数')
  66. if (this.tagname == '' || this.tagname == null) {
  67. this.$modal.msgError('请输入设备参数名')
  68. return false
  69. }
  70. getWATagNameValues({ tagName: this.tagname }).then((response) => {
  71. console.log(response)
  72. this.message = response.message
  73. })
  74. },
  75. getdirect() {
  76. console.log('直接获取获取参数值')
  77. if (this.tagname == '' || this.tagname == null) {
  78. this.$modal.msgError('请输入设备参数名')
  79. return false
  80. }
  81. var param = { Tags: [
  82. { Name: this.tagname },
  83. ]}
  84. const instance = axios.create({
  85. baseURL: 'http://127.0.0.1/WaWebService/Json', // 目标服务器的URL
  86. timeout: 3000, // 请求超时时间
  87. headers: {
  88. 'Content-Type': 'application/json',
  89. Authorization: 'Basic YWRtaW46',
  90. },
  91. })
  92. instance
  93. .post('/GetTagValue/瑞莱', param)
  94. .then((response) => {
  95. console.log(response.data.Values)
  96. this.message = response.data.Values[0].Value
  97. })
  98. .catch((error) => {
  99. // 处理错误
  100. console.error(error)
  101. })
  102. },
  103. set() {
  104. console.log('设置参数')
  105. if (this.tagname == '' || this.tagname == null) {
  106. this.$modal.msgError('请输入设备参数名')
  107. return false
  108. }
  109. if (this.tagvalue == '' || this.tagvalue == null) {
  110. this.$modal.msgError('请输入设备参数值')
  111. return false
  112. }
  113. setWATagNameValues({ tagName: this.tagname, tagValue: this.tagvalue }).then((response) => {
  114. console.log(response)
  115. this.message = response.message
  116. })
  117. },
  118. getlog() {
  119. console.log('获取历史数据')
  120. getWADataLog().then((response) => {
  121. console.log(response)
  122. this.message = response.message
  123. })
  124. },
  125. exit() {
  126. if (this.ws) {
  127. this.ws.close()
  128. this.ws = null
  129. }
  130. },
  131. },
  132. }
  133. </script>