ReportModule.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  1. <template>
  2. <div class="report_module">
  3. <div class="module_title" v-if="showHeader">
  4. <div class="title_left">
  5. <template v-if="showTitle && titleList.length">
  6. <template v-for="(item, index) in titleList">
  7. <span :class="{ span_item: index != titleList.length - 1 }">{{
  8. item
  9. }}</span>
  10. <span v-if="index != titleList.length - 1" class="split_line"
  11. >/</span
  12. >
  13. </template>
  14. </template>
  15. <slot name="title_left" />
  16. </div>
  17. <div class="title_right">
  18. <slot name="title_right" />
  19. <template v-if="showPrintBtn">
  20. <el-button
  21. class="default_button"
  22. :loading="state.printLoading"
  23. @click="PrintPdf"
  24. >
  25. <img
  26. v-if="!state.printLoading"
  27. src="@/assets/icon/print_icon.webp"
  28. />打印PDF
  29. </el-button>
  30. </template>
  31. <template v-if="showExportBtn">
  32. <el-button
  33. class="default_button"
  34. :loading="state.exportLoading"
  35. @click="ExportExcel"
  36. >
  37. <img
  38. v-if="!state.exportLoading"
  39. src="@/assets/icon/export_icon.webp"
  40. />导出Excel
  41. </el-button>
  42. </template>
  43. </div>
  44. </div>
  45. <div
  46. :class="[`module_${tableOrChart}`, { table_42: tableOrChart == 'table' }]"
  47. >
  48. <!-- 其他 -->
  49. <slot name="module_qita" />
  50. <!-- 表格或图表显示 -->
  51. <slot name="module_table_chart" />
  52. <!-- 表格分页 -->
  53. <div
  54. class="page_pagination"
  55. v-if="tableOrChart == 'table' && showTablePage"
  56. >
  57. <el-pagination
  58. background
  59. :current-page="currentPage"
  60. :page-size="pageSize"
  61. :page-sizes="pageSizes"
  62. :layout="total > pageSize ? 'total,sizes,prev,pager,next' : 'total,sizes'"
  63. :total="total"
  64. @size-change="ChangePageSize"
  65. @current-change="ChangeCurrentPage"
  66. />
  67. </div>
  68. </div>
  69. <!-- 描述 -->
  70. <div v-if="showDescribe" class="module_describe">
  71. <div
  72. ref="textContainer"
  73. class="text_container"
  74. :class="{ expanded: state.isExpanded }"
  75. >
  76. <slot name="module_describe"></slot>
  77. </div>
  78. <button
  79. v-if="state.showExpandButton"
  80. @click="ToggleExpand"
  81. class="toggle_button"
  82. :class="state.isExpanded ? 'show_expanded' : 'hide_expanded'"
  83. >
  84. {{ state.isExpanded ? "收起" : "展开" }}
  85. </button>
  86. </div>
  87. </div>
  88. </template>
  89. <script lang="ts" setup>
  90. import { onMounted, reactive, nextTick, ref } from "vue";
  91. interface TitleListType {
  92. showHeader?: boolean;
  93. titleList?: string[];
  94. showTitle?: boolean;
  95. showPrintBtn?: boolean;
  96. showExportBtn?: boolean;
  97. tableOrChart?: "table" | "chart" | "qita";
  98. showTablePage?: boolean;
  99. currentPage?: number;
  100. pageSize?: number;
  101. pageSizes?: number[];
  102. total?: number;
  103. showDescribe?: boolean;
  104. }
  105. const props = withDefaults(defineProps<TitleListType>(), {
  106. showHeader: true,
  107. titleList: () => [], //标题
  108. showTitle: true, //是否显示标题
  109. showPrintBtn: true, //是否显示打印按钮
  110. showExportBtn: true, //是否显示导出按钮
  111. tableOrChart: "table", //表格、图表、其他
  112. showTablePage: true, //是否显示分页
  113. currentPage: 1,
  114. pageSize: 10,
  115. pageSizes: () => [10, 20, 30, 40, 50, 100],
  116. total: 0,
  117. showDescribe: true, //是否显示描述
  118. });
  119. const emit = defineEmits<{
  120. ChangeCurrentPage: [val: number];
  121. ChangePageSize: [val: number];
  122. PrintPdf: [];
  123. ExportExcel: [];
  124. }>();
  125. // 状态管理
  126. const state = reactive({
  127. printLoading: false,
  128. exportLoading: false,
  129. isExpanded: false,
  130. showExpandButton: true,
  131. });
  132. const textContainer = ref<HTMLElement | null>(null);
  133. // 分页大小事件
  134. const ChangePageSize = (val: number) => {
  135. emit("ChangePageSize", val);
  136. };
  137. // 当前页码事件
  138. const ChangeCurrentPage = (val: number) => {
  139. emit("ChangeCurrentPage", val);
  140. };
  141. // 打印PDF
  142. const PrintPdf = () => {
  143. emit("PrintPdf");
  144. };
  145. // 设置打印PDF加载状态
  146. const SetPrintLoading = (val: boolean) => {
  147. state.printLoading = val;
  148. };
  149. // 导出Excel
  150. const ExportExcel = () => {
  151. emit("ExportExcel");
  152. };
  153. // 设置导出Excel加载状态
  154. const SetExportLoading = (val: boolean) => {
  155. state.exportLoading = val;
  156. };
  157. //文本展开收起逻辑
  158. const checkLines = () => {
  159. const container = textContainer.value;
  160. if (!container) return;
  161. const lineHeight = parseInt(
  162. window.getComputedStyle(container).lineHeight || "24",
  163. 10,
  164. );
  165. const textHeight = container.scrollHeight;
  166. const lines = Math.ceil(textHeight / lineHeight);
  167. state.showExpandButton = lines > 3;
  168. };
  169. // 文本展开收起事件
  170. const ToggleExpand = () => {
  171. state.isExpanded = !state.isExpanded;
  172. };
  173. onMounted(() => {
  174. nextTick(() => checkLines());
  175. });
  176. defineExpose({
  177. SetExportLoading,
  178. SetPrintLoading,
  179. });
  180. </script>
  181. <style lang="scss" scoped>
  182. .report_module {
  183. width: 100%;
  184. background-color: #fff;
  185. margin-top: 10px;
  186. border-radius: 10px;
  187. &:nth-child(1) {
  188. margin-top: 0;
  189. }
  190. .module_title {
  191. width: 100%;
  192. padding: 20px 20px 10px;
  193. box-sizing: border-box;
  194. margin: auto;
  195. display: flex;
  196. align-items: center;
  197. justify-content: space-between;
  198. .title_left {
  199. display: inline-flex;
  200. align-items: center;
  201. flex-wrap: wrap;
  202. font-weight: 600;
  203. font-size: 16px;
  204. color: #333333;
  205. text-align: left;
  206. line-height: 36px;
  207. .span_item {
  208. font-weight: 400;
  209. font-size: 16px;
  210. color: #999999;
  211. }
  212. .split_line {
  213. font-weight: 400;
  214. font-size: 16px;
  215. color: #999999;
  216. margin: 0 6px;
  217. }
  218. }
  219. .title_right {
  220. display: flex;
  221. justify-content: flex-end;
  222. align-items: center;
  223. gap: 10px;
  224. :deep(.el-button) {
  225. span {
  226. display: flex;
  227. align-items: center;
  228. }
  229. img {
  230. width: 16px;
  231. height: 16px;
  232. margin-right: 4px;
  233. }
  234. }
  235. .default_button {
  236. margin-left: 0px;
  237. height: 36px;
  238. line-height: 36px;
  239. padding: 0 10px;
  240. font-weight: 400;
  241. font-size: 14px;
  242. color: #666666;
  243. display: flex;
  244. align-items: center;
  245. &:active,
  246. &:focus {
  247. outline: none; // 去掉点击后的轮廓
  248. box-shadow: none; // 去掉点击后的阴影
  249. background-color: inherit; // 保持背景颜色不变
  250. color: #666666; // 保持文字颜色不变
  251. border: 1px solid #dcdfe6;
  252. }
  253. &:hover {
  254. background-color: #f9f9f9;
  255. border: 1px solid #dcdfe6;
  256. color: #666;
  257. }
  258. }
  259. :deep(.button_set_header) {
  260. //设置表头
  261. font-size: 14px;
  262. color: #2e64fa;
  263. border: 1px solid #2e64fa;
  264. padding: 0px 10px !important;
  265. }
  266. :deep(.right_item) {
  267. font-size: 14px;
  268. color: #999;
  269. font-weight: 400;
  270. cursor: pointer;
  271. height: 30px;
  272. line-height: 30px;
  273. margin-right: 5px;
  274. border-bottom: 2px solid #ffffff;
  275. &.no_border {
  276. border-bottom: 0 !important;
  277. }
  278. &.item_active {
  279. font-size: 14px;
  280. color: #2e64fa;
  281. font-weight: 500;
  282. cursor: pointer;
  283. border-bottom: 2px solid #2e64fa;
  284. }
  285. }
  286. }
  287. }
  288. .module_table {
  289. width: 100%;
  290. padding: 0 20px 14px;
  291. box-sizing: border-box;
  292. border-collapse: collapse;
  293. :deep(.el-table) {
  294. border-radius: 6px;
  295. border-left: 0px;
  296. border-right: 0px;
  297. .el-table__header {
  298. .cell {
  299. font-size: 14px;
  300. }
  301. }
  302. .cell {
  303. display: block;
  304. text-align: center;
  305. white-space: nowrap;
  306. padding: 0 0 0 4px !important;
  307. }
  308. }
  309. :deep(.table_row_blue) {
  310. color: #2e64fa;
  311. cursor: pointer;
  312. }
  313. }
  314. .module_chart {
  315. width: 100%;
  316. padding: 0 20px;
  317. box-sizing: border-box;
  318. min-height: 360px;
  319. //无数据显示
  320. :deep(.no_content_data) {
  321. background-image: url("../assets/bg/no_content_bg.png");
  322. background-repeat: no-repeat;
  323. background-size: 360px auto;
  324. background-position: 50% 30%;
  325. color: #999999;
  326. justify-content: center;
  327. display: flex;
  328. align-items: center;
  329. min-height: 360px;
  330. span {
  331. margin-top: 80px;
  332. font-size: 14px;
  333. }
  334. }
  335. }
  336. .module_describe {
  337. width: 100%;
  338. padding: 14px 20px;
  339. box-sizing: border-box;
  340. font-weight: 400;
  341. font-size: 14px;
  342. color: #999999;
  343. line-height: 24px;
  344. text-align: left;
  345. .text_container {
  346. position: relative;
  347. overflow: hidden;
  348. text-overflow: ellipsis;
  349. display: -webkit-box;
  350. -webkit-line-clamp: 3;
  351. -webkit-box-orient: vertical;
  352. transition: max-height 0.3s ease-out;
  353. max-height: 72px;
  354. p {
  355. line-height: 22px;
  356. }
  357. }
  358. .text_container.expanded {
  359. -webkit-line-clamp: unset;
  360. max-height: none;
  361. }
  362. .toggle_button {
  363. margin-top: 8px;
  364. cursor: pointer;
  365. background: none;
  366. border: none;
  367. color: #2e64fa;
  368. font-size: 14px;
  369. line-height: 1;
  370. width: 100%;
  371. height: 24px;
  372. text-align: right;
  373. padding: 0 20px 0 0;
  374. }
  375. .show_expanded {
  376. background-image: url("@/assets/icon/up_expanded.webp");
  377. background-size: 16px 16px;
  378. background-position: 100% 50%;
  379. background-repeat: no-repeat;
  380. }
  381. .hide_expanded {
  382. background-image: url("@/assets/icon/down_expanded.webp");
  383. background-size: 16px 16px;
  384. background-position: 100% 50%;
  385. background-repeat: no-repeat;
  386. }
  387. }
  388. .module_qita {
  389. width: 100%;
  390. display: flex;
  391. :deep(.content_left) {
  392. padding-left: 20px;
  393. box-sizing: border-box;
  394. }
  395. :deep(.content_right) {
  396. padding-right: 20px;
  397. box-sizing: border-box;
  398. }
  399. :deep(.table_42) {
  400. padding-bottom: 0;
  401. .el-table {
  402. border-left: 0px;
  403. border-right: 0px;
  404. .cell {
  405. display: block;
  406. text-align: center;
  407. white-space: nowrap;
  408. padding: 0 0 0 4px !important;
  409. }
  410. }
  411. }
  412. }
  413. :deep(.el-loading-spinner) {
  414. .el-loading-text {
  415. font-size: 14px;
  416. margin: 0 auto;
  417. }
  418. .circular {
  419. width: 20px;
  420. height: 20px;
  421. color: #2e64fa;
  422. }
  423. }
  424. }
  425. </style>