device-detail.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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: "#000000",
  113. fontWeight: "bold",
  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. // 撑满父容器高度:tab 固定在顶部,滚动区域在 tab 下面
  230. display: flex;
  231. flex-direction: column;
  232. height: 100%;
  233. box-sizing: border-box;
  234. .device-tab {
  235. flex-shrink: 0;
  236. position: sticky;
  237. top: 0;
  238. z-index: 10;
  239. background-color: #f9f9fb;
  240. border-radius: 5px;
  241. border: 1px solid #fff;
  242. margin-bottom: 10px;
  243. }
  244. .device-content {
  245. display: flex;
  246. flex-direction: column;
  247. flex: 1;
  248. min-height: 0;
  249. box-sizing: border-box;
  250. overflow-y: auto;
  251. /* 查询条件卡片 */
  252. .filter-card {
  253. flex-shrink: 0;
  254. width: 100%;
  255. padding: 12px 10px;
  256. box-sizing: border-box;
  257. background-color: #fff;
  258. border-radius: 10px;
  259. margin-bottom: 10px;
  260. .filter-row {
  261. width: 100%;
  262. display: flex;
  263. align-items: center;
  264. & + .filter-row {
  265. margin-top: 10px;
  266. }
  267. .filter-label {
  268. flex-shrink: 0;
  269. width: 64px;
  270. display: flex;
  271. align-items: center;
  272. font-size: 13px;
  273. color: #333;
  274. .req {
  275. color: #f5222d;
  276. font-size: 13px;
  277. margin-right: 3px;
  278. }
  279. }
  280. .filter-picker {
  281. flex: 1;
  282. min-width: 0;
  283. }
  284. .filter-btn {
  285. flex-shrink: 0;
  286. width: 64px;
  287. height: 32px;
  288. margin-left: 8px;
  289. box-sizing: border-box;
  290. display: flex;
  291. align-items: center;
  292. justify-content: center;
  293. border-radius: 4px;
  294. font-size: 13px;
  295. }
  296. .btn-primary {
  297. color: #fff;
  298. background: linear-gradient(90deg, #3f8cff 0%, #2b7cff 100%);
  299. }
  300. .btn-plain {
  301. color: #2b7cff;
  302. background-color: #fff;
  303. border: 1px solid #2b7cff;
  304. }
  305. .is-disabled {
  306. opacity: 0.6;
  307. }
  308. }
  309. }
  310. .bot-area {
  311. flex: 1;
  312. min-height: 0;
  313. width: 100%;
  314. padding: 10px;
  315. box-sizing: border-box;
  316. background-color: #fff;
  317. border-radius: 10px;
  318. box-shadow: 0 2px 8px rgba(43, 124, 255, 0.08);
  319. .h-table {
  320. display: flex;
  321. flex-direction: column;
  322. width: 100%;
  323. height: 100%;
  324. box-sizing: border-box;
  325. border: 1px solid #bcd7fb;
  326. border-radius: 4px;
  327. overflow: hidden;
  328. .table-head {
  329. flex-shrink: 0;
  330. display: flex;
  331. align-items: center;
  332. height: 38px;
  333. background-color: transparent;
  334. border-bottom: 1px solid #bcd7fb;
  335. box-sizing: border-box;
  336. .head-item {
  337. height: 100%;
  338. display: flex;
  339. justify-content: center;
  340. align-items: center;
  341. box-sizing: border-box;
  342. font-size: 12px;
  343. font-weight: 600;
  344. color: #1a6dff;
  345. text-align: center;
  346. border-right: 1px solid #bcd7fb;
  347. &:last-child {
  348. border-right: none;
  349. }
  350. }
  351. }
  352. .table-content {
  353. flex: 1;
  354. min-height: 0;
  355. overflow-y: auto;
  356. .content-tr {
  357. display: flex;
  358. align-items: stretch;
  359. min-height: 44px;
  360. box-sizing: border-box;
  361. border-bottom: 1px solid #cfe1fa;
  362. &:last-child {
  363. border-bottom: none;
  364. }
  365. &:nth-child(odd) {
  366. background-color: #f5f9ff;
  367. }
  368. &:nth-child(even) {
  369. background-color: #e9f3ff;
  370. }
  371. .content-td {
  372. display: flex;
  373. justify-content: center;
  374. align-items: center;
  375. box-sizing: border-box;
  376. padding: 6px 4px;
  377. font-size: 12px;
  378. color: #333;
  379. text-align: center;
  380. word-break: break-all;
  381. border-right: 1px solid #cfe1fa;
  382. &:last-child {
  383. border-right: none;
  384. }
  385. }
  386. }
  387. }
  388. }
  389. }
  390. }
  391. }
  392. /* 日期选择器样式覆盖 */
  393. ::v-deep .uni-date-editor--x {
  394. box-sizing: border-box;
  395. height: 32px;
  396. border-radius: 4px;
  397. border-color: #dcdfe6;
  398. background-color: #fff;
  399. }
  400. ::v-deep .uni-date-x {
  401. flex-direction: row-reverse;
  402. height: 32px;
  403. background-color: transparent;
  404. }
  405. ::v-deep .uni-date-x .icon-calendar {
  406. padding-left: 0;
  407. padding-right: 6px;
  408. }
  409. ::v-deep .uni-date__x-input {
  410. height: 32px !important;
  411. line-height: 32px !important;
  412. padding-left: 8px !important;
  413. font-size: 12px !important;
  414. color: #333 !important;
  415. text-align: left;
  416. }
  417. </style>