index.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <template>
  2. <div class="app-container">
  3. <el-row>
  4. <el-col :span="24" class="card-box">
  5. <el-card>
  6. <div slot="header"><span>搜索信息</span></div>
  7. <div class="el-table el-table--enable-row-hover el-table--medium">
  8. <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" label-width="120px">
  9. <el-form-item label="活动开始时间" prop="startTime">
  10. <el-date-picker clearable
  11. v-model="queryParams.startTime"
  12. type="date"
  13. value-format="yyyy-MM-dd"
  14. placeholder="请选择活动开始时间">
  15. </el-date-picker>
  16. </el-form-item>
  17. <el-form-item label="活动结束时间" prop="endTime">
  18. <el-date-picker clearable
  19. v-model="queryParams.endTime"
  20. type="date"
  21. value-format="yyyy-MM-dd"
  22. placeholder="请选择活动结束时间">
  23. </el-date-picker>
  24. </el-form-item>
  25. <el-form-item>
  26. <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
  27. <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
  28. </el-form-item>
  29. </el-form>
  30. </div>
  31. </el-card>
  32. </el-col>
  33. <el-col :span="8" class="card-box">
  34. <el-card>
  35. <div slot="header"><span>活动统计</span></div>
  36. <div class="el-table el-table--enable-row-hover el-table--medium">
  37. <div ref="activities" style="height: 500px" />
  38. </div>
  39. </el-card>
  40. </el-col>
  41. <el-col :span="16" class="card-box">
  42. <el-card>
  43. <div slot="header">
  44. <span>人数统计</span>
  45. </div>
  46. <el-row :gutter="24">
  47. <el-col :span="4" v-for="(item, index) in userData" :key="index"><div style="margin-top: 8px;">{{ item.name }}: {{ item.value }}人</div></el-col>
  48. </el-row>
  49. <div class="el-table el-table--enable-row-hover el-table--medium">
  50. <div ref="usedmemory" style="height: 440px" />
  51. </div>
  52. </el-card>
  53. </el-col>
  54. </el-row>
  55. </div>
  56. </template>
  57. <script>
  58. import { activityCountByType, userCountByType, userCountByTag, userTotalCountByTag, userTimesByTag, userTotalTimesByTag } from "@/api/stat/index";
  59. import echarts from "echarts";
  60. export default {
  61. name: "Cache",
  62. dicts: ['user_tags'],
  63. data() {
  64. return {
  65. activities: null,
  66. // cache信息
  67. cache: [],
  68. queryParams: {},
  69. dateRange: [],
  70. userData: [],
  71. titleList: [
  72. { name: '文化娱乐', value: 'whyl' },
  73. { name: '志愿服务', value: 'zyfu' },
  74. { name: '教育宣讲', value: 'jyxj' },
  75. { name: '治理防范', value: 'zlff' },
  76. { name: '环境卫生', value: 'hjws' },
  77. { name: '关爱服务', value: 'gafw' }
  78. ]
  79. }
  80. },
  81. mounted() {
  82. this.handleQuery();
  83. // this.openLoading();
  84. },
  85. methods: {
  86. // 搜索
  87. handleQuery() {
  88. this.$modal.loading("正在加载活动统计数据,请稍候!");
  89. this.getActivity();
  90. this.getUser();
  91. this.getUserList();
  92. },
  93. // 重置
  94. resetQuery() {
  95. this.dateRange = [];
  96. this.resetForm("queryForm");
  97. this.handleQuery();
  98. },
  99. /** 人数信息 */
  100. async getUserList() {
  101. const typeUser = await userCountByTag(this.queryParams);
  102. // 用户群体按字典排序
  103. typeUser.data.sort((a, b) =>
  104. (this.dict.type.user_tags.find(tag => tag.label === a.name)?.raw.dictSort ?? Infinity) -
  105. (this.dict.type.user_tags.find(tag => tag.label === b.name)?.raw.dictSort ?? Infinity)
  106. );
  107. const allUser = await userTotalTimesByTag(this.queryParams);
  108. const allData = [{ name: '总人次', value: allUser.data }];
  109. this.userData = [ ...allData, ...typeUser?.data ];
  110. this.$modal.closeLoading();
  111. },
  112. async getActivity() {
  113. const res = await activityCountByType(this.queryParams);
  114. const data = res?.data.map(e => {
  115. const type = this.titleList.find(j => j.value == e.name);
  116. if (type) e.name = type.name;
  117. return e;
  118. });;
  119. const myChart = echarts.init(this.$refs.activities, 'macarons');
  120. const option = {
  121. tooltip: {
  122. trigger: 'item',
  123. formatter: "{b}: {c} ({d}%)",
  124. },
  125. series: [
  126. {
  127. type: "pie",
  128. roseType: "radius",
  129. radius: [15, 95],
  130. center: ["50%", "38%"],
  131. data,
  132. animationEasing: "cubicInOut",
  133. animationDuration: 1000,
  134. }
  135. ]
  136. };
  137. myChart.setOption(option);
  138. },
  139. async getUser() {
  140. const res = await userCountByType(this.queryParams);
  141. const data = res?.data.map(e => {
  142. const type = this.titleList.find(j => j.value == e.name);
  143. if (type) e.name = type.name;
  144. return e;
  145. });
  146. const myChart = echarts.init(this.$refs.usedmemory);
  147. const option = {
  148. xAxis: {
  149. type: 'category',
  150. data: (() => {
  151. let list = [];
  152. data.map((item) => {
  153. list.push(item.name);
  154. });
  155. return list;
  156. })(),
  157. },
  158. yAxis: {
  159. type: 'value'
  160. },
  161. series: [
  162. {
  163. data,
  164. type: 'bar',
  165. showBackground: true,
  166. backgroundStyle: {
  167. color: 'rgba(180, 180, 180, 0.2)'
  168. },
  169. label: {
  170. show: true,
  171. position: 'top'
  172. },
  173. itemStyle: {
  174. normal: {
  175. color: function(params) {
  176. return '#3f48cc'
  177. }
  178. }
  179. }
  180. }
  181. ]
  182. };
  183. myChart.setOption(option);
  184. }
  185. }
  186. };
  187. </script>