report-wv-bak.html 25 KB

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