index.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488
  1. <template>
  2. <div style="margin-top: 10px">
  3. <el-row :gutter="24" justify="space-around">
  4. <re-col
  5. v-for="(item, index) in chartData"
  6. :key="index"
  7. v-motion
  8. class="mb-18"
  9. :value="4"
  10. :md="12"
  11. :sm="12"
  12. :xs="24"
  13. :initial="{
  14. opacity: 0,
  15. y: 100
  16. }"
  17. :enter="{
  18. opacity: 1,
  19. y: 0,
  20. transition: {
  21. delay: 80 * (index + 1)
  22. }
  23. }"
  24. >
  25. <el-card class="line-card" shadow="never">
  26. <div class="flex justify-between">
  27. <span class="text-md font-medium">
  28. {{ item.name }}
  29. </span>
  30. <div
  31. class="w-8 h-8 flex justify-center items-center rounded-md"
  32. :style="{
  33. backgroundColor: isDark ? 'transparent' : item.bgColor
  34. }"
  35. >
  36. <IconifyIconOffline
  37. :icon="item.icon"
  38. :color="item.color"
  39. width="18"
  40. height="18"
  41. />
  42. </div>
  43. </div>
  44. <div class="flex justify-between items-start mt-3">
  45. <div class="w-1/2">
  46. <ReNormalCountTo
  47. :duration="item.duration"
  48. :fontSize="'1.6em'"
  49. :startVal="100"
  50. :endVal="item.value"
  51. />
  52. <!-- <p class="font-medium text-green-500">{{ item.percent }}</p> -->
  53. </div>
  54. <!-- <ChartLine
  55. v-if="item.data.length > 1"
  56. class="w-1/2!"
  57. :color="item.color"
  58. :data="item.data"
  59. /> -->
  60. <!-- <ChartRound v-else class="w-1/2!" /> -->
  61. </div>
  62. </el-card>
  63. </re-col>
  64. <re-col
  65. v-motion
  66. class="mb-18"
  67. :value="18"
  68. :xs="24"
  69. :initial="{
  70. opacity: 0,
  71. y: 100
  72. }"
  73. :enter="{
  74. opacity: 1,
  75. y: 0,
  76. transition: {
  77. delay: 400
  78. }
  79. }"
  80. >
  81. <el-card class="bar-card" shadow="never">
  82. <div class="flex justify-between">
  83. <span class="text-md font-medium">一周概览</span>
  84. <Segmented v-model="curWeek" :options="optionsBasis" />
  85. </div>
  86. <div class="flex justify-between items-start mt-3">
  87. <ChartBar
  88. :attendPerson="barChartData[curWeek].attendPerson"
  89. :arrivePerson="barChartData[curWeek].arrivePerson"
  90. :onlinePerson="barChartData[curWeek].onlinePerson"
  91. />
  92. </div>
  93. </el-card>
  94. </re-col>
  95. <re-col
  96. v-motion
  97. class="mb-[18px]"
  98. :value="6"
  99. :xs="24"
  100. :initial="{
  101. opacity: 0,
  102. y: 100
  103. }"
  104. :enter="{
  105. opacity: 1,
  106. y: 0,
  107. transition: {
  108. delay: 480
  109. }
  110. }"
  111. >
  112. <el-card shadow="never">
  113. <div class="flex justify-between">
  114. <span class="text-md font-medium">基站项目分布</span>
  115. </div>
  116. <el-scrollbar height="373" class="mt-3 show-scrollbar">
  117. <div class="scroll-content">
  118. <div
  119. v-for="(item, index) in progressData"
  120. :key="index"
  121. :class="[
  122. 'flex',
  123. 'justify-between',
  124. 'items-start',
  125. index === 0 ? 'mt-8' : 'mt-[2.15rem]'
  126. ]"
  127. >
  128. <el-progress
  129. :indeterminate="true"
  130. :text-inside="true"
  131. :percentage="item.percentage"
  132. :stroke-width="21"
  133. :color="item.color"
  134. striped
  135. striped-flow
  136. :duration="item.duration"
  137. >
  138. <span style="margin-right: 5px">{{ item.ancNum }}</span>
  139. </el-progress>
  140. <span
  141. class="text-nowrap ml-2 text-text_color_regular text-sm"
  142. style="width: 120px"
  143. >
  144. {{ item.projName }}
  145. </span>
  146. </div>
  147. </div>
  148. </el-scrollbar>
  149. </el-card>
  150. </re-col>
  151. <re-col
  152. v-motion
  153. class="mb-[18px]"
  154. :value="18"
  155. :xs="24"
  156. :initial="{
  157. opacity: 0,
  158. y: 100
  159. }"
  160. :enter="{
  161. opacity: 1,
  162. y: 0,
  163. transition: {
  164. delay: 560
  165. }
  166. }"
  167. >
  168. <el-card shadow="never" class="h-[380px]">
  169. <div class="flex justify-between">
  170. <span class="text-md font-medium">数据统计</span>
  171. </div>
  172. <WelcomeTable class="mt-3" />
  173. </el-card>
  174. </re-col>
  175. <re-col
  176. v-motion
  177. class="mb-[18px]"
  178. :value="6"
  179. :xs="24"
  180. :initial="{
  181. opacity: 0,
  182. y: 100
  183. }"
  184. :enter="{
  185. opacity: 1,
  186. y: 0,
  187. transition: {
  188. delay: 640
  189. }
  190. }"
  191. >
  192. <el-card shadow="never" class="h-[380px]">
  193. <div class="flex justify-between">
  194. <span class="text-md font-medium">最新动态</span>
  195. </div>
  196. <el-scrollbar max-height="504" class="mt-3">
  197. <el-timeline>
  198. <el-timeline-item
  199. v-for="(item, index) in tableData"
  200. :key="index"
  201. center
  202. placement="top"
  203. :icon="
  204. markRaw(
  205. useRenderFlicker({
  206. background: randomGradient({
  207. randomizeHue: true
  208. })
  209. })
  210. )
  211. "
  212. :timestamp="dayjs(item.tm).format('YYYY-MM-DD hh:mm:ss')"
  213. >
  214. <p class="text-text_color_regular text-sm">
  215. {{ `新增 1 条考勤记录,考勤人数 ${item.attendPerson}` }}
  216. </p>
  217. </el-timeline-item>
  218. </el-timeline>
  219. </el-scrollbar>
  220. </el-card>
  221. </re-col>
  222. </el-row>
  223. </div>
  224. </template>
  225. <script setup lang="ts">
  226. import { ref, markRaw, onMounted } from "vue";
  227. import ReCol from "@/components/ReCol";
  228. import { useDark, randomGradient, dayjs } from "./utils";
  229. import WelcomeTable from "./components/table/index.vue";
  230. import { ReNormalCountTo } from "@/components/ReCountTo";
  231. import { useRenderFlicker } from "@/components/ReFlicker";
  232. import { ChartBar, ChartLine, ChartRound } from "./components/charts";
  233. import Segmented, { type OptionsType } from "@/components/ReSegmented";
  234. import { chartData, barChartData, progressData, tableData } from "./data";
  235. import { fetchHisAttend } from "@/api/attend";
  236. import Attend from "@/model/attend.js";
  237. defineOptions({
  238. name: "Welcome"
  239. });
  240. const vGlobal = window.vueGlobal;
  241. const { isDark } = useDark();
  242. const attends = ref([]);
  243. const now = new Date();
  244. const thisWeekBegin = new Date(
  245. now.getFullYear(),
  246. now.getMonth(),
  247. now.getDate() - now.getDay()
  248. );
  249. const thisWeekEnd = new Date(
  250. now.getFullYear(),
  251. now.getMonth(),
  252. now.getDate() - now.getDay() + 6
  253. );
  254. const lastWeekBegin = new Date(
  255. thisWeekBegin.getFullYear(),
  256. thisWeekBegin.getMonth(),
  257. thisWeekBegin.getDate() - 7
  258. );
  259. const lastWeekEnd = new Date(
  260. thisWeekBegin.getFullYear(),
  261. thisWeekBegin.getMonth(),
  262. thisWeekBegin.getDate() - 1
  263. );
  264. let curWeek = ref(1); // 0上周、1本周
  265. const optionsBasis: Array<OptionsType> = [
  266. {
  267. label: "上周"
  268. },
  269. {
  270. label: "本周"
  271. }
  272. ];
  273. const firstRun = () => {
  274. chartData.value[0].value = vGlobal.vecProject.length; // 项目总数量
  275. chartData.value[1].value = 0; // 运行项目数量
  276. chartData.value[2].value = 0; // 人员数量
  277. chartData.value[3].value = vGlobal.vecAnchor.length; // 基站数量
  278. chartData.value[4].value = 0; // 在线基站数
  279. chartData.value[5].value = vGlobal.vecTag.length; // 标签数量
  280. let cntProjRun = 0;
  281. progressData.value.splice(0);
  282. for (const proj of vGlobal.vecProject) {
  283. if (proj.status == 2) {
  284. continue;
  285. }
  286. cntProjRun++;
  287. chartData.value[2].value += proj.persons.length;
  288. let ancProjNum = 0;
  289. for (const anc of vGlobal.vecAnchor) {
  290. if (Number(anc.projId) == Number(proj.id)) {
  291. ancProjNum++;
  292. }
  293. }
  294. const percent = Math.floor((ancProjNum * 100.0) / vGlobal.vecAnchor.length);
  295. progressData.value.push({
  296. projName: proj.name,
  297. percentage: percent,
  298. duration: 5,
  299. color: "#41b6ff",
  300. ancNum: ancProjNum
  301. });
  302. }
  303. chartData.value[1].value = cntProjRun; // 运行项目数量
  304. };
  305. const statAttend = () => {
  306. let i = 0,
  307. j = 0;
  308. for (i = 0; i < 2; i++) {
  309. const weekData = barChartData.value[i];
  310. for (j = 0; j < 7; j++) {
  311. weekData.attendPerson[j] = 0;
  312. weekData.arrivePerson[j] = 0;
  313. weekData.onlinePerson[j] = 0;
  314. }
  315. }
  316. let idx = 0;
  317. let curAtDate = new Date(
  318. lastWeekBegin.getFullYear(),
  319. lastWeekBegin.getMonth(),
  320. lastWeekBegin.getDate() + 2
  321. );
  322. let numDay = 0;
  323. console.log("numDay 0", numDay, curAtDate);
  324. for (const attend of attends.value) {
  325. while (Number(attend["tm"]) > curAtDate.getTime()) {
  326. numDay++;
  327. curAtDate = new Date(
  328. lastWeekBegin.getFullYear(),
  329. lastWeekBegin.getMonth(),
  330. lastWeekBegin.getDate() + numDay + 2
  331. );
  332. }
  333. console.log("numDay", numDay, curAtDate);
  334. let weekIdx = Math.floor(numDay / 7);
  335. let dayIdx = numDay % 7;
  336. let cntArrive = 0;
  337. let cntOnline = 0;
  338. for (const item of attend.items) {
  339. if (Number(item["confirm"])) {
  340. cntArrive++;
  341. }
  342. if (Number(item["rssi"]) != 0) {
  343. cntOnline++;
  344. }
  345. }
  346. const weekData = barChartData.value[weekIdx];
  347. console.log("barChartData", barChartData.value, weekIdx, weekData);
  348. weekData.attendPerson[dayIdx] += attend.items.length;
  349. weekData.arrivePerson[dayIdx] += cntArrive;
  350. weekData.onlinePerson[dayIdx] += cntOnline;
  351. }
  352. };
  353. const schedule = () => {
  354. chartData.value[4].value = 0;
  355. for (const v of vGlobal.vecAnchor) {
  356. if (v.isOnline) {
  357. chartData.value[4].value++;
  358. }
  359. }
  360. const queryParams = {
  361. beginTime: lastWeekBegin.getTime(),
  362. endTime: thisWeekEnd.getTime(),
  363. sortMode: 1
  364. };
  365. fetchHisAttend(queryParams).then(res => {
  366. if (res.success) {
  367. attends.value = [];
  368. tableData.value = [];
  369. for (const item of res.items) {
  370. const obj = JSON.parse(item.jstr);
  371. const attend = new Attend(obj);
  372. attends.value.push(attend);
  373. attend.ancAddr = Number(item["ancAddr"]) || 0;
  374. let cntArrive = 0;
  375. let cntOnline = 0;
  376. for (const item of attend.items) {
  377. if (Number(item["confirm"])) {
  378. cntArrive++;
  379. }
  380. if (Number(item["rssi"]) != 0) {
  381. cntOnline++;
  382. }
  383. }
  384. tableData.value.push({
  385. tm: attend.tm,
  386. projName: vGlobal.getProjName(attend.projId),
  387. locName: vGlobal.getLocName(attend.projId, attend.locId),
  388. ancAddr: attend.ancAddr,
  389. attendPerson: attend.items.length,
  390. arrivePerson: cntArrive,
  391. onlinePerson: cntOnline,
  392. items: attend.items
  393. });
  394. tableData.value.reverse();
  395. }
  396. statAttend();
  397. }
  398. });
  399. };
  400. onMounted(() => {
  401. const ci = setInterval(() => {
  402. if (vGlobal.isInited()) {
  403. clearInterval(ci);
  404. firstRun();
  405. schedule();
  406. // setInterval(() => {
  407. // schedule();
  408. // }, 1000 * 10);
  409. }
  410. }, 100);
  411. });
  412. </script>
  413. <style lang="scss" scoped>
  414. // 移除过度使用的!important,改用更具体的选择器提高优先级
  415. :deep(.el-card) {
  416. --el-card-border-color: none;
  417. .el-progress--line {
  418. width: 85%;
  419. }
  420. .el-progress-bar__innerText {
  421. font-size: 15px;
  422. }
  423. // 修复滚动条显示问题
  424. .el-scrollbar:not(.show-scrollbar) .el-scrollbar__bar {
  425. display: none;
  426. }
  427. .el-timeline-item {
  428. margin: 0 6px;
  429. }
  430. }
  431. // 增强滚动条样式兼容性
  432. .el-scrollbar__wrap {
  433. overflow-x: hidden;
  434. }
  435. :deep(.el-scrollbar__bar.is-vertical) {
  436. right: 0 !important;
  437. width: 6px;
  438. opacity: 0.6; /* 确保可见性 */
  439. }
  440. // 修复卡片间距问题
  441. .line-card,
  442. .bar-card {
  443. margin-bottom: -48px;
  444. }
  445. // 确保动画兼容性
  446. :deep(.v-motion) {
  447. backface-visibility: hidden; /* 解决动画闪烁问题 */
  448. }
  449. </style>