Log-fb070c89.js 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  1. import { d as defineComponent, r as ref, a as computed, o as onMounted, z as nextTick, p as onActivated, w as watch, c as createVNode, n as reactive, b as createElementBlock, e as createBaseVNode, f as withCtx, u as useRouter, j as openBlock, F as Fragment, x as renderList, k as createBlock, t as toDisplayString, B as unref } from "./index-5e4623ce.js";
  2. import { B as BackTop } from "./index-9e456003.js";
  3. import { P as PullRefresh } from "./index-e8b8fc91.js";
  4. import { S as SwipeCell } from "./index-73d5a905.js";
  5. import { C as Cell } from "./index-8540448e.js";
  6. import { C as CusNavigation } from "./CusNavigation-87012716.js";
  7. import { p as post_promise } from "./index-18735c56.js";
  8. import { t as timestampToTime } from "./index-dd255780.js";
  9. import { u as useExpose } from "./use-scope-id-0b5b8615.js";
  10. import { c as createNamespace, m as makeNumericProp, z as makeStringProp, O as windowWidth, w as withInstall } from "./index-487cde8c.js";
  11. import { L as Loading } from "./index-217c49a0.js";
  12. import "./index-eef3af38.js";
  13. import "./on-popup-reopen-c5ca1603.js";
  14. import "./use-route-726f0d0b.js";
  15. import "./axios-8cd254ce.js";
  16. import "./function-call-dc072a29.js";
  17. import "./mount-component-2b0f7b23.js";
  18. const [name, bem] = createNamespace("text-ellipsis");
  19. const textEllipsisProps = {
  20. rows: makeNumericProp(1),
  21. dots: makeStringProp("..."),
  22. content: makeStringProp(""),
  23. expandText: makeStringProp(""),
  24. collapseText: makeStringProp(""),
  25. position: makeStringProp("end")
  26. };
  27. var stdin_default = defineComponent({
  28. name,
  29. props: textEllipsisProps,
  30. emits: ["clickAction"],
  31. setup(props, {
  32. emit,
  33. slots
  34. }) {
  35. const text = ref(props.content);
  36. const expanded = ref(false);
  37. const hasAction = ref(false);
  38. const root = ref();
  39. const actionRef = ref();
  40. let needRecalculate = false;
  41. const actionText = computed(() => expanded.value ? props.collapseText : props.expandText);
  42. const pxToNum = (value) => {
  43. if (!value)
  44. return 0;
  45. const match = value.match(/^\d*(\.\d*)?/);
  46. return match ? Number(match[0]) : 0;
  47. };
  48. const cloneContainer = () => {
  49. if (!root.value || !root.value.isConnected)
  50. return;
  51. const originStyle = window.getComputedStyle(root.value);
  52. const container = document.createElement("div");
  53. const styleNames = Array.prototype.slice.apply(originStyle);
  54. styleNames.forEach((name2) => {
  55. container.style.setProperty(name2, originStyle.getPropertyValue(name2));
  56. });
  57. container.style.position = "fixed";
  58. container.style.zIndex = "-9999";
  59. container.style.top = "-9999px";
  60. container.style.height = "auto";
  61. container.style.minHeight = "auto";
  62. container.style.maxHeight = "auto";
  63. container.innerText = props.content;
  64. document.body.appendChild(container);
  65. return container;
  66. };
  67. const calcEllipsisText = (container, maxHeight) => {
  68. var _a, _b;
  69. const {
  70. content,
  71. position,
  72. dots
  73. } = props;
  74. const end = content.length;
  75. const middle = 0 + end >> 1;
  76. const actionHTML = slots.action ? (_b = (_a = actionRef.value) == null ? void 0 : _a.outerHTML) != null ? _b : "" : props.expandText;
  77. const calcEllipse = () => {
  78. const tail = (left, right) => {
  79. if (right - left <= 1) {
  80. if (position === "end") {
  81. return content.slice(0, left) + dots;
  82. }
  83. return dots + content.slice(right, end);
  84. }
  85. const middle2 = Math.round((left + right) / 2);
  86. if (position === "end") {
  87. container.innerText = content.slice(0, middle2) + dots;
  88. } else {
  89. container.innerText = dots + content.slice(middle2, end);
  90. }
  91. container.innerHTML += actionHTML;
  92. if (container.offsetHeight > maxHeight) {
  93. if (position === "end") {
  94. return tail(left, middle2);
  95. }
  96. return tail(middle2, right);
  97. }
  98. if (position === "end") {
  99. return tail(middle2, right);
  100. }
  101. return tail(left, middle2);
  102. };
  103. return tail(0, end);
  104. };
  105. const middleTail = (leftPart, rightPart) => {
  106. if (leftPart[1] - leftPart[0] <= 1 && rightPart[1] - rightPart[0] <= 1) {
  107. return content.slice(0, leftPart[0]) + dots + content.slice(rightPart[1], end);
  108. }
  109. const leftMiddle = Math.floor((leftPart[0] + leftPart[1]) / 2);
  110. const rightMiddle = Math.ceil((rightPart[0] + rightPart[1]) / 2);
  111. container.innerText = props.content.slice(0, leftMiddle) + props.dots + props.content.slice(rightMiddle, end);
  112. container.innerHTML += actionHTML;
  113. if (container.offsetHeight >= maxHeight) {
  114. return middleTail([leftPart[0], leftMiddle], [rightMiddle, rightPart[1]]);
  115. }
  116. return middleTail([leftMiddle, leftPart[1]], [rightPart[0], rightMiddle]);
  117. };
  118. return props.position === "middle" ? middleTail([0, middle], [middle, end]) : calcEllipse();
  119. };
  120. const calcEllipsised = () => {
  121. const container = cloneContainer();
  122. if (!container) {
  123. needRecalculate = true;
  124. return;
  125. }
  126. const {
  127. paddingBottom,
  128. paddingTop,
  129. lineHeight
  130. } = container.style;
  131. const maxHeight = Math.ceil((Number(props.rows) + 0.5) * pxToNum(lineHeight) + pxToNum(paddingTop) + pxToNum(paddingBottom));
  132. if (maxHeight < container.offsetHeight) {
  133. hasAction.value = true;
  134. text.value = calcEllipsisText(container, maxHeight);
  135. } else {
  136. hasAction.value = false;
  137. text.value = props.content;
  138. }
  139. document.body.removeChild(container);
  140. };
  141. const toggle = (isExpanded = !expanded.value) => {
  142. expanded.value = isExpanded;
  143. };
  144. const onClickAction = (event) => {
  145. toggle();
  146. emit("clickAction", event);
  147. };
  148. const renderAction = () => {
  149. const action = slots.action ? slots.action({
  150. expanded: expanded.value
  151. }) : actionText.value;
  152. return createVNode("span", {
  153. "ref": actionRef,
  154. "class": bem("action"),
  155. "onClick": onClickAction
  156. }, [action]);
  157. };
  158. onMounted(() => {
  159. calcEllipsised();
  160. if (slots.action) {
  161. nextTick(calcEllipsised);
  162. }
  163. });
  164. onActivated(() => {
  165. if (needRecalculate) {
  166. needRecalculate = false;
  167. calcEllipsised();
  168. }
  169. });
  170. watch([windowWidth, () => [props.content, props.rows, props.position]], calcEllipsised);
  171. useExpose({
  172. toggle
  173. });
  174. return () => createVNode("div", {
  175. "ref": root,
  176. "class": bem()
  177. }, [expanded.value ? props.content : text.value, hasAction.value ? renderAction() : null]);
  178. }
  179. });
  180. const TextEllipsis = withInstall(stdin_default);
  181. const index = "";
  182. const _hoisted_1 = { style: { "display": "flex", "flex-direction": "column", "height": "100vh" } };
  183. const _hoisted_2 = {
  184. class: "container",
  185. style: { "overflow-y": "auto", "flex-grow": "1" }
  186. };
  187. const _hoisted_3 = { style: { "text-align": "left" } };
  188. const _hoisted_4 = { style: { "display": "flex", "justify-content": "space-between", "margin-bottom": "5px" } };
  189. const _hoisted_5 = { style: { "font-size": "0.9rem", "color": "#000", "font-weight": "bold" } };
  190. const _hoisted_6 = { style: { "display": "flex", "align-items": "flex-end" } };
  191. const _hoisted_7 = { style: { "width": "100%", "word-wrap": "break-word", "text-align": "justify" } };
  192. const _hoisted_8 = { key: 0 };
  193. const _hoisted_9 = {
  194. key: 1,
  195. style: { "text-align": "center", "padding": "20px", "color": "#ccc" }
  196. };
  197. const _hoisted_10 = {
  198. key: 2,
  199. style: { "text-align": "center", "padding": "20px" }
  200. };
  201. const _hoisted_11 = {
  202. key: 3,
  203. style: { "text-align": "center", "padding": "20px", "color": "#ccc" }
  204. };
  205. const _hoisted_12 = {
  206. key: 4,
  207. style: { "text-align": "center", "padding": "20px" }
  208. };
  209. const _sfc_main = /* @__PURE__ */ defineComponent({
  210. __name: "Log",
  211. setup(__props) {
  212. const router = useRouter();
  213. const page = reactive({
  214. total: 0,
  215. pageNum: 1,
  216. pageSize: 10,
  217. pages: 0
  218. });
  219. const dataList = ref([]);
  220. const refreshing = ref(false);
  221. const isLoading = ref(false);
  222. const finished = ref(false);
  223. const getData = () => {
  224. console.log("onload.....");
  225. post_promise({ url: "/device/searchRecord", data: {
  226. size: page.pageSize,
  227. page: page.pageNum,
  228. sort: "createtime",
  229. order: "desc",
  230. keyWord: deviceId.value,
  231. mac: ""
  232. } }).then((result) => {
  233. console.log(result);
  234. isLoading.value = false;
  235. refreshing.value = false;
  236. if (result.code == 0) {
  237. const dataArr = result.data;
  238. const total = result.total;
  239. const pages = Math.ceil(total / page.pageSize);
  240. console.log(pages);
  241. console.log(dataArr);
  242. if (page.pageNum == 1) {
  243. dataList.value.splice(0, dataList.value.length);
  244. }
  245. dataList.value.push(...dataArr);
  246. page.pages = pages;
  247. page.total = total;
  248. console.log(dataList.value, pages);
  249. }
  250. }, (result) => {
  251. console.log(result);
  252. isLoading.value = false;
  253. refreshing.value = false;
  254. }).catch((ex) => {
  255. console.log(ex);
  256. isLoading.value = false;
  257. refreshing.value = false;
  258. });
  259. };
  260. const onRefresh = () => {
  261. console.log("onrefresh...");
  262. console.log(refreshing.value);
  263. page.pageNum = 1;
  264. finished.value = false;
  265. isLoading.value = true;
  266. getData();
  267. };
  268. const deviceId = ref("");
  269. watch(() => router.currentRoute.value.params, (newParams, oldParams) => {
  270. console.log("路由参数发生了变化", newParams, oldParams);
  271. if (newParams.deviceId) {
  272. deviceId.value = newParams.deviceId;
  273. getData();
  274. }
  275. });
  276. onMounted(() => {
  277. console.log("onMounted");
  278. deviceId.value = router.currentRoute.value.params.deviceId;
  279. getData();
  280. });
  281. const clickLoading = () => {
  282. console.log("clickLoading");
  283. page.pageNum++;
  284. isLoading.value = true;
  285. getData();
  286. };
  287. return (_ctx, _cache) => {
  288. const _component_CusNavigation = CusNavigation;
  289. const _component_van_text_ellipsis = TextEllipsis;
  290. const _component_van_cell = Cell;
  291. const _component_van_swipe_cell = SwipeCell;
  292. const _component_van_loading = Loading;
  293. const _component_van_pull_refresh = PullRefresh;
  294. const _component_van_back_top = BackTop;
  295. return openBlock(), createElementBlock("div", _hoisted_1, [
  296. createVNode(_component_CusNavigation, {
  297. gobackabled: "",
  298. title: "设备日志(" + deviceId.value + ")"
  299. }, null, 8, ["title"]),
  300. createBaseVNode("div", _hoisted_2, [
  301. createVNode(_component_van_pull_refresh, {
  302. style: { "min-height": "100%" },
  303. modelValue: refreshing.value,
  304. "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => refreshing.value = $event),
  305. onRefresh
  306. }, {
  307. default: withCtx(() => [
  308. (openBlock(true), createElementBlock(Fragment, null, renderList(dataList.value, (item) => {
  309. return openBlock(), createBlock(_component_van_swipe_cell, { style: { "background-color": "#fff", "margin-bottom": "10px" } }, {
  310. default: withCtx(() => [
  311. createVNode(_component_van_cell, { clickable: "" }, {
  312. default: withCtx(() => [
  313. createBaseVNode("div", _hoisted_3, [
  314. createBaseVNode("div", _hoisted_4, [
  315. createBaseVNode("div", _hoisted_5, toDisplayString(unref(timestampToTime)(item.time)), 1)
  316. ]),
  317. createBaseVNode("div", _hoisted_6, [
  318. createBaseVNode("div", _hoisted_7, [
  319. createVNode(_component_van_text_ellipsis, {
  320. rows: 5,
  321. content: JSON.stringify(item)
  322. }, null, 8, ["content"])
  323. ])
  324. ])
  325. ])
  326. ]),
  327. _: 2
  328. }, 1024)
  329. ]),
  330. _: 2
  331. }, 1024);
  332. }), 256)),
  333. createBaseVNode("div", null, [
  334. refreshing.value ? (openBlock(), createElementBlock("div", _hoisted_8)) : dataList.value.length == 0 ? (openBlock(), createElementBlock("div", _hoisted_9, _cache[1] || (_cache[1] = [
  335. createBaseVNode("span", null, "暂无数据", -1)
  336. ]))) : isLoading.value ? (openBlock(), createElementBlock("div", _hoisted_10, [
  337. createVNode(_component_van_loading, {
  338. type: "spinner",
  339. color: "#1989fa"
  340. })
  341. ])) : page.pages <= page.pageNum ? (openBlock(), createElementBlock("div", _hoisted_11, _cache[2] || (_cache[2] = [
  342. createBaseVNode("span", null, "没有更多了", -1)
  343. ]))) : (openBlock(), createElementBlock("div", _hoisted_12, [
  344. createBaseVNode("span", { onClick: clickLoading }, "点击加载")
  345. ]))
  346. ])
  347. ]),
  348. _: 1
  349. }, 8, ["modelValue"]),
  350. createVNode(_component_van_back_top, {
  351. target: ".container",
  352. right: "5vw",
  353. bottom: "80px"
  354. })
  355. ])
  356. ]);
  357. };
  358. }
  359. });
  360. export {
  361. _sfc_main as default
  362. };