sheet.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 handleCellStyle = (cell) : string => {
  43. return `
  44. color: ${cell.fc};
  45. font-weight: ${cell.bl ? 'bold' : 'normal'};
  46. font-style: ${cell.it ? 'italic' : 'normal'};
  47. text-align: ${HtObj.value[cell.HorizontalType]};
  48. font-family: ${handleFF(cell.ff)};
  49. `
  50. };
  51. const handleFF = (ff:string|number) : string => {
  52. return ff ? (typeof ff == 'number' ? SheetFFType[ff] : ff) : ''
  53. }
  54. initTableCellsWid('init',props.sceneConfig)
  55. </script>
  56. <template>
  57. <div :class="['table-wrapper',dynamicSty ]">
  58. <table
  59. cellpadding="0"
  60. cellspacing="0"
  61. ref="tableRef"
  62. :class="config.Watermark?'background-watermark':'no-water'"
  63. :style="{'font-size':(config.FontSize||12)+'px',backgroundImage: 'url('+config.Watermark+')'}"
  64. >
  65. <tbody>
  66. <tr
  67. v-for="(item,index) in props.data"
  68. :key="index"
  69. :style="`height:${getSize(index,'height')}`"
  70. >
  71. <td
  72. :class="['data-cell',{
  73. 'one-bg':(index+1)%2&&index>0&&!config.Watermark,
  74. 'tow-bg': (index+1)%2!==0&&index>0,
  75. 'head-column': index === 0,
  76. }]"
  77. v-for="(cell,cell_index) in item"
  78. :key="cell_index"
  79. :colspan="cell.mc.cs||1"
  80. :rowspan="cell.mc.rs||1"
  81. :style="`
  82. width:${getSize(cell_index,'width')};
  83. background: ${cell.bg};
  84. font-size: ${props.config.FontSize||cell.fs||12}px;
  85. ${!cell.ct.s ? handleCellStyle(cell) : ''}
  86. `"
  87. @mousemove="e =>isCanDrag && handleMouseMove(e,index,cell_index)"
  88. @mousedown="e =>isCanDrag && handleMouseDown(e,index,cell_index)"
  89. >
  90. <!-- 单元格拆分 -->
  91. <div class="split-word" v-if="cell.ct.s" :style="`text-align: ${HtObj[cell.HorizontalType]};`">
  92. <span
  93. v-for="(word,word_index) in cell.ct.s"
  94. :key="`${index}_${cell_index}_${word_index}`"
  95. :style="handleCellStyle(word)"
  96. >{{word.v}}</span>
  97. </div>
  98. <div v-else
  99. :style="`text-decoration:${cell.un?'underline':cell.cl?'line-through':'normal'};`">{{cell.m}}</div>
  100. </td>
  101. </tr>
  102. </tbody>
  103. </table>
  104. </div>
  105. </template>
  106. <style lang='less' scoped>
  107. ::-webkit-scrollbar {
  108. width: 6px;
  109. height: 6px;
  110. }
  111. ::-webkit-scrollbar-track {
  112. background: rgb(239, 239, 239);
  113. border-radius: 2px;
  114. }
  115. ::-webkit-scrollbar-thumb {
  116. background: #ccc;
  117. border-radius: 10px;
  118. }
  119. ::-webkit-scrollbar-thumb:hover {
  120. background: #888;
  121. }
  122. ::-webkit-scrollbar-corner {
  123. background: #666;
  124. }
  125. .table-wrapper {
  126. max-width: calc(100vw - 20px);
  127. margin: 0 auto;
  128. // margin-right: -5px;
  129. overflow: auto;
  130. }
  131. table {
  132. width: 100%;
  133. font-size: 14px;
  134. color: #333;
  135. border-collapse: collapse;
  136. td,
  137. th {
  138. // min-width: 120px;
  139. word-break: break-all;
  140. word-wrap: break-word;
  141. line-height: 1.2em;
  142. border: 1px solid #dcdfe6;
  143. // height: 40px;
  144. text-align: center;
  145. // border-left: none;
  146. // border-top: none;
  147. &:first-child {
  148. border-left: 1px solid #dcdfe6;
  149. }
  150. }
  151. .data-cell{
  152. color: #333;
  153. &.one-bg {
  154. background-color: #EFEEF1;
  155. }
  156. &.two-bg {
  157. background-color: #fff;
  158. }
  159. }
  160. .thead-sticky {
  161. position: sticky;
  162. top: 0;
  163. }
  164. .head-column {
  165. background-color: #505B78;
  166. color: #fff;
  167. }
  168. .split-word {
  169. span { display: inline; }
  170. }
  171. }
  172. .no-water{
  173. td,
  174. th {
  175. background-color: #fff;
  176. }
  177. .head-column {
  178. background-color: #505B78;
  179. color: #fff;
  180. }
  181. }
  182. .pc-sty table {
  183. table-layout: auto;
  184. td,th {
  185. width: auto;
  186. height: auto;
  187. padding: 0.4em 0;
  188. }
  189. }
  190. .mobile-sty table {
  191. table-layout: auto;
  192. td,th {
  193. min-width: 120px;
  194. height: 40px;
  195. }
  196. }
  197. .background-watermark{
  198. background-repeat: no-repeat;
  199. background-position: center center;
  200. background-size: 100%;
  201. }
  202. </style>