You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

197 lines
4.7 KiB

2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
  1. <template>
  2. <div class="excel_container">
  3. <div class="common_grid" v-for="item in 14 * 14" :key="item">
  4. <div v-if="isTableHeader(item)" class="table_header_box">
  5. {{ getHeaderText(item) }}
  6. </div>
  7. <div class="box" v-else @click="planPath(item)">
  8. <p class="line1">{{ getLine(item, 1) }}</p>
  9. <p class="line2">{{ getLine(item, 2) }}</p>
  10. <div class="path" v-if="showPath(item)">
  11. <p class="path_number">{{ getNumber(item) }}</p>
  12. </div>
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script setup>
  18. import { ref, onMounted } from 'vue'
  19. import { useTaskStore } from '@/store'
  20. const taskStore = useTaskStore()
  21. const props = defineProps({
  22. excelData: {
  23. type: Array,
  24. },
  25. })
  26. const getLine = (index, position) => {
  27. const arr = props.excelData.filter(item => item.num == index)
  28. if (arr?.length > 0) {
  29. const obj = arr[0]
  30. if (obj.secondSign && obj.firstSign) {
  31. if (position == 1) {
  32. // 截取后4位
  33. return obj.firstSign.substr(-4)
  34. } else {
  35. // 截取后4位
  36. return obj.secondSign.substr(-4)
  37. }
  38. }
  39. }
  40. return ''
  41. }
  42. const showPath = item => {
  43. const testArr = taskStore.pathData.filter(it => it.number == item)
  44. if (testArr?.length > 0) {
  45. return true
  46. }
  47. return false
  48. }
  49. const getNumber = item => {
  50. const testArr = taskStore.pathData.filter(it => it.number == item)
  51. if (testArr?.length > 0) {
  52. return testArr[0].orderNumber
  53. }
  54. return ''
  55. }
  56. const planPath = item => {
  57. // 将没有结果的格子排除掉
  58. if (getLine(item, 1) && getLine(item, 2)) {
  59. // 转换item =》 coord
  60. // 数组自记录order
  61. const coord = transItemToCoord(item)
  62. // 校验下当前数组中是否有该coord 有则删除,并且修改其余的order
  63. const testArr = taskStore.pathData.filter(item => item.coord == coord)
  64. if (testArr?.length > 0) {
  65. // 有
  66. const leftArr = taskStore.pathData.filter(item => item.coord != coord)
  67. const del = testArr[0]
  68. const delOrder = del.orderNumber
  69. leftArr.map(item => {
  70. // 将大于要删除order的项 order都减1
  71. if (item.orderNumber > delOrder) {
  72. item.orderNumber = item.orderNumber - 1
  73. }
  74. })
  75. taskStore.updatePathData(leftArr)
  76. } else {
  77. // 没有
  78. let obj = {}
  79. obj.coord = coord
  80. obj.number = item
  81. obj.orderNumber = taskStore.pathData.length + 1
  82. const arr = [...taskStore.pathData]
  83. arr.push(obj)
  84. taskStore.updatePathData(arr)
  85. }
  86. }
  87. }
  88. const transItemToCoord = item => {
  89. const mainLine = Math.floor(item / 14)
  90. let minorLine = 0
  91. if (item % 14 == 0) {
  92. minorLine = 13
  93. } else {
  94. minorLine = (item % 14) - 1
  95. }
  96. return `${mainLine}-${minorLine}`
  97. }
  98. const isTableHeader = index => {
  99. return index <= 14 || index % 14 == 1
  100. }
  101. const getHeaderText = index => {
  102. if (index <= 14 && index > 1) {
  103. return index - 1
  104. }
  105. const arr = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N']
  106. if (index % 14 == 1) {
  107. return arr[parseInt(index / 14) - 1]
  108. }
  109. }
  110. </script>
  111. <style lang="scss" scoped>
  112. .excel_container {
  113. width: 1000px;
  114. height: 800px;
  115. display: grid;
  116. grid-template-columns: repeat(14, 1fr);
  117. grid-template-rows: repeat(14, 1fr);
  118. border: 1px solid #ebebeb;
  119. box-sizing: border-box;
  120. border-radius: 6px;
  121. overflow: hidden;
  122. .common_grid {
  123. border: 1px solid #ebebeb;
  124. margin-left: -1px;
  125. margin-top: -1px;
  126. .box {
  127. width: 100%;
  128. height: 100%;
  129. padding: 7px;
  130. background: #ffffff;
  131. font-size: 18px;
  132. font-weight: 500;
  133. color: #b3b3b3;
  134. box-sizing: border-box;
  135. display: flex;
  136. flex-direction: column;
  137. align-items: center;
  138. justify-content: space-between;
  139. position: relative;
  140. .path {
  141. position: absolute;
  142. left: 0;
  143. right: 0;
  144. top: 0;
  145. bottom: 0;
  146. width: 100%;
  147. height: 100%;
  148. display: flex;
  149. align-items: center;
  150. justify-content: center;
  151. background: rgba(76, 90, 224, 0.9);
  152. .path_number {
  153. font-size: 22px;
  154. color: #fff;
  155. }
  156. }
  157. }
  158. .success {
  159. cursor: pointer;
  160. background: #e1fff1;
  161. color: #01ff82;
  162. }
  163. .fail {
  164. cursor: pointer;
  165. background: #fee2e2;
  166. color: #fe0c0c;
  167. }
  168. .process {
  169. cursor: pointer;
  170. background: #4350dc;
  171. color: #ffffff;
  172. }
  173. .cur {
  174. cursor: pointer;
  175. }
  176. .table_header_box {
  177. background: #f1f1f1;
  178. box-sizing: border-box;
  179. font-size: 26px;
  180. font-weight: bold;
  181. color: #3d3d3d;
  182. display: flex;
  183. align-items: center;
  184. justify-content: center;
  185. height: 100%;
  186. }
  187. }
  188. }
  189. </style>