InternetExtruder.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429
  1. <template>
  2. <view class="InternetExtruder">
  3. <view class="mainBox-image">
  4. <view class="image-title">实时温度</view>
  5. <view class="image-list">
  6. <l-echart ref="chart"></l-echart>
  7. <!-- <qiun-data-charts type="gauge" :chartData="chartData" background="none" :opts="opts" /> -->
  8. </view>
  9. </view>
  10. <view>
  11. <uni-table border stripe emptyText="暂无更多数据">
  12. <!-- 表头行 -->
  13. <uni-tr>
  14. <uni-th align="center" width="200rpx"></uni-th>
  15. <uni-th align="center">油温(℃)</uni-th>
  16. <uni-th align="center">速度(mm/s)</uni-th>
  17. <uni-th align="center">压力 (Kg/cm²)</uni-th>
  18. </uni-tr>
  19. <!-- 表格数据行 -->
  20. <template v-if="tableData.length">
  21. <uni-tr>
  22. <uni-td>当日峰值</uni-td>
  23. <uni-td>{{ tableData[0].maxValue }}</uni-td>
  24. <uni-td>{{ tableData[1].maxValue }}</uni-td>
  25. <uni-td>{{ tableData[2].maxValue }}</uni-td>
  26. </uni-tr>
  27. <uni-tr>
  28. <uni-td>当日谷值</uni-td>
  29. <uni-td>{{ tableData[0].minValue }}</uni-td>
  30. <uni-td>{{ tableData[1].minValue }}</uni-td>
  31. <uni-td>{{ tableData[2].minValue }}</uni-td>
  32. </uni-tr>
  33. <uni-tr>
  34. <uni-td>当日均值</uni-td>
  35. <uni-td>{{ tableData[0].avgValue }}</uni-td>
  36. <uni-td>{{ tableData[1].avgValue }}</uni-td>
  37. <uni-td>{{ tableData[2].avgValue }}</uni-td>
  38. </uni-tr>
  39. </template>
  40. </uni-table>
  41. </view>
  42. </view>
  43. </template>
  44. <script>
  45. // import uCharts from '@/plugins/stan-ucharts/u-charts/u-charts-2.js'
  46. // import * as echarts from 'echarts'
  47. import { get, postJ } from '@/utils/api.js'
  48. import * as echarts from '@/uni_modules/lime-echart/static/echarts.min'
  49. import { debounce } from 'lodash'
  50. import mqtt from './mqtt'
  51. export default {
  52. mixins: [mqtt],
  53. data () {
  54. return {
  55. opts: {},
  56. chartData: {},
  57. tableData: [],
  58. propertyList: [
  59. {
  60. name: '油温',
  61. property: 'oil_temp'
  62. },
  63. {
  64. name: '速度',
  65. property: 'speed'
  66. },
  67. {
  68. name: '压力',
  69. property: 'measure_pressure'
  70. }
  71. ],
  72. // mqtt 订阅类别
  73. topIc_type: 'EXTRUDER_TOPIC'
  74. }
  75. },
  76. props: ['realData', 'info'],
  77. computed: {
  78. // mqtt topic
  79. TOPIC () {
  80. if (this.info.iotId) {
  81. return {
  82. topic: `/${this.topIc_type}/${this.info.iotId}`,
  83. qos: 0
  84. }
  85. } else {
  86. return null
  87. }
  88. }
  89. },
  90. created () {
  91. this.getTableData()
  92. if (this.TOPIC) {
  93. this.mqttInit()
  94. }
  95. },
  96. mounted () {
  97. this.initGauge()
  98. },
  99. methods: {
  100. async initGauge () {
  101. console.log(this.info)
  102. let option = {
  103. tooltip: {
  104. show: false
  105. },
  106. series: [
  107. {
  108. zlevel: 1,
  109. ...this.getGaugeSeries(),
  110. center: ['25%', '30%'],
  111. splitNumber: 4,
  112. min: 0,
  113. max: this.getMax(this.info.measure_pressure || 0, 12),
  114. name: 'Pressure',
  115. backgroundColor: '#000',
  116. data: [
  117. {
  118. value: this.realData.measure_pressure
  119. ? this.realData.measure_pressure.value
  120. : 0,
  121. name: '压力表'
  122. }
  123. ],
  124. detail: {
  125. width: '60%',
  126. lineHeight: 40,
  127. height: 40,
  128. fontSize: 18,
  129. borderRadius: 8,
  130. offsetCenter: [0, '30%'],
  131. valueAnimation: true,
  132. formatter: function (value) {
  133. return `${value}kg/cm²`
  134. }
  135. }
  136. },
  137. // {
  138. // ...this.getGaugeSeriesBg(),
  139. // center: ['25%', '28%']
  140. // },
  141. {
  142. ...this.getGaugeSeries(),
  143. zlevel: 1,
  144. splitNumber: 4,
  145. min: 0,
  146. max: this.getMax(this.info.speed || 0, 80),
  147. center: ['75%', '30%'],
  148. name: 'Pressure1',
  149. data: [
  150. {
  151. value: this.realData.speed ? this.realData.speed.value : 0,
  152. name: '速度表'
  153. }
  154. ],
  155. detail: {
  156. width: '60%',
  157. lineHeight: 40,
  158. height: 40,
  159. fontSize: 18,
  160. borderRadius: 8,
  161. offsetCenter: [0, '30%'],
  162. valueAnimation: true,
  163. formatter: function (value) {
  164. return `${value}m/s`
  165. }
  166. }
  167. },
  168. // {
  169. // ...this.getGaugeSeriesBg(),
  170. // center: ['75%', '28%']
  171. // },
  172. {
  173. ...this.getGaugeSeries(),
  174. zlevel: 1,
  175. splitNumber: 4,
  176. min: 0,
  177. max: this.getMax(this.info.oil_temp || 0, 4000),
  178. center: ['25%', '80%'],
  179. name: 'Pressure2',
  180. data: [
  181. {
  182. value: this.realData.oil_temp
  183. ? this.realData.oil_temp.value
  184. : 0,
  185. name: '油温表'
  186. }
  187. ],
  188. detail: {
  189. width: '60%',
  190. lineHeight: 40,
  191. height: 40,
  192. fontSize: 18,
  193. borderRadius: 8,
  194. offsetCenter: [0, '30%'],
  195. valueAnimation: true,
  196. formatter: function (value) {
  197. return `${value}度`
  198. }
  199. }
  200. }
  201. // {
  202. // ...this.getGaugeSeriesBg(),
  203. // center: ['25%', '75%']
  204. // }
  205. ]
  206. }
  207. this.$refs.chart.init(echarts, chart => {
  208. chart.setOption(option)
  209. })
  210. },
  211. async getTableData () {
  212. function fnNum (num) {
  213. return num < 10 ? '0' + num : num
  214. }
  215. let startTime
  216. let endTime
  217. let ndate = new Date()
  218. let year = ndate.getFullYear()
  219. let month = ndate.getMonth() + 1
  220. let day = ndate.getDate()
  221. let _date = `${year}-${fnNum(month)}-${fnNum(day)}`
  222. startTime = _date + ' 00:00:00'
  223. endTime = _date + ' 23:59:59'
  224. const resList = await Promise.all(
  225. this.propertyList.map(i =>
  226. postJ(
  227. this.apiUrl +
  228. `/asset/getEquHistory?equId=${this.info.id}&startTime=${startTime}&endTime=${endTime}&timeType=3&property=${i.property}`
  229. )
  230. )
  231. )
  232. this.tableData = resList.map(i => {
  233. if (i?.success) {
  234. return i.data || {}
  235. }
  236. return {}
  237. })
  238. },
  239. // mqtt处理数据
  240. initMqttData (items) {
  241. console.log('mqtt处理数据', items)
  242. for (const [key, obj] of Object.entries(items)) {
  243. const realData = this.realData
  244. realData[key].value = obj.value
  245. realData[key].time = obj.time
  246. this.$emit('update:realData', realData)
  247. }
  248. let initGauge = debounce(this.initGauge, 1000)
  249. initGauge()
  250. },
  251. getGaugeSeriesBg () {
  252. return {
  253. data: [],
  254. startAngle: 360,
  255. endAngle: 0,
  256. radius: '41%',
  257. type: 'gauge',
  258. detail: {
  259. show: false
  260. },
  261. title: {
  262. show: false
  263. },
  264. axisLabel: {
  265. show: false
  266. },
  267. splitLine: {
  268. show: false
  269. },
  270. axisTick: {
  271. show: false
  272. },
  273. axisLine: {
  274. lineStyle: {
  275. width: 100,
  276. color: [[1, '#fff']]
  277. }
  278. },
  279. progress: {
  280. show: false
  281. },
  282. anchor: {
  283. show: false
  284. },
  285. pointer: {
  286. show: false
  287. }
  288. }
  289. },
  290. getGaugeSeries () {
  291. return {
  292. startAngle: 200,
  293. endAngle: -20,
  294. radius: '40%',
  295. type: 'gauge',
  296. detail: {
  297. valueAnimation: true,
  298. formatter: '{value}'
  299. },
  300. title: {
  301. show: true,
  302. offsetCenter: [0, '65%'],
  303. color: '#9e9e9e',
  304. fontSize: 14
  305. },
  306. axisLabel: {
  307. rotate: 360,
  308. distance: -38,
  309. color: '#666666',
  310. fontSize: 18
  311. },
  312. splitLine: {
  313. show: false
  314. },
  315. axisTick: {
  316. show: false
  317. },
  318. axisLine: {
  319. roundCap: true,
  320. lineStyle: {
  321. width: 12,
  322. // color:'#dddefd',
  323. color: [[1, '#B9BEFF']]
  324. }
  325. },
  326. progress: {
  327. show: true,
  328. roundCap: true,
  329. width: 12,
  330. itemStyle: {
  331. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [
  332. {
  333. offset: 0,
  334. color: '#15b4ff'
  335. },
  336. {
  337. offset: 1,
  338. color: '#716dff'
  339. }
  340. ]),
  341. shadowColor: 'rgba(0,138,255,0.45)',
  342. shadowBlur: 10,
  343. shadowOffsetX: 2,
  344. shadowOffsetY: 2
  345. }
  346. },
  347. itemStyle: {
  348. color: '#7a71ff',
  349. shadowColor: 'rgba(0,138,255,0.45)',
  350. shadowBlur: 10,
  351. shadowOffsetX: 2,
  352. shadowOffsetY: 2,
  353. borderCap: 'round'
  354. },
  355. anchor: {
  356. show: true,
  357. showAbove: true
  358. },
  359. pointer: {
  360. icon: 'path://M2090.36389,615.30999 L2090.36389,615.30999 C2091.48372,615.30999 2092.40383,616.194028 2092.44859,617.312956 L2096.90698,728.755929 C2097.05155,732.369577 2094.2393,735.416212 2090.62566,735.56078 C2090.53845,735.564269 2090.45117,735.566014 2090.36389,735.566014 L2090.36389,735.566014 C2086.74736,735.566014 2083.81557,732.63423 2083.81557,729.017692 C2083.81557,728.930412 2083.81732,728.84314 2083.82081,728.755929 L2088.2792,617.312956 C2088.32396,616.194028 2089.24407,615.30999 2090.36389,615.30999 Z',
  361. length: '75%',
  362. width: 12,
  363. offsetCenter: [0, 8]
  364. // itemStyle: {
  365. // color: '#7a71ff',
  366. // }
  367. }
  368. }
  369. },
  370. getMax (data, def = 100) {
  371. let half = def / 2
  372. if (data <= def) {
  373. return def
  374. }
  375. const n = data % half
  376. const m = Math.floor(data / half)
  377. return n === 0 ? m * half : (m + 1) * half
  378. }
  379. }
  380. }
  381. </script>
  382. <style lang="scss" scoped>
  383. .InternetExtruder /deep/.uni-table {
  384. min-width: 100vw !important;
  385. .uni-table-td,
  386. .uni-table-th {
  387. padding: 20rpx 10rpx !important;
  388. text-align: center !important;
  389. }
  390. }
  391. .mainBox-image {
  392. width: 100%;
  393. .image-title {
  394. width: 98%;
  395. margin: 16rpx auto 0;
  396. font-size: 28rpx;
  397. font-weight: bold;
  398. color: #000;
  399. }
  400. .image-list {
  401. width: 100vw;
  402. display: flex;
  403. align-items: center;
  404. justify-content: space-between;
  405. .charts-box {
  406. width: 100vw;
  407. height: 800rpx;
  408. }
  409. }
  410. }
  411. </style>