EtaTable.ce.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <script setup>
  2. import {ref,nextTick} from 'vue'
  3. import {infoByCode} from './api/getData.js'
  4. import {parseQueryString} from "./utils/index"
  5. const props=defineProps({
  6. src:'',
  7. width:'',
  8. height:'',
  9. style:''
  10. })
  11. const params=parseQueryString(props.src)
  12. const info=ref({})
  13. const showData = ref(false);
  14. const sheetRef=ref(null)
  15. const sheetFooter=ref(null)
  16. const setDefaultSource=(sourceText)=>{
  17. return JSON.stringify({
  18. isShow: true,
  19. text: sourceText,
  20. color: "#606266",
  21. fontSize: 9
  22. })
  23. }
  24. async function getTableData(){
  25. const res = await infoByCode({ UniqueCode: params.code, FromScene: Number(params.fromScene||'') });
  26. if(res.Ret !== 200) return
  27. info.value=res.Data
  28. if(!info.value.SourcesFrom){
  29. info.value.SourcesFrom = res.Data.ExcelSource?setDefaultSource(res.Data.ExcelSource||''):''
  30. }
  31. showData.value = true;
  32. nextTick(()=>{
  33. console.log(sheetRef.value.clientWidth);
  34. sheetFooter.value && (sheetFooter.value.style.maxWidth=sheetRef.value?.clientWidth+'px')
  35. })
  36. }
  37. getTableData()
  38. </script>
  39. <template>
  40. <div
  41. v-if="showData"
  42. class="sheet-show-wrapper"
  43. ref="sheetRef"
  44. >
  45. <h3 class="title">{{info.ExcelName}}</h3>
  46. <div class="table-wrapper">
  47. <table
  48. cellpadding="0"
  49. cellspacing="0"
  50. :style="`font-size: ${info.Config?.FontSize||12}PX`"
  51. >
  52. <tbody>
  53. <tr
  54. v-for="(item,index) in info.TableInfo?.TableDataList"
  55. :key="index"
  56. >
  57. <td
  58. :class="['data-cell',{
  59. 'one-bg':(index+1)%2&&index>0,
  60. 'tow-bg': (index+1)%2!==0&&index>0,
  61. 'head-column': index === 0
  62. }]"
  63. v-for="(cell,cell_index) in item"
  64. :key="cell_index"
  65. :colspan="cell.mc.cs||1"
  66. :rowspan="cell.mc.rs||1"
  67. :style="`
  68. color: ${cell.fc};
  69. font-weight: ${cell.bl ? 'bold' : 'normal'};
  70. font-style: ${cell.it ? 'italic' : 'normal'};
  71. background: ${cell.bg};
  72. `"
  73. >
  74. <div class="split-word" v-if="cell.ct.s">
  75. <span
  76. v-for="(word,word_index) in cell.ct.s"
  77. :key="`${index}_${cell_index}_${word_index}`"
  78. :style="`
  79. color: ${word.fc};
  80. font-weight: ${word.bl ? 'bold' : 'normal'};
  81. font-style: ${word.it ? 'italic' : 'normal'};
  82. `"
  83. >{{word.v}}</span>
  84. </div>
  85. <div v-else>{{cell.m}}</div>
  86. </td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. </div>
  91. <div class="sheet-source" ref="sheetFooter"
  92. v-if="info.SourcesFrom&&JSON.parse(info.SourcesFrom).isShow"
  93. :style="`
  94. color: ${ JSON.parse(info.SourcesFrom).color };
  95. font-size: ${ JSON.parse(info.SourcesFrom).fontSize }px;
  96. `"
  97. >
  98. source:<em>{{ JSON.parse(info.SourcesFrom).text}}</em>
  99. </div>
  100. </div>
  101. </template>
  102. <style lang="scss" scoped>
  103. .sheet-show-wrapper {
  104. max-width: 1200PX;
  105. overflow: hidden;
  106. position: relative;
  107. margin: 0 auto;
  108. background: #fff;
  109. .title {
  110. font-size: 17PX;
  111. font-weight: normal;
  112. padding: 0 10PX;
  113. margin: 0 0 8PX 0;
  114. }
  115. .table-wrapper {
  116. max-width: calc(100vw - 20PX);
  117. margin: 0 auto;
  118. overflow: auto;
  119. table {
  120. width: 100%;
  121. font-size: 14PX;
  122. color: #333;
  123. table-layout: auto;
  124. td,
  125. th {
  126. width: auto;
  127. height: auto;
  128. padding: 0.4em 0;
  129. word-break: break-all;
  130. word-wrap: break-word;
  131. line-height: 1.2em;
  132. border: 1PX solid #dcdfe6;
  133. text-align: center;
  134. background-color: #fff;
  135. border-left: none;
  136. border-top: none;
  137. &:first-child {
  138. border-left: 1PX solid #dcdfe6;
  139. }
  140. }
  141. .data-cell{
  142. color: #333;
  143. &.one-bg {
  144. background-color: #EFEEF1;
  145. }
  146. &.two-bg {
  147. background-color: #fff;
  148. }
  149. }
  150. .thead-sticky {
  151. position: sticky;
  152. top: 0;
  153. }
  154. .head-column {
  155. background-color: #505B78;
  156. color: #fff;
  157. }
  158. .split-word {
  159. span { display: inline; }
  160. }
  161. }
  162. }
  163. .sheet-source{
  164. margin-top: 5PX;
  165. min-width: 150PX;
  166. overflow: hidden;
  167. text-overflow: ellipsis;
  168. white-space: nowrap;
  169. }
  170. }
  171. </style>