StatisticalAnalysis.vue 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. <template>
  2. <div class="mainBox" v-loading="getDataStatus">
  3. <!-- 搜索区域 -->
  4. <div class="searchBox">
  5. <div style="font-size: large">
  6. <!-- 对比时间:
  7. <el-date-picker
  8. v-model="lastTimes"
  9. type="daterange"
  10. unlink-panels
  11. range-separator="到"
  12. start-placeholder="开始时间"
  13. end-placeholder="结束时间"
  14. disabled
  15. size="large"
  16. style="margin-right: 30px"
  17. /> -->
  18. 搜索时间:
  19. <el-date-picker
  20. v-model="nowTimes"
  21. type="daterange"
  22. :clearable="false"
  23. unlink-panels
  24. range-separator="到"
  25. start-placeholder="开始时间"
  26. end-placeholder="结束时间"
  27. :shortcuts="shortcutsFun"
  28. size="large"
  29. />
  30. </div>
  31. </div>
  32. <!-- 服务调用card -->
  33. <div class="flex">
  34. <card
  35. v-for="item in TopCardDatas"
  36. :key="item.name"
  37. class="card flex"
  38. :title="item.name"
  39. :value="item.value"
  40. :growth="item.growth"
  41. :iconName="item.iconName"
  42. :iconColor="item.iconColor"
  43. :upStatus="item.upStatus"
  44. />
  45. </div>
  46. <!-- 服务类信息统计 -->
  47. <div class="bigCard">
  48. <div class="bigCard_title">服务类信息统计</div>
  49. <div class="tools">
  50. <el-button @click="downFileAllServiceDatas" :disabled="exportLoading">
  51. <!-- 这个要查询查询时间范围内的所有服务数据 -->
  52. <el-icon v-if="!exportLoading"><Upload /></el-icon>
  53. <el-icon v-else><Loading class="loading-icon" /></el-icon>
  54. 导出数据
  55. </el-button>
  56. <el-button :disabled="dialogLoading" type="primary" @click="showDetailReport">
  57. <!-- 这个直接弹窗展示所有的服务调用数据,而不是下载 -->
  58. <el-icon v-if="!dialogLoading"><TrendCharts /></el-icon>
  59. <!-- 让图标旋转 -->
  60. <el-icon v-else><Loading class="loading-icon" /></el-icon>
  61. 详细报告
  62. </el-button>
  63. </div>
  64. <div class="flex">
  65. <div style="width: 48%; height: 400px">
  66. <EchartsDome :chartOption="chartOptions['服务调用趋势']" title="服务调用趋势" />
  67. </div>
  68. <div style="width: 48%; height: 400px">
  69. <EchartsDome title="服务类别分布" :chartOption="chartOptions['服务类别分布']" />
  70. </div>
  71. </div>
  72. <div style="width: 100%; height: 400px">
  73. <Table title="服务调用TOP10" :tableData="tableDatas" />
  74. </div>
  75. </div>
  76. <!-- 服务调用详情弹窗 -->
  77. <el-dialog
  78. v-model="showServerDetailReport"
  79. width="80%"
  80. :close-on-click-modal="false"
  81. :close-on-press-escape="false"
  82. :show-close="true"
  83. title="服务调用详情"
  84. >
  85. <div style="width: 100%; position: relative; padding-bottom: 30px" v-loading="dialogLoading">
  86. <!-- 过滤条件,全字段(除了调用时间)下拉框选择 -->
  87. <div style="width: 100%; margin-bottom: 10px; z-index: 1000">
  88. <!-- 再添加一个调用次数筛选 -->
  89. <div style="display: flex; align-items: center; margin-bottom: 10px">
  90. <span style="margin-right: 10px">调用次数:</span>
  91. <el-slider
  92. v-model="selectedModel['count']"
  93. :min="countMin"
  94. :max="countMax"
  95. range
  96. @change="changeSelectModel"
  97. style="width: calc(60%); margin: 0 20px"
  98. />
  99. 最小值:
  100. <el-input-number
  101. v-model="selectedModel.count[0]"
  102. :min="countMin"
  103. :max="selectedModel.count[1]"
  104. @change="changeSelectModel"
  105. />
  106. 最大值:
  107. <el-input-number
  108. v-model="selectedModel.count[1]"
  109. :min="selectedModel.count[0]"
  110. :max="countMax"
  111. @change="changeSelectModel"
  112. />
  113. </div>
  114. <!-- 支持筛选条件清空 -->
  115. <el-select
  116. style="width: 200px; margin-right: 10px"
  117. v-for="(value, key, index) in selectOptions"
  118. :key="key + index"
  119. v-model="selectedModel[key]"
  120. @change="changeSelectModel"
  121. :placeholder="'请选择' + selectKeyName[key]"
  122. filterable
  123. clearable
  124. >
  125. <el-option v-for="item in value" :key="item" :label="item" :value="item" />
  126. </el-select>
  127. <!-- 再添加一个时间搜索范围,字段是date, 格式是YYYY-MM-DD -->
  128. <el-date-picker
  129. style="margin-right: 10px"
  130. v-model="selectedModel['date']"
  131. type="daterange"
  132. clearable
  133. unlink-panels
  134. @change="changeSelectModel"
  135. :disabled-date="disabledDate"
  136. range-separator="到"
  137. start-placeholder="开始时间"
  138. end-placeholder="结束时间"
  139. />
  140. <!-- 重置按钮 -->
  141. <el-button type="primary" @click="resetSelectModel">重置</el-button>
  142. </div>
  143. <el-table
  144. :data="showServerData"
  145. style="width: 100%"
  146. height="500px"
  147. border
  148. fit
  149. highlight-current-row
  150. >
  151. <el-table-column prop="application" label="应用名称" />
  152. <el-table-column prop="path_comment" label="服务名称" />
  153. <el-table-column prop="unit" label="委办单位" width="200" />
  154. <el-table-column prop="type" label="服务类别" width="120" />
  155. <el-table-column prop="count" label="调用次数" width="100" />
  156. <el-table-column prop="date" label="调用时间" width="120" />
  157. </el-table>
  158. <div style="float: right; padding-top: 10px">
  159. <el-pagination
  160. v-model:current-page="currentPage"
  161. v-model:page-size="pageSize"
  162. :page-sizes="[50, 100, 200, 500]"
  163. background
  164. layout="total, sizes, prev, pager, next, jumper"
  165. :total="tableDataTotal"
  166. @size-change="handleSizeChange"
  167. @current-change="handleCurrentChange"
  168. />
  169. </div>
  170. </div>
  171. </el-dialog>
  172. <!-- 委办信息统计 -->
  173. <div class="bigCard">
  174. <div class="bigCard_title">委办信息统计</div>
  175. <div class="flex">
  176. <div style="width: 28%; height: 400px">
  177. <EchartsDome :chartOption="chartOptions['委办分布']" title="委办分布" />
  178. </div>
  179. <div style="width: 68%; height: 400px">
  180. <EchartsDome :chartOption="chartOptions['委办活跃度趋势']" title="委办活跃度趋势" />
  181. </div>
  182. </div>
  183. <!-- <div style="width: 100%; height: 400px">
  184. <EchartsDome :chartOption="chartOptions['用户部门分布']" title="用户部门分布" />
  185. </div> -->
  186. </div>
  187. <!-- 应用类信息统计 -->
  188. <div class="bigCard">
  189. <div class="bigCard_title">应用类信息统计</div>
  190. <div class="flex">
  191. <div style="width: 33%; height: 400px">
  192. <EchartsDome :chartOption="chartOptions['热点应用TOP10排名']" title="热点应用TOP10排名" />
  193. </div>
  194. <div style="width: 33%; height: 400px">
  195. <EchartsDome :chartOption="chartOptions['栏目统计分布']" title="栏目统计分布" />
  196. </div>
  197. <div style="width: 33%; height: 400px">
  198. <EchartsDome :chartOption="chartOptions['应用状态分布']" title="应用状态分布" />
  199. </div>
  200. </div>
  201. </div>
  202. <!-- 数据类信息统计 -->
  203. <div class="bigCard">
  204. <div class="bigCard_title">数据类信息统计</div>
  205. <div class="flex">
  206. <div style="width: 50%; height: 400px">
  207. <EchartsDome :chartOption="chartOptions['数据类别分布']" title="数据类别分布" />
  208. </div>
  209. <div style="width: 50%; height: 400px">
  210. <EchartsDome :chartOption="chartOptions['数据质量评分']" title="数据质量评分" />
  211. </div>
  212. </div>
  213. </div>
  214. <!-- 区级特色信息统计 -->
  215. <div class="bigCard">
  216. <div class="bigCard_title">区级特色信息统计</div>
  217. <div class="flex" style="margin-top: 20px">
  218. <div class="flex_column" style="width: 28%; height: 420px">
  219. <card
  220. class="card2 flex"
  221. :title="'服务机构总数'"
  222. value="8"
  223. :growth="'较上个月增长了12%'"
  224. iconColor="#2563db"
  225. :upStatus="1"
  226. />
  227. <card
  228. class="card2 flex"
  229. :title="'服务总数'"
  230. value="100"
  231. :growth="'较上个月下降了12%'"
  232. iconColor="#16a34a"
  233. :upStatus="-1"
  234. />
  235. <card
  236. class="card2 flex"
  237. :title="'服务调用总次数'"
  238. value="1000"
  239. :growth="'较上个月增长了12%'"
  240. iconColor="#9333ea"
  241. :upStatus="1"
  242. />
  243. </div>
  244. <div style="width: 68%; height: 420px">
  245. <EchartsDome :chartOption="chartOptions['服务调用趋势']" title="服务调用趋势" />
  246. </div>
  247. </div>
  248. </div>
  249. </div>
  250. </template>
  251. <script>
  252. import card from "@/components/yxgl/card.vue";
  253. import EchartsDome from "@/components/yxgl/EchartsDome.vue";
  254. import Table from "@/components/yxgl/table.vue";
  255. import appCenter from "@/api/appCenter";
  256. import { countlmType } from "@/api/count";
  257. export default {
  258. name: "",
  259. components: {
  260. card,
  261. EchartsDome,
  262. Table,
  263. },
  264. data() {
  265. return {
  266. // 导出Loading状态
  267. exportLoading: false,
  268. // 弹窗加载状态
  269. dialogLoading: false,
  270. // 获取数据状态
  271. getDataStatus: false,
  272. // 比较的时间范围(默认60天到30天前,主要跟nowTimes有关系)
  273. lastTimes: [],
  274. // 当前选中的时间范围
  275. nowTimes: [],
  276. // 服务调用详情弹窗是否显示
  277. showServerDetailReport: false,
  278. // 服务调用详情数据
  279. serverData: [],
  280. // 展示的详细数据(能根据时间和字段模糊筛选)
  281. showServerData: [],
  282. // 筛选条件下拉框选项
  283. selectOptions: {
  284. application: [],
  285. path_comment: [],
  286. unit: [],
  287. type: [],
  288. },
  289. selectKeyName: {
  290. application: "应用名称",
  291. path_comment: "服务名称",
  292. unit: "委办单位",
  293. count: "调用次数",
  294. type: "服务类型",
  295. },
  296. // 筛选条件下拉框选中的值
  297. selectedModel: {
  298. application: "",
  299. path_comment: "",
  300. unit: "",
  301. type: "",
  302. count: "",
  303. date: "",
  304. },
  305. // 调用次数范围的最小值和最大值
  306. countMin: 0,
  307. countMax: 0,
  308. tableColumns: ["application", "path_comment", "unit", "count", "type", "date"],
  309. // 分页大小
  310. pageSize: 50,
  311. // 当前页码
  312. currentPage: 1,
  313. // 表格数据总条数
  314. tableDataTotal: 0,
  315. TopCardDatas: [
  316. {
  317. name: "委办总数",
  318. value: "0",
  319. growth: "--",
  320. iconColor: "#2563db",
  321. iconName: "OfficeBuilding",
  322. upStatus: 0,
  323. },
  324. {
  325. name: "系统总数",
  326. value: "0",
  327. growth: "--",
  328. iconColor: "#16a34a",
  329. iconName: "WalletFilled",
  330. upStatus: 0,
  331. },
  332. {
  333. name: "服务总数",
  334. value: "0",
  335. growth: "--",
  336. iconColor: "#9333ea",
  337. iconName: "CollectionTag",
  338. upStatus: 0,
  339. },
  340. {
  341. name: "服务调用总数",
  342. value: "0",
  343. growth: "--",
  344. iconColor: "#ca8a04",
  345. iconName: "Paperclip",
  346. upStatus: 0,
  347. },
  348. ],
  349. shortcutsFun: this.shortcuts(),
  350. chartOptions: {},
  351. tableDatas: [],
  352. };
  353. },
  354. watch: {
  355. nowTimes: {
  356. handler(newVal, oldVal) {
  357. if (newVal !== oldVal && newVal.length > 0) {
  358. // 计算出比较的时间范围
  359. this.lastTimes = [
  360. this.$moment(
  361. new Date(
  362. new Date(newVal[0]).setTime(
  363. new Date(newVal[0]).getTime() - (newVal[1] - newVal[0]) - 24 * 60 * 60 * 1000
  364. )
  365. )
  366. ).format("YYYY-MM-DD 00:00:00"),
  367. this.$moment(new Date(newVal[0])).format("YYYY-MM-DD 00:00:00"),
  368. ];
  369. this.initChart();
  370. // 栏目统计分布
  371. this.getColumnCount();
  372. }
  373. },
  374. deep: true,
  375. // immediate: true,
  376. },
  377. },
  378. mounted() {
  379. this.$nextTick(() => {
  380. this.nowTimes = [
  381. new Date(new Date().setTime(new Date() - 3600 * 1000 * 24 * 30)),
  382. new Date(),
  383. ];
  384. });
  385. },
  386. methods: {
  387. // 禁用日期选择器中未来的日期(不能选择nowTimes以外的时间)
  388. disabledDate(time) {
  389. return (
  390. time.getTime() > this.nowTimes[1].getTime() ||
  391. time.getTime() < this.nowTimes[0].getTime() - 24 * 60 * 60 * 1000
  392. );
  393. },
  394. // 分页大小改变时,更新展示数据
  395. handleSizeChange() {
  396. this.dialogLoading = true;
  397. let searchDatas = this.serverData.filter((item) => {
  398. return (
  399. (!this.selectedModel.application ||
  400. item.application === this.selectedModel.application) &&
  401. (!this.selectedModel.path_comment ||
  402. item.path_comment === this.selectedModel.path_comment) &&
  403. (!this.selectedModel.unit || item.unit === this.selectedModel.unit) &&
  404. (!this.selectedModel.type || item.type === this.selectedModel.type)
  405. );
  406. });
  407. // 添加时间范围搜索逻辑
  408. if (this.selectedModel.date) {
  409. searchDatas = searchDatas.filter((item) => {
  410. return (
  411. new Date(item.date).getTime() >=
  412. new Date(
  413. this.$moment(new Date(this.selectedModel.date[0])).format("YYYY-MM-DD 00:00:00")
  414. ).getTime() &&
  415. new Date(item.date).getTime() <=
  416. new Date(
  417. this.$moment(new Date(this.selectedModel.date[1])).format("YYYY-MM-DD 23:59:59")
  418. ).getTime()
  419. );
  420. });
  421. }
  422. // 添加调用次数范围搜索逻辑
  423. if (this.selectedModel.count) {
  424. searchDatas = searchDatas.filter((item) => {
  425. return (
  426. item.count >= this.selectedModel.count[0] && item.count <= this.selectedModel.count[1]
  427. );
  428. });
  429. }
  430. // 格式化日期为YYYY-MM-DD格式
  431. searchDatas.forEach((item) => {
  432. item.date = this.$moment(new Date(item.date)).format("YYYY-MM-DD");
  433. });
  434. // 分页展示数据
  435. this.showServerData = searchDatas.slice(
  436. (this.currentPage - 1) * this.pageSize,
  437. this.currentPage * this.pageSize
  438. );
  439. // 遍历筛选条件下拉框选项,更新每个选项的数组
  440. for (let key in this.selectOptions) {
  441. this.selectOptions[key] = [
  442. ...new Set(searchDatas.map((item) => (item[key] ? item[key] : "未知"))),
  443. ];
  444. }
  445. // 更新分页组件数据
  446. this.tableDataTotal = searchDatas.length;
  447. this.showServerDetailReport = true;
  448. this.dialogLoading = false;
  449. },
  450. handleCurrentChange() {
  451. this.handleSizeChange();
  452. },
  453. // 筛选条件下拉框选中值改变时,触发的事件
  454. changeSelectModel() {
  455. // console.log(this.selectedModel);
  456. // 重置当前页码为第一页
  457. this.currentPage = 1;
  458. // 处理分页数据
  459. this.handleSizeChange();
  460. },
  461. // 重置筛选条件下拉框选中的值
  462. resetSelectModel() {
  463. for (let key in this.selectedModel) {
  464. this.selectedModel[key] = "";
  465. }
  466. this.selectedModel.count = [this.countMin, this.countMax];
  467. this.handleSizeChange();
  468. },
  469. // 打开弹窗,渲染table列表,展示查询时间的所有数据详情
  470. showDetailReport() {
  471. this.dialogLoading = true;
  472. // 要先请求,然后时间排序一下。
  473. appCenter
  474. .getServiceDataByDate({
  475. nowTimes: [
  476. this.$moment(new Date(this.nowTimes[0])).format("YYYY-MM-DD 00:00:00"),
  477. this.$moment(new Date(this.nowTimes[1])).format("YYYY-MM-DD 23:59:59"),
  478. ],
  479. })
  480. .then((res) => {
  481. if (res && res.code == 200) {
  482. if (res.content && res.content.length > 0) {
  483. res.content.forEach((item) => {
  484. this.tableColumns.forEach((key) => {
  485. if (item[key] == undefined) {
  486. item[key] = "未知";
  487. }
  488. });
  489. });
  490. this.serverData = res.content;
  491. // 得到count的最大值和最小值
  492. this.countMax = Math.max(...this.serverData.map((item) => item.count));
  493. this.countMin = Math.min(...this.serverData.map((item) => item.count));
  494. this.resetSelectModel();
  495. this.handleSizeChange();
  496. } else {
  497. this.$message({
  498. message: "暂无数据",
  499. type: "warning",
  500. });
  501. }
  502. }
  503. })
  504. .catch((e) => {
  505. this.$message({
  506. message: e,
  507. type: "error",
  508. });
  509. })
  510. .finally(() => {
  511. this.dialogLoading = false;
  512. });
  513. },
  514. initChart() {
  515. this.getDataStatus = true;
  516. // 获取运行管理页面数据
  517. appCenter
  518. .getAllYxglDatas({
  519. nowTimes: [
  520. this.$moment(new Date(this.nowTimes[0])).format("YYYY-MM-DD 00:00:00"),
  521. this.$moment(new Date(this.nowTimes[1])).format("YYYY-MM-DD 23:59:59"),
  522. ],
  523. lastTimes: this.lastTimes,
  524. })
  525. .then((res) => {
  526. if (res && res.code == 200) {
  527. if (res.content.TopCardDatas && typeof res.content.TopCardDatas === "object") {
  528. // 不能覆盖iconName
  529. this.TopCardDatas.forEach((cardItem) => {
  530. res.content.TopCardDatas.forEach((cardData) => {
  531. if (cardItem.name == cardData.name) {
  532. cardItem.value = cardData.value;
  533. cardItem.growth = cardData.growth;
  534. cardItem.upStatus = cardData.upStatus;
  535. }
  536. });
  537. });
  538. }
  539. this.dataToOption("服务调用趋势", "line", [...res.content.serviceCountTrend], {
  540. legend: { data: ["调用次数"] },
  541. xData: [],
  542. xKey: "date",
  543. xFormart: "YYYY-MM-DD",
  544. yAxis: {
  545. type: "value",
  546. name: "调用次数",
  547. axisLine: { lineStyle: { color: "#42a5f5" } }, // 区分样式
  548. },
  549. yData: {
  550. key: "count",
  551. name: "调用次数",
  552. color: "#42a5f5",
  553. data: [],
  554. yAxisIndex: 0,
  555. },
  556. });
  557. let serviceCountType = [];
  558. serviceCountType = res.content.serviceCountType;
  559. if (res.content.serviceCountType && res.content.serviceCountType.length > 0) {
  560. serviceCountType.forEach((item) => {
  561. if (!item.type) {
  562. item.type = "未知";
  563. }
  564. });
  565. }
  566. // 初始化服务类别分布,这个地方需要先根据serviceType进行groupBy统计调用次数
  567. this.dataToOption("服务类别分布", "pie", serviceCountType, {
  568. pieKey: { value: "count", name: "type" },
  569. pieData: [],
  570. padAngle: 0,
  571. borderRadius: 0,
  572. label: {},
  573. });
  574. // 服务调用TOP10
  575. let serviceDatas = [];
  576. serviceDatas = res.content.serviceCountTop;
  577. if (serviceDatas && serviceDatas.length > 0) {
  578. serviceDatas.forEach((item) => {
  579. if (!item.path_comment) {
  580. item.path_comment = "未知";
  581. }
  582. if (!item.type) {
  583. item.type = "未知";
  584. }
  585. });
  586. }
  587. // 排序
  588. serviceDatas.sort((a, b) => b.count - a.count);
  589. this.initTableDatas(serviceDatas.slice(0, 10));
  590. let serviceCountUnit = [];
  591. serviceCountUnit = res.content.serviceCountUnit;
  592. if (serviceCountUnit && serviceCountUnit.length > 0) {
  593. serviceCountUnit.forEach((item) => {
  594. if (!item.unit) {
  595. item.unit = "未知";
  596. }
  597. });
  598. }
  599. // 委办分布
  600. this.dataToOption("委办分布", "pie", serviceCountUnit, {
  601. pieKey: { value: "count", name: "unit" },
  602. pieData: [],
  603. legend: {
  604. show: false,
  605. bottom: 10,
  606. },
  607. radius: "60%",
  608. padAngle: 0,
  609. borderRadius: 0,
  610. label: {},
  611. });
  612. // 先同步一下legend
  613. let serviceCountUnitTrendLegend = [];
  614. serviceCountUnit.forEach((item) => {
  615. serviceCountUnitTrendLegend.push(item.unit);
  616. });
  617. this.dataToOption("委办活跃度趋势", "line", [...res.content.serviceCountUnitTrend], {
  618. legend: { data: serviceCountUnitTrendLegend },
  619. xData: [],
  620. xKey: "date",
  621. xFormart: "YYYY-MM-DD",
  622. yAxis: {
  623. type: "value",
  624. axisLine: { lineStyle: { color: "#42a5f5" } }, // 区分样式
  625. },
  626. yDatas: { auto: true },
  627. });
  628. let serviceDatas2 = [];
  629. serviceDatas2 = res.content.serviceCountApplicationTop;
  630. // 排序
  631. serviceDatas2.sort((a, b) => b.count - a.count);
  632. let forData = serviceDatas2.slice(0, 10);
  633. let showApplicationTopDatas = [];
  634. for (let i = forData.length - 1; i >= 0; i--) {
  635. showApplicationTopDatas.push(forData[i]);
  636. }
  637. // 用户部门分布
  638. this.dataToOption("热点应用TOP10排名", "bar", showApplicationTopDatas, {
  639. showLegend: false,
  640. xData: [],
  641. xKey: "application",
  642. yData: {
  643. key: "count",
  644. name: "调用次数",
  645. color: "#42a5f5",
  646. data: [],
  647. },
  648. });
  649. // 数据类别分布
  650. if (res.content.dataTypes && res.content.dataTypes.length > 0) {
  651. this.dataToOption("数据类别分布", "pie", [...res.content.dataTypes], {
  652. pieKey: { value: "count", name: "service_name" },
  653. pieData: [],
  654. legend: {
  655. bottom: 10,
  656. },
  657. radius: "60%",
  658. padAngle: 0,
  659. borderRadius: 0,
  660. label: {},
  661. });
  662. }
  663. // console.log("getAllYxglDatas", res);
  664. }
  665. this.getDataStatus = false;
  666. })
  667. .catch((error) => {
  668. this.getDataStatus = false;
  669. this.$message({
  670. type: "error",
  671. message: "服务器忙碌,请稍后重试!",
  672. });
  673. });
  674. // 应用状态分布,cloumnId:1659
  675. appCenter
  676. .getDmsDataList({
  677. columnId: systemConfig.columnIds[1],
  678. pageSize: 1000,
  679. page: 0,
  680. })
  681. .then((res) => {
  682. if (res.code == 200) {
  683. let dmsDatas = res.content.data;
  684. let tableDatas = [];
  685. // 根据状态进行groupBy统计个数
  686. let statusMap = {};
  687. dmsDatas.forEach((item) => {
  688. if (statusMap[item.appstauts + ""]) {
  689. statusMap[item.appstauts + ""] += 1;
  690. } else {
  691. statusMap[item.appstauts + ""] = 1;
  692. }
  693. });
  694. // 转换为数组
  695. for (let key in statusMap) {
  696. if (statusMap[key] && key) {
  697. tableDatas.push({
  698. name: this.$getDmsTypes("appstatus", key),
  699. value: statusMap[key],
  700. });
  701. }
  702. }
  703. this.dataToOption("应用状态分布", "pie", tableDatas, {
  704. pieKey: { value: "value", name: "name" },
  705. pieData: [],
  706. });
  707. } else {
  708. this.$message({
  709. type: "error",
  710. message: "服务器忙碌,请稍后重试!",
  711. });
  712. }
  713. });
  714. this.dataToOption("数据质量评分", "radar", null, null);
  715. },
  716. getColumnCount() {
  717. let param = {
  718. start: this.$moment(new Date(this.nowTimes[0])).format("YYYY-MM-DD"),
  719. end: this.$moment(new Date(this.nowTimes[1])).format("YYYY-MM-DD"),
  720. };
  721. countlmType(param.start, param.end).then((res) => {
  722. // let columnDatas = [
  723. // {count: 3, service_name: "任务"},
  724. // {count: 5, service_name: "反馈信息"},
  725. // {count: 7, service_name: "其它"},
  726. // ];
  727. if (res.length > 0) {
  728. this.dataToOption("栏目统计分布", "pie", [...res], {
  729. pieKey: { value: "count", name: "service_name" },
  730. pieData: [],
  731. legend: {
  732. bottom: 10,
  733. },
  734. radius: "60%",
  735. padAngle: 0,
  736. borderRadius: 0,
  737. label: {},
  738. });
  739. }
  740. })
  741. },
  742. // 导出所选时间范围内的所有服务数据
  743. downFileAllServiceDatas() {
  744. this.exportLoading = true;
  745. appCenter
  746. .downFileAllServiceDatas({ nowTimes: this.nowTimes })
  747. .then((res) => {
  748. const blob = res; // 响应体是 Blob 类型
  749. if (!blob) {
  750. that.$message.error("下载失败:文件流为空");
  751. reject("文件流为空");
  752. return;
  753. }
  754. if (!(blob instanceof Blob) || blob.size === 0) {
  755. this.$message.error("文件流解析失败,无法生成下载链接");
  756. return;
  757. }
  758. const url = window.URL.createObjectURL(blob); // 将 Blob 转为临时 URL
  759. const link = document.createElement("a");
  760. link.href = url;
  761. link.download = "服务信息统计.xlsx"; // 设置下载文件名
  762. link.style.display = "none";
  763. document.body.appendChild(link);
  764. link.click(); // 触发点击下载
  765. document.body.removeChild(link);
  766. window.URL.revokeObjectURL(url); // 销毁临时 URL,避免内存泄漏
  767. })
  768. .catch((e) => {
  769. this.$message({
  770. message: "导出数据失败",
  771. type: "error",
  772. });
  773. })
  774. .finally(() => {
  775. this.exportLoading = false;
  776. });
  777. },
  778. /**
  779. * 数据转换为图表选项
  780. * @param title 图表标题
  781. * @param type 图表类型
  782. * @param datas 原始数据
  783. * @param keyRule 解析规则
  784. */
  785. async dataToOption(title, type, datas, keyRule) {
  786. // 根据规则解析数据
  787. if (keyRule) {
  788. datas.forEach((item) => {
  789. // 有的图表没有X轴
  790. if (keyRule.xKey) {
  791. if (keyRule.xFormart) {
  792. item[keyRule.xKey] = this.$moment(item[keyRule.xKey]).format(keyRule.xFormart);
  793. }
  794. keyRule.xData.push(item[keyRule.xKey]);
  795. }
  796. if (keyRule.yData) {
  797. keyRule.yData.data.push(item[keyRule.yData.key]);
  798. keyRule.series = [
  799. {
  800. name: keyRule.yData.name,
  801. type: "line",
  802. smooth: true,
  803. data: keyRule.yData.data,
  804. lineStyle: {
  805. color: keyRule.yData.color ? keyRule.yData.color : "",
  806. type: keyRule.yData.ifDashed ? "dashed" : "",
  807. }, // 蓝色线条
  808. itemStyle: keyRule.yData.color,
  809. symbol: "circle", // 节点形状
  810. symbolSize: 6, // 节点大小
  811. },
  812. ];
  813. }
  814. if (keyRule.yDatas) {
  815. // 先根据lenged得到data集合
  816. for (let name of keyRule.legend.data) {
  817. if (keyRule.yDatas[name]) {
  818. keyRule.yDatas[name].data.push(item[name]);
  819. } else {
  820. keyRule.yDatas[name] = {
  821. name: name,
  822. data: [item[name]],
  823. };
  824. }
  825. }
  826. }
  827. if (keyRule.pieKey) {
  828. keyRule.pieData.push({
  829. value: item[keyRule.pieKey.value],
  830. name: item[keyRule.pieKey.name],
  831. });
  832. }
  833. });
  834. // 专门用来处理多y数据的series
  835. if (keyRule.yDatas) {
  836. keyRule.series = [];
  837. for (let name of keyRule.legend.data) {
  838. keyRule.series.push({
  839. name: name,
  840. type: "line",
  841. smooth: true,
  842. data: keyRule.yDatas[name].data,
  843. symbol: "circle", // 节点形状
  844. symbolSize: 6, // 节点大小
  845. });
  846. }
  847. }
  848. }
  849. let _option = {};
  850. switch (type) {
  851. case "line":
  852. // 折线图基础
  853. _option = {
  854. legend: {
  855. data: keyRule.legend.data,
  856. },
  857. tooltip: {
  858. show: true,
  859. trigger: "axis",
  860. axisPointer: { type: "shadow" },
  861. },
  862. // 默认样式
  863. xAxis: {
  864. type: "category",
  865. data: keyRule.xData,
  866. axisTick: { show: false }, // 隐藏刻度
  867. splitLine: { show: false }, // 隐藏分割线
  868. axisLabel: {
  869. color: "#F2F3F5cc", // 字体颜色(支持十六进制、RGB、颜色名)
  870. fontSize: 14, // 可选:字体大小
  871. fontWeight: "normal", // 可选:字体粗细
  872. },
  873. },
  874. yAxis: {
  875. type: "value",
  876. axisLabel: {
  877. color: "#42a5f5cc", // 字体颜色(支持十六进制、RGB、颜色名)
  878. fontSize: 14, // 可选:字体大小
  879. fontWeight: "normal", // 可选:字体粗细
  880. },
  881. splitLine: { lineStyle: { color: "#42a5f532" } },
  882. },
  883. series: keyRule.series,
  884. };
  885. break;
  886. case "pie":
  887. // 饼状图
  888. _option = {
  889. tooltip: {
  890. trigger: "item",
  891. },
  892. legend: keyRule.legend
  893. ? keyRule.legend
  894. : {
  895. orient: "vertical",
  896. top: "50%",
  897. right: 10,
  898. },
  899. series: [
  900. {
  901. name: title,
  902. type: "pie",
  903. radius: keyRule.radius ? keyRule.radius : ["40%", "70%"],
  904. avoidLabelOverlap: false,
  905. padAngle: keyRule.padAngle != undefined ? keyRule.padAngle : 5,
  906. itemStyle: {
  907. borderRadius: keyRule.borderRadius != undefined ? keyRule.borderRadius : 10,
  908. },
  909. label:
  910. keyRule.label != undefined
  911. ? keyRule.label
  912. : {
  913. show: false,
  914. position: "center",
  915. },
  916. emphasis: {
  917. label: {
  918. show: true,
  919. fontSize: 20,
  920. fontWeight: "bold",
  921. },
  922. },
  923. labelLine: {
  924. show: true,
  925. },
  926. data: keyRule.pieData,
  927. },
  928. ],
  929. };
  930. break;
  931. case "bar":
  932. // 柱状图
  933. _option = {
  934. tooltip: {
  935. trigger: "axis",
  936. axisPointer: {
  937. type: "shadow",
  938. },
  939. },
  940. legend: {
  941. show: keyRule.showLegend ? keyRule.showLegend : false,
  942. data: keyRule.legend,
  943. },
  944. xAxis: {
  945. type: "value",
  946. axisLabel: {
  947. color: "#42a5f5cc", // 字体颜色(支持十六进制、RGB、颜色名)
  948. fontSize: 14, // 可选:字体大小
  949. fontWeight: "normal", // 可选:字体粗细
  950. },
  951. splitLine: { lineStyle: { color: "#42a5f532" } },
  952. },
  953. yAxis: {
  954. type: "category",
  955. data: keyRule.xData,
  956. axisLabel: {
  957. color: "#F2F3F5cc", // 字体颜色(支持十六进制、RGB、颜色名)
  958. fontSize: 14, // 可选:字体大小
  959. fontWeight: "normal", // 可选:字体粗细
  960. },
  961. },
  962. series: [
  963. {
  964. name: keyRule.yData.name,
  965. type: "bar",
  966. label: {
  967. show: true,
  968. },
  969. emphasis: {
  970. focus: "series",
  971. },
  972. data: keyRule.yData.data,
  973. },
  974. ],
  975. };
  976. break;
  977. default:
  978. // 雷达图
  979. _option = {
  980. tooltip: {
  981. trigger: "axis",
  982. },
  983. legend: {
  984. show: false,
  985. left: "center",
  986. },
  987. radar: [
  988. {
  989. indicator: [
  990. { name: "健壮性", max: 100 },
  991. { name: "完整性", max: 100 },
  992. { name: "一致性", max: 100 },
  993. { name: "及时性", max: 100 },
  994. { name: "准确性", max: 100 },
  995. ],
  996. },
  997. ],
  998. series: [
  999. {
  1000. type: "radar",
  1001. areaStyle: {},
  1002. data: [
  1003. {
  1004. value: [93, 85, 92, 95, 93],
  1005. name: "",
  1006. },
  1007. ],
  1008. },
  1009. ],
  1010. };
  1011. break;
  1012. }
  1013. this.chartOptions[title] = _option;
  1014. },
  1015. // 服务调用列表
  1016. initTableDatas(serviceTypeDatas2) {
  1017. this.tableDatas = serviceTypeDatas2;
  1018. },
  1019. // 时间范围自定义时间
  1020. shortcuts() {
  1021. return [
  1022. {
  1023. text: "当天",
  1024. value: () => {
  1025. const end = new Date();
  1026. const start = new Date();
  1027. return [start, end];
  1028. },
  1029. },
  1030. {
  1031. text: "最近7天",
  1032. value: () => {
  1033. const end = new Date();
  1034. const start = new Date();
  1035. start.setTime(start.getTime() - 3600 * 1000 * 24 * 6);
  1036. return [start, end];
  1037. },
  1038. },
  1039. {
  1040. text: "最近30天",
  1041. value: () => {
  1042. const end = new Date();
  1043. const start = new Date();
  1044. start.setTime(start.getTime() - 3600 * 1000 * 24 * 29);
  1045. return [start, end];
  1046. },
  1047. },
  1048. {
  1049. text: "最近90天",
  1050. value: () => {
  1051. const end = new Date();
  1052. const start = new Date();
  1053. start.setTime(start.getTime() - 3600 * 1000 * 24 * 89);
  1054. return [start, end];
  1055. },
  1056. },
  1057. {
  1058. text: "最近1年",
  1059. value: () => {
  1060. const end = new Date();
  1061. const start = new Date();
  1062. start.setTime(start.getTime() - 3600 * 1000 * 24 * 364);
  1063. return [start, end];
  1064. },
  1065. },
  1066. ];
  1067. },
  1068. },
  1069. };
  1070. </script>
  1071. <style lang="less" scoped>
  1072. .mainBox {
  1073. width: calc(100% - 60px);
  1074. margin: 30px;
  1075. padding-bottom: 80px;
  1076. & > div {
  1077. margin: 20px 0;
  1078. display: flex;
  1079. }
  1080. .card {
  1081. width: calc(25% - 56px);
  1082. border-radius: 5px;
  1083. padding: 20px 18px;
  1084. // background: #00000032;
  1085. background: #eeeeee0b;
  1086. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  1087. }
  1088. .card2 {
  1089. width: 100%;
  1090. border-radius: 5px;
  1091. padding: 20px 18px;
  1092. // background: rgba(255, 255, 255, 0.1);
  1093. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  1094. }
  1095. .bigCard {
  1096. width: calc(100% - 36px);
  1097. border-radius: 5px;
  1098. padding: 20px 18px;
  1099. // background: #00000032;
  1100. position: relative;
  1101. flex-direction: column;
  1102. background: #eeeeee0b;
  1103. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.3);
  1104. .tools {
  1105. position: absolute;
  1106. top: 20px;
  1107. right: 20px;
  1108. display: flex;
  1109. flex-direction: row;
  1110. justify-content: flex-end;
  1111. }
  1112. &_title {
  1113. font-size: 20px;
  1114. font-weight: bold;
  1115. }
  1116. }
  1117. .flex {
  1118. display: flex;
  1119. flex-direction: row;
  1120. justify-content: space-between;
  1121. }
  1122. .flex_column {
  1123. display: flex;
  1124. flex-direction: column;
  1125. justify-content: space-between;
  1126. align-items: flex-start;
  1127. box-sizing: border-box;
  1128. }
  1129. .searchBox {
  1130. width: 100%;
  1131. height: 50px;
  1132. line-height: 50px;
  1133. text-align: center;
  1134. font-size: 20px;
  1135. font-weight: bold;
  1136. flex-direction: row-reverse;
  1137. display: flex;
  1138. }
  1139. }
  1140. // 日期选择框样式
  1141. .demo-date-picker {
  1142. display: flex;
  1143. width: 100%;
  1144. padding: 0;
  1145. flex-wrap: wrap;
  1146. }
  1147. .demo-date-picker .block {
  1148. padding: 1.5rem 0;
  1149. text-align: center;
  1150. border-right: solid 1px var(--el-border-color);
  1151. flex: 1;
  1152. min-width: 400px;
  1153. display: flex;
  1154. flex-direction: column;
  1155. align-items: center;
  1156. }
  1157. .demo-date-picker .block:last-child {
  1158. border-right: none;
  1159. }
  1160. .demo-date-picker .demonstration {
  1161. display: block;
  1162. color: var(--el-text-color-secondary);
  1163. font-size: 14px;
  1164. margin-bottom: 1rem;
  1165. }
  1166. @media screen and (max-width: 1200px) {
  1167. .demo-date-picker .block {
  1168. flex: 0 0 100%;
  1169. padding: 1rem 0;
  1170. min-width: auto;
  1171. border-right: none;
  1172. border-bottom: solid 1px var(--el-border-color);
  1173. }
  1174. .demo-date-picker .block:last-child {
  1175. border-bottom: none;
  1176. }
  1177. }
  1178. // 弹窗加载状态图标
  1179. .loading-icon {
  1180. // 图标顺时针旋转动画
  1181. animation: loading-icon-spin 2s linear infinite;
  1182. }
  1183. @keyframes loading-icon-spin {
  1184. 0% {
  1185. transform: rotate(0deg);
  1186. }
  1187. 100% {
  1188. transform: rotate(360deg);
  1189. }
  1190. }
  1191. </style>