bigscreen.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. import { sldCommonService } from "@/utils/utils";
  2. import moment from "moment";
  3. export default {
  4. namespace: "bigscreen",
  5. state: {
  6. overviewData: {
  7. loading: false,
  8. data: {},
  9. },
  10. portalTrafficData: {
  11. loading: false,
  12. data: {},
  13. options: [
  14. {
  15. label: "近7日",
  16. value: {
  17. startTime:
  18. moment()
  19. .subtract(7, "days")
  20. .format("YYYY-MM-DD") + " 00:00:00",
  21. endTime:
  22. moment()
  23. .subtract(1, "days")
  24. .format("YYYY-MM-DD") + " 23:59:59:999",
  25. },
  26. },
  27. {
  28. label: "近30日",
  29. value: {
  30. startTime:
  31. moment()
  32. .subtract(30, "days")
  33. .format("YYYY-MM-DD") + " 00:00:00",
  34. endTime:
  35. moment()
  36. .subtract(1, "days")
  37. .format("YYYY-MM-DD") + " 23:59:59:999",
  38. },
  39. },
  40. ],
  41. current: "近7日",
  42. },
  43. enquireData: {
  44. loading: false,
  45. data: {},
  46. options: [
  47. {
  48. label: "近7日",
  49. value: {
  50. startTime:
  51. moment()
  52. .subtract(7, "days")
  53. .format("YYYY-MM-DD") + " 00:00:00",
  54. endTime:
  55. moment()
  56. .subtract(1, "days")
  57. .format("YYYY-MM-DD") + " 23:59:59:999",
  58. },
  59. },
  60. {
  61. label: "近30日",
  62. value: {
  63. startTime:
  64. moment()
  65. .subtract(30, "days")
  66. .format("YYYY-MM-DD") + " 00:00:00",
  67. endTime:
  68. moment()
  69. .subtract(1, "days")
  70. .format("YYYY-MM-DD") + " 23:59:59:999",
  71. },
  72. },
  73. ],
  74. current: "近7日",
  75. },
  76. overseasEnquireLocationData: {
  77. loading: false,
  78. data: [],
  79. },
  80. distributorEnquireLocationData: {
  81. loading: false,
  82. data: [],
  83. },
  84. memberAddTrendData: {
  85. loading: false,
  86. data: [],
  87. },
  88. productAddTrendData: {
  89. loading: false,
  90. data: [],
  91. },
  92. searchRankData: {
  93. loading: false,
  94. data: [],
  95. options: [
  96. {
  97. label: "昨日",
  98. value: {
  99. startTime:
  100. moment()
  101. .subtract(1, "days")
  102. .format("YYYY-MM-DD") + " 00:00:00",
  103. endTime:
  104. moment()
  105. .subtract(1, "days")
  106. .format("YYYY-MM-DD") + " 23:59:59:999",
  107. },
  108. },
  109. {
  110. label: "近7日",
  111. value: {
  112. startTime:
  113. moment()
  114. .subtract(7, "days")
  115. .format("YYYY-MM-DD") + " 00:00:00",
  116. endTime:
  117. moment()
  118. .subtract(1, "days")
  119. .format("YYYY-MM-DD") + " 23:59:59:999",
  120. },
  121. },
  122. {
  123. label: "近30日",
  124. value: {
  125. startTime:
  126. moment()
  127. .subtract(30, "days")
  128. .format("YYYY-MM-DD") + " 00:00:00",
  129. endTime:
  130. moment()
  131. .subtract(1, "days")
  132. .format("YYYY-MM-DD") + " 23:59:59:999",
  133. },
  134. },
  135. ],
  136. current: "昨日",
  137. },
  138. storeTrafficData: {
  139. loading: false,
  140. data: [],
  141. options: [
  142. {
  143. label: "昨日",
  144. value: {
  145. startTime:
  146. moment()
  147. .subtract(1, "days")
  148. .format("YYYY-MM-DD") + " 00:00:00",
  149. endTime:
  150. moment()
  151. .subtract(1, "days")
  152. .format("YYYY-MM-DD") + " 23:59:59:999",
  153. },
  154. },
  155. {
  156. label: "近7日",
  157. value: {
  158. startTime:
  159. moment()
  160. .subtract(7, "days")
  161. .format("YYYY-MM-DD") + " 00:00:00",
  162. endTime:
  163. moment()
  164. .subtract(1, "days")
  165. .format("YYYY-MM-DD") + " 23:59:59:999",
  166. },
  167. },
  168. {
  169. label: "近30日",
  170. value: {
  171. startTime:
  172. moment()
  173. .subtract(30, "days")
  174. .format("YYYY-MM-DD") + " 00:00:00",
  175. endTime:
  176. moment()
  177. .subtract(1, "days")
  178. .format("YYYY-MM-DD") + " 23:59:59:999",
  179. },
  180. },
  181. ],
  182. current: "昨日",
  183. },
  184. mapContainerData: {
  185. loading: false,
  186. data: [],
  187. },
  188. updateTime: "",
  189. },
  190. effects: {
  191. // 平台数据汇总
  192. *load_overview({ payload }, { call, put }) {
  193. yield put({
  194. type: "setOverviewData",
  195. payload: { loading: true },
  196. });
  197. const response = yield call(
  198. sldCommonService,
  199. payload,
  200. "get",
  201. "v3/statistics/screen/analysis/dataSummary"
  202. );
  203. yield put({
  204. type: "setOverviewData",
  205. payload: { data: response.data, loading: false },
  206. });
  207. },
  208. // 门户流量
  209. *load_portal_traffic({ payload }, { call, put, select }) {
  210. const current = yield select(
  211. (state) => state.bigscreen.portalTrafficData.current
  212. );
  213. const options = yield select(
  214. (state) => state.bigscreen.portalTrafficData.options
  215. );
  216. const condition = options.filter((item) => item.label == current)[0]
  217. .value;
  218. payload = { ...payload, ...condition };
  219. yield put({
  220. type: "setPortalTrafficData",
  221. payload: { loading: true },
  222. });
  223. const response = yield call(
  224. sldCommonService,
  225. payload,
  226. "get",
  227. "v3/statistics/screen/analysis/flowTrend"
  228. );
  229. yield put({
  230. type: "setPortalTrafficData",
  231. payload: { data: response.data, loading: false },
  232. });
  233. },
  234. // 询盘概况
  235. *load_enquire_data({ payload }, { call, put, select }) {
  236. const current = yield select(
  237. (state) => state.bigscreen.enquireData.current
  238. );
  239. const options = yield select(
  240. (state) => state.bigscreen.enquireData.options
  241. );
  242. const condition = options.filter((item) => item.label == current)[0]
  243. .value;
  244. payload = { ...payload, ...condition };
  245. yield put({
  246. type: "setEnquireData",
  247. payload: { loading: true },
  248. });
  249. const response = yield call(
  250. sldCommonService,
  251. payload,
  252. "get",
  253. "v3/statistics/screen/analysis/enquiryTrend"
  254. );
  255. yield put({
  256. type: "setEnquireData",
  257. payload: { data: response.data, loading: false },
  258. });
  259. },
  260. // 海外询盘地区分布
  261. *load_overseas_enquire_location({ payload }, { call, put, select }) {
  262. yield put({
  263. type: "setOverseasEnquireLocation",
  264. payload: { loading: true },
  265. });
  266. const response = yield call(
  267. sldCommonService,
  268. payload,
  269. "get",
  270. "v3/statistics/screen/analysis/enquiryDistribution"
  271. );
  272. yield put({
  273. type: "setOverseasEnquireLocation",
  274. payload: { data: response.data, loading: false },
  275. });
  276. },
  277. // 供应链企业地区分布
  278. *load_distributor_enquire_location({ payload }, { call, put, select }) {
  279. yield put({
  280. type: "setDistributorEnquireLocation",
  281. payload: { loading: true },
  282. });
  283. const response = yield call(
  284. sldCommonService,
  285. payload,
  286. "get",
  287. "v3/statistics/screen/analysis/regionDistribution"
  288. );
  289. yield put({
  290. type: "setDistributorEnquireLocation",
  291. payload: { data: response.data, loading: false },
  292. });
  293. },
  294. // 新增会员趋势
  295. *load_add_member_trend({ payload }, { put, call }) {
  296. yield put({
  297. type: "setMemberAddTrendData",
  298. payload: { loading: true },
  299. });
  300. const response = yield call(
  301. sldCommonService,
  302. payload,
  303. "get",
  304. "v3/statistics/screen/analysis/memberTrend"
  305. );
  306. yield put({
  307. type: "setMemberAddTrendData",
  308. payload: { data: response.data, loading: false },
  309. });
  310. },
  311. // 新增商品趋势
  312. *load_add_product_trend({ payload }, { put, call }) {
  313. yield put({
  314. type: "setProductAddTrendData",
  315. payload: { loading: true },
  316. });
  317. const response = yield call(
  318. sldCommonService,
  319. payload,
  320. "get",
  321. "v3/statistics/screen/analysis/goodsTrend"
  322. );
  323. yield put({
  324. type: "setProductAddTrendData",
  325. payload: { data: response.data, loading: false },
  326. });
  327. },
  328. // 门户关键词搜索
  329. *load_search_rank({ payload }, { put, call, select }) {
  330. const current = yield select(
  331. (state) => state.bigscreen.searchRankData.current
  332. );
  333. const options = yield select(
  334. (state) => state.bigscreen.searchRankData.options
  335. );
  336. const condition = options.filter((item) => item.label == current)[0]
  337. .value;
  338. payload = { ...payload, ...condition };
  339. yield put({
  340. type: "setSearchRankData",
  341. payload: { loading: true },
  342. });
  343. const response = yield call(
  344. sldCommonService,
  345. payload,
  346. "get",
  347. "v3/statistics/screen/analysis/searchRank"
  348. );
  349. yield put({
  350. type: "setSearchRankData",
  351. payload: { data: response.data, loading: false },
  352. });
  353. },
  354. // 店铺流量排行
  355. *load_store_traffic({ payload }, { put, call, select }) {
  356. const current = yield select(
  357. (state) => state.bigscreen.storeTrafficData.current
  358. );
  359. const options = yield select(
  360. (state) => state.bigscreen.storeTrafficData.options
  361. );
  362. const condition = options.filter((item) => item.label == current)[0]
  363. .value;
  364. payload = { ...payload, ...condition };
  365. yield put({
  366. type: "setStoreTrafficData",
  367. payload: { loading: true },
  368. });
  369. const response = yield call(
  370. sldCommonService,
  371. payload,
  372. "get",
  373. "v3/statistics/screen/analysis/storeFlowRank"
  374. );
  375. yield put({
  376. type: "setStoreTrafficData",
  377. payload: { data: response.data, loading: false },
  378. });
  379. },
  380. // 世界地图站点数据
  381. *load_world_map({ payload }, { put, call, select }) {
  382. yield put({
  383. type: "setWorldMapData",
  384. payload: { loading: true },
  385. });
  386. const response = yield call(
  387. sldCommonService,
  388. payload,
  389. "get",
  390. "v3/statistics/screen/analysis/memberDistribution"
  391. );
  392. yield put({
  393. type: "setWorldMapData",
  394. payload: { data: response.data, loading: false },
  395. });
  396. },
  397. // 初始化数据
  398. *load_data({ payload }, { put, call, all }) {
  399. // 更新时间
  400. const now = new Date();
  401. const pad = (n) => n.toString().padStart(2, "0");
  402. const currentTime = `${now.getFullYear()}-${pad(
  403. now.getMonth() + 1
  404. )}-${pad(now.getDate())} ${pad(now.getHours())}:${pad(
  405. now.getMinutes()
  406. )}:${pad(now.getSeconds())}`;
  407. yield put({
  408. type: "setUpdateTime",
  409. payload: currentTime,
  410. });
  411. yield all([
  412. put({ type: "load_overview" }),
  413. put({ type: "load_portal_traffic" }),
  414. put({ type: "load_enquire_data" }),
  415. put({ type: "load_overseas_enquire_location" }),
  416. put({ type: "load_distributor_enquire_location" }),
  417. put({ type: "load_add_member_trend" }),
  418. put({ type: "load_add_product_trend" }),
  419. put({ type: "load_search_rank" }),
  420. put({ type: "load_store_traffic" }),
  421. put({ type: "load_world_map" }),
  422. ]);
  423. },
  424. },
  425. reducers: {
  426. setWorldMapData(state, { payload }) {
  427. return {
  428. ...state,
  429. mapContainerData: {
  430. ...state.mapContainerData,
  431. ...payload,
  432. },
  433. };
  434. },
  435. setStoreTrafficData(state, { payload }) {
  436. return {
  437. ...state,
  438. storeTrafficData: {
  439. ...state.storeTrafficData,
  440. ...payload,
  441. },
  442. };
  443. },
  444. setUpdateTime(state, { payload }) {
  445. return {
  446. ...state,
  447. updateTime: payload,
  448. };
  449. },
  450. setSearchRankData(state, { payload }) {
  451. return {
  452. ...state,
  453. searchRankData: {
  454. ...state.searchRankData,
  455. ...payload,
  456. },
  457. };
  458. },
  459. setOverviewData(state, { payload }) {
  460. return {
  461. ...state,
  462. overviewData: {
  463. ...state.overviewData,
  464. ...payload,
  465. },
  466. };
  467. },
  468. setPortalTrafficData(state, { payload }) {
  469. return {
  470. ...state,
  471. portalTrafficData: {
  472. ...state.portalTrafficData,
  473. ...payload,
  474. },
  475. };
  476. },
  477. setEnquireData(state, { payload }) {
  478. return {
  479. ...state,
  480. enquireData: {
  481. ...state.enquireData,
  482. ...payload,
  483. },
  484. };
  485. },
  486. setOverseasEnquireLocation(state, { payload }) {
  487. return {
  488. ...state,
  489. overseasEnquireLocationData: {
  490. ...state.overseasEnquireLocationData,
  491. ...payload,
  492. },
  493. };
  494. },
  495. setDistributorEnquireLocation(state, { payload }) {
  496. return {
  497. ...state,
  498. distributorEnquireLocationData: {
  499. ...state.distributorEnquireLocationData,
  500. ...payload,
  501. },
  502. };
  503. },
  504. setMemberAddTrendData(state, { payload }) {
  505. return {
  506. ...state,
  507. memberAddTrendData: {
  508. ...state.memberAddTrendData,
  509. ...payload,
  510. },
  511. };
  512. },
  513. setProductAddTrendData(state, { payload }) {
  514. return {
  515. ...state,
  516. productAddTrendData: {
  517. ...state.productAddTrendData,
  518. ...payload,
  519. },
  520. };
  521. },
  522. },
  523. subscriptions: {
  524. setup({ history }) {
  525. // Subscribe history(url) change, trigger `load` action if pathname is `/`
  526. return history.listen(({ pathname, search }) => {
  527. if (typeof window.ga !== "undefined") {
  528. window.ga("send", "pageview", pathname + search);
  529. }
  530. });
  531. },
  532. },
  533. };