deviceLogs.js 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453
  1. "use strict";
  2. const common_vendor = require("../../../common/vendor.js");
  3. require("../../../stores/dict.js");
  4. require("../../../stores/user.js");
  5. require("../../../utils/storage.js");
  6. require("../../../utils/constant.js");
  7. require("../../../utils/auth.js");
  8. require("../../../utils/request.js");
  9. require("../../../config.js");
  10. require("../../../utils/errorCode.js");
  11. require("../../../utils/common.js");
  12. if (!Array) {
  13. const _easycom_u_navbar2 = common_vendor.resolveComponent("u-navbar");
  14. const _easycom_u_button2 = common_vendor.resolveComponent("u-button");
  15. const _easycom_u_icon2 = common_vendor.resolveComponent("u-icon");
  16. const _easycom_u_loadmore2 = common_vendor.resolveComponent("u-loadmore");
  17. const _easycom_u_empty2 = common_vendor.resolveComponent("u-empty");
  18. const _easycom_u__input2 = common_vendor.resolveComponent("u--input");
  19. const _easycom_u_popup2 = common_vendor.resolveComponent("u-popup");
  20. const _easycom_u_datetime_picker2 = common_vendor.resolveComponent("u-datetime-picker");
  21. (_easycom_u_navbar2 + _easycom_u_button2 + _easycom_u_icon2 + _easycom_u_loadmore2 + _easycom_u_empty2 + _easycom_u__input2 + _easycom_u_popup2 + _easycom_u_datetime_picker2)();
  22. }
  23. const _easycom_u_navbar = () => "../../../node-modules/uview-plus/components/u-navbar/u-navbar.js";
  24. const _easycom_u_button = () => "../../../node-modules/uview-plus/components/u-button/u-button.js";
  25. const _easycom_u_icon = () => "../../../node-modules/uview-plus/components/u-icon/u-icon.js";
  26. const _easycom_u_loadmore = () => "../../../node-modules/uview-plus/components/u-loadmore/u-loadmore.js";
  27. const _easycom_u_empty = () => "../../../node-modules/uview-plus/components/u-empty/u-empty.js";
  28. const _easycom_u__input = () => "../../../node-modules/uview-plus/components/u--input/u--input.js";
  29. const _easycom_u_popup = () => "../../../node-modules/uview-plus/components/u-popup/u-popup.js";
  30. const _easycom_u_datetime_picker = () => "../../../node-modules/uview-plus/components/u-datetime-picker/u-datetime-picker.js";
  31. if (!Math) {
  32. (_easycom_u_navbar + _easycom_u_button + _easycom_u_icon + _easycom_u_loadmore + _easycom_u_empty + _easycom_u__input + _easycom_u_popup + _easycom_u_datetime_picker)();
  33. }
  34. const _sfc_main = {
  35. __name: "deviceLogs",
  36. setup(__props) {
  37. const { proxy } = common_vendor.getCurrentInstance();
  38. const instance = common_vendor.getCurrentInstance();
  39. const {
  40. device_log_type,
  41. device_type,
  42. mqtt_cmd_templet_task
  43. } = proxy.$useDict("device_log_type", "device_type", "mqtt_cmd_templet_task");
  44. const dicts = common_vendor.reactive({
  45. device_type: [],
  46. device_log_type: [],
  47. mqtt_cmd_templet_task: []
  48. });
  49. const searchMenu = common_vendor.reactive({
  50. showPopMenu: false,
  51. selStatus: 0,
  52. style: {
  53. marginTop: "174rpx"
  54. },
  55. searchMenu_body_style: {
  56. height: "600rpx"
  57. },
  58. params: {
  59. deviceId: void 0,
  60. type: void 0,
  61. beginLogBeginTime: void 0,
  62. endLogBeginTime: void 0
  63. }
  64. });
  65. function openSearchMenu() {
  66. searchMenu.showPopMenu = true;
  67. getTreeData();
  68. }
  69. function resetSearchMenu() {
  70. searchMenu.params.deviceId = void 0;
  71. searchMenu.params.type = void 0;
  72. }
  73. function doSearch(o) {
  74. if (o == 0)
  75. resetSearchMenu();
  76. setTimeout(function() {
  77. searchMenu.showPopMenu = false;
  78. data.curPage = 1;
  79. getList();
  80. }, 500);
  81. }
  82. function formatDate(time) {
  83. return time.getFullYear() + "-" + (time.getMonth() + 1 < 10 ? "0" : "") + (time.getMonth() + 1) + "-" + (time.getDate() < 10 ? "0" : "") + time.getDate() + " " + (time.getHours() < 10 ? "0" : "") + time.getHours() + ":" + (time.getMinutes() < 10 ? "0" : "") + time.getMinutes() + ":" + (time.getSeconds() < 10 ? "0" : "") + time.getSeconds();
  84. }
  85. const picLogMenu = common_vendor.reactive({
  86. showPopMenu: false,
  87. showTimePicker: false,
  88. selTimeIdx: 0,
  89. selTime: Number(new Date()),
  90. style: {
  91. marginTop: "174rpx"
  92. },
  93. searchMenu_body_style: {
  94. height: "600rpx"
  95. },
  96. params: {
  97. deviceId: void 0,
  98. logType: void 0,
  99. startTime: void 0,
  100. endTime: void 0
  101. },
  102. reqUrls: {
  103. sendCommand: "/device/mqtt/senCommand"
  104. }
  105. });
  106. function showTimePicker(idx) {
  107. picLogMenu.selTimeIdx = idx;
  108. if (0 == idx) {
  109. picLogMenu.selTime = Number(new Date(picLogMenu.params.startTime));
  110. console.log("--------", picLogMenu.params.startTime, new Date(picLogMenu.params.startTime));
  111. } else {
  112. picLogMenu.selTime = Number(new Date(picLogMenu.params.endTime));
  113. }
  114. picLogMenu.showTimePicker = true;
  115. }
  116. function onSelectTime(o) {
  117. var time = new Date(o.value);
  118. if (0 == picLogMenu.selTimeIdx) {
  119. picLogMenu.params.startTime = formatDate(time);
  120. } else {
  121. picLogMenu.params.endTime = formatDate(time);
  122. }
  123. console.log("----------", o, picLogMenu.selTime.toLocaleString(), time);
  124. picLogMenu.showTimePicker = false;
  125. }
  126. function onCancelSelectTime() {
  127. picLogMenu.showTimePicker = false;
  128. }
  129. function formatter(type, value) {
  130. if (type === "year") {
  131. return `${value}年`;
  132. }
  133. if (type === "month") {
  134. return `${value}月`;
  135. }
  136. if (type === "day") {
  137. return `${value}日`;
  138. }
  139. if (type === "hour") {
  140. return `${value}时`;
  141. }
  142. if (type === "minute") {
  143. return `${value}分`;
  144. }
  145. return value;
  146. }
  147. function openPicLogMenu() {
  148. picLogMenu.showPopMenu = true;
  149. }
  150. function sendCommand() {
  151. if (!picLogMenu.params.deviceId || picLogMenu.params.deviceId.length == 0) {
  152. proxy.$modal.msg("请填写机器编号~");
  153. return;
  154. }
  155. if (!picLogMenu.params.logType || picLogMenu.params.logType.length == 0) {
  156. proxy.$modal.msg("请选择指令类型~");
  157. return;
  158. }
  159. var templet = void 0;
  160. console.log(dicts.mqtt_cmd_templet_task);
  161. templet = JSON.parse(proxy.$getDictByCode(dicts.mqtt_cmd_templet_task, "log").value);
  162. templet.data.logType = picLogMenu.params.logType;
  163. templet.data.startTime = picLogMenu.params.startTime;
  164. templet.data.endTime = picLogMenu.params.endTime;
  165. var params = [{
  166. deviceId: picLogMenu.params.deviceId,
  167. templet
  168. }];
  169. console.log("------------", JSON.stringify(params));
  170. proxy.$request({
  171. url: picLogMenu.reqUrls.sendCommand,
  172. data: params,
  173. method: "post"
  174. }).then((res) => {
  175. console.log("***", res);
  176. proxy.$modal.msg("指令已下发~");
  177. resolve(res);
  178. }).catch((err) => {
  179. console.log("***", err);
  180. });
  181. }
  182. const data = common_vendor.reactive({
  183. reqUrls: {
  184. list: "/device/device-log/page"
  185. },
  186. curPage: 1,
  187. loadmoreStatus: "nomore",
  188. params: {
  189. readState: 1,
  190. priority: 1,
  191. page: {
  192. current: 1,
  193. size: 10,
  194. orders: [
  195. {
  196. asc: false,
  197. column: "create_time"
  198. }
  199. ]
  200. }
  201. },
  202. fullHeight: 0,
  203. screenHeight: 1920,
  204. // screenWidht:1080,
  205. dataList: [],
  206. total: 0
  207. });
  208. common_vendor.onMounted(() => {
  209. dicts.device_log_type = [{ value: null, label: "全部" }].concat(device_log_type.value);
  210. dicts.mqtt_cmd_templet_task = [{ value: null, label: "全部" }].concat(mqtt_cmd_templet_task.value);
  211. data.screenHeight = common_vendor.index.getSystemInfoSync().windowHeight;
  212. searchMenu.searchMenu_body_style.height = data.screenHeight - 90 + "px";
  213. var time = new Date();
  214. picLogMenu.params.startTime = formatDate(time);
  215. time.setTime(time.getTime() + 30 * 60 * 1e3);
  216. picLogMenu.params.endTime = formatDate(time);
  217. proxy.$refs.datetimePicker.setFormatter(formatter);
  218. getList();
  219. const query = common_vendor.index.createSelectorQuery().in(instance);
  220. query.select(".scrollview").boundingClientRect((r) => {
  221. common_vendor.index.getSystemInfo({
  222. success(res) {
  223. const model = res.model;
  224. const modelInclude = [
  225. "iPhone X",
  226. "iPhone XR",
  227. "iPhone XS",
  228. "iPhone XS MAX",
  229. "iPhone 12/13 mini",
  230. "iPhone 12/13 (Pro)",
  231. "iPhone 12/13 Pro Max",
  232. "iPhone 14 Pro Max"
  233. ];
  234. let safeDistance = modelInclude.includes(model);
  235. console.log(res.windowHeight, r.top);
  236. let h = 0;
  237. if (safeDistance) {
  238. h = res.windowHeight - r.top;
  239. } else {
  240. h = res.windowHeight - r.top;
  241. }
  242. data.fullHeight += h + "px";
  243. }
  244. });
  245. }).exec();
  246. });
  247. function scrolltolower() {
  248. if (data.loadmoreStatus == "nomore")
  249. return;
  250. data.curPage++;
  251. getList();
  252. }
  253. function getList() {
  254. return new Promise((resolve2, reject) => {
  255. data.params.page.current = data.curPage;
  256. data.params.deviceId = searchMenu.params.deviceId;
  257. data.params.type = searchMenu.params.type;
  258. if (data.curPage == 1) {
  259. data.dataList = [];
  260. }
  261. proxy.$request({
  262. url: data.reqUrls.list,
  263. data: data.params,
  264. method: "post"
  265. }).then((res) => {
  266. console.log("***", res);
  267. if (res.records) {
  268. data.dataList = data.dataList.concat(res.records);
  269. }
  270. data.total = res.total;
  271. if (res.records.length < 10) {
  272. data.loadmoreStatus = "nomore";
  273. } else {
  274. data.loadmoreStatus = "loadmore";
  275. }
  276. resolve2(res);
  277. }).catch((err) => {
  278. reject(err);
  279. });
  280. });
  281. }
  282. function showLog(file) {
  283. proxy.$tab.navigateTo(`/pages/xy_system/logs/logFile?file=${file}`);
  284. }
  285. function rightClick() {
  286. console.log("点击了右侧");
  287. }
  288. return (_ctx, _cache) => {
  289. return common_vendor.e({
  290. a: common_vendor.o(rightClick),
  291. b: common_vendor.p({
  292. title: "设备日志",
  293. titleStyle: "color:#fff;fontSize:36rpx;",
  294. bgColor: "#2C6FF3",
  295. autoBack: true,
  296. leftIconColor: "#fff",
  297. placeholder: true
  298. }),
  299. c: common_vendor.t(data.total),
  300. d: common_vendor.o(openPicLogMenu),
  301. e: common_vendor.p({
  302. size: "mini"
  303. }),
  304. f: common_vendor.o(getList),
  305. g: common_vendor.p({
  306. size: "mini"
  307. }),
  308. h: common_vendor.p({
  309. name: "arrow-right",
  310. size: "14"
  311. }),
  312. i: common_vendor.o(openSearchMenu),
  313. j: data.dataList.length > 0
  314. }, data.dataList.length > 0 ? common_vendor.e({
  315. k: common_vendor.f(data.dataList, (item1, index1, i0) => {
  316. return common_vendor.e({
  317. a: item1.deviceName
  318. }, item1.deviceName ? {
  319. b: common_vendor.t(item1.deviceId),
  320. c: common_vendor.t(item1.deviceId)
  321. } : {
  322. d: common_vendor.t(item1.deviceId)
  323. }, {
  324. e: common_vendor.t(common_vendor.unref(proxy).$getDictByValue(dicts.device_log_type, item1.type).label),
  325. f: common_vendor.t(item1.logName),
  326. g: common_vendor.o(($event) => showLog(item1.logName), item1.deviceId),
  327. h: common_vendor.t(item1.logBeginTime),
  328. i: common_vendor.t(item1.logEndTime),
  329. j: item1.deviceId
  330. });
  331. }),
  332. l: data.dataList.length > 0
  333. }, data.dataList.length > 0 ? {
  334. m: common_vendor.p({
  335. status: data.loadmoreStatus
  336. })
  337. } : {}) : {
  338. n: common_vendor.p({
  339. mode: "data",
  340. text: "数据为空"
  341. })
  342. }, {
  343. o: common_vendor.o(scrolltolower),
  344. p: data.fullHeight,
  345. q: common_vendor.o(($event) => searchMenu.params.deviceId = $event),
  346. r: common_vendor.p({
  347. placeholder: "请输入设备编号",
  348. border: "surround",
  349. modelValue: searchMenu.params.deviceId
  350. }),
  351. s: common_vendor.f(dicts.device_log_type, (item, index, i0) => {
  352. return {
  353. a: common_vendor.t(item.label),
  354. b: common_vendor.n(searchMenu.params.type == item.value ? "tab-item tab-show" : "tab-item"),
  355. c: common_vendor.o(($event) => searchMenu.params.type = item.value, item.value),
  356. d: item.value
  357. };
  358. }),
  359. t: common_vendor.o(($event) => doSearch(0)),
  360. v: common_vendor.p({
  361. size: "normal",
  362. plain: true,
  363. text: "关闭"
  364. }),
  365. w: common_vendor.o(resetSearchMenu),
  366. x: common_vendor.p({
  367. size: "normal",
  368. type: "primary",
  369. plain: true,
  370. text: "重置"
  371. }),
  372. y: common_vendor.o(($event) => doSearch(1)),
  373. z: common_vendor.p({
  374. size: "normal",
  375. type: "primary",
  376. text: "查找"
  377. }),
  378. A: common_vendor.s(searchMenu.searchMenu_body_style),
  379. B: common_vendor.p({
  380. show: searchMenu.showPopMenu,
  381. duration: "0",
  382. customStyle: searchMenu.style,
  383. round: 10,
  384. mode: "right",
  385. duration: 300,
  386. overlay: false
  387. }),
  388. C: common_vendor.o(($event) => picLogMenu.params.deviceId = $event),
  389. D: common_vendor.p({
  390. placeholder: "请输入设备编号",
  391. border: "surround",
  392. modelValue: picLogMenu.params.deviceId
  393. }),
  394. E: common_vendor.f(dicts.device_log_type, (item, index, i0) => {
  395. return {
  396. a: common_vendor.t(item.label),
  397. b: item.label != "全部",
  398. c: common_vendor.n(picLogMenu.params.logType == item.value ? "tab-item tab-show" : "tab-item"),
  399. d: common_vendor.o(($event) => picLogMenu.params.logType = item.value, item.value),
  400. e: item.value
  401. };
  402. }),
  403. F: common_vendor.o(($event) => picLogMenu.params.startTime = $event),
  404. G: common_vendor.p({
  405. placeholder: "",
  406. border: "surround",
  407. modelValue: picLogMenu.params.startTime
  408. }),
  409. H: common_vendor.o(($event) => showTimePicker(0)),
  410. I: common_vendor.o(($event) => picLogMenu.params.endTime = $event),
  411. J: common_vendor.p({
  412. placeholder: "",
  413. border: "surround",
  414. modelValue: picLogMenu.params.endTime
  415. }),
  416. K: common_vendor.o(($event) => showTimePicker(1)),
  417. L: common_vendor.sr("datetimePicker", "b96d7042-17,b96d7042-11"),
  418. M: common_vendor.o(onSelectTime),
  419. N: common_vendor.o(onCancelSelectTime),
  420. O: common_vendor.o(($event) => picLogMenu.selTime = $event),
  421. P: common_vendor.p({
  422. show: picLogMenu.showTimePicker,
  423. mode: "datetime",
  424. modelValue: picLogMenu.selTime
  425. }),
  426. Q: common_vendor.o(($event) => picLogMenu.showPopMenu = false),
  427. R: common_vendor.p({
  428. size: "normal",
  429. plain: true,
  430. text: "关闭"
  431. }),
  432. S: common_vendor.o(($event) => sendCommand()),
  433. T: common_vendor.p({
  434. size: "normal",
  435. type: "primary",
  436. text: "捞日志"
  437. }),
  438. U: common_vendor.s(searchMenu.searchMenu_body_style),
  439. V: common_vendor.p({
  440. show: picLogMenu.showPopMenu,
  441. duration: "0",
  442. customStyle: picLogMenu.style,
  443. round: 10,
  444. mode: "right",
  445. duration: 300,
  446. overlay: false
  447. })
  448. });
  449. };
  450. }
  451. };
  452. const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-b96d7042"], ["__file", "F:/兴元/开门柜项目/平台端管理系统小程序/src/pages/xy_system/logs/deviceLogs.vue"]]);
  453. wx.createPage(MiniProgramPage);