sheet.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. <script setup lang='ts'>
  2. import { PropType,computed,ref, nextTick } from 'vue';
  3. import { isMobile } from '@/utils/utils';
  4. import { useResizeTable } from '@/hooks/sheet/useResizeTable.js';
  5. import { useRoute } from 'vue-router';
  6. const route = useRoute();
  7. const isCanDrag = computed(() => { //在研报内的研报id
  8. return route.query.sourceId ? true :false
  9. });
  10. const tableRef = ref(null)
  11. const {
  12. columnsWArr,
  13. rowsHArr,
  14. handleMouseDown,
  15. handleMouseMove,
  16. handleMouseOut,
  17. initTableCellsWid,
  18. getSize,
  19. SheetFFType,
  20. } = useResizeTable(tableRef)
  21. const props = defineProps({
  22. data: {
  23. type: Array as PropType<any[]>,
  24. required: true
  25. },
  26. config: {
  27. type: Object
  28. },
  29. sceneConfig: { //应用存储信息
  30. type: Object
  31. }
  32. })
  33. //手机端pc端又要不同样式
  34. const dynamicSty = computed(()=>{
  35. return isMobile() ? 'mobile-sty' : 'pc-sty';
  36. })
  37. const HtObj=ref({
  38. 0:"center",
  39. 1:'left',
  40. 2:'right'
  41. })
  42. const handleFF = (ff) => {
  43. return ff ? (typeof ff == 'number' ? SheetFFType[ff] : ff) : ''
  44. }
  45. initTableCellsWid('init',props.sceneConfig)
  46. </script>
  47. <template>
  48. <div :class="['table-wrapper',dynamicSty ]">
  49. <table
  50. cellpadding="0"
  51. cellspacing="0"
  52. ref="tableRef"
  53. >
  54. <tbody>
  55. <tr
  56. v-for="(item,index) in props.data"
  57. :key="index"
  58. :style="`height:${getSize(index,'height')}`"
  59. >
  60. <td
  61. :class="['data-cell',{
  62. 'one-bg':(index+1)%2&&index>0,
  63. 'tow-bg': (index+1)%2!==0&&index>0,
  64. 'head-column': index === 0,
  65. }]"
  66. v-for="(cell,cell_index) in item"
  67. :key="cell_index"
  68. :colspan="cell.mc.cs||1"
  69. :rowspan="cell.mc.rs||1"
  70. :style="`
  71. color: ${cell.fc};
  72. font-weight: ${cell.bl ? 'bold' : 'normal'};
  73. font-style: ${cell.it ? 'italic' : 'normal'};
  74. background: ${cell.bg};
  75. text-align: ${HtObj[cell.HorizontalType]};
  76. font-size: ${cell.fs||props.config.FontSize||12}px;
  77. width:${index==0?getSize(cell_index,'width'):'auto'};
  78. ${cell.ct.s ? '' : `font-family: ${handleFF(cell.ff)};`}
  79. `"
  80. @mousemove="e =>isCanDrag && handleMouseMove(e,index,cell_index)"
  81. @mousedown="e =>isCanDrag && handleMouseDown(e,index,cell_index)"
  82. >
  83. <!-- 单元格拆分 -->
  84. <div class="split-word" v-if="cell.ct.s">
  85. <span
  86. v-for="(word,word_index) in cell.ct.s"
  87. :key="`${index}_${cell_index}_${word_index}`"
  88. :style="`
  89. color: ${word.fc};
  90. font-weight: ${word.bl ? 'bold' : 'normal'};
  91. font-style: ${word.it ? 'italic' : 'normal'};
  92. font-family: ${handleFF(word.ff)};
  93. `"
  94. >{{word.v}}</span>
  95. </div>
  96. <div v-else>{{cell.m}}</div>
  97. </td>
  98. </tr>
  99. </tbody>
  100. </table>
  101. </div>
  102. </template>
  103. <style lang='less' scoped>
  104. ::-webkit-scrollbar {
  105. width: 6px;
  106. height: 6px;
  107. }
  108. ::-webkit-scrollbar-track {
  109. background: rgb(239, 239, 239);
  110. border-radius: 2px;
  111. }
  112. ::-webkit-scrollbar-thumb {
  113. background: #ccc;
  114. border-radius: 10px;
  115. }
  116. ::-webkit-scrollbar-thumb:hover {
  117. background: #888;
  118. }
  119. ::-webkit-scrollbar-corner {
  120. background: #666;
  121. }
  122. .table-wrapper {
  123. max-width: calc(100vw - 20px);
  124. margin: 0 auto;
  125. // margin-right: -5px;
  126. overflow: auto;
  127. }
  128. table {
  129. width: 100%;
  130. font-size: 14px;
  131. color: #333;
  132. td,
  133. th {
  134. // min-width: 120px;
  135. word-break: break-all;
  136. word-wrap: break-word;
  137. line-height: 1.2em;
  138. border: 1px solid #dcdfe6;
  139. // height: 40px;
  140. text-align: center;
  141. background-color: #fff;
  142. border-left: none;
  143. border-top: none;
  144. &:first-child {
  145. border-left: 1px solid #dcdfe6;
  146. }
  147. }
  148. .data-cell{
  149. color: #333;
  150. &.one-bg {
  151. background-color: #EFEEF1;
  152. }
  153. &.two-bg {
  154. background-color: #fff;
  155. }
  156. }
  157. .thead-sticky {
  158. position: sticky;
  159. top: 0;
  160. }
  161. .head-column {
  162. background-color: #505B78;
  163. color: #fff;
  164. }
  165. .split-word {
  166. span { display: inline; }
  167. }
  168. }
  169. .pc-sty table {
  170. table-layout: auto;
  171. td,th {
  172. width: auto;
  173. height: auto;
  174. padding: 0.4em 0;
  175. }
  176. }
  177. .mobile-sty table {
  178. table-layout: auto;
  179. td,th {
  180. min-width: 120px;
  181. height: 40px;
  182. }
  183. }
  184. </style>