StatisticalAnalysis.vue 37 KB

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