device-detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. <template>
  2. <view class="device-detail">
  3. <view class="device-tab">
  4. <u-tabs
  5. class="devic-box-tab"
  6. :current="PageCur"
  7. :list="tabList"
  8. :activeStyle="activeTabStyle"
  9. :inactiveStyle="inactiveTabStyle"
  10. :itemStyle="tabItemStyle"
  11. lineColor="#2b7cff"
  12. :lineWidth="24"
  13. :lineHeight="3"
  14. @click="NavChange"
  15. ></u-tabs>
  16. </view>
  17. <view class="device-content">
  18. <view class="filter-card" v-if="PageCur != 0">
  19. <view class="filter-row">
  20. <view class="filter-label">
  21. <text class="req">*</text>
  22. <text>开始时间</text>
  23. </view>
  24. <uni-datetime-picker
  25. class="filter-picker"
  26. :clear-icon="false"
  27. placeholder="请选择开始时间"
  28. :disabled="isDisabled"
  29. type="datetime"
  30. v-model="datetimeStart"
  31. @change="changeStart"
  32. />
  33. <view
  34. class="filter-btn btn-primary"
  35. :class="{ 'is-disabled': isDisabled }"
  36. @click="getSearch"
  37. >查询</view
  38. >
  39. </view>
  40. <view class="filter-row">
  41. <view class="filter-label">
  42. <text class="req">*</text>
  43. <text>结束时间</text>
  44. </view>
  45. <uni-datetime-picker
  46. class="filter-picker"
  47. :clear-icon="false"
  48. placeholder="请选择结束时间"
  49. :disabled="isDisabled"
  50. type="datetime"
  51. v-model="datetimeEnd"
  52. @change="changeEnd"
  53. />
  54. <view
  55. class="filter-btn btn-plain"
  56. :class="{ 'is-disabled': isDisabled }"
  57. @click="getReset"
  58. >重置</view
  59. >
  60. </view>
  61. </view>
  62. <view class="bot-area">
  63. <view class="h-table">
  64. <view class="table-head">
  65. <view
  66. class="head-item"
  67. v-for="(item, index) in currentHead"
  68. :key="index"
  69. :style="{ width: item.width }"
  70. >{{ item.title }}</view
  71. >
  72. </view>
  73. <view class="table-content">
  74. <view
  75. class="content-tr"
  76. v-for="(ite, ind) in currentData"
  77. :key="ind"
  78. >
  79. <view
  80. class="content-td"
  81. v-for="(col, ci) in currentHead"
  82. :key="ci"
  83. :style="{ width: col.width }"
  84. >{{ cellText(ite, col.key) }}</view
  85. >
  86. </view>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </template>
  93. <script>
  94. import api from "@/api/api";
  95. import uniDatetimePicker from "../../../uni_modules/uni-datetime-picker/components/uni-datetime-picker/uni-datetime-picker.vue";
  96. export default {
  97. name: "deviceDetail",
  98. components: {
  99. uniDatetimePicker,
  100. },
  101. props: {},
  102. watch: {},
  103. data() {
  104. return {
  105. isDisabled: true,
  106. datetimeStart: null,
  107. datetimeEnd: null,
  108. PageCur: 0,
  109. tabList: [{ name: "实时预警" }, { name: "报警历史" }],
  110. tabItemStyle: { height: "46px", padding: "0 24px" },
  111. activeTabStyle: {
  112. color: "#2b7cff",
  113. fontWeight: "600",
  114. fontSize: "15px",
  115. },
  116. inactiveTabStyle: { color: "#666666", fontSize: "15px" },
  117. headList: [
  118. { title: "设备名称", key: "devicename", width: "20%" },
  119. { title: "报警类型", key: "nwartype_dictText", width: "20%" },
  120. { title: "报警开始时间", key: "starttime", width: "34%" },
  121. { title: "报警描述", key: "wardescrip", width: "26%" },
  122. ],
  123. tableData: [],
  124. tableDataHis: [],
  125. };
  126. },
  127. mounted() {
  128. this.getTableList();
  129. },
  130. methods: {
  131. NavChange: function (item) {
  132. this.PageCur = item.index;
  133. this.isDisabled = item.index ? false : true;
  134. if (item.index) {
  135. (this.datetimeStart = Date.now() - 1 * 24 * 3600 * 1000),
  136. (this.datetimeEnd = Date.now()),
  137. this.getHistoryList();
  138. } else {
  139. this.getTableList();
  140. }
  141. },
  142. //开始时间选项切换
  143. changeStart(date) {
  144. console.log(date, "date------------");
  145. this.datetimeStart = date;
  146. },
  147. //结束时间选项切换
  148. changeEnd(date) {
  149. this.datetimeEnd = date;
  150. },
  151. //获取实时监测列表数据
  152. getTableList() {
  153. new Promise((resolve, reject) => {
  154. api
  155. .warningList({ isok: 0 })
  156. .then((response) => {
  157. if (response.data.code == 200) {
  158. console.log(response.data, "设备详情数据-------");
  159. let data = response.data.result;
  160. this.tableData = data.list;
  161. } else {
  162. reject(response);
  163. }
  164. })
  165. .catch((error) => {
  166. console.log("catch===>response", response);
  167. reject(error);
  168. });
  169. });
  170. },
  171. //获取历史监测列表数据
  172. getHistoryList() {
  173. new Promise((resolve, reject) => {
  174. api
  175. .historyList({
  176. pages: 1,
  177. size: 200,
  178. starttime_begin: this.datetimeStart,
  179. starttime_end: this.datetimeEnd,
  180. })
  181. .then((response) => {
  182. if (response.data.code == 200) {
  183. console.log(response.data, "设备历史详情数据-------");
  184. let data = response.data.result;
  185. this.tableDataHis = data.records;
  186. } else {
  187. reject(response);
  188. }
  189. })
  190. .catch((error) => {
  191. console.log("catch===>response", response);
  192. reject(error);
  193. });
  194. });
  195. },
  196. //查询列表数据
  197. getSearch() {
  198. this.getHistoryList();
  199. },
  200. //重置列表数据
  201. getReset() {
  202. this.datetimeStart = Date.now() - 1 * 24 * 3600 * 1000;
  203. this.datetimeEnd = Date.now();
  204. this.getHistoryList();
  205. },
  206. //表格单元格文本
  207. cellText(item, key) {
  208. const value = item ? item[key] : "";
  209. return value === null || value === undefined || value === ""
  210. ? "--"
  211. : value;
  212. },
  213. },
  214. computed: {
  215. //当前表格表头
  216. currentHead() {
  217. return this.headList;
  218. },
  219. //当前表格数据
  220. currentData() {
  221. return this.isDisabled ? this.tableData : this.tableDataHis;
  222. },
  223. },
  224. };
  225. </script>
  226. <style lang="scss" scoped>
  227. .device-detail {
  228. position: relative;
  229. box-sizing: border-box;
  230. .device-tab {
  231. position: sticky;
  232. top: 0;
  233. z-index: 10;
  234. margin-bottom: 20rpx;
  235. }
  236. .devic-box-tab {
  237. padding: 0px 10px !important;
  238. }
  239. .device-content {
  240. display: flex;
  241. flex-direction: column;
  242. height: auto;
  243. min-height: 600px;
  244. box-sizing: border-box;
  245. overflow: hidden;
  246. /* 查询条件卡片 */
  247. .filter-card {
  248. flex-shrink: 0;
  249. width: 100%;
  250. padding: 12px 10px;
  251. box-sizing: border-box;
  252. background-color: #fff;
  253. border-radius: 10px;
  254. margin-bottom: 10px;
  255. .filter-row {
  256. width: 100%;
  257. display: flex;
  258. align-items: center;
  259. & + .filter-row {
  260. margin-top: 10px;
  261. }
  262. .filter-label {
  263. flex-shrink: 0;
  264. width: 64px;
  265. display: flex;
  266. align-items: center;
  267. font-size: 13px;
  268. color: #333;
  269. .req {
  270. color: #f5222d;
  271. font-size: 13px;
  272. margin-right: 3px;
  273. }
  274. }
  275. .filter-picker {
  276. flex: 1;
  277. min-width: 0;
  278. }
  279. .filter-btn {
  280. flex-shrink: 0;
  281. width: 64px;
  282. height: 32px;
  283. margin-left: 8px;
  284. box-sizing: border-box;
  285. display: flex;
  286. align-items: center;
  287. justify-content: center;
  288. border-radius: 4px;
  289. font-size: 13px;
  290. }
  291. .btn-primary {
  292. color: #fff;
  293. background: linear-gradient(90deg, #3f8cff 0%, #2b7cff 100%);
  294. }
  295. .btn-plain {
  296. color: #2b7cff;
  297. background-color: #fff;
  298. border: 1px solid #2b7cff;
  299. }
  300. .is-disabled {
  301. opacity: 0.6;
  302. }
  303. }
  304. }
  305. .bot-area {
  306. flex: 1;
  307. min-height: 0;
  308. width: 100%;
  309. padding: 10px;
  310. box-sizing: border-box;
  311. background-color: #fff;
  312. border-radius: 10px;
  313. box-shadow: 0 2px 8px rgba(43, 124, 255, 0.08);
  314. .h-table {
  315. display: flex;
  316. flex-direction: column;
  317. width: 100%;
  318. height: 100%;
  319. box-sizing: border-box;
  320. border: 1px solid #bcd7fb;
  321. border-radius: 4px;
  322. overflow: hidden;
  323. .table-head {
  324. flex-shrink: 0;
  325. display: flex;
  326. align-items: center;
  327. height: 38px;
  328. background-color: transparent;
  329. border-bottom: 1px solid #bcd7fb;
  330. box-sizing: border-box;
  331. .head-item {
  332. height: 100%;
  333. display: flex;
  334. justify-content: center;
  335. align-items: center;
  336. box-sizing: border-box;
  337. font-size: 12px;
  338. font-weight: 600;
  339. color: #1a6dff;
  340. text-align: center;
  341. border-right: 1px solid #bcd7fb;
  342. &:last-child {
  343. border-right: none;
  344. }
  345. }
  346. }
  347. .table-content {
  348. flex: 1;
  349. min-height: 0;
  350. overflow-y: auto;
  351. .content-tr {
  352. display: flex;
  353. align-items: stretch;
  354. min-height: 44px;
  355. box-sizing: border-box;
  356. border-bottom: 1px solid #cfe1fa;
  357. &:last-child {
  358. border-bottom: none;
  359. }
  360. &:nth-child(odd) {
  361. background-color: #f5f9ff;
  362. }
  363. &:nth-child(even) {
  364. background-color: #e9f3ff;
  365. }
  366. .content-td {
  367. display: flex;
  368. justify-content: center;
  369. align-items: center;
  370. box-sizing: border-box;
  371. padding: 6px 4px;
  372. font-size: 12px;
  373. color: #333;
  374. text-align: center;
  375. word-break: break-all;
  376. border-right: 1px solid #cfe1fa;
  377. &:last-child {
  378. border-right: none;
  379. }
  380. }
  381. }
  382. }
  383. }
  384. }
  385. }
  386. }
  387. /* 日期选择器样式覆盖 */
  388. ::v-deep .uni-date-editor--x {
  389. box-sizing: border-box;
  390. height: 32px;
  391. border-radius: 4px;
  392. border-color: #dcdfe6;
  393. background-color: #fff;
  394. }
  395. ::v-deep .uni-date-x {
  396. flex-direction: row-reverse;
  397. height: 32px;
  398. background-color: transparent;
  399. }
  400. ::v-deep .uni-date-x .icon-calendar {
  401. padding-left: 0;
  402. padding-right: 6px;
  403. }
  404. ::v-deep .uni-date__x-input {
  405. height: 32px !important;
  406. line-height: 32px !important;
  407. padding-left: 8px !important;
  408. font-size: 12px !important;
  409. color: #333 !important;
  410. text-align: left;
  411. }
  412. </style>