index.vue 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view style="position: fixed;top:44px;z-index: 100;width: 100%;">
  5. <uni-nav-bar right-icon="search" title="设备列表" @clickRight="clickRight"></uni-nav-bar>
  6. <view class="inputs" :style="{'width':width}">
  7. <input type="text" value="" placeholder="请输入设备ID或设备名称" v-model="imports" @input="searchinput"
  8. class="inputbox" :clearable="false" />
  9. <u-icon name="search" size="40" class="icon" @click="search"></u-icon>
  10. </view>
  11. </view>
  12. <view class="utabs_box">
  13. <view class="utabs">
  14. <u-tabs :list="list" :is-scroll="true" :current="currents" @change="change" item-width="140"
  15. font-size="24" gutter="20" bar-width="60" active-color="#42b983" v-if="list.length"></u-tabs>
  16. </view>
  17. </view>
  18. <view class="loading" v-if="loadingtf">
  19. <image src="../../static/images/ajax-loader.gif" mode="" class="img"></image>
  20. </view>
  21. <view class="list">
  22. <view class="list_item" v-for="(item,index) in eqlistdata" :key="index" @click="historys(item)">
  23. <view class="list_item_top">
  24. <p class="p1">
  25. <image :src="'http://www.hnyfwlw.com:8006/bigdata_app/image/fourMoodBase/'+type_id+'.png'"
  26. mode=""></image>
  27. {{item.device_name==''?"--":item.device_name}}
  28. </p>
  29. <p :class="[item.is_online?'p2':'p_out']">{{item.is_online?"在线":"离线"}}</p>
  30. </view>
  31. <view class="list_item_text">
  32. <p>设备ID:{{item.imei || item.device_id}}</p>
  33. <p>适配用户:{{item.real_name==''?"无":item.real_name}}</p>
  34. <p>最新上报时间:{{item.addtime|timeFormat()}}</p>
  35. <p>添加设备时间:{{item.uptime|timeFormat()}}</p>
  36. <p>设备已运行:{{item.days}}天</p>
  37. </view>
  38. <view class="list_item_btn" v-if="infoalter" @click.stop="modification(item)">
  39. 信息修改
  40. </view>
  41. </view>
  42. </view>
  43. <view class="top" v-if="isTop" @click="top">
  44. <image :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/6209a98f0cb3b5086f2ca36152c9269.png'"
  45. mode=""></image>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import {
  51. Debounce,
  52. Throttle
  53. } from "../../util/anitthro.js"
  54. export default {
  55. data() {
  56. return {
  57. list: [],
  58. current: 0,
  59. currents: 0,
  60. page: 1,
  61. size: 10,
  62. eqlistdata: [],
  63. isTop: false,
  64. infoalter: false, // 权限设置,
  65. type_id: 0, //设备类型,
  66. imgpath: [],
  67. loadingtf: false,
  68. width: 0, //顶部搜索栏宽度
  69. imports: "" //搜索设备ID
  70. }
  71. },
  72. methods: {
  73. async eqlist(tf) { //设备列表
  74. this.loadingtf = true
  75. const res = await this.$myRequest({
  76. url: '/api/api_gateway?method=forecast.worm_lamp.lamp_list',
  77. data: {
  78. device_type_id: this.type_id,
  79. page: this.page,
  80. page_size: this.size,
  81. device_id: this.imports,
  82. }
  83. })
  84. this.loadingtf = false
  85. var newtime = +new Date() / 1000
  86. if (tf) {
  87. this.eqlistdata = this.eqlistdata.concat(res.data)
  88. } else {
  89. this.eqlistdata = res.data
  90. }
  91. for (var i = 0; i < this.eqlistdata.length; i++) {
  92. var days = (newtime - this.eqlistdata[i].uptime) / 60 / 60 / 24
  93. this.eqlistdata[i].days = Math.round(days)
  94. }
  95. console.log(res)
  96. },
  97. async xyeqlist(tf) { //设备列表
  98. this.loadingtf = true
  99. const res = await this.$myRequest({
  100. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_list',
  101. data: {
  102. device_type_id: this.type_id,
  103. page: this.page,
  104. page_size: this.size,
  105. device_id: this.imports,
  106. }
  107. })
  108. this.loadingtf = false
  109. var newtime = +new Date() / 1000
  110. if (tf) {
  111. this.eqlistdata = this.eqlistdata.concat(res.data)
  112. } else {
  113. this.eqlistdata = res.data
  114. }
  115. for (var i = 0; i < this.eqlistdata.length; i++) {
  116. var days = (newtime - this.eqlistdata[i].uptime) / 60 / 60 / 24
  117. this.eqlistdata[i].days = Math.round(days)
  118. }
  119. console.log(res)
  120. },
  121. //camera.camera_manage.list_camera
  122. async camera() { //监控
  123. const res = await this.$myRequest({
  124. url: '/api/api_gateway?method=camera.camera_manage.list_camera',
  125. data: {
  126. page_size: 1,
  127. }
  128. })
  129. this.accessToken = res.accessToken
  130. },
  131. // homes.user_device_type
  132. async usertype() { //设备列表
  133. const res = await this.$myRequest({
  134. url: '/api/api_gateway?method=home.homes.user_device_type',
  135. })
  136. console.log(res)
  137. for (var i = 0; i < res.length; i++) {
  138. var obj = {
  139. name: res[i].type_name,
  140. id: res[i].id
  141. }
  142. this.list.push(obj)
  143. }
  144. if (res.length) {
  145. console.log(this.list)
  146. this.type_id = this.list[0].id
  147. if (this.list[0].id == 10) {
  148. this.xyeqlist()
  149. } else {
  150. this.eqlist()
  151. }
  152. }
  153. },
  154. change(index) { //头部导航栏的点击
  155. this.imports = ""
  156. this.current = index
  157. this.currents = index
  158. this.page = 1
  159. this.eqlistdata = []
  160. this.type_id = this.list[index].id
  161. if (this.list[index].id == 10) {
  162. this.xyeqlist()
  163. } else {
  164. this.eqlist()
  165. }
  166. },
  167. clickRight() { //搜索
  168. this.width = '90%'
  169. },
  170. modification(item) {
  171. uni.navigateTo({
  172. url: "./modification?data=" + JSON.stringify(item) + "&id=" + this.type_id,
  173. })
  174. },
  175. top() {
  176. uni.pageScrollTo({
  177. scrollTop: 0,
  178. duration: 500
  179. })
  180. },
  181. historys(item) {
  182. switch (this.type_id) {
  183. case 2:
  184. uni.navigateTo({
  185. url: "../prevention/equipmentdetails?shebei=" + JSON.stringify(item)
  186. })
  187. break;
  188. case 5:
  189. console.log(item)
  190. var obj = {}
  191. obj.d_id = item.d_id
  192. obj.equip_id = item.imei
  193. obj.is_online = item.is_online
  194. obj.lat = item.lat
  195. obj.lng = item.lng
  196. obj.equip_name = item.device_name
  197. obj.uptime = item.addtime
  198. uni.navigateTo({
  199. url: "../environment/equipment?shebei=" + JSON.stringify(obj)
  200. })
  201. break;
  202. case 6:
  203. uni.navigateTo({
  204. url: "/pages/webview?device_id=" + item.imei + "&accessToken=" + this.accessToken
  205. })
  206. break;
  207. case 3:
  208. item.type = this.type_id
  209. uni.navigateTo({
  210. url: "../cb/equip-detail/equip-detail?info=" + JSON.stringify(item)
  211. })
  212. break;
  213. case 4:
  214. item.type = this.type_id
  215. uni.navigateTo({
  216. url: "../cb/equip-detail/equip-detail?info=" + JSON.stringify(item)
  217. })
  218. break;
  219. default:
  220. item.type = this.type_id
  221. uni.navigateTo({
  222. url: "../cb/xy2.0/particulars?info=" + JSON.stringify(item)
  223. })
  224. break;
  225. }
  226. },
  227. search() { //搜索
  228. this.eqlistdata = []
  229. this.page = 1
  230. if (this.list[this.currents].id == 10) {
  231. this.xyeqlist()
  232. } else {
  233. this.eqlist()
  234. }
  235. },
  236. searchinput() {
  237. Debounce(() => {
  238. this.eqlistdata = []
  239. this.page = 1
  240. if (this.list[this.currents].id == 10) {
  241. this.xyeqlist()
  242. } else {
  243. this.eqlist()
  244. }
  245. }, 1000)()
  246. },
  247. },
  248. onShow() {
  249. this.list = []
  250. this.camera()
  251. this.current = 0
  252. this.currents = 0
  253. this.page = 1
  254. this.usertype()
  255. this.width = 0
  256. uni.getStorage({
  257. key: "jurisdiction",
  258. success: (res) => {
  259. console.log(JSON.parse(res.data))
  260. let items = JSON.parse(res.data).filter((item) => {
  261. return item.purview_name == "设备管理"
  262. })
  263. let items2 = items[0].children.filter((item) => {
  264. return item.purview_name == "设备列表"
  265. })
  266. console.log(items2[0].children)
  267. this.infoalter = items2[0].children.some((item) => {
  268. return item.purview_name == "修改名称" || item.purview_name == "添加位置"
  269. })
  270. console.log(this.infoalter)
  271. },
  272. })
  273. },
  274. onReachBottom() {
  275. this.page++
  276. if (this.type_id == 10) {
  277. this.xyeqlist(true)
  278. } else {
  279. this.eqlist(true)
  280. }
  281. },
  282. onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
  283. if (e.scrollTop > 200) { //距离大于200时显示
  284. this.isTop = true
  285. } else { //距离小于200时隐藏
  286. this.isTop = false
  287. }
  288. }
  289. }
  290. </script>
  291. <style lang="scss">
  292. /deep/.uni-icons {
  293. font-size: 40rpx !important;
  294. }
  295. .inputs {
  296. height: 54rpx;
  297. background-color: #E4E4E4;
  298. border-radius: 27rpx;
  299. position: absolute;
  300. right: 34rpx;
  301. top: 20rpx;
  302. transition: width 0.5s;
  303. overflow: hidden;
  304. padding-top: 8rpx;
  305. box-sizing: border-box;
  306. .inputbox {
  307. width: 85%;
  308. text-indent: 1rem;
  309. font-size: 26rpx;
  310. }
  311. .icon {
  312. position: absolute;
  313. top: 8rpx;
  314. right: 26rpx;
  315. }
  316. }
  317. .utabs_box {
  318. width: 100%;
  319. position: fixed;
  320. top: 88px;
  321. background-color: #FFFFFF;
  322. z-index: 100;
  323. .utabs {
  324. width: 95%;
  325. margin: 0 auto;
  326. }
  327. }
  328. .loading {
  329. position: fixed;
  330. top: 440px;
  331. width: 95%;
  332. left: 2.5%;
  333. text-align: center;
  334. .img {
  335. width: 300rpx;
  336. height: 40rpx;
  337. }
  338. }
  339. .list {
  340. width: 100%;
  341. background-color: #FDFDFD;
  342. margin-top: 280rpx;
  343. margin-bottom: 100rpx;
  344. .list_item {
  345. width: 90%;
  346. margin: 20rpx auto;
  347. padding: 20rpx 20rpx;
  348. box-sizing: border-box;
  349. position: relative;
  350. background-color: #FFFFFF;
  351. box-shadow: 0 0 10rpx #bcb9ca;
  352. .list_item_top {
  353. display: flex;
  354. justify-content: space-between;
  355. .p1 {
  356. height: 60rpx;
  357. line-height: 60rpx;
  358. font-size: 28rpx;
  359. image {
  360. width: 40rpx;
  361. height: 40rpx;
  362. vertical-align: text-top;
  363. margin-right: 20rpx;
  364. }
  365. }
  366. .p2 {
  367. height: 60rpx;
  368. line-height: 60rpx;
  369. font-size: 28rpx;
  370. color: #42b983;
  371. }
  372. .p_out {
  373. height: 60rpx;
  374. line-height: 60rpx;
  375. font-size: 28rpx;
  376. color: red;
  377. }
  378. }
  379. .list_item_text {
  380. margin-top: 20rpx;
  381. p {
  382. font-size: 24rpx;
  383. color: #636363;
  384. margin-top: 10rpx;
  385. }
  386. p:first-child {
  387. font-size: 28rpx;
  388. font-weight: 700;
  389. }
  390. }
  391. .list_item_btn {
  392. width: 126rpx;
  393. color: #42b983;
  394. height: 40rpx;
  395. text-align: center;
  396. border: 1rpx solid #42b983;
  397. border-radius: 25rpx;
  398. font-size: 24rpx;
  399. line-height: 35rpx;
  400. position: absolute;
  401. top: 136rpx;
  402. right: 20rpx;
  403. }
  404. }
  405. }
  406. .top {
  407. position: fixed;
  408. right: 30px;
  409. bottom: 100px;
  410. z-index: 100;
  411. image {
  412. width: 100rpx;
  413. height: 100rpx;
  414. }
  415. }
  416. </style>