index.vue 14 KB

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