index.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="hc-page-box">
  3. <HcCard>
  4. <template #header>
  5. <el-button type="primary">查看表单</el-button>
  6. </template>
  7. <div class="hc-table-form-data-item">
  8. <el-scrollbar>
  9. <div id="table-form-1" class="hc-excel-table-form"/>
  10. </el-scrollbar>
  11. </div>
  12. </HcCard>
  13. </div>
  14. </template>
  15. <script setup>
  16. import {onMounted, onUnmounted, ref} from "vue";
  17. import {data} from './data.js'
  18. import {getIndex, deepClone} from "vue-utils-plus";
  19. import HTableForm from "~src/plugins/HTableForm"
  20. import {getStoreData, setStoreData, delStoreData} from "~uti/storage";
  21. onMounted(() => {
  22. getExcelHtml()
  23. })
  24. const formData = ref({})
  25. const getExcelHtml = () => {
  26. HTableForm.createForm({
  27. template: data,
  28. tableForm: formData.value,
  29. keys: {},
  30. appId: `#table-form-1`,
  31. onLeftClick: (key) => {
  32. setShiftTableForm(key)
  33. },
  34. })
  35. }
  36. const isCtrlKey = ref(false)
  37. const checkKeyList = ref([])
  38. const copyKeyList = ref(getStoreData('TableFormCopyKeyList') || [])
  39. //设置选择数据
  40. const setShiftTableForm = (key) => {
  41. if (isCtrlKey.value) {
  42. const form = formData.value
  43. const keys = checkKeyList.value
  44. const index = getIndex(keys, 'key', key)
  45. if (index === -1) {
  46. keys.push({key, val: form[key] ?? ''})
  47. } else {
  48. keys.splice(index, 1)
  49. }
  50. checkKeyList.value = keys
  51. HTableForm.setCheckKeyStyle(key, index !== -1)
  52. console.log(keys)
  53. }
  54. }
  55. //全局按键按下监听
  56. document.onkeydown = (event) => {
  57. const {key, ctrlKey} = event
  58. //按下ctrl键
  59. if (ctrlKey && key === 'Control') {
  60. isCtrlKey.value = true
  61. }
  62. //按下复制快捷键
  63. if (ctrlKey && key === 'c') {
  64. const keysList = deepClone(checkKeyList.value)
  65. setStoreData('TableFormCopyKeyList', keysList)
  66. copyKeyList.value = keysList
  67. keysList.forEach(item => {
  68. HTableForm.setCheckKeyStyle(item['key'], true)
  69. })
  70. checkKeyList.value = []
  71. }
  72. //按下粘贴快捷键
  73. if (ctrlKey && key === 'v') {
  74. const keysList = deepClone(copyKeyList.value)
  75. const checkList = checkKeyList.value
  76. checkList.forEach(item => {
  77. if (keysList.length > 0) {
  78. formData.value[item['key']] = keysList[0]?.val ?? item['val']
  79. keysList.splice(0, 1) //删除第一个元素
  80. }
  81. HTableForm.setCheckKeyStyle(item['key'], true)
  82. })
  83. //清除缓存
  84. checkKeyList.value = []
  85. copyKeyList.value = []
  86. delStoreData('TableFormCopyKeyList')
  87. }
  88. }
  89. //全局键盘放开监听
  90. document.onkeyup = (event) => {
  91. const {key, ctrlKey} = event
  92. if (!ctrlKey && key === 'Control') {
  93. isCtrlKey.value = false
  94. }
  95. }
  96. onUnmounted(() => {
  97. document.onkeydown = null
  98. document.onkeyup = null
  99. })
  100. </script>
  101. <style lang="scss">
  102. //插入特殊字符弹窗的输入框
  103. .hc-table-form-data-item .hc-excel-table-form td,
  104. .hc-table-form-data-item .hc-excel-table-form td .el-input .el-input__wrapper .el-input__inner,
  105. .el-form-item.special-form-item .el-form-item__content .el-input .el-input__wrapper .el-input__inner {
  106. font-family: "EUDC", 宋体, v-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol" !important;
  107. }
  108. .hc-table-form-data-item {
  109. position: relative;
  110. padding: 12px;
  111. height: 100%;
  112. overflow: hidden;
  113. background-color: white;
  114. .hc-excel-table-form {
  115. position: relative;
  116. display: flex;
  117. padding: 10px;
  118. justify-content: center;
  119. td {
  120. padding: 6px;
  121. .el-input {
  122. background-color: #ffffff !important;
  123. border-radius: 3px;
  124. color: #606266;
  125. .el-input__wrapper {
  126. background-color: inherit;
  127. caret-color: var(--el-color-primary);
  128. }
  129. .el-input__suffix-inner {
  130. width: 18px;
  131. }
  132. }
  133. .el-textarea {
  134. width: 100%;
  135. height: 100%;
  136. .el-textarea__inner {
  137. min-height: initial !important;
  138. background-color: #ffffff;
  139. border-radius: 3px;
  140. color: #606266;
  141. height: 100%;
  142. caret-color: var(--el-color-primary);
  143. }
  144. }
  145. //日期选择框
  146. .el-date-editor.el-input .el-input__wrapper,
  147. .el-date-editor.el-date-editor--datetimerange.el-input__wrapper {
  148. height: 100%;
  149. width: 100%;
  150. }
  151. //焦点
  152. .el-input .el-input__wrapper.is-focus, .el-input .el-input__wrapper:hover,
  153. .el-textarea .el-textarea__inner:hover {
  154. box-shadow: 0 0 0 1.5px var(--el-input-focus-border-color) inset;
  155. background-color: #eddac4;
  156. }
  157. //公式
  158. &[gscolor] {
  159. .el-input, .el-textarea .el-textarea__inner {
  160. background-color: #dcdcdc !important;
  161. }
  162. }
  163. //文本选中颜色
  164. .el-input .el-input__wrapper input,
  165. .el-textarea textarea {
  166. &::selection {
  167. background: var(--el-color-primary-light-9);
  168. color: var(--el-color-primary);
  169. }
  170. &::-moz-selection {
  171. background: var(--el-color-primary-light-9);
  172. color: var(--el-color-primary);
  173. }
  174. }
  175. //下拉框
  176. .el-select {
  177. width: 100%;
  178. height: 100%;
  179. }
  180. }
  181. //非输入框颜色
  182. td:not([titlexx]), td[titlexx*=''],
  183. td:not([title]), td[title*=''] {
  184. background-color: white !important;
  185. user-select: none;
  186. }
  187. }
  188. .hc-no-table-form {
  189. position: relative;
  190. height: 100%;
  191. display: flex;
  192. justify-content: center;
  193. align-items: center;
  194. .table-form-no {
  195. position: relative;
  196. img {
  197. width: 350px;
  198. }
  199. .desc {
  200. text-align: center;
  201. font-size: 20px;
  202. color: #aaa;
  203. }
  204. }
  205. }
  206. }
  207. </style>