browse_footprint.js 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. new Vue({
  2. el: "#app",
  3. delimiters: ["[[", "]]"],
  4. mounted() {
  5. if (
  6. location.href.indexOf("plugin.browse-footprint.admin.index.detail") !== -1
  7. ) {
  8. this.currentPage = "details";
  9. this.search.timeType = timeType;
  10. this.search.pageType = pageType;
  11. this.search.portType = pagePort;
  12. if (startTime && endTime) {
  13. this.search["time"] = [new Date(startTime), new Date(endTime)];
  14. }
  15. this.getDetails();
  16. } else {
  17. this.currentPage = "list";
  18. this.getFootprint();
  19. }
  20. },
  21. data() {
  22. return {
  23. currentPage: "list", //* 当前所在的页面 list=浏览轨迹页面 details=详情页
  24. indexConcept: {}, //* 指数概念
  25. pageType: [], //* 页面类型
  26. portType: [], //* 端口类型
  27. footprintData: [], //* 访问轨迹列表数据
  28. footprintPagination: {
  29. page: 1, //* 访问轨迹列表页数
  30. loading: false, //* 访问轨迹列表是否加载中
  31. finished: false, //* 访问轨迹列表数据是否加载完成
  32. total: 0, //* 访问轨迹数据总数
  33. per_page: 0, //*访问轨迹每页数量
  34. },
  35. detailInfo: null, //* 详情信息
  36. detailMemberList: [], //* 详情访问的会员数据
  37. detailPagination: {
  38. page: 1, //* 访问轨迹列表页数
  39. loading: false, //* 访问轨迹列表是否加载中
  40. finished: false, //* 访问轨迹列表数据是否加载完成
  41. total: 0, //* 访问轨迹数据总数
  42. per_page: 0, //*访问轨迹每页数量
  43. },
  44. isChangeConditions: false, //* 是否修改了搜索条件
  45. search: {
  46. //* 搜索相关
  47. time: null,
  48. timeType: 1,
  49. pageType: "all",
  50. portType: 0,
  51. pageUrl: "",
  52. sharer_info: null,
  53. },
  54. nowTime: null,
  55. };
  56. },
  57. methods: {
  58. //* 根据search对象生成请求参数
  59. generateRequestParams() {
  60. const conditions = this.search;
  61. const requestData = {
  62. search: {
  63. s_div_time: "",
  64. e_div_time: "",
  65. port_type: conditions.portType == 0 ? "" : conditions.portType,
  66. sharer_info: conditions.sharer_info,
  67. },
  68. };
  69. if (conditions.timeType !== null) {
  70. requestData.search["time_type"] = conditions.timeType;
  71. if (conditions.timeType == 5) {
  72. requestData.search.s_div_time = conditions.time[0];
  73. requestData.search.e_div_time = conditions.time[1];
  74. }
  75. }
  76. if (conditions.pageType === "all") {
  77. requestData.search.page_type = "";
  78. } else {
  79. requestData.search.page_type = conditions.pageType;
  80. }
  81. if (conditions.pageUrl) {
  82. requestData.search.url = conditions.pageUrl;
  83. }
  84. return requestData;
  85. },
  86. async fetchData(URL, requestParams) {
  87. return await this.$http
  88. .post(URL, requestParams)
  89. .then(function (response) {
  90. return response.json();
  91. })
  92. .then(({ result, data, msg }) => {
  93. if (result == 0) {
  94. this.$message({
  95. message: msg,
  96. type: "error",
  97. });
  98. }
  99. return data;
  100. })
  101. .catch((err) => {
  102. return err;
  103. });
  104. },
  105. getFootprint(page = null) {
  106. if (this.isChangeConditions) {
  107. this.detailPagination.page = 1;
  108. this.footprintPagination.page = 1;
  109. }
  110. if (typeof page != "number") {
  111. page = this.footprintPagination.page;
  112. }
  113. const loading = this.$loading({
  114. target: ".data-list",
  115. });
  116. const requestData = this.generateRequestParams();
  117. requestData["page"] = page;
  118. this.fetchData(listApi, requestData).then((res) => {
  119. if (!this.nowTime) {
  120. this.nowTime = res.now_time;
  121. }
  122. //* 分页处理
  123. this.footprintPagination.total = res.page_data.total;
  124. this.footprintPagination.per_page = res.page_data.per_page;
  125. this.footprintPagination.page = res.page_data.current_page;
  126. this.indexConcept = res.index_overview;
  127. this.pageType = res.page_type_arr;
  128. this.portType = res.port_type_arr;
  129. let footprint = res.list;
  130. let start = res.page_data.from;
  131. for (let i = 0; i < footprint.length; i++) {
  132. footprint[i]["serialNumer"] = start++;
  133. }
  134. this.footprintData = footprint;
  135. loading.close();
  136. this.footprintPagination.loading = false;
  137. this.isChangeConditions = false;
  138. });
  139. },
  140. getDetails(page = null) {
  141. if (this.isChangeConditions) {
  142. this.detailPagination.page = 1;
  143. this.footprintPagination.page = 1;
  144. }
  145. if (typeof page != "number") {
  146. page = this.detailPagination.page;
  147. }
  148. const loading = this.$loading({
  149. target: ".visit-member",
  150. });
  151. const requestParams = this.generateRequestParams();
  152. requestParams["page_type"] = pageType;
  153. requestParams["page_type_id"] = pageTypeId;
  154. delete requestParams["search"]["page_type"];
  155. requestParams["page"] = page;
  156. this.fetchData(detailsApi, requestParams).then((res) => {
  157. if (this.nowTime === null) {
  158. this.nowTime = res.nowTime;
  159. }
  160. //* 分页处理
  161. this.detailPagination.total = res.page_data.total;
  162. this.detailPagination.per_page = res.page_data.per_page;
  163. this.detailPagination.page = res.page_data.current_page;
  164. this.indexConcept = res.index_overview;
  165. this.portType = res.port_type_arr;
  166. this.detailInfo = [res.info];
  167. this.detailMemberList = res.list;
  168. this.isChangeConditions = false;
  169. loading.close();
  170. });
  171. },
  172. switchSearchTime(timeType) {
  173. this.search.timeType = timeType;
  174. this.search.time = null;
  175. this.isChangeConditions = true;
  176. },
  177. changeSearchTime(time) {
  178. if (time === null) {
  179. this.search.timeType = null;
  180. return;
  181. }
  182. this.search.timeType = 5;
  183. this.isChangeConditions = true;
  184. },
  185. switchPort(portType) {
  186. this.search.portType = portType;
  187. this.isChangeConditions = true;
  188. },
  189. copyLink(url) {
  190. const copyInputEl = document.querySelector(".copy-link input");
  191. copyInputEl.setAttribute("value", url);
  192. copyInputEl.select();
  193. document.execCommand("copy");
  194. copyInputEl.blur();
  195. this.$message({
  196. message: "复制成功",
  197. type: "success",
  198. });
  199. },
  200. exportData() {
  201. let url = exportUrl;
  202. let params = this.generateRequestParams()["search"];
  203. if (this.currentPage === "list") {
  204. params["export_type"] = "index";
  205. } else {
  206. params["export_type"] = "detail";
  207. params["page_type"] = pageType;
  208. params["page_type_id"] = pageTypeId;
  209. }
  210. for (let i in params) {
  211. if (params[i] || params[i] === 0) {
  212. url += "&" + i + "=" + params[i];
  213. }
  214. }
  215. if (this.currentPage === "list" && this.search.pageType == "all") {
  216. url += "&page_type";
  217. }
  218. window.location.href = url;
  219. },
  220. routerToDetails(itemIndex) {
  221. let item = this.footprintData[itemIndex];
  222. let params = this.generateRequestParams();
  223. params["search"]["page_type_id"] = item["page_type_id"];
  224. params["search"]["page_type"] = item["en_page_type"];
  225. params = params["search"];
  226. delete params["url"];
  227. let uri = [];
  228. for (const key in params) {
  229. if (params[key]) {
  230. uri.push(`${key}=${params[key]}`);
  231. } else {
  232. uri.push(`${key}=`);
  233. }
  234. }
  235. uri = uri.join("&");
  236. window.location.href = detailsUrl + `&${uri}`;
  237. },
  238. },
  239. watch: {
  240. "search.pageType"() {
  241. this.isChangeConditions = true;
  242. },
  243. "search.time"() {
  244. this.isChangeConditions = true;
  245. },
  246. "search.pageType"() {
  247. this.isChangeConditions = true;
  248. },
  249. },
  250. });