report-wv1.html 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. <!DOCTYPE html>
  2. <html lang="zh">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>Document</title>
  8. <link rel='stylesheet' href='../luckysheet/dist/plugins/plugins.css' />
  9. <link rel='stylesheet' href='../luckysheet/dist/plugins/css/pluginsCss.css' />
  10. <link rel='stylesheet' href='../luckysheet/dist/css/luckysheet.css' />
  11. <link rel='stylesheet' href='../luckysheet/dist/assets/iconfont/iconfont.css' />
  12. <link rel="stylesheet" href="../dist/css/layui.css">
  13. <style>
  14. .la-btn {
  15. position: absolute;
  16. left: 50%;
  17. bottom: 35px;
  18. transform: translate(-50%);
  19. padding: 0 2%;
  20. }
  21. .btn {
  22. width: 100%;
  23. }
  24. .layui-laypage-em {
  25. background-color: #1e9fff !important;
  26. }
  27. .model {
  28. width: 100%;
  29. height: 100%;
  30. background: rgba(0, 0, 0, 0.3);
  31. position: fixed;
  32. z-index: 9999;
  33. }
  34. .table-box {
  35. width: 300px;
  36. height: 300px;
  37. background: #ffffff;
  38. margin: auto;
  39. position: absolute;
  40. top: 0;
  41. left: 0;
  42. right: 0;
  43. bottom: 0;
  44. padding: 10px;
  45. overflow-y: auto;
  46. }
  47. .head {
  48. display: flex;
  49. justify-content: flex-end;
  50. font-size: 20px;
  51. font-weight: bold;
  52. color: #000000;
  53. }
  54. .cel {
  55. cursor: pointer;
  56. }
  57. #table {
  58. width: 100%;
  59. margin-top: 20px;
  60. font-size: 18px;
  61. }
  62. #table tr {
  63. width: 100%;
  64. height: 30px;
  65. }
  66. #table td {
  67. border-bottom: 1px solid #000000;
  68. border-top: 1px solid #000000;
  69. padding: 5px;
  70. }
  71. .layui-layer-title {
  72. text-align: center;
  73. font-size: 16px;
  74. padding: 0 81px;
  75. }
  76. .layui-layer {
  77. top: 70 !important;
  78. }
  79. </style>
  80. </head>
  81. <body>
  82. <div id="luckysheet" style="margin:0px;padding:0px;position:absolute;width:100%;height:90%;left: 0px;top: 0px;">
  83. </div>
  84. <table id="demo" lay-filter="test"></table>
  85. <!-- <div class="model" style="display: none;">
  86. <div class="table-box">
  87. <div class="head"> -->
  88. <!-- <div>运行记录</div> -->
  89. <!-- <div class="cel">×</div>
  90. </div>
  91. <table id="table">
  92. <tr>
  93. <th>
  94. 运行内容
  95. </th>
  96. </tr>
  97. </table>
  98. </div>
  99. </div> -->
  100. <div class="la-btn">
  101. <button id="recordBtn" type="button" class="layui-btn layui-btn-normal layui-btn-sm btn">运行记录</button>
  102. </div>
  103. <script src="../jquery.min.js"></script>
  104. <script src="../dist/layui.js"></script>
  105. <script src="../luckysheet/dist/luckysheet.umd.js"></script>
  106. <script src="../luckysheet/dist/plugins/js/plugin.js"></script>
  107. <script src="./echarts.js"></script>
  108. <script src="./cqcyCode.js"></script>
  109. <script src="./canvertChart.js"></script>
  110. <!-- uni 的 SDK -->
  111. <script src="./wvIP.js"></script>
  112. <script src="./plugins/axios.min.js"></script>
  113. <script type="text/javascript" src="../luckysheet/dist/plugins/js/uni-webview-js0.0.3_index.js"></script>
  114. <script src="./plugins/excelopput.js"></script>
  115. <script src="./plugins/exceljs.min.js"></script>
  116. <script>
  117. $(function() {
  118. document.addEventListener('UniAppJSBridgeReady', function() {
  119. uni.getEnv(function(res) {
  120. console.log('当前环境:' + JSON.stringify(res));
  121. window.sessionName = 'device_report_index'
  122. sessionStorage.removeItem(window.sessionName)
  123. const id = window.location.search.split('?id=')[1]
  124. const baseUrl = "http://192.168.0.40:8081"
  125. // const baseUrl = window.location.origin
  126. axios.defaults.baseURL = baseUrl
  127. var reportTableName
  128. axios.get('/reportTable/getReportTableById?id=' + id).then(res => {
  129. console.log(res, 'res');
  130. const data = res.data
  131. if (data.code === 200) {
  132. // 报表数据
  133. let tableData = JSON.parse(data.data.reportTableData)
  134. let option = tableData.option
  135. // 基础数据项值
  136. let baseItem = tableData.baseItem
  137. // 数据项
  138. let reportTableItemList = data.data.reportTableItemList
  139. let reportChartList = data.data.reportChartList
  140. // 报表类型
  141. let reportTableType = data.data.reportTableType
  142. //报表名
  143. reportTableName = data.data.reportTableName
  144. let luckysheetOption = {
  145. container: 'luckysheet', // 设定 DOM 容器的 id
  146. title: '报表模板', // 设定表格名称
  147. lang: 'zh', // 设定表格语言
  148. showinfobar: false, // 是否显示顶部信息栏
  149. showtoolbar: false, // 是否显示工具栏
  150. showtoolbarConfig: {
  151. paintFormat: true, //格式刷
  152. moreFormats: true, // 单元格格式
  153. font: true, // 字体
  154. fontSize: true, // 字号大小
  155. bold: true, // 粗体 (Ctrl+B)
  156. italic: true, // 斜体 (Ctrl+I)
  157. strikethrough: true, // 删除线 (Alt+Shift+5)
  158. underline: true, // 下划线 (Alt+Shift+6)
  159. textColor: true, // 文本颜色
  160. fillColor: true, // 单元格颜色
  161. border: true, // 边框
  162. mergeCell: true, // 合并单元格
  163. horizontalAlignMode: true, // 水平对齐方式
  164. verticalAlignMode: true, // 垂直对齐方式
  165. function: true, // 公式
  166. // image: true
  167. // chart: true
  168. },
  169. showsheetbar: false, // 是否显示底部 sheet 页按钮
  170. sheetFormulaBar: false, // 是否显示公式
  171. row: 120, // 是否显示底部 sheet 页按钮
  172. data: [{
  173. "name": "统计报表", //工作表名称
  174. }],
  175. cellRightClickConfig: { // 自定义配置单元格右击菜单
  176. copy: true, // 复制
  177. copyAs: false, // 复制为
  178. paste: true, // 粘贴
  179. insertRow: true, // 插入行
  180. insertColumn: true, // 插入列
  181. deleteRow: true, // 删除选中行
  182. deleteColumn: true, // 删除选中列
  183. deleteCell: false, // 删除单元格
  184. hideRow: false, // 隐藏选中行和显示选中行
  185. hideColumn: false, // 隐藏选中列和显示选中列
  186. rowHeight: true, // 行高
  187. columnWidth: true, // 列宽
  188. clear: false, // 清除内容
  189. matrix: false, // 矩阵操作选区
  190. sort: false, // 排序选区
  191. filter: false, // 筛选选区
  192. chart: true, // 图表生成
  193. image: false, // 插入图片
  194. link: false, // 插入链接
  195. data: false, // 数据验证
  196. cellFormat: false // 设置单元格格式
  197. },
  198. plugins: ['chart']
  199. }
  200. if (!option) {
  201. option = JSON.parse(JSON.stringify(luckysheetOption))
  202. }
  203. option.data = tableData.data
  204. // 设置工作表保护
  205. option.data[0].config.authority = {
  206. sheet: 1, // 如果为 1 或 true,则该工作表受到保护;如果为 0 或 false,则该工作表不受保护。
  207. hintText: '该工作表受到保护,无法操作', // 弹窗提示的文字
  208. }
  209. // 关闭右键菜单
  210. option.cellRightClickConfig.chart = false
  211. option.cellRightClickConfig.columnWidth = false
  212. option.cellRightClickConfig.rowHeight = false
  213. option.cellRightClickConfig.deleteColumn = false
  214. option.cellRightClickConfig.deleteRow = false
  215. option.cellRightClickConfig.insertColumn = false
  216. option.cellRightClickConfig.insertRow = false
  217. // 关闭工具栏
  218. option.showtoolbar = false
  219. option.enableAddRow = false
  220. option.showtoolbarConfig = {
  221. bold: false,
  222. border: false,
  223. fillColor: false,
  224. font: false,
  225. fontSize: false,
  226. function: false,
  227. horizontalAlignMode: false,
  228. italic: false,
  229. mergeCell: false,
  230. moreFormats: false,
  231. paintFormat: false,
  232. strikethrough: false,
  233. textColor: false,
  234. underline: false,
  235. verticalAlignMode: false
  236. }
  237. // 钩子函数
  238. option.hook = {
  239. workbookCreateAfter() {
  240. // 图表操作
  241. for (let i in reportChartList) {
  242. insertEChartInfo(reportChartList[i])
  243. }
  244. // 绘制基础数据项
  245. drawBaseInfo(baseItem)
  246. // 绘制数据值
  247. drawTableData(reportTableItemList,
  248. reportTableType, data.data)
  249. luckysheet.setRangeShow('BH1')
  250. convertChart(tableData)
  251. printExcel()
  252. }
  253. }
  254. luckysheet.create(option)
  255. } else {
  256. }
  257. })
  258. function printExcel() {
  259. let currentSelected = luckysheet.getRange()
  260. luckysheet.hideGridLines()
  261. // 如果当前选中区只是一个单元格,则认为选取无效。
  262. if (currentSelected[0] != null &&
  263. (currentSelected[0].row[1] - currentSelected[0].row[0] >= 1 ||
  264. currentSelected[0].column[1] - currentSelected[0].column[0] >= 1)) {
  265. // 生成base64图片
  266. //let imgSrc = luckysheet.getScreenshot();
  267. setTimeout(() => {
  268. luckysheet.getScreenshotNew((imgSrc) => {
  269. console.info('printImg', imgSrc)
  270. // top.document.write(`<img src='${imgSrc}'/>`)
  271. luckysheet.showGridLines();
  272. })
  273. }, 200)
  274. } else {
  275. // 获取打印区域的行列
  276. let RowColumn = getPrintSheetArea();
  277. // 因需要打印左边的边框,需重新设置第一列
  278. //RowColumn.column[0] = 0;
  279. // 进行选区操作
  280. luckysheet.setRangeShow(RowColumn);
  281. const cellData = handelCell(luckysheet.getAllSheets()[0].celldata)
  282. let {
  283. minR,
  284. maxR,
  285. minC,
  286. maxC
  287. } = cellData
  288. luckysheet.setRangeShow({
  289. row: [0, maxR],
  290. column: [0, maxC]
  291. });
  292. // let imgSrc = luckysheet.getScreenshot(); // 生成base64图片
  293. // console.log(imgSrc);
  294. setTimeout(() => {
  295. luckysheet.getScreenshotNew((imgSrc) => {
  296. console.info('printImg', imgSrc)
  297. let arr = [imgSrc]
  298. exportSheetExcel(luckysheet.getAllSheets()[0],
  299. arr, reportTableName)
  300. // top.document.write(`<img src='${imgSrc}'/>`)
  301. luckysheet.showGridLines();
  302. })
  303. }, 800)
  304. }
  305. }
  306. function handelCell(data) {
  307. let minR = data[0].r
  308. let maxR = data[data.length - 1].r
  309. let minC = data[0].c
  310. let cData = data.map(item => {
  311. return item.c
  312. })
  313. let maxC = cData.sort(function(a, b) {
  314. return b - a;
  315. })[0];
  316. return {
  317. minR,
  318. maxR,
  319. minC,
  320. maxC
  321. }
  322. }
  323. function getPrintSheetArea() {
  324. const sheetData = luckysheet.getSheetData();
  325. let objRowColumn = {
  326. row: [0, 0], //行
  327. column: [0, 0], //列
  328. };
  329. // * item是行、index是行索引、it是一行里的一格、itemIndex是这一格在这一行里的列索引
  330. sheetData.forEach((item, index) => {
  331. //行数
  332. item.forEach((it, itemIndex) => {
  333. if (it !== null && it.v) {
  334. // console.log(index, it)
  335. if (objRowColumn.row[1] < index) {
  336. objRowColumn.row[1] = index; //row第二位
  337. }
  338. if (objRowColumn.column[1] < itemIndex) {
  339. objRowColumn.column[1] =
  340. itemIndex; //column第二位
  341. }
  342. }
  343. });
  344. });
  345. return objRowColumn;
  346. }
  347. /** 绘制表格数据 */
  348. function drawTableData(tableItemList, type, tableInfo) {
  349. if (!tableItemList || tableItemList.length == 0) {
  350. updateLocalExcelContent()
  351. return
  352. }
  353. // 事件驱动报表
  354. if (type == 2 || type == 4) {
  355. tableItemList.forEach((tableItem, i) => {
  356. if (i == 0) {
  357. let valueTimeList = tableItem.valueTimeList ? tableItem
  358. .valueTimeList.split(',') : []
  359. valueTimeList = withDateFormatLength(valueTimeList)
  360. let xAxis = tableItem.xaxis
  361. let yAxis = tableItem.yaxis - 1
  362. if (valueTimeList.length == 0) {
  363. luckysheet.setCellValue(xAxis, yAxis, '')
  364. } else {
  365. valueTimeList.forEach((v, j) => {
  366. luckysheet.setCellValue(xAxis + j, yAxis,
  367. v)
  368. })
  369. }
  370. }
  371. let valueList = tableItem.valueList ? tableItem.valueList
  372. .split(',') : []
  373. let xAxis = tableItem.xaxis
  374. let yAxis = tableItem.yaxis
  375. if (valueList.length == 0) {
  376. luckysheet.setCellValue(xAxis, yAxis, '')
  377. } else {
  378. valueList.forEach((v, j) => {
  379. luckysheet.setCellValue(xAxis + j, yAxis,
  380. v)
  381. })
  382. }
  383. })
  384. updateLocalExcelContent()
  385. return
  386. }
  387. // 设备报表
  388. if (type == 5 || type == 6) {
  389. tableItemList.forEach((tableItem, i) => {
  390. let standby = tableItem.standby ? JSON.parse(tableItem
  391. .standby) : {}
  392. let dataIndex = standby.index != null ? standby.index : -1
  393. let valueList = tableItem.valueList ? tableItem.valueList
  394. .split(',') : []
  395. let xAxis = tableItem.xaxis
  396. let yAxis = tableItem.yaxis
  397. // 序号、时间处理
  398. if (tableItem.timeItemType == 0) { // 序号、开始时间
  399. let valueIndexList = tableItem.valueIndexList ? tableItem
  400. .valueIndexList.split(',') : []
  401. deviceReportUpdateData('${index}', valueIndexList, false)
  402. let valueTimeList = tableItem.valueTimeList ? tableItem
  403. .valueTimeList.split(',') : []
  404. valueTimeList = withDateFormatLength(valueTimeList)
  405. deviceReportUpdateData('${startTime}', valueTimeList,
  406. false)
  407. }
  408. if (tableItem.timeItemType == 1) { // 结束时间
  409. let valueTimeList = tableItem.valueTimeList ? tableItem
  410. .valueTimeList.split(',') : []
  411. valueTimeList = withDateFormatLength(valueTimeList)
  412. deviceReportUpdateData('${stopTime}', valueTimeList,
  413. tableInfo.isGenCountTime == 1)
  414. }
  415. if (valueList.length == 0) {
  416. luckysheet.setCellValue(xAxis, yAxis, '')
  417. } else {
  418. valueList.forEach((v, j) => {
  419. luckysheet.setCellValue(xAxis + j, yAxis, v)
  420. })
  421. }
  422. })
  423. updateLocalExcelContent()
  424. return
  425. }
  426. // 其余报表信息
  427. tableItemList.forEach((tableItem, i) => {
  428. // let standby = tableItem.standby ? JSON.parse(tableItem.standby) :
  429. // {}
  430. // let dataIndex = standby.index != null ? standby.index : -1
  431. let valueList = tableItem.valueList ? tableItem.valueList.split(
  432. ',') : []
  433. // let val = (dataIndex == -1 || (dataIndex + 1) > valueList
  434. // .length) ?
  435. // cqcyCode['invalidData'] : valueList[dataIndex]
  436. let xAxis = tableItem.xaxis
  437. let yAxis = tableItem.yaxis
  438. if (valueList.length == 0) {
  439. luckysheet.setCellValue(xAxis, yAxis, '')
  440. } else {
  441. valueList.forEach((v, j) => {
  442. luckysheet.setCellValue(xAxis + j, yAxis, v)
  443. })
  444. }
  445. })
  446. updateLocalExcelContent()
  447. }
  448. /** 设备报表时间特殊处理 */
  449. function deviceReportUpdateData(field, dataList, hasCalc) {
  450. let indexPos = sessionStorage.getItem(window.sessionName)
  451. if (indexPos) {
  452. let pos = indexPos.split(',')
  453. if (field == '${index}') {
  454. let yAxis = parseInt(pos[0])
  455. let xAxis = parseInt(pos[1])
  456. dataList.forEach((v, j) => {
  457. luckysheet.setCellValue(yAxis + j, xAxis, j + 1)
  458. })
  459. } else if (field == '${startTime}') {
  460. let yAxis = parseInt(pos[0])
  461. let xAxis = parseInt(pos[1]) + 1
  462. dataList.forEach((v, j) => {
  463. luckysheet.setCellValue(yAxis + j, xAxis, v)
  464. })
  465. } else if (field == '${stopTime}') {
  466. let yAxis = parseInt(pos[0])
  467. let xAxis = parseInt(pos[1]) + 2
  468. dataList.forEach((v, j) => {
  469. luckysheet.setCellValue(yAxis + j, xAxis, v)
  470. if (hasCalc) {
  471. let startDate = luckysheet.getCellValue(yAxis + j,
  472. xAxis - 1)
  473. let minutes = calculateMinutes(startDate, v)
  474. luckysheet.setCellValue(yAxis + j, xAxis + 1,
  475. minutes)
  476. }
  477. })
  478. }
  479. return
  480. }
  481. let option = luckysheet.getAllSheets()[0]
  482. option.celldata.map(item => {
  483. if (item.v.v) {
  484. item.v.v = String(item.v.v).trim()
  485. // 替换${xxx}内部数据
  486. if (item.v.v.match(/\${([^}]+)}/g)) {
  487. if (item.v.v.indexOf(field) > -1) {
  488. let yAxis = item.r
  489. let xAxis = item.c
  490. if (field == '${index}') {
  491. sessionStorage.setItem(window.sessionName,
  492. yAxis + ',' + xAxis)
  493. dataList.forEach((v, j) => {
  494. luckysheet.setCellValue(yAxis + j,
  495. xAxis, j + 1)
  496. })
  497. } else {
  498. dataList.forEach((v, j) => {
  499. luckysheet.setCellValue(yAxis + j,
  500. xAxis, v)
  501. if (hasCalc) {
  502. let startDate = luckysheet
  503. .getCellValue(yAxis + j,
  504. xAxis - 1)
  505. let minutes = calculateMinutes(
  506. startDate, v)
  507. luckysheet.setCellValue(yAxis +
  508. j, xAxis + 1, minutes)
  509. }
  510. })
  511. }
  512. }
  513. }
  514. }
  515. })
  516. }
  517. /** 删除不合理数据值 */
  518. function updateLocalExcelContent() {
  519. let option = luckysheet.getAllSheets()[0]
  520. option.celldata.map(item => {
  521. if (item.v.v) {
  522. item.v.v = String(item.v.v).trim()
  523. // 替换${xxx}内部数据
  524. if (item.v.v.match(/\${([^}]+)}/g)) {
  525. luckysheet.setCellValue(item.r, item.c, '')
  526. }
  527. }
  528. })
  529. }
  530. /** 计算分钟数 */
  531. function calculateMinutes(time1, time2) {
  532. // 将时间字符串转换为Date对象
  533. let date1 = new Date(time1);
  534. let date2 = new Date(time2);
  535. // 计算时间差(以毫秒为单位)
  536. let diffInMilliseconds = Math.abs(date2.getTime() - date1.getTime());
  537. // 将时间差转换为分钟
  538. let minutes = Math.floor(diffInMilliseconds / 1000 / 60);
  539. return minutes;
  540. }
  541. /** 绘制基础数据项布局信息 */
  542. function drawBaseInfo(baseData) {
  543. if (!baseData) return
  544. let option = luckysheet.getAllSheets()[0]
  545. option.celldata.map(item => {
  546. if (item.v.v) {
  547. item.v.v = String(item.v.v).trim()
  548. if (item.v.v.match(/\${([^}]+)}/g)) { // 替换${xxx}内部数据
  549. if (item.v.v.indexOf('${currDate}') > -1) {
  550. let val = item.v.v
  551. val = val.replace('${currDate}', baseData.currDate)
  552. luckysheet.setCellValue(item.r, item.c, val)
  553. }
  554. if (item.v.v.indexOf('${currDateTime}') > -1) {
  555. let val = item.v.v
  556. val = val.replace('${currDateTime}', baseData
  557. .currDateTime)
  558. luckysheet.setCellValue(item.r, item.c, val)
  559. }
  560. if (item.v.v.indexOf('${userName}') > -1) {
  561. let val = item.v.v
  562. val = val.replace('${userName}', baseData.userName)
  563. luckysheet.setCellValue(item.r, item.c, val)
  564. }
  565. if (item.v.v.indexOf('${winUserName}') > -1) {
  566. let val = item.v.v
  567. val = val.replace('${winUserName}', baseData
  568. .winUserName)
  569. luckysheet.setCellValue(item.r, item.c, val)
  570. }
  571. }
  572. }
  573. })
  574. }
  575. function withDateFormatLength(listDate) {
  576. if (!listDate || listDate.length == 0) {
  577. return []
  578. }
  579. let arr = []
  580. listDate.forEach((date) => {
  581. arr.push(date.substring(0, 19))
  582. })
  583. return arr
  584. }
  585. /** 向 Excel 插入图表 */
  586. function insertEChartInfo(chart) {
  587. let _self = this
  588. let info = JSON.parse(chart.standby)
  589. let reportChartItemList = chart.reportChartItemList
  590. let chartType = chart.chartType
  591. // 系列
  592. let series = info.option.series
  593. for (let i in series) {
  594. let temp = series[i]
  595. temp.data = []
  596. for (let j in reportChartItemList) {
  597. let _name = reportChartItemList[j].describe ?
  598. reportChartItemList[j].describe : reportChartItemList[j]
  599. .itemName
  600. if (chartType == 'pie') {
  601. info.option.legend = null
  602. info.option.tooltip = {
  603. trigger: 'item',
  604. formatter: '{b0}<br /> <b>{c0}</b>'
  605. }
  606. temp.name = _name
  607. let names = reportChartItemList[i].valueTimeList ?
  608. reportChartItemList[i].valueTimeList.split(',') : [];
  609. names = withDateFormatLength(names);
  610. let vals = reportChartItemList[i].valueList ?
  611. reportChartItemList[i].valueList.split(',') : [];
  612. names.forEach((name, j) => {
  613. temp.data.push({
  614. 'name': name,
  615. 'value': vals[j]
  616. })
  617. })
  618. } else {
  619. let _t = []
  620. let t = reportChartItemList[i].valueList ?
  621. reportChartItemList[i].valueList.split(',') : []
  622. t.forEach((temp) => {
  623. _t.push(parseFloat(temp))
  624. })
  625. temp.data = _t
  626. }
  627. }
  628. }
  629. if (chartType != 'pie') {
  630. // x 轴
  631. let xAxis = info.option.xAxis
  632. let legend = info.option.legend
  633. // xAxis.data = []
  634. legend.data = []
  635. let axisLabel = {};
  636. axisLabel.rotate = 20;
  637. xAxis.axisLabel = axisLabel
  638. let times = (reportChartItemList[0].valueTimeList) ? reportChartItemList[
  639. 0].valueTimeList.split(",") : []
  640. xAxis.data = (reportChartItemList && reportChartItemList.length > 0) ?
  641. withDateFormatLength(times) : []
  642. // xAxis.data = xAxis.data.slice(0, 7)
  643. for (let i in reportChartItemList) {
  644. let name = reportChartItemList[i].describe ? reportChartItemList[i]
  645. .describe : reportChartItemList[i].itemName
  646. // xAxis.data.push(name)
  647. legend.data.push(name)
  648. }
  649. }
  650. setTimeout(() => {
  651. const sheet = luckysheet.getLuckysheetfile()[0]
  652. let optionData = sheet.data
  653. try {
  654. let flag = false
  655. insertLuckysheetEChart({
  656. selector: '#luckysheet',
  657. info,
  658. sheet,
  659. optionData,
  660. echarts,
  661. luckysheet,
  662. $,
  663. _self,
  664. flag
  665. })
  666. } catch (e) {
  667. console.log(999, e == 'echarts is not defined')
  668. console.error(e)
  669. }
  670. }, 200)
  671. }
  672. $('#recordBtn').on('click', () => {
  673. $('.model').show()
  674. const token = window.localStorage.getItem('C_TOKEN')
  675. layui.use('table', function() {
  676. var table = layui.table;
  677. var layer = layui.layer;
  678. layer.open({
  679. type: 1,
  680. title: '运行记录',
  681. content: $('#demo'),
  682. offset: ['30px', '45px'],
  683. end: function() {
  684. $('#demo').hide();
  685. $('.layui-table-view').hide()
  686. },
  687. cancel: function(index, layero) {
  688. $('.layui-layer-content')
  689. .hide()
  690. }
  691. });
  692. var tableReload = table.render({
  693. elem: '#demo',
  694. width: 300,
  695. page: {
  696. elem: '#demo',
  697. layout: ['prev', 'page', 'next',
  698. 'count'
  699. ]
  700. },
  701. url: `${baseUrl}/reportTable/getAutoChReportTable`,
  702. headers: {
  703. token: token
  704. },
  705. where: {
  706. autoTableId: id
  707. },
  708. text: {
  709. none: '暂无数据' //默认:无数据。
  710. },
  711. cols: [
  712. [{
  713. field: 'reportTableName',
  714. title: null,
  715. width: 300
  716. }]
  717. ],
  718. parseData: function(res) {
  719. return {
  720. "code": 0,
  721. "msg": res.msg,
  722. "count": res.data.count,
  723. "data": res.data
  724. .reportTableList
  725. };
  726. }
  727. });
  728. //触发行单击事件
  729. table.on('row(test)', function(obj) {
  730. const id = obj.data.id
  731. const title = obj.data
  732. .reportTableName
  733. uni.navigateTo({
  734. url: `/pages/reportForm/report-detail/recordDetail?id=${id}&title=${title}`
  735. })
  736. });
  737. $('th').hide()
  738. });
  739. })
  740. });
  741. });
  742. })
  743. </script>
  744. </body>
  745. </html>