index.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <!--
  2. * @Descripttion:
  3. * @Author: qianlishi
  4. * @Date: 2021-3-19 10:23:24
  5. * @Last Modified by: Raod
  6. * @Last Modified time: 2022-1-26 11:04:24
  7. !-->
  8. <template>
  9. <div class="layout">
  10. <div class="layout-right">
  11. <div class="block">
  12. <div class="download">
  13. <a v-if="reportCode != null" download="xxx.xlsx">
  14. <el-button type="text" @click="download('gaea_template_excel')">
  15. <i class="iconfont iconexcel"></i>导出excel
  16. </el-button>
  17. </a>
  18. <a v-if="reportCode != null" download="xxx.pdf">
  19. <el-button type="text" @click="download('gaea_template_pdf')">
  20. <i class="iconfont iconpdf"></i>导出pdf
  21. </el-button>
  22. </a>
  23. </div>
  24. <el-form class="">
  25. <h2>表格查询</h2>
  26. <div v-for="(item, num) in tableData2" :key="num + 'excel'">
  27. <h4>{{ item.name }}</h4>
  28. <div
  29. v-for="(son, y) in item.children"
  30. :key="y + 'excel2'"
  31. class="search_input"
  32. >
  33. <label>{{ son.name }}:</label>
  34. <el-input v-model="son.value" />
  35. </div>
  36. </div>
  37. <el-button style="width: 100%" @click="searchPreview">查询</el-button>
  38. </el-form>
  39. <!--<el-pagination :current-page="currentPage4" :page-sizes="[100, 200, 300, 400]" :page-size="100" layout="total, sizes, prev, pager, next, jumper" :total="400" @size-change="handleSizeChange" @current-change="handleCurrentChange" />-->
  40. </div>
  41. </div>
  42. <div class="layout-middle">
  43. <div
  44. id="luckysheet"
  45. style="margin:0px;padding:0px;position:absolute;width:100%;height:95vh;left: 0px;top: 30px;bottom:0px;"
  46. />
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import { preview, exportExcel } from "@/api/GaeaReport";
  52. export default {
  53. name: "Login",
  54. components: {},
  55. data() {
  56. return {
  57. options: {},
  58. sheet: {},
  59. reportId: null,
  60. reportCode: null,
  61. reportName: null,
  62. dataSet: null,
  63. tableData2: [],
  64. excelData: {},
  65. params: {
  66. reportCode: "",
  67. setParam: ""
  68. }
  69. };
  70. },
  71. mounted() {
  72. this.preview();
  73. },
  74. created() {
  75. this.reportCode = this.$route.query.reportCode;
  76. },
  77. methods: {
  78. async searchPreview() {
  79. const arr = this.toObject(this.tableData2);
  80. this.params.setParam = JSON.stringify(arr);
  81. //每次都重新加载需要改成刷新
  82. this.preview();
  83. },
  84. async preview() {
  85. this.excelData = {};
  86. this.params.reportCode = this.reportCode;
  87. const { code, data } = await preview(this.params);
  88. if (code != 200) return;
  89. this.reportName = JSON.parse(data.jsonStr).name;
  90. // 渲染查询表单
  91. this.params.setParam = JSON.parse(data.setParam);
  92. const extendArry = [];
  93. const extendObj = this.params.setParam;
  94. for (const i in extendObj) {
  95. const children = [];
  96. for (const y in extendObj[i]) {
  97. children.push({ name: y, value: extendObj[i][y] });
  98. }
  99. extendArry.push({ name: i, children: children });
  100. }
  101. this.tableData2 = extendArry;
  102. this.excelData = data.jsonStr;
  103. this.sheetData = data == null ? [{}] : JSON.parse(data.jsonStr);
  104. // console.log(this.excelData)
  105. // console.log(this.sheetData)
  106. this.createSheet();
  107. },
  108. async download(val) {
  109. // if (val == "gaea_template_pdf") {
  110. // this.$message("暂不支持pdf");
  111. // return;
  112. // }
  113. const result = {};
  114. result["reportCode"] = this.reportCode;
  115. result["setParam"] = JSON.stringify(this.params.setParam);
  116. if (val != "") {
  117. result["exportType"] = val;
  118. }
  119. this.getCellStyleData(result);
  120. const { code, message } = await exportExcel(result);
  121. if (code != 200) return;
  122. this.$message.success(message);
  123. },
  124. // 表单封装json
  125. toObject(val) {
  126. const objfirst = {};
  127. const objSecond = {};
  128. val.forEach(el => {
  129. el.name ? (objfirst[el.name] = el.children) : "";
  130. });
  131. for (const key in objfirst) {
  132. const newObj = {};
  133. objfirst[key].map(ev => {
  134. Object.assign(newObj, { [ev.name]: ev.value });
  135. });
  136. objSecond[key] = newObj;
  137. }
  138. return objSecond;
  139. },
  140. //初始化表格
  141. createSheet() {
  142. const options = {
  143. container: "luckysheet", // 设定DOM容器的id
  144. title: "", // 设定表格名称
  145. lang: "zh", // 设定表格语言
  146. plugins: ["chart"],
  147. data: [
  148. {
  149. name: "report", //工作表名称
  150. color: "", //工作表颜色
  151. index: 0, //工作表索引
  152. status: 1, //激活状态
  153. order: 0, //工作表的下标
  154. hide: 0, //是否隐藏
  155. row: 36, //行数
  156. column: 18, //列数
  157. defaultRowHeight: 19, //自定义行高
  158. defaultColWidth: 73, //自定义列宽
  159. celldata: [], //初始化使用的单元格数据
  160. config: {
  161. merge: {}, //合并单元格
  162. rowlen: {}, //表格行高
  163. columnlen: {}, //表格列宽
  164. rowhidden: {}, //隐藏行
  165. colhidden: {}, //隐藏列
  166. borderInfo: {}, //边框
  167. authority: {} //工作表保护
  168. },
  169. scrollLeft: 0, //左右滚动条位置
  170. scrollTop: 315, //上下滚动条位置
  171. luckysheet_select_save: [], //选中的区域
  172. calcChain: [], //公式链
  173. isPivotTable: false, //是否数据透视表
  174. pivotTable: {}, //数据透视表设置
  175. filter_select: {}, //筛选范围
  176. filter: null, //筛选配置
  177. luckysheet_alternateformat_save: [], //交替颜色
  178. luckysheet_alternateformat_save_modelCustom: [], //自定义交替颜色
  179. luckysheet_conditionformat_save: {}, //条件格式
  180. frozen: {}, //冻结行列配置
  181. chart: [], //图表配置
  182. zoomRatio: 1, // 缩放比例
  183. image: [], //图片
  184. showGridLines: 1, //是否显示网格线
  185. dataVerification: {} //数据验证配置
  186. }
  187. ]
  188. };
  189. options.data = this.sheetData;
  190. // console.log(this.sheetData)
  191. $(function() {
  192. luckysheet.create(options);
  193. });
  194. },
  195. getCellStyleData(result) {
  196. const sheetData = luckysheet.getluckysheetfile(); // 获取整个表格的数据
  197. const rowDatas = {};
  198. for (let sheetIndex in sheetData) {
  199. const sheet = sheetData[sheetIndex];
  200. if (sheet && sheet.data) {
  201. for (let rowIndex in sheet.data) {
  202. const row = sheet.data[rowIndex];
  203. rowDatas[rowIndex]=row;
  204. }
  205. }
  206. }
  207. result["rowDatas"] = JSON.stringify(rowDatas);;
  208. },
  209. }
  210. };
  211. </script>
  212. <style src="../../../../static/luckysheet/assets/iconfont/iconfont.css" />
  213. <style scoped lang="scss">
  214. .download {
  215. width: 100%;
  216. float: left;
  217. button {
  218. color: #444;
  219. width: 90px;
  220. text-align: left;
  221. .svg-icon {
  222. font-size: 16px;
  223. margin-right: 10px;
  224. }
  225. }
  226. }
  227. .block {
  228. position: relative;
  229. z-index: 10000;
  230. top: 0;
  231. background: #fff;
  232. width: 100%;
  233. h2 {
  234. font-size: 14px;
  235. line-height: 30px;
  236. }
  237. h4 {
  238. font-size: 12px;
  239. }
  240. .search_input {
  241. font-size: 12px;
  242. margin-bottom: 10px;
  243. label {
  244. line-height: 20px;
  245. }
  246. }
  247. }
  248. .layout {
  249. display: block;
  250. position: relative;
  251. margin: 0;
  252. padding: 0;
  253. }
  254. .layout-middle {
  255. display: block;
  256. position: absolute;
  257. left: 200px;
  258. right: 0;
  259. width: calc(100% - 200px);
  260. margin: 0;
  261. padding: 0;
  262. .excel-designer {
  263. display: block;
  264. position: relative;
  265. margin: 0;
  266. padding: 0;
  267. }
  268. }
  269. .layout-right {
  270. display: block;
  271. position: absolute;
  272. top: 0;
  273. left: 0;
  274. padding: 20px;
  275. width: 200px;
  276. min-height: 99.98vh;
  277. border-left: 1px solid #dcdee2;
  278. border-color: #e8eaec;
  279. background: #fff;
  280. border-radius: 4px;
  281. font-size: 14px;
  282. -webkit-transition: all 0.2s ease-in-out;
  283. transition: all 0.2s ease-in-out;
  284. }
  285. </style>