index.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693
  1. <!--
  2. * @Author: lide1202@hotmail.com
  3. * @Date: 2021-3-13 11:04:24
  4. * @Last Modified by: lide1202@hotmail.com
  5. * @Last Modified time: 2021-3-13 11:04:24
  6. !-->
  7. <template>
  8. <div class="layout">
  9. <div class="layout-left">
  10. <div class="add-collection">
  11. 数据集管理
  12. <el-button
  13. type="text"
  14. icon="el-icon-circle-plus-outline"
  15. @click="queryAllDataSet()"
  16. />
  17. </div>
  18. <div>
  19. <el-collapse
  20. v-for="(item, indexs) in dataSet"
  21. :key="indexs"
  22. v-model="activeNames"
  23. @change="handleChange"
  24. >
  25. <el-collapse-item :title="item.setName" :name="item.id">
  26. <el-popconfirm
  27. :title="'确定删除' + item.setName + '吗?'"
  28. @confirm="del(item)"
  29. >
  30. <el-button
  31. slot="reference"
  32. type="text"
  33. icon="el-icon-close"
  34. class="delect-all"
  35. />
  36. </el-popconfirm>
  37. <draggable
  38. v-model="item.setParamList"
  39. :sort="false"
  40. group="people"
  41. style="margin-left: 10px"
  42. @start="onStart(item.setCode, $event)"
  43. >
  44. <!-- <transition-group> -->
  45. <div
  46. v-for="(i, index) in item.setParamList"
  47. :key="index"
  48. class="field-container"
  49. >
  50. <div class="aRow">
  51. <span>{{ i }}</span>
  52. </div>
  53. </div>
  54. <!-- </transition-group> -->
  55. </draggable>
  56. </el-collapse-item>
  57. </el-collapse>
  58. </div>
  59. </div>
  60. <div class="layout-middle">
  61. <div class="push_btn">
  62. <el-tooltip class="item" effect="dark" content="预览" placement="bottom-start">
  63. <el-button type="text" @click="preview()">
  64. <i class="iconfont iconfuzhi"></i>
  65. </el-button>
  66. </el-tooltip>
  67. <el-tooltip class="item" effect="dark" content="保存" placement="bottom-start">
  68. <el-button type="text" @click="save()">
  69. <i class="iconfont iconsave"></i>
  70. </el-button>
  71. </el-tooltip>
  72. <el-tooltip
  73. class="item"
  74. effect="dark"
  75. content="导入xlsx"
  76. placement="bottom-start"
  77. >
  78. <input style="font-size: 16px" type="file" @change="uploadExcel" />
  79. </el-tooltip>
  80. </div>
  81. <div
  82. id="luckysheet"
  83. style="
  84. margin: 0px;
  85. padding: 0px;
  86. position: absolute;
  87. width: 100%;
  88. height: 95vh;
  89. left: 0px;
  90. top: 45px;
  91. bottom: 0px;
  92. "
  93. />
  94. <div id="qrCode" ref="qrCodeDiv" />
  95. <img id="barCode" />
  96. </div>
  97. <div class="layout-right">
  98. <el-tabs v-model="activeName" @tab-click="handleClick">
  99. <el-tab-pane label="基础配置" name="first">
  100. <el-form ref="rightForm" :model="rightForm" label-width="70px">
  101. <el-form-item label="坐标">
  102. <el-input v-model="rightForm.coordinate" />
  103. </el-form-item>
  104. <el-form-item label="值">
  105. <el-input v-model="rightForm.value" />
  106. </el-form-item>
  107. <el-form-item label="自动扩展" v-if="rightForm.autoIsShow">
  108. <el-col :span="12">
  109. <el-switch v-model="rightForm.auto" @change="autoChangeFunc($event)" />
  110. </el-col>
  111. <el-col :span="12">
  112. <el-tooltip
  113. class="item"
  114. effect="dark"
  115. content="只针对静态数据的单元格,具体参考文档"
  116. placement="top"
  117. >
  118. <i class="el-icon-question"> </i>
  119. </el-tooltip>
  120. </el-col>
  121. </el-form-item>
  122. </el-form>
  123. </el-tab-pane>
  124. </el-tabs>
  125. </div>
  126. <el-dialog title="数据集管理" :visible.sync="outerVisible">
  127. <el-table
  128. ref="multipleTable"
  129. :data="dataSetData"
  130. tooltip-effect="dark"
  131. style="width: 100%; height: 60vh; overflow-y: scroll"
  132. @selection-change="handleSelectionChange"
  133. >
  134. <el-table-column type="selection" width="55" />
  135. <el-table-column label="数据集名称" width="120" prop="setName" />
  136. <el-table-column prop="setDesc" label="数据集描述" width="180" />
  137. <el-table-column prop="setCode" label="数据集编码" show-overflow-tooltip />
  138. </el-table>
  139. <div slot="footer" class="dialog-footer">
  140. <el-button @click="outerVisible = false">取 消</el-button>
  141. <el-button type="primary" @click="checkDataSet()">确定 </el-button>
  142. </div>
  143. </el-dialog>
  144. </div>
  145. </template>
  146. <script>
  147. import draggable from "vuedraggable";
  148. import { queryAllDataSet, detail, detailByReportCode } from "@/api/GaeaReport";
  149. import { addReportExcel, editReportExcel } from "@/api/report";
  150. import ColorPicker from "../components/colorPicker.vue";
  151. // import QRCode from 'qrcodejs2'
  152. // import JsBarcode from 'jsbarcode'
  153. export default {
  154. name: "Excels",
  155. components: {
  156. draggable,
  157. ColorPicker,
  158. },
  159. data() {
  160. return {
  161. luckysheet,
  162. activeName: "first",
  163. activeNames: ["1"],
  164. reportId: null,
  165. accessKey: null,
  166. reportCode: "",
  167. options: [],
  168. sheet: {},
  169. sheetData: [],
  170. dataSetData: [],
  171. reportExcelDto: {
  172. id: null,
  173. jsonStr: "",
  174. setCodes: "",
  175. setParam: "",
  176. reportCode: "",
  177. },
  178. multipleSelection: [],
  179. rightForm: {
  180. coordinate: "",
  181. value: "",
  182. r: "",
  183. c: "",
  184. auto: false,
  185. autoIsShow: false,
  186. },
  187. qrCodeForm: {
  188. type: "QRCode",
  189. content: "https://www.baidu.com",
  190. width: 125,
  191. height: 125,
  192. colorDark: "#333333", // 二维码颜色
  193. colorLight: "#ffffff", // 二维码背景色
  194. // correctLevel: QRCode.CorrectLevel.L, // 容错率,L/M/H
  195. ri: 0,
  196. ci: 0,
  197. currentSrc: "",
  198. },
  199. barCodeForm: {
  200. type: "BarCode",
  201. format: "CODE39",
  202. displayValue: true,
  203. content: "99999999999",
  204. lineColor: "#000",
  205. background: "#fff",
  206. width: 100,
  207. height: 40,
  208. ri: 0,
  209. ci: 0,
  210. currentSrc: "",
  211. },
  212. formPrintSetting: {
  213. size: "",
  214. pixel1: "",
  215. pixel2: "",
  216. },
  217. pixelList: [
  218. { paper: "A4", width: 210, height: 297 },
  219. { paper: "A3", width: 297, height: 420 },
  220. { paper: "Letter", width: 216, height: 279 },
  221. { paper: "Legal", width: 216, height: 355 },
  222. { paper: "Executive", width: 184, height: 266 },
  223. ],
  224. dataSet: [],
  225. outerVisible: false,
  226. printVisible: false,
  227. pop: false,
  228. setCode: null,
  229. draggableFieldLabel: null,
  230. dialogVisible: false,
  231. dialogBarCode: false,
  232. paperList: [],
  233. // 纸张标识
  234. paper: "",
  235. // 纸张宽高
  236. width: "",
  237. height: "",
  238. // 清晰度
  239. definition: "",
  240. // 是否套打
  241. isBackend: "",
  242. dpi: "",
  243. pxWidth: "",
  244. pxHeight: "",
  245. show: false,
  246. config: "",
  247. settings: {},
  248. qrCodeList: [],
  249. moveDataelse: {
  250. x: null,
  251. y: null,
  252. },
  253. };
  254. },
  255. mounted() {},
  256. created() {
  257. this.reportCode = this.$route.query.reportCode;
  258. this.accessKey = this.$route.query.accessKey;
  259. this.loadDataSet();
  260. this.design();
  261. },
  262. methods: {
  263. uploadExcel(evt) {
  264. const files = evt.target.files;
  265. if (files == null || files.length == 0) {
  266. this.$message.error("没有文件被上传");
  267. return;
  268. }
  269. let name = files[0].name;
  270. let suffixArr = name.split("."),
  271. suffix = suffixArr[suffixArr.length - 1];
  272. if (suffix != "xlsx") {
  273. this.$message.error("现在只支持上传xlsx文件");
  274. return;
  275. }
  276. let that=this;
  277. LuckyExcel.transformExcelToLucky(
  278. files[0],
  279. function (exportJson, luckysheetfile) {
  280. if (exportJson.sheets == null || exportJson.sheets.length == 0) {
  281. that.$message.error("Failed to read the content of the excel file, currently does not support xls files!");
  282. return;
  283. }
  284. that.luckysheet.destroy();
  285. // that.luckysheet.refresh({
  286. // container: "luckysheet",
  287. // showinfobar: false,
  288. // data: exportJson.sheets,
  289. // title: exportJson.info.name,
  290. // userInfo: exportJson.info.name.creator,
  291. // });
  292. that.createSheet(exportJson)
  293. },
  294. function (error) {
  295. // 如果抛出任何错误,则处理错误
  296. that.$message.error(error);
  297. }
  298. );
  299. },
  300. handleClose() {
  301. this.printVisible = false;
  302. },
  303. handleChange(val) {},
  304. // 右侧信息配置tabs
  305. handleClick(tab, event) {},
  306. async design() {
  307. // 根据reportCode获取单条报表
  308. const { code, data } = await detailByReportCode(this.reportCode);
  309. if (data != null) {
  310. this.reportId = data.id;
  311. }
  312. this.sheetData = data == null ? [{}] : JSON.parse(data.jsonStr);
  313. console.log(this.sheetData);
  314. this.createSheet();
  315. if (data != null) {
  316. if (data.setCodes != null && data.setCodes !== "") {
  317. let dataSetList = data.setCodes.split("|");
  318. dataSetList.forEach((code) => {
  319. this.dataSetData.forEach((setData) => {
  320. if (code === setData.setCode) {
  321. this.detail(setData.id);
  322. }
  323. });
  324. });
  325. }
  326. }
  327. },
  328. //初始化表格
  329. createSheet(exportJson) {
  330. //将vue对象传入
  331. const that = this;
  332. const options = {
  333. container: "luckysheet", // 设定DOM容器的id
  334. title: "", // 设定表格名称
  335. lang: "zh", // 设定表格语言
  336. plugins: ["chart"],
  337. hook: {
  338. cellDragStop: function (cell, postion, sheetFile, ctx, event) {
  339. // console.info("cellDragStop-cell",cell);
  340. // console.info("cellDragStop-postion", postion);
  341. // console.info("cellDragStop-sheetFile", sheetFile);
  342. // console.info("cellDragStop-ctx",ctx);
  343. // console.info("cellDragStop-event", event);
  344. // console.log("cellDragStop-draggableFieldLabel", that);
  345. that.luckysheet.setCellValue(postion.r, postion.c, that.draggableFieldLabel);
  346. },
  347. cellMousedown: function (cell, postion, sheetFile, ctx) {
  348. //单元格点击事件
  349. that.rightForm.coordinate = postion.r + "," + postion.c;
  350. that.rightForm.r = postion.r;
  351. that.rightForm.c = postion.c;
  352. that.rightForm.value = cell == null ? "" : cell.v;
  353. that.rightForm.autoIsShow = true;
  354. //判断单元格是否是静态数据并且是合并单元格
  355. if (cell != null && (cell.v == undefined || cell.v.indexOf("#{") === -1)) {
  356. that.rightForm.autoIsShow = true;
  357. if (cell.auto != null && cell.auto == "1") {
  358. that.rightForm.auto = true;
  359. } else {
  360. that.rightForm.auto = false;
  361. }
  362. } else {
  363. that.rightForm.auto = false;
  364. }
  365. },
  366. },
  367. data: [
  368. {
  369. name: "report", //工作表名称
  370. color: "", //工作表颜色
  371. index: 0, //工作表索引
  372. status: 1, //激活状态
  373. order: 0, //工作表的下标
  374. hide: 0, //是否隐藏
  375. row: 36, //行数
  376. column: 18, //列数
  377. defaultRowHeight: 19, //自定义行高
  378. defaultColWidth: 73, //自定义列宽
  379. celldata: [], //初始化使用的单元格数据
  380. config: {
  381. merge: {}, //合并单元格
  382. rowlen: {}, //表格行高
  383. columnlen: {}, //表格列宽
  384. rowhidden: {}, //隐藏行
  385. colhidden: {}, //隐藏列
  386. borderInfo: {}, //边框
  387. authority: {}, //工作表保护
  388. },
  389. scrollLeft: 0, //左右滚动条位置
  390. scrollTop: 315, //上下滚动条位置
  391. luckysheet_select_save: [], //选中的区域
  392. calcChain: [], //公式链
  393. isPivotTable: false, //是否数据透视表
  394. pivotTable: {}, //数据透视表设置
  395. filter_select: {}, //筛选范围
  396. filter: null, //筛选配置
  397. luckysheet_alternateformat_save: [], //交替颜色
  398. luckysheet_alternateformat_save_modelCustom: [], //自定义交替颜色
  399. luckysheet_conditionformat_save: {}, //条件格式
  400. frozen: {}, //冻结行列配置
  401. chart: [], //图表配置
  402. zoomRatio: 1, // 缩放比例
  403. image: [], //图片
  404. showGridLines: 1, //是否显示网格线
  405. dataVerification: {}, //数据验证配置
  406. },
  407. ],
  408. };
  409. this.sheetData = this.sheetData.map((val) => {
  410. if (!val.name) {
  411. val.name = "Sheet1";
  412. }
  413. return val;
  414. });
  415. options.data = this.sheetData;
  416. $(function () {
  417. if(exportJson){
  418. options.data= exportJson.sheets;
  419. options.title= exportJson.info.name;
  420. options.userInfo= exportJson.info.name.creator;
  421. }
  422. console.log(options);
  423. that.luckysheet.create(options);
  424. });
  425. },
  426. onStart(setCode, evt) {
  427. this.setCode = setCode;
  428. let fieldLabel = evt.item.innerText; // 列名称
  429. this.draggableFieldLabel = "#{" + this.setCode + "." + fieldLabel + "}";
  430. console.log("evt", evt);
  431. console.log("draggableFieldLabel", this.draggableFieldLabel);
  432. },
  433. async loadDataSet() {
  434. const { code, data } = await queryAllDataSet();
  435. this.dataSetData = data;
  436. if (code != "200") return;
  437. },
  438. doCancel() {
  439. this.pop = false;
  440. },
  441. async save() {
  442. // console.log(luckysheet.toJson())
  443. // console.log(luckysheet.getAllSheets())
  444. // console.log(luckysheet.getSheetData(0))
  445. const jsonData = luckysheet.getAllSheets();
  446. for (let i = 0; i < jsonData.length; i++) {
  447. //清空data数据,以celldata数据为主
  448. jsonData[i]["data"] = [];
  449. }
  450. this.reportExcelDto.jsonStr = JSON.stringify(luckysheet.getAllSheets());
  451. let setCodeList = [];
  452. let setParams = {};
  453. this.dataSet.forEach((code) => {
  454. setCodeList.push(code.setCode);
  455. if (code.dataSetParamDtoList != null && code.dataSetParamDtoList.length > 0) {
  456. let dataSetParam = {};
  457. code.dataSetParamDtoList.forEach((value) => {
  458. dataSetParam[value.paramName] = value.sampleItem;
  459. });
  460. setParams[code.setCode] = dataSetParam;
  461. }
  462. });
  463. this.reportExcelDto.setParam = JSON.stringify(setParams);
  464. this.reportExcelDto.setCodes = setCodeList.join("|");
  465. this.reportExcelDto.reportCode = this.reportCode;
  466. if (this.reportId == null) {
  467. const { code } = await addReportExcel(this.reportExcelDto);
  468. if (code != "200") return;
  469. this.$message.success("保存成功");
  470. } else {
  471. this.reportExcelDto.id = this.reportId;
  472. const { code } = await editReportExcel(this.reportExcelDto);
  473. if (code != "200") return;
  474. this.$message.success("更新成功");
  475. }
  476. },
  477. async detailByReportCode(reportCode) {
  478. const { code, data } = await detailByReportCode(reportCode);
  479. if (data != null) {
  480. this.reportId = data.id;
  481. }
  482. },
  483. async preview() {
  484. let routeUrl = this.$router.resolve({
  485. path: "/excelreport/viewer",
  486. query: { reportCode: this.reportCode },
  487. });
  488. window.open(routeUrl.href, "_blank");
  489. },
  490. async queryAllDataSet() {
  491. this.outerVisible = true;
  492. },
  493. handleSelectionChange(val) {
  494. this.multipleSelection = val;
  495. },
  496. checkDataSet() {
  497. this.outerVisible = false;
  498. if (this.multipleSelection.length > 1) {
  499. this.$message({
  500. message: "一次最多勾选一个数据集",
  501. type: "warning",
  502. });
  503. this.outerVisible = true;
  504. } else {
  505. this.detail(this.multipleSelection[0].id);
  506. }
  507. },
  508. async detail(id) {
  509. const { code, data } = await detail(id);
  510. if (code != 200) return;
  511. let flag = true;
  512. this.dataSet.forEach((value) => {
  513. if (value.setCode === data.setCode) {
  514. flag = false;
  515. }
  516. });
  517. if (flag) {
  518. this.dataSet.push(data);
  519. }
  520. },
  521. del(val) {
  522. for (let i = 0; i < this.dataSet.length; i++) {
  523. if (this.dataSet[i].setCode === val.setCode) {
  524. this.dataSet.splice(i, 1);
  525. }
  526. }
  527. },
  528. autoChangeFunc(auto) {
  529. if (auto) {
  530. luckysheet.setCellValue(this.rightForm.r, this.rightForm.c, { auto: "1" });
  531. } else {
  532. luckysheet.setCellValue(this.rightForm.r, this.rightForm.c, { auto: "0" });
  533. }
  534. },
  535. },
  536. };
  537. </script>
  538. <style src="../../../../static/luckysheet/assets/iconfont/iconfont.css" />
  539. <style scoped lang="scss">
  540. .position {
  541. position: absolute;
  542. z-index: 100;
  543. }
  544. #qrCode,
  545. #barCode {
  546. display: none;
  547. }
  548. .yulancopy {
  549. font-size: 16px;
  550. }
  551. .baocun {
  552. font-size: 17px;
  553. }
  554. .el-collapse {
  555. position: relative;
  556. border-top: 0 solid #e6ebf5;
  557. border-bottom: 0 solid #e6ebf5;
  558. }
  559. .el-collapse-item__header {
  560. border-bottom: 0 solid #e6ebf5 !important;
  561. }
  562. .delect-all {
  563. position: absolute;
  564. top: 10px;
  565. right: 30px;
  566. color: #333;
  567. }
  568. .push_btn {
  569. position: absolute;
  570. z-index: 100;
  571. top: 5px;
  572. left: 3px;
  573. .iconfont {
  574. color: black;
  575. }
  576. }
  577. .add-collection {
  578. line-height: 30px;
  579. .el-button {
  580. font-size: 16px !important;
  581. vertical-align: middle;
  582. margin-left: 20px;
  583. }
  584. }
  585. .layout {
  586. display: block;
  587. position: relative;
  588. margin: 0;
  589. padding: 0;
  590. border: 1px solid #d7dde4;
  591. }
  592. .layout-left {
  593. display: block;
  594. position: absolute;
  595. padding: 20px;
  596. width: 230px;
  597. min-height: 99.98vh;
  598. border-right: 1px solid #eee;
  599. border-color: #e8eaec;
  600. background: #fff;
  601. border-radius: 4px;
  602. font-size: 14px;
  603. -webkit-transition: all 0.2s ease-in-out;
  604. transition: all 0.2s ease-in-out;
  605. top: 0;
  606. left: 0;
  607. .field-container {
  608. display: block;
  609. position: relative;
  610. width: 100%;
  611. margin: 0;
  612. cursor: pointer;
  613. line-height: 30px;
  614. .aRow {
  615. padding: 0 10px;
  616. .operation {
  617. float: right;
  618. display: none;
  619. .el-button--text {
  620. color: #333 !important;
  621. }
  622. }
  623. &:hover {
  624. .operation {
  625. display: block;
  626. }
  627. background: #f7fafd;
  628. }
  629. }
  630. }
  631. }
  632. .layout-middle {
  633. display: block;
  634. position: absolute;
  635. left: 230px;
  636. right: 230px;
  637. width: calc(100% - 460px);
  638. margin: 0;
  639. padding: 0;
  640. .excel-designer {
  641. display: block;
  642. position: relative;
  643. margin: 0;
  644. padding: 0;
  645. }
  646. }
  647. .layout-right {
  648. display: block;
  649. position: absolute;
  650. top: 0;
  651. right: 0;
  652. padding: 20px;
  653. width: 230px;
  654. min-height: 99.98vh;
  655. border-left: 1px solid #dcdee2;
  656. border-color: #e8eaec;
  657. background: #fff;
  658. border-radius: 4px;
  659. font-size: 14px;
  660. -webkit-transition: all 0.2s ease-in-out;
  661. transition: all 0.2s ease-in-out;
  662. }
  663. </style>