ReportModule.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. <template>
  2. <div class="report_module">
  3. <div class="module_title">
  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 }">{{ item }}</span><span
  8. v-if="index != titleList.length - 1" class="split_line">/</span>
  9. </template>
  10. </template>
  11. <slot name="title_left" />
  12. </div>
  13. <div class="title_right">
  14. <slot name="title_right" />
  15. <template v-if="showPrintBtn">
  16. <el-button class="default_button" :loading="state.printLoading">
  17. <img v-if="!state.printLoading" src="@/assets/icon/print_icon.webp" alt="打印PDF" />打印PDF
  18. </el-button>
  19. </template>
  20. <template v-if="showExportBtn">
  21. <el-button class="default_button" :loading="state.exportLoading">
  22. <img v-if="!state.exportLoading" src="@/assets/icon/export_icon.webp" alt="导出Excel" />导出Excel
  23. </el-button>
  24. </template>
  25. </div>
  26. </div>
  27. <div :class="[`module_${tableOrChart}`, { table_42: tableOrChart == 'table' }]">
  28. <!-- 表格或图表显示 -->
  29. <slot name="module_table_chart" />
  30. <!-- 表格分页 -->
  31. <div class="page_pagination" v-if="tableOrChart == 'table' && showTablePage && (total > pageSize)">
  32. <el-pagination background :current-page="currentPage" :page-size="pageSize" :page-sizes="pageSizes"
  33. layout="total,sizes,prev,pager,next" :total="total" @size-change="HandleSizeChange"
  34. @current-change="HandleCurrentChange" />
  35. </div>
  36. </div>
  37. <!-- 描述 -->
  38. <div v-if="showDescribe" class="module_describe">
  39. <div ref="textContainer" class="text_container" :class="{ 'expanded': state.isExpanded }">
  40. <slot name="module_describe"></slot>
  41. </div>
  42. <button v-if="state.showExpandButton" @click="ToggleExpand" class="toggle_button"
  43. :class="state.isExpanded ? 'show_expanded' : 'hide_expanded'">
  44. {{ state.isExpanded ? '收起' : '展开' }}
  45. </button>
  46. </div>
  47. </div>
  48. </template>
  49. <script lang="ts" setup>
  50. import { onMounted, reactive, nextTick, ref } from 'vue'
  51. interface TitleListType {
  52. titleList?: string[]
  53. showTitle?: boolean
  54. showPrintBtn?: boolean
  55. showExportBtn?: boolean
  56. tableOrChart?: 'table' | 'chart'
  57. showTablePage?: boolean
  58. currentPage?: number
  59. pageSize?: number
  60. pageSizes?: number[]
  61. total?: number
  62. showDescribe?: boolean
  63. }
  64. const props = withDefaults(defineProps<TitleListType>(), {
  65. titleList: () => [],
  66. showTitle: true,
  67. showPrintBtn: true,
  68. showExportBtn: true,
  69. tableOrChart: 'table',
  70. showTablePage: true,
  71. currentPage: 1,
  72. pageSize: 10,
  73. pageSizes: () => [10, 20, 30, 40, 50, 100],
  74. total: 0,
  75. showDescribe: true
  76. })
  77. const emit = defineEmits<{
  78. 'update:currentPage': [val: number]
  79. 'update:pageSize': [val: number]
  80. }>()
  81. // 状态管理
  82. const state = reactive({
  83. printLoading: false,
  84. exportLoading: false,
  85. isExpanded: false,
  86. showExpandButton: true
  87. })
  88. const textContainer = ref<HTMLElement | null>(null)
  89. // 分页事件
  90. const HandleSizeChange = (val: number) => {
  91. emit('update:pageSize', val)
  92. }
  93. const HandleCurrentChange = (val: number) => {
  94. emit('update:currentPage', val)
  95. }
  96. //文本展开收起逻辑
  97. const checkLines = () => {
  98. const container = textContainer.value
  99. if (!container) return
  100. const lineHeight = parseInt(
  101. window.getComputedStyle(container).lineHeight || '24',
  102. 10
  103. )
  104. const textHeight = container.scrollHeight
  105. const lines = Math.ceil(textHeight / lineHeight)
  106. state.showExpandButton = lines > 3
  107. }
  108. const ToggleExpand = () => {
  109. state.isExpanded = !state.isExpanded
  110. }
  111. onMounted(() => {
  112. nextTick(() => checkLines())
  113. })
  114. </script>
  115. <style lang="scss" scoped>
  116. .report_module {
  117. width: 100%;
  118. background-color: #fff;
  119. margin-top: 10px;
  120. border-radius: 10px;
  121. .module_title {
  122. width: 100%;
  123. padding: 20px 20px 10px;
  124. box-sizing: border-box;
  125. margin: auto;
  126. font-weight: 600;
  127. font-size: 16px;
  128. color: #333333;
  129. text-align: left;
  130. line-height: 36px;
  131. display: flex;
  132. justify-content: space-between;
  133. .title_left {
  134. display: inline-flex;
  135. align-items: center;
  136. flex-wrap: wrap;
  137. .span_item {
  138. font-weight: 400;
  139. font-size: 16px;
  140. color: #999999;
  141. }
  142. .split_line {
  143. font-weight: 400;
  144. font-size: 16px;
  145. color: #999999;
  146. margin: 0 6px;
  147. }
  148. }
  149. .title_right {
  150. display: flex;
  151. justify-content: flex-end;
  152. align-items: center;
  153. gap: 10px;
  154. .default_button {
  155. margin-left: 0px;
  156. height: 36px;
  157. line-height: 36px;
  158. padding: 0 10px;
  159. font-weight: 400;
  160. font-size: 14px;
  161. color: #666666;
  162. display: flex;
  163. align-items: center;
  164. &:active,
  165. &:focus {
  166. outline: none; // 去掉点击后的轮廓
  167. box-shadow: none; // 去掉点击后的阴影
  168. background-color: inherit; // 保持背景颜色不变
  169. color: #666666; // 保持文字颜色不变
  170. border: 1px solid #DCDFE6;
  171. }
  172. &:hover {
  173. background-color: #f9f9f9;
  174. border: 1px solid #DCDFE6;
  175. color: #666;
  176. }
  177. span {
  178. display: flex;
  179. align-items: center;
  180. }
  181. img {
  182. width: 16px;
  183. height: 16px;
  184. margin-right: 4px;
  185. }
  186. .el-icon-loading {
  187. color: #666;
  188. }
  189. }
  190. }
  191. }
  192. .module_table {
  193. width: 100%;
  194. padding: 0 20px 14px;
  195. box-sizing: border-box;
  196. border-collapse: collapse;
  197. }
  198. .module_chart {
  199. width: 100%;
  200. padding: 0 20px;
  201. box-sizing: border-box;
  202. min-height: 360px;
  203. }
  204. .module_describe {
  205. width: 100%;
  206. padding: 14px 20px;
  207. box-sizing: border-box;
  208. font-weight: 400;
  209. font-size: 14px;
  210. color: #999999;
  211. line-height: 24px;
  212. text-align: left;
  213. .text_container {
  214. position: relative;
  215. overflow: hidden;
  216. text-overflow: ellipsis;
  217. display: -webkit-box;
  218. -webkit-line-clamp: 3;
  219. -webkit-box-orient: vertical;
  220. transition: max-height 0.3s ease-out;
  221. max-height: 72px;
  222. p {
  223. line-height: 22px;
  224. }
  225. }
  226. .text_container.expanded {
  227. -webkit-line-clamp: unset;
  228. max-height: none;
  229. }
  230. .toggle_button {
  231. margin-top: 8px;
  232. cursor: pointer;
  233. background: none;
  234. border: none;
  235. color: #2E64FA;
  236. font-size: 14px;
  237. line-height: 1;
  238. width: 100%;
  239. height: 24px;
  240. text-align: right;
  241. padding: 0 20px 0 0;
  242. }
  243. .show_expanded {
  244. background-image: url('@/assets/icon/up_expanded.webp');
  245. background-size: 16px 16px;
  246. background-position: 100% 50%;
  247. background-repeat: no-repeat;
  248. }
  249. .hide_expanded {
  250. background-image: url('@/assets/icon/down_expanded.webp');
  251. background-size: 16px 16px;
  252. background-position: 100% 50%;
  253. background-repeat: no-repeat;
  254. }
  255. }
  256. }
  257. </style>