index.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <!-- <u-sticky bgColor="#fff"> </u-sticky> -->
  3. <scroll-view scroll-x>
  4. <view>
  5. <!-- 下拉选择 -->
  6. <!-- <view class="searchSelect shadow" v-if="flag">
  7. <view class="cu-bar search bg-white">
  8. <view class="search-form round" style="margin-top: 0">
  9. <input
  10. @focus="InputFocus"
  11. @blur="InputBlur"
  12. @input="handleInput()"
  13. v-model="searchInput"
  14. :adjust-position="false"
  15. type="text"
  16. placeholder=""
  17. confirm-type="search"
  18. style="border: none !important"
  19. />
  20. <text class="cuIcon-search"></text>
  21. </view>
  22. </view>
  23. <view class="select-items">
  24. <view
  25. class="site-item"
  26. v-if="!searchList.length"
  27. style="text-align: center"
  28. >暂无结果</view
  29. >
  30. <view
  31. class="select-item"
  32. v-for="(item, index) in searchList"
  33. @click="clickSelectItem(item, index)"
  34. :key="index"
  35. >{{ item.owner_name }}</view
  36. >
  37. </view>
  38. </view> -->
  39. <!-- 下拉选择 end -->
  40. <!-- 图表 -->
  41. <!-- <view class="section1 section bg-white padding-xs">
  42. <view
  43. class="
  44. static-tabs
  45. grid
  46. margin-bottom
  47. text-center
  48. col-3
  49. margin-top-sm margin-bottom-sm
  50. "
  51. >
  52. <view
  53. :class="['padding-sm ', Inv == 0 ? 'active' : '']"
  54. @click="Inv = 0"
  55. >报警信息统计</view
  56. >
  57. <view
  58. :class="['padding-sm ', Inv == 1 ? 'active' : '']"
  59. @click="Inv = 1"
  60. >数据等级统计</view
  61. >
  62. <view
  63. :class="['padding-sm ', Inv == 2 ? 'active' : '']"
  64. @click="Inv = 2"
  65. >设备运行状态</view
  66. >
  67. </view>
  68. <view class="time text-center"
  69. >统计时段:{{ staticData.statisticalPeriod }}
  70. </view>
  71. <view style="height: 570rpx">
  72. <view v-if="Inv == 0"> </view>
  73. <view v-if="Inv == 1"> </view>
  74. <view v-if="Inv == 2" class="chart3-box">
  75. <ul class="chart3-icon">
  76. <li>
  77. <image
  78. src="@/static/images/index/chart3-1.png"
  79. style="width: 64rpx; height: 64rpx"
  80. ></image>
  81. </li>
  82. <li>
  83. <image
  84. src="@/static/images/index/chart3-2.png"
  85. style="width: 64rpx; height: 64rpx"
  86. ></image>
  87. </li>
  88. <li>
  89. <image
  90. src="@/static/images/index/chart3-3.png"
  91. style="width: 64rpx; height: 64rpx"
  92. ></image>
  93. </li>
  94. <li>
  95. <image
  96. src="@/static/images/index/chart3-4.png"
  97. style="width: 64rpx; height: 64rpx"
  98. ></image>
  99. </li>
  100. <li>
  101. <image
  102. src="@/static/images/index/chart3-5.png"
  103. style="width: 64rpx; height: 64rpx"
  104. ></image>
  105. </li>
  106. </ul>
  107. </view>
  108. </view>
  109. </view> -->
  110. <!-- 图表 end-->
  111. <!-- 轮播图 开始 -->
  112. <u-swiper :list="arrayList.swiperList" indicator indicatorMode="line" radius="0" height="160" circular> </u-swiper>
  113. <!-- 轮播图 结束 -->
  114. <!-- 宫格列表 -->
  115. <view class="section2 section bg-white" style="margin-bottom: 10px" v-if="arrayList.recentlyUsed.length > 0">
  116. <view style="color: #000000; font-size: 14px; padding: 10px 10px 5px 10px">最近使用</view>
  117. <view class="cu-list grid col-5 no-border">
  118. <view class="cu-item justify-center align-center" @tap="navItemClick(item)" v-for="(item, index) in arrayList.recentlyUsed" :key="index">
  119. <image :src="item.meta.icon" style="width: 40px; height: 40px"></image>
  120. <!-- <view class="cu-tag badge" v-if="item.badge != 0">
  121. <block v-if="item.badge != 0">{{ item.badge > 99 ? "99+" : item.badge }}</block>
  122. </view> -->
  123. <text style="font-size: 13px">{{ item.meta.title }}</text>
  124. </view>
  125. </view>
  126. </view>
  127. <!-- 宫格列表 end -->
  128. <!-- 宫格列表 -->
  129. <view class="section2 section bg-white">
  130. <view style="color: #000000; font-size: 14px; padding: 10px 10px 5px 10px">常用功能</view>
  131. <view class="cu-list grid col-5 no-border">
  132. <view class="cu-item justify-center align-center" @tap="navItemClick(item)" v-for="(item, index) in arrayList.cuIconList" :key="index">
  133. <image :src="item.meta.icon" style="width: 40px; height: 40px"></image>
  134. <!-- <view class="cu-tag badge" v-if="item.badge != 0">
  135. <block v-if="item.badge != 0">{{ item.badge > 99 ? "99+" : item.badge }}</block>
  136. </view> -->
  137. <text style="font-size: 13px">{{ item.meta.title }}</text>
  138. </view>
  139. </view>
  140. </view>
  141. <!-- 宫格列表 end -->
  142. </view>
  143. </scroll-view>
  144. </template>
  145. <script setup>
  146. import searchSelect from "@/components/searchSelect/searchSelect.vue";
  147. import json from "@/static/js/json.js"; //引入api请求封装方法
  148. import * as jwx from "@/utils/jssdk.js"; //引入js sdk的封装
  149. import { onReady, onLoad, onShow, onNavigationBarButtonTap } from "@dcloudio/uni-app";
  150. import { ref, onMounted, inject, shallowRef, reactive, getCurrentInstance } from "vue";
  151. import { getToken, setToken, removeToken } from "@/utils/auth";
  152. import useStores from "@/store/modules/user.js";
  153. import publicStore from "@/store/modules/public";
  154. import { scan_push, getHomePageData, getFunctionalModuleStatistics, getAppRouters } from "@/api/index";
  155. const useStore = useStores();
  156. const publicStores = publicStore(); //全局公共Store
  157. const BASE_URL = inject("$BASE_URL");
  158. const arrayList = reactive({
  159. InputBottom: 0,
  160. staticData: "",
  161. indicator: [],
  162. datavalue: [],
  163. dataname: [],
  164. Inv: 0,
  165. flag: false,
  166. searchList: [],
  167. searchList2: [],
  168. searchInput: "",
  169. selectedCode: 10012,
  170. codeResult: "",
  171. swiperList: ["../static/images/index/banner1.png", "../static/images/index/banner2.jpg", "../static/images/index/banner3.jpg"],
  172. // cuIconList: json.cuIconList,
  173. recentlyUsed: [],
  174. });
  175. onLoad((option) => {
  176. //获取首页标题
  177. if (uni.getStorageSync("homeTitle")) {
  178. uni.setNavigationBarTitle({
  179. title: uni.getStorageSync("homeTitle"),
  180. });
  181. } else {
  182. uni.setNavigationBarTitle({
  183. title: "首页",
  184. });
  185. }
  186. if (uni.getStorageSync(useStore.$state.name)) {
  187. arrayList.recentlyUsed = uni.getStorageSync(useStore.$state.name);
  188. }
  189. // var res = uni.getStorageSync("selectedCode");
  190. // var res2 = uni.getStorageSync("selectedName");
  191. // if (res) {
  192. // uni.setNavigationBarTitle({
  193. // title: res2,
  194. // });
  195. // }
  196. // // 图表切换渲染
  197. // hackReset.value = false;
  198. // nextTick(() => {
  199. // hackReset.value = true;
  200. // });
  201. getAppRoutersData();
  202. });
  203. async function init() {
  204. window.location.href = BASE_URL + "Com/getPageAuthorization1";
  205. }
  206. //扫码
  207. function scanQRCode() {
  208. // console.log(1);
  209. // scanCode();
  210. // 将this赋值给that
  211. let that = this;
  212. // 微信公众号获取位置
  213. jwx.configWeiXin((jweixin) => {
  214. jweixin.scanQRCode({
  215. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  216. scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
  217. success: function (res) {
  218. setTimeout(function () {
  219. /* 放1000ms后执行的代码 */
  220. alert(res.resultStr);
  221. that.getCodeResult({
  222. ercode: res.resultStr,
  223. });
  224. }, 1000);
  225. },
  226. });
  227. });
  228. }
  229. function scanCode() {
  230. uni.scanCode({
  231. scanType: ["qrCode"],
  232. success: (res) => {
  233. console.log("扫码成功", res);
  234. },
  235. fail: (err) => {
  236. console.log("扫码失败", err);
  237. },
  238. complete: () => {
  239. console.log("扫码结束");
  240. },
  241. });
  242. }
  243. // 扫码成功后请求
  244. async function getCodeResult(param = {}) {
  245. scan_push(param).then((res) => {
  246. if (res.data.flag) {
  247. uni.showToast({
  248. title: "扫码成功",
  249. icon: "none",
  250. });
  251. }
  252. });
  253. }
  254. //获取地理位置
  255. function getLocation() {
  256. // 将this赋值给that
  257. let that = this;
  258. // 微信公众号获取位置
  259. jwx.configWeiXin((jweixin) => {
  260. alert(22);
  261. jweixin.getLocation({
  262. type: "gcj02", // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
  263. success: function (res) {
  264. alert(res.longitude);
  265. },
  266. });
  267. });
  268. }
  269. // 九宫格页面跳转
  270. function navItemClick(item) {
  271. if (item.path) {
  272. item.sort = 0;
  273. arrayList.recentlyUsed.push(item);
  274. if (arrayList.recentlyUsed.length > 0) {
  275. arrayList.recentlyUsed = arrayList.recentlyUsed.filter((currentValue, currentIndex, selfArr) => {
  276. return selfArr.findIndex((x) => x.path === currentValue.path) === currentIndex;
  277. });
  278. arrayList.recentlyUsed.filter((el) => {
  279. if (el.path === item.path) {
  280. el.sort++;
  281. }
  282. });
  283. }
  284. arrayList.recentlyUsed = publicStores.sortEvent(arrayList.recentlyUsed, 1);
  285. uni.setStorageSync(useStore.$state.name, arrayList.recentlyUsed);
  286. uni.navigateTo({
  287. url: item.path,
  288. });
  289. } else {
  290. uni.showModal({
  291. title: "Tips",
  292. content: "此模块开发中~",
  293. showCancel: false,
  294. success: function (res) {
  295. if (res.confirm) {
  296. } else if (res.cancel) {
  297. }
  298. },
  299. });
  300. }
  301. }
  302. function showTag() {
  303. arrayList.flag = !arrayList.flag;
  304. }
  305. // 下拉选择
  306. function clickSelectItem(item, index) {
  307. arrayList.staticData = "";
  308. arrayList.selectedCode = item.owner_code;
  309. uni.setStorageSync("selectedCode", item.owner_code);
  310. uni.setStorageSync("selectedName", item.owner_name);
  311. arrayList.searchInput = item.owner_name;
  312. uni.setNavigationBarTitle({
  313. title: arrayList.searchInput,
  314. });
  315. getHomeData({
  316. company_code: uni.getStorageSync("selectedCode"),
  317. });
  318. getHandleData({
  319. company_code: uni.getStorageSync("selectedCode"),
  320. });
  321. arrayList.flag = false;
  322. }
  323. function handleInput() {
  324. var newlist = arrayList.searchList2.filter((item) => item.owner_name.indexOf(arrayList.searchInput) > -1);
  325. arrayList.searchList = newlist;
  326. }
  327. function InputFocus(e) {
  328. arrayList.InputBottom = e.detail.height;
  329. }
  330. function InputBlur(e) {
  331. arrayList.InputBottom = 0;
  332. }
  333. function getAppRoutersData() {
  334. getAppRouters({
  335. // domain: window.location.host.indexOf("localhost") != -1 ? "localhost:81" : window.location.host,
  336. // platformType: "MOB",
  337. // domain :'172.16.120.165:13201'
  338. // domain :'172.16.120.165:13203'
  339. }).then((res) => {
  340. console.log(res.data);
  341. res.data.forEach((el) => {
  342. // const modules = import.meta.glob("@/static/icons/*.svg");
  343. el.meta.icon = `/static/icons/${el.meta.icon}.svg`;
  344. });
  345. arrayList.cuIconList = res.data;
  346. });
  347. }
  348. //echarts图表请求
  349. async function getHomeData(param = {}) {
  350. getHomePageData(param).then((res) => {
  351. // console.log('首页请求staticData')
  352. // console.log(res.data.data[0])
  353. arrayList.staticData = res.data.data[0];
  354. // var data = res.data.data[0]
  355. var datavalue = [
  356. arrayList.staticData.fire_water_count,
  357. arrayList.staticData.alarm_host_count,
  358. arrayList.staticData.electrical_fire_count,
  359. arrayList.staticData.other_count,
  360. arrayList.staticData.video_monitoring_count,
  361. ];
  362. var dataname = ["消防水系统", "报警主机", "电气火灾", "其他", "监控视频"];
  363. var color = ["#3C8BF0", "#06CDF8", "#0ECB70", "#6744EF", "#FFD803"];
  364. var aa = [
  365. arrayList.staticData.fire_water_count,
  366. arrayList.staticData.alarm_host_count,
  367. arrayList.staticData.electrical_fire_count,
  368. arrayList.staticData.other_count,
  369. arrayList.staticData.video_monitoring_count,
  370. ];
  371. aa.sort(function (a, b) {
  372. return a - b;
  373. });
  374. aa = aa.pop();
  375. var datamax = [aa, aa, aa, aa, aa];
  376. arrayList.datavalue = datavalue;
  377. arrayList.dataname = dataname;
  378. dataname.map((val, ind) => {
  379. arrayList.indicator.push({
  380. name: val,
  381. max: datamax[ind],
  382. color: color[ind],
  383. });
  384. });
  385. arrayList.indicator = arrayList.indicator.slice(-5);
  386. });
  387. }
  388. // 未处理告警请求
  389. async function getHandleData(param = {}) {
  390. getFunctionalModuleStatistics(param).then((res) => {
  391. arrayList.cuIconList[0].badge = res.data.data[0].comprehensive_alarm_count;
  392. arrayList.cuIconList[2].badge = res.data.data[0].fire_brigade_inspector_count;
  393. });
  394. }
  395. // 自定义导航事件
  396. onNavigationBarButtonTap((e) => {
  397. if (e.float == "right") {
  398. // alert("你点击了扫一扫");
  399. scanQRCode();
  400. } else {
  401. // alert("你点击了获取位置");
  402. // getLocation()
  403. showTag();
  404. }
  405. });
  406. </script>
  407. <style lang="scss">
  408. page {
  409. background-color: #f5f6f7;
  410. }
  411. .select-items {
  412. overflow: auto;
  413. height: 80vh;
  414. }
  415. .static-tabs {
  416. border-radius: 50rpx;
  417. border: 1rpx solid #4074e7;
  418. }
  419. .static-tabs > view {
  420. color: #4074e7;
  421. font-size: 30rpx;
  422. }
  423. .static-tabs > view.active {
  424. color: #fff;
  425. background: #4074e7;
  426. }
  427. .static-tabs > view:first-child {
  428. border-top-left-radius: 50rpx;
  429. border-bottom-left-radius: 50rpx;
  430. }
  431. .static-tabs > view:nth-child(2) {
  432. border-left: 1px solid #4074e7;
  433. border-right: 1px solid #4074e7;
  434. }
  435. .static-tabs > view:last-child {
  436. border-top-right-radius: 50rpx;
  437. border-bottom-right-radius: 50rpx;
  438. }
  439. /* 检测时间 */
  440. .time {
  441. border-radius: 50rpx;
  442. background: #fafcff;
  443. border: 1px solid #e8f1ff;
  444. padding: 20rpx;
  445. color: #666666;
  446. font-size: 30rpx;
  447. }
  448. .chart3-box {
  449. position: relative;
  450. }
  451. .chart3-icon {
  452. width: 90%;
  453. position: absolute;
  454. top: 60rpx;
  455. left: 30rpx;
  456. z-index: 1;
  457. }
  458. .chart3-icon li {
  459. padding-top: 25rpx;
  460. }
  461. ul,
  462. li {
  463. padding: 0;
  464. margin: 0;
  465. list-style: none;
  466. }
  467. </style>