index.vue 17 KB

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