index.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <div class="RealOnline">
  3. <el-breadcrumb separator-class="el-icon-arrow-right">
  4. <el-breadcrumb-item>新媒体</el-breadcrumb-item>
  5. <el-breadcrumb-item>用户分析</el-breadcrumb-item>
  6. <el-breadcrumb-item>实时访客</el-breadcrumb-item>
  7. </el-breadcrumb>
  8. <el-card class="box-card">
  9. <el-form
  10. ref="form"
  11. :model="form"
  12. size="small"
  13. :inline="true"
  14. label-width="120px"
  15. class="demo-form-inline"
  16. >
  17. <el-form-item label="应用">
  18. <el-select v-model="form.app" placeholder="请选择时段">
  19. <el-option
  20. v-for="item in cycle"
  21. :key="item.value"
  22. :label="item.label"
  23. :value="item.value"
  24. :disabled="item.disabled"
  25. >
  26. </el-option>
  27. </el-select>
  28. </el-form-item>
  29. <el-form-item label="粒度">
  30. <el-select v-model="form.lidu" placeholder="请选择粒度">
  31. <el-option
  32. v-for="item in lidu"
  33. :key="item.value"
  34. :label="item.label"
  35. :value="item.value"
  36. :disabled="item.disabled"
  37. >
  38. </el-option>
  39. </el-select>
  40. </el-form-item>
  41. <el-form-item style="float: right">
  42. <el-button type="primary" @click="regularData">查询</el-button>
  43. </el-form-item>
  44. </el-form>
  45. </el-card>
  46. <br />
  47. <el-card>
  48. <div class="totalText" style="display: flex; text-align: center">
  49. <div
  50. class="totalItem"
  51. v-for="(item, i) in total"
  52. :key="i + item"
  53. :style="{ color: item.color }"
  54. >
  55. <countTo
  56. :startVal="0"
  57. :endVal="item.value"
  58. :duration="1500"
  59. ></countTo>
  60. <p v-text="item.name" style="font-size: 16px; color: #000"></p>
  61. </div>
  62. </div>
  63. </el-card>
  64. <br />
  65. <el-card class="box-card">
  66. <div class="realLineChart" ref="realLineChart"></div>
  67. </el-card>
  68. </div>
  69. </template>
  70. <script>
  71. // @ is an alias to /src
  72. import countTo from '@/components/counto/vue-countTo.vue';
  73. import {
  74. getRealAppOnline,
  75. getRule,
  76. getAppList,
  77. getSearchData,
  78. } from '@/api/index';
  79. import { defaultAppNameFunc } from '@/utils/tool.js';
  80. import * as echarts from 'echarts/core';
  81. import { LineChart } from 'echarts/charts';
  82. import {
  83. TitleComponent,
  84. TooltipComponent,
  85. GridComponent,
  86. ToolboxComponent,
  87. LegendComponent,
  88. } from 'echarts/components';
  89. import { CanvasRenderer } from 'echarts/renderers';
  90. echarts.use([
  91. TitleComponent,
  92. TooltipComponent,
  93. GridComponent,
  94. LineChart,
  95. CanvasRenderer,
  96. ToolboxComponent,
  97. LegendComponent,
  98. ]);
  99. // import config from "@/config/index";
  100. let chart = undefined,
  101. time = undefined;
  102. export default {
  103. name: 'RealOnline',
  104. data() {
  105. return {
  106. form: {
  107. app: '',
  108. lidu: '',
  109. },
  110. total: {},
  111. tableData: [],
  112. cycle: [],
  113. lidu: [],
  114. realForm: {},
  115. };
  116. },
  117. mounted() {
  118. this.init();
  119. },
  120. computed: {},
  121. methods: {
  122. async init() {
  123. if (chart && chart.dispose) chart.dispose();
  124. const { source, appli, lidu } = await this.getAppListFunc();
  125. appli.map(v => {
  126. if ((length.length && source[v.mcode]) || source.length === 0)
  127. this.cycle.push({
  128. value: v.mname,
  129. label: v.mname,
  130. });
  131. });
  132. this.lidu = lidu.map(v => {
  133. return {
  134. value: v.mcode,
  135. label: v.mname,
  136. };
  137. });
  138. this.form = {
  139. // app: (this.cycle[0] || { value: "" }).value,
  140. app: defaultAppNameFunc(this.cycle),
  141. lidu: '60',
  142. };
  143. this.regularData();
  144. },
  145. regularData() {
  146. if (time) clearInterval(time);
  147. this.realForm = {
  148. appName: this.form.app,
  149. minute: this.form.lidu,
  150. };
  151. this.onSubmit();
  152. time = setInterval(this.onSubmit, 5000);
  153. },
  154. onSubmit() {
  155. getRealAppOnline(this.realForm)
  156. .then(r => {
  157. if (!this.$refs.realLineChart) return;
  158. const li = r.list || [],
  159. T = r.total || {},
  160. keys = Object.keys(T),
  161. total = [],
  162. color = ['rgb(244, 127, 146)', 'rgb(17, 160, 248)'];
  163. const keyList = [],
  164. valueList_active = [],
  165. valueList_newUser = [];
  166. for (let i = 0; i < keys.length; i++) {
  167. const v = keys[i];
  168. if (typeof T[v].value !== 'number') continue;
  169. let p = {
  170. name: T[v].name,
  171. value: T[v].value,
  172. color: color[i % 2],
  173. };
  174. total.push(p);
  175. }
  176. this.total = total;
  177. li.map(v => {
  178. const key = v.recMinute.split(' ')[1] || '';
  179. keyList.push(key);
  180. valueList_active.push(v.active);
  181. valueList_newUser.push(v.newUser);
  182. });
  183. this.createImage(keyList, valueList_active, valueList_newUser);
  184. })
  185. .catch(() => {
  186. if (!chart) return;
  187. chart.clear();
  188. });
  189. },
  190. createImage(keyList, valueList_active, valueList_newUser) {
  191. if (!chart) {
  192. chart = echarts.init(this.$refs.realLineChart);
  193. window.onresize = chart.resize;
  194. }
  195. chart.resize({
  196. height: (this.$refs.realLineChart.offsetWidth * 4) / 16,
  197. });
  198. chart.setOption({
  199. tooltip: {
  200. confine: true,
  201. trigger: 'axis',
  202. },
  203. toolbox: {
  204. feature: {
  205. saveAsImage: {
  206. type: 'jpg',
  207. name: '实时',
  208. },
  209. },
  210. },
  211. grid: {
  212. left: '3%',
  213. right: '4%',
  214. bottom: '3%',
  215. containLabel: true,
  216. },
  217. legend: {
  218. data: ['活跃用户', '新增用户'],
  219. },
  220. xAxis: {
  221. type: 'category',
  222. boundaryGap: true,
  223. data: keyList,
  224. },
  225. yAxis: {
  226. type: 'value',
  227. minInterval: 1,
  228. axisLabel: {
  229. formatter(v) {
  230. let val = v;
  231. if (val >= 100000000) {
  232. val = (val / 100000000).toFixed(2) + '亿';
  233. } else if (val >= 10000) {
  234. val = (val / 10000).toFixed(2) + '万';
  235. }
  236. return val;
  237. },
  238. },
  239. },
  240. color: ['rgb(17, 160, 248)', 'rgb(244, 127, 146)'],
  241. series: [
  242. {
  243. name: '活跃用户',
  244. data: valueList_active,
  245. symbolSize: 0,
  246. lineStyle: {
  247. width: 1,
  248. },
  249. type: 'line',
  250. smooth: true,
  251. areaStyle: {
  252. color: {
  253. type: 'linear',
  254. x: 0,
  255. y: 0,
  256. x2: 0,
  257. y2: 1,
  258. colorStops: [
  259. {
  260. offset: 0,
  261. color: 'rgba(17, 160, 248, 0.8)', // 0% 处的颜色
  262. },
  263. {
  264. offset: 1,
  265. color: 'rgba(17, 160, 248, 0.1)', // 100% 处的颜色
  266. },
  267. ],
  268. global: false, // 缺省为 false
  269. },
  270. },
  271. },
  272. {
  273. name: '新增用户',
  274. data: valueList_newUser,
  275. symbolSize: 0,
  276. lineStyle: {
  277. width: 1,
  278. },
  279. type: 'line',
  280. smooth: true,
  281. areaStyle: {
  282. color: {
  283. type: 'linear',
  284. x: 0,
  285. y: 0,
  286. x2: 0,
  287. y2: 1,
  288. colorStops: [
  289. {
  290. offset: 0,
  291. color: 'rgba(244, 127, 146, 0.8)', // 0% 处的颜色
  292. },
  293. {
  294. offset: 1,
  295. color: 'rgba(244, 127, 146, 0.1)', // 100% 处的颜色
  296. },
  297. ],
  298. global: false, // 缺省为 false
  299. },
  300. },
  301. },
  302. ],
  303. });
  304. },
  305. async getAppListFunc() {
  306. const { r, li, lidu } = await this.getAppListOri();
  307. let source = {
  308. length: 0,
  309. },
  310. appli = [];
  311. let prvList = r.output.data.prvRolectrl || [];
  312. for (let i = 0; i < prvList.length; i++) {
  313. const v = prvList[i];
  314. if (v.controlid == 'RMT_SOURCE')
  315. (source[v.detid] = true), (source.length = source.length + 1);
  316. }
  317. if (li.status === '0') appli = li.output.data || [];
  318. return {
  319. source,
  320. appli,
  321. lidu,
  322. };
  323. },
  324. async getAppListOri() {
  325. const roleid = JSON.parse(
  326. window.parent.localStorage.userinfo || '{}'
  327. ).roleid;
  328. const r = await getRule({
  329. db: 'authplat',
  330. exportMark: '0',
  331. menuid: 400,
  332. roleid,
  333. });
  334. const li = await getAppList({
  335. exportMark: '0',
  336. gcode: 'SOURCE',
  337. pageid: 1,
  338. pagesize: 1000,
  339. });
  340. const defaultAppName = li.status == '0' ? li.output.data[0].mname : '';
  341. const lidu = await getSearchData({
  342. gcode: 'TIME_MINUTE',
  343. source: defaultAppName,
  344. });
  345. return { r, li, lidu };
  346. },
  347. },
  348. components: { countTo },
  349. };
  350. </script>
  351. <style>
  352. .RealOnline {
  353. margin: 10px 15px;
  354. }
  355. .RealOnline .has-seconds .el-time-spinner__wrapper:last-child {
  356. display: none;
  357. }
  358. .totalText {
  359. display: flex;
  360. }
  361. .totalText .totalItem {
  362. flex: 1;
  363. position: relative;
  364. font-size: 42px;
  365. font-weight: 700;
  366. font-family: sans-serif;
  367. }
  368. .totalText .totalItem:not(:last-child)::after {
  369. position: absolute;
  370. top: 0;
  371. right: 0;
  372. bottom: 0;
  373. content: '';
  374. display: block;
  375. width: 1px;
  376. background: #e7eef0;
  377. }
  378. </style>