dataCurve.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. <template>
  2. <view>
  3. <view class="all">
  4. <view class="chart">
  5. <view class="charts-box">
  6. <best-gauge :config="gaugeOption"></best-gauge>
  7. </view>
  8. <view class="charts-box">
  9. <best-gauge :config="gaugeOption2"></best-gauge>
  10. </view>
  11. </view>
  12. <view class="white">
  13. <view class="title1">
  14. <text class="param">空调排风温度变化</text>
  15. <view class="tiao"></view>
  16. </view>
  17. <view>
  18. <canvas canvas-id="canvasLineA" id="canvasLineA" class="charts" @touchmove="moveLineA"
  19. @touchend="moveLineA"></canvas>
  20. <!-- 画布,图表的HTML部分-->
  21. </view>
  22. </view>
  23. <view class="white1">
  24. <view class="title1">
  25. <text class="param">空调排风湿度变化</text>
  26. <view class="tiao"></view>
  27. </view>
  28. <view>
  29. <canvas canvas-id="canvasLineA11" id="canvasLineA11" class="charts" @touchmove="moveLineA11"
  30. @touchend="moveLineA11"></canvas>
  31. <!-- 画布,图表的HTML部分-->
  32. </view>
  33. </view>
  34. <view class="anniu">
  35. <image class="anniu" src="../../static/设备菜单/前往列表@2x.png" @tap="back"></image>
  36. </view>
  37. </view>
  38. </view>
  39. </template>
  40. <script>
  41. //仪表盘组件
  42. import bestGauge from '@/components/best-gauge/best-gauge.vue'
  43. //引入u-charts组件
  44. import uCharts from '@/components/u-charts/u-charts.js'
  45. var _self; //用于全局使用this
  46. var _self11; //用于全局使用this
  47. var canvaLineA = null; //uCharts实例
  48. var canvaLineA11 = null; //uCharts实例
  49. export default {
  50. components: {
  51. bestGauge,
  52. },
  53. data() {
  54. let _width = uni.upx2px(350);
  55. return {
  56. timeData: {
  57. time1: '',
  58. time2: '',
  59. time3: '',
  60. time4: '',
  61. time5: ''
  62. },
  63. WDdata: {
  64. WD1: '',
  65. WD2: '',
  66. WD3: '',
  67. WD4: '',
  68. WD5: '',
  69. },
  70. SDdata: {
  71. SD1: '',
  72. SD2: '',
  73. SD3: '',
  74. SD4: '',
  75. SD5: '',
  76. },
  77. formData: {
  78. WD_1: '',
  79. SD_1: '',
  80. QX: '2', //星期
  81. WD_SJ: '12',
  82. SD_SJ: '23',
  83. WD_SD: '34',
  84. SD_SD: '45',
  85. },
  86. cWidth: '',
  87. cHeight: '', //画布的宽高
  88. //仪表盘部分
  89. gaugeOption: { //定义参数
  90. id: 'gaugeId0',
  91. value: '',
  92. axisTickLength: 2 //该属性与axisTick互斥,存在axisTickLength并大于0,axisTick就无效
  93. },
  94. gaugeOption2: { //定义参数
  95. name: 'CK01排风湿度显示',
  96. id: 'gaugeId1',
  97. value: '',
  98. unit: '%',
  99. axisTickLength: 2 //该属性与axisTick互斥,存在axisTickLength并大于0,axisTick就无效
  100. },
  101. //折线图部分
  102. //温度
  103. data: { //数据
  104. categories: ['3时', '6时', '9时', '12时', '15时', '18时', '21时', '24时'],
  105. series: [{
  106. name: "温度实际值",
  107. data: [40, 30, 36, 44, 34],
  108. }, {
  109. name: "温度设定值",
  110. data: [10, 25, 23, 33, 23],
  111. color: "#336633"
  112. }]
  113. },
  114. //湿度
  115. data11: { //数据
  116. categories11: ['3时', '6时', '9时', '12时', '15时', '18时', '21时', '24时'],
  117. series11: [{
  118. name: "湿度实际值",
  119. data: [40, 30, 36, 44, 38],
  120. }, {
  121. name: "湿度设定值",
  122. data: [10, 25, 23, 33, 23],
  123. color: "red"
  124. }]
  125. },
  126. }
  127. },
  128. onLoad() {
  129. this.getWD_SJ()
  130. this.getSD_SJ()
  131. this.getWD_SD()
  132. this.getSD_SD()
  133. this.getWD_1()
  134. this.getSD_1()
  135. this.cWidth = uni.upx2px(702);
  136. this.cHeight = uni.upx2px(500); //设置宽高
  137. _self = this //声明this
  138. _self.showLineA("canvasLineA", _self.data); //触发执行函数
  139. _self11 = this //声明this
  140. _self11.showLineA11("canvasLineA11", _self11.data11); //触发执行函数
  141. },
  142. methods: {
  143. async getWD_SJ(e) {
  144. let vm = this;
  145. let url = uni.$api.deviceParam.detail;
  146. let data = {
  147. id: "292",
  148. };
  149. let res = await uni.$http.get(url, data);
  150. this.formData.WD_SJ = res.data.data.deviceParam.value;
  151. console.log(this.formData.WD_SJ);
  152. this.data.series[0].data[0] = this.formData.WD_SJ
  153. console.log("实际温度:" + this.data.series[0].data[0]);
  154. },
  155. async getSD_SJ(e) {
  156. let vm = this;
  157. let url = uni.$api.deviceParam.detail;
  158. let data = {
  159. id: "280",
  160. };
  161. let res = await uni.$http.get(url, data);
  162. this.formData.SD_SJ = res.data.data.deviceParam.value;
  163. console.log(this.formData.SD_SJ);
  164. this.data11.series11[0].data[0] = this.formData.SD_SJ
  165. console.log("实际湿度:" + this.data11.series11[0].data[0]);
  166. },
  167. async getWD_SD(e) {
  168. let vm = this;
  169. let url = uni.$api.deviceParam.detail;
  170. let data = {
  171. id: "296",
  172. };
  173. let res = await uni.$http.get(url, data);
  174. this.formData.WD_SD = res.data.data.deviceParam.value;
  175. console.log(this.formData.WD_SD);
  176. this.data.series[1].data[0] = this.formData.WD_SD
  177. console.log("设定温度:" + this.data.series[1].data[0]);
  178. },
  179. async getSD_SD(e) {
  180. let vm = this;
  181. var XQ = this.formData.QX;
  182. let url = uni.$api.deviceParam.detail;
  183. let data = {
  184. id: "231",
  185. };
  186. let res = await uni.$http.get(url, data);
  187. this.formData.SD_SD = res.data.data.deviceParam.value;
  188. console.log(this.formData.SD_SD);
  189. if (XQ == 1) {
  190. this.data11.series11[1].data[0] = this.formData.SD_SD
  191. console.log("周一设定湿度:" + this.data11.series11[1].data[0]);
  192. }
  193. if (XQ == 2) {
  194. this.data11.series11[1].data[1] = this.formData.SD_SD
  195. console.log("周二设定湿度:" + this.data11.series11[1].data[1]);
  196. }
  197. },
  198. back() {
  199. uni.navigateTo({
  200. url: '/pages/device/deviceInfo/deviceInfo'
  201. })
  202. },
  203. showLineA(canvasId, chartData) {
  204. canvaLineA = new uCharts({ //这些配置项的意思看这:https://www.kancloud.cn/qiun/ucharts/1172125
  205. $this: _self, //指针
  206. canvasId: canvasId, //id
  207. type: 'line', //类型
  208. colors: ['#F45E41'], //每一条的颜色
  209. fontSize: 14, //字体大小
  210. padding: [15, 15, 0, 15], //空白区域值
  211. legend: { //图例相关配置
  212. show: true,
  213. padding: 5,
  214. lineHeight: 11,
  215. margin: 0,
  216. },
  217. dataLabel: false, //显示数据标签内容值
  218. categories: chartData.categories, //数据类别
  219. series: chartData.series, //数据列表
  220. xAxis: { //X轴配置
  221. gridColor: '#CCCCCC', //X轴网格颜色
  222. gridType: 'dash', //X轴网格线型 'solid'为实线、'dash'为虚线`
  223. dashLength: 8, //X轴网格为虚线时,单段虚线长度
  224. },
  225. yAxis: { //y轴配置
  226. gridType: 'dash',
  227. gridColor: '#CCCCCC',
  228. dashLength: 8,
  229. },
  230. width: _self.cWidth, //canvas宽度,单位为px
  231. height: _self.cHeight, //canvas高度,单位为px
  232. extra: { //扩展配置
  233. line: {
  234. type: 'curve' //曲线 curve曲线,straight直线
  235. }
  236. }
  237. });
  238. },
  239. moveLineA(e) {
  240. canvaLineA.showToolTip(e, { //详情框
  241. format: function(item, category) {
  242. return category + ' ' + item.name + ':' + item.data + '℃'
  243. }
  244. });
  245. },
  246. //湿度
  247. showLineA11(canvasId, chartData) {
  248. canvaLineA11 = new uCharts({ //这些配置项的意思看这:https://www.kancloud.cn/qiun/ucharts/1172125
  249. $this: _self11, //指针
  250. canvasId: canvasId, //id
  251. type: 'line', //类型
  252. colors: ['#007AFF'], //每一条的颜色
  253. fontSize: 14, //字体大小
  254. padding: [15, 15, 0, 15], //空白区域值
  255. legend: { //图例相关配置
  256. show: true,
  257. padding: 5,
  258. lineHeight: 11,
  259. margin: 0,
  260. },
  261. dataLabel: false, //显示数据标签内容值
  262. categories: chartData.categories11, //数据类别
  263. series: chartData.series11, //数据列表
  264. xAxis: { //X轴配置
  265. gridColor: '#CCCCCC', //X轴网格颜色
  266. gridType: 'dash', //X轴网格线型 'solid'为实线、'dash'为虚线`
  267. dashLength: 8, //X轴网格为虚线时,单段虚线长度
  268. },
  269. yAxis: { //y轴配置
  270. gridType: 'dash',
  271. gridColor: '#CCCCCC',
  272. dashLength: 8,
  273. },
  274. width: _self11.cWidth, //canvas宽度,单位为px
  275. height: _self11.cHeight, //canvas高度,单位为px
  276. extra: { //扩展配置
  277. line: {
  278. type: 'curve' //曲线 curve曲线,straight直线
  279. }
  280. }
  281. });
  282. },
  283. moveLineA11(e) {
  284. canvaLineA11.showToolTip(e, { //详情框
  285. format: function(item, category) {
  286. return category + ' ' + item.name + ':' + item.data + '%'
  287. }
  288. });
  289. },
  290. async getWD_1(e) {
  291. let vm = this;
  292. let url = uni.$api.deviceParam.detail;
  293. let data = {
  294. id: "207",
  295. };
  296. let res = await uni.$http.get(url, data);
  297. console.log('form发生了submit事件')
  298. this.gaugeOption.value = res.data.data.deviceParam.value;
  299. },
  300. async getSD_1(e) {
  301. let vm = this;
  302. let url = uni.$api.deviceParam.detail;
  303. let data = {
  304. id: "293",
  305. };
  306. let res = await uni.$http.get(url, data);
  307. console.log('form发生了submit事件')
  308. this.gaugeOption2.value = res.data.data.deviceParam.value;
  309. },
  310. }
  311. }
  312. </script>
  313. <style>
  314. .anniu {
  315. width: 116rpx;
  316. height: 116rpx;
  317. float: right;
  318. margin-top: 20rpx;
  319. }
  320. .charts {
  321. margin-top: 60rpx;
  322. width: 702rpx;
  323. height: 500rpx;
  324. background-color: #FFFFFF;
  325. }
  326. .title1 {
  327. display: flex;
  328. flex-direction: column;
  329. align-items: center;
  330. }
  331. .tiao {
  332. width: 60px;
  333. height: 3px;
  334. margin-top: 20rpx;
  335. background: #007AFF;
  336. }
  337. .param {
  338. font-size: 38rpx;
  339. font-weight: 550;
  340. margin-top: 40rpx;
  341. }
  342. .white {
  343. width: 702rpx;
  344. height: 720rpx;
  345. margin-left: 24rpx;
  346. background-color: white;
  347. margin-top: 28rpx;
  348. border-radius: 10rpx;
  349. }
  350. .white1 {
  351. width: 702rpx;
  352. height: 720rpx;
  353. margin-left: 24rpx;
  354. background-color: white;
  355. margin-top: 28rpx;
  356. border-radius: 10rpx;
  357. }
  358. .chart {
  359. font-size: 26rpx;
  360. height: 300px;
  361. /* background:white; */
  362. background: rgb(30, 130, 250);
  363. display: flex;
  364. flex-direction: row;
  365. align-items: center;
  366. justify-content: center;
  367. }
  368. .charts-box {
  369. margin-left: 8rpx;
  370. margin-right: 8rpx;
  371. }
  372. </style>