Browse Source

修复 插入频率,在生成的频率表中再次插入频率数据,插入的数据没有回显出来

ZaiZai 1 year ago
parent
commit
4cbaee1a7c
3 changed files with 26 additions and 223 deletions
  1. 5 1
      src/components/table-form/index.vue
  2. 15 19
      src/plugins/HTableForm.js
  3. 6 203
      src/test/index.vue

+ 5 - 1
src/components/table-form/index.vue

@@ -74,6 +74,7 @@ const colsKeys = ref(props.cols)
 
 //样式
 const tableFormApp = ref(null)
+const tableFormVM = ref(null)
 const tableFormStyle = ref('')
 const isTableForm = ref(false)
 
@@ -166,7 +167,7 @@ const getExcelHtml = () => {
     if (temp && pkeyId) {
         //渲染表单
         isTableForm.value = true
-        tableFormApp.value = HTableForm.createForm({
+        const {app, vm} = HTableForm.createForm({
             pid: pid,
             template: temp,
             keys: colsKeys.value,
@@ -187,6 +188,8 @@ const getExcelHtml = () => {
                 setShiftTableForm(key, pid)
             },
         })
+        tableFormApp.value = app
+        tableFormVM.value = vm
         excelForm.value.isRenderForm = true
         nextTick(() => {
             HTableForm.setByClassKeyup(colsKeys.value, pid)
@@ -355,6 +358,7 @@ const getFormData = () => {
 //设置表单数据
 const setFormData = (data) => {
     excelForm.value = data
+    tableFormVM.value?.setFormData(excelForm.value)
 }
 
 //获取表单效验数据

+ 15 - 19
src/plugins/HTableForm.js

@@ -29,8 +29,9 @@ const components = {
 export default class HTableForm {
 
     static tableFormApp = null
+    static tableFormVM = null
 
-    static createForm({template, tableForm, keys, appId, pid, onRight, onBlur, onLeftClick, onFormDataChange}) 
+    static createForm({template, tableForm, keys, appId, pid, onRight, onBlur, onLeftClick, onFormDataChange})
     {
         const _this = this;
         const app = createApp({
@@ -46,12 +47,6 @@ export default class HTableForm {
             components,
             //监听数据,伪双向绑定(v-model)
             watch: {
-                tableForm: {
-                    handler(obj) {
-                        this.formData = obj
-                    },
-                    deep: true
-                },
                 formData: {
                     handler(obj) {
                         tableForm = obj
@@ -147,13 +142,14 @@ export default class HTableForm {
                 },
             }
         })
-        app.mount(appId)
+        const vm = app.mount(appId)
         this.tableFormApp = app
-        return app
+        this.tableFormVM = vm
+        return {app, vm}
     }
 
     //处理日期范围数据
-    static setPickerKey(data) 
+    static setPickerKey(data)
     {
         const pickerKey = data['pickerKey'] || ''
         if (pickerKey) {
@@ -172,7 +168,7 @@ export default class HTableForm {
     }
 
     //处理日期时间框的切换事件
-    static setByClassKeyup(keys, pid = '') 
+    static setByClassKeyup(keys, pid = '')
     {
         try {
             let poppers = document.getElementsByClassName('hc-table-form-date-picker')
@@ -193,7 +189,7 @@ export default class HTableForm {
     }
 
     //设置事件
-    static setElementsEvent(elements, key, keys, pid = '') 
+    static setElementsEvent(elements, key, keys, pid = '')
     {
         if (elements.length > 0) {
             const _this = this;
@@ -215,7 +211,7 @@ export default class HTableForm {
     }
 
     //计算上下左右快捷键的
-    static setKeyupData({target}, type, keys, pid = '') 
+    static setKeyupData({target}, type, keys, pid = '')
     {
         const key = target.id
         //处理快捷键数据和事件
@@ -278,7 +274,7 @@ export default class HTableForm {
     }
 
     //设置元素焦点
-    static setElementFocus(key, pid) 
+    static setElementFocus(key, pid)
     {
         if (key) {
             try {
@@ -289,7 +285,7 @@ export default class HTableForm {
     }
 
     //获取表单元素
-    static getQuerySelector(key, pid = '') 
+    static getQuerySelector(key, pid = '')
     {
         let dom;
         if (pid) {
@@ -301,7 +297,7 @@ export default class HTableForm {
     }
 
     //设置表单样式
-    static setFormStyle(key, name = 'hc-red-border', pid = '', add = false) 
+    static setFormStyle(key, name = 'hc-red-border', pid = '', add = false)
     {
         const dom = this.getQuerySelector(key, pid)
         const parent = dom?.parentElement ?? ''
@@ -313,7 +309,7 @@ export default class HTableForm {
         }
     }
 
-    static setFormClass(dom, name = 'hc-red-border', add = false) 
+    static setFormClass(dom, name = 'hc-red-border', add = false)
     {
         const classStr = dom.getAttribute('class')
         const classArr = classStr.split(' ')
@@ -327,7 +323,7 @@ export default class HTableForm {
     }
 
     //设置选中样式
-    static setCheckKeyStyle(key, pid = '', remove = false) 
+    static setCheckKeyStyle(key, pid = '', remove = false)
     {
         if (remove) {
             this.setFormStyle(key, 'hc-green-border', pid)
@@ -337,7 +333,7 @@ export default class HTableForm {
     }
 
     //设置全局按键监听
-    static setOnEventKey({onCtrlDown, onCtrlDownC, onCtrlDownV, onCtrlUp}) 
+    static setOnEventKey({onCtrlDown, onCtrlDownC, onCtrlDownV, onCtrlUp})
     {
         //全局按键按下监听
         document.onkeydown = (event) => {

+ 6 - 203
src/test/index.vue

@@ -1,217 +1,20 @@
 <template>
     <div class="hc-page-box">
-        <HcCard>
+        <HcCard scrollbar>
             <template #header>
-                <el-button type="primary">查看表单</el-button>
+                <el-button type="primary">按钮</el-button>
             </template>
-            <div class="hc-table-form-data-item">
-                <el-scrollbar>
-                    <div id="table-form-1" class="hc-excel-table-form"/>
-                </el-scrollbar>
-            </div>
+
         </HcCard>
     </div>
 </template>
 
 <script setup>
-import {onMounted, onUnmounted, ref} from "vue";
-import {data} from './data.js'
-import {arrIndex, deepClone} from "js-fast-way"
-import HTableForm from "~src/plugins/HTableForm"
-import {getStoreValue, setStoreValue, delStoreValue} from "~uti/storage";
+import {nextTick, onMounted, ref} from "vue";
+import { getRandomFrom } from "js-fast-way"
+//import {data} from './data.js'
 
 onMounted(() => {
-    getExcelHtml()
-})
-
-const formData = ref({})
-
-const getExcelHtml = () => {
-    HTableForm.createForm({
-        template: data,
-        tableForm: formData.value,
-        keys: {},
-        appId: `#table-form-1`,
-        onLeftClick: (key) => {
-            setShiftTableForm(key)
-        },
-    })
-}
-
-const isCtrlKey = ref(false)
-const checkKeyList = ref([])
-const copyKeyList = ref(getStoreValue('TableFormCopyKeyList') || [])
 
-//设置选择数据
-const setShiftTableForm = (key) => {
-    if (isCtrlKey.value) {
-        const form = formData.value
-        const keys = checkKeyList.value
-        const index = arrIndex(keys, 'key', key)
-        if (index === -1) {
-            keys.push({key, val: form[key] ?? ''})
-        } else {
-            keys.splice(index, 1)
-        }
-        checkKeyList.value = keys
-        HTableForm.setCheckKeyStyle(key, index !== -1)
-        console.log(keys)
-    }
-}
-
-//全局按键按下监听
-document.onkeydown = (event) => {
-    const {key, ctrlKey} = event
-    //按下ctrl键
-    if (ctrlKey && key === 'Control') {
-        isCtrlKey.value = true
-    }
-    //按下复制快捷键
-    if (ctrlKey && key === 'c') {
-        const keysList = deepClone(checkKeyList.value)
-        setStoreValue('TableFormCopyKeyList', keysList)
-        copyKeyList.value = keysList
-        keysList.forEach(item => {
-            HTableForm.setCheckKeyStyle(item['key'], true)
-        })
-        checkKeyList.value = []
-    }
-    //按下粘贴快捷键
-    if (ctrlKey && key === 'v') {
-        const keysList = deepClone(copyKeyList.value)
-        const checkList = checkKeyList.value
-        checkList.forEach(item => {
-            if (keysList.length > 0) {
-                formData.value[item['key']] = keysList[0]?.val ?? item['val']
-                keysList.splice(0, 1) //删除第一个元素
-            }
-            HTableForm.setCheckKeyStyle(item['key'], true)
-        })
-        //清除缓存
-        checkKeyList.value = []
-        copyKeyList.value = []
-        delStoreValue('TableFormCopyKeyList')
-    }
-}
-
-//全局键盘放开监听
-document.onkeyup = (event) => {
-    const {key, ctrlKey} = event
-    if (!ctrlKey && key === 'Control') {
-        isCtrlKey.value = false
-    }
-}
-
-onUnmounted(() => {
-    document.onkeydown = null
-    document.onkeyup = null
 })
 </script>
-
-<style lang="scss">
-//插入特殊字符弹窗的输入框
-.hc-table-form-data-item .hc-excel-table-form td,
-.hc-table-form-data-item .hc-excel-table-form td .el-input .el-input__wrapper .el-input__inner,
-.el-form-item.special-form-item .el-form-item__content .el-input .el-input__wrapper .el-input__inner {
-    font-family: "EUDC", 宋体, v-sans, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol" !important;
-}
-.hc-table-form-data-item {
-    position: relative;
-    padding: 12px;
-    height: 100%;
-    overflow: hidden;
-    background-color: white;
-    .hc-excel-table-form {
-        position: relative;
-        display: flex;
-        padding: 10px;
-        justify-content: center;
-        td {
-            padding: 6px;
-            .el-input {
-                background-color: #ffffff !important;
-                border-radius: 3px;
-                color: #606266;
-                .el-input__wrapper {
-                    background-color: inherit;
-                    caret-color: var(--el-color-primary);
-                }
-                .el-input__suffix-inner {
-                    width: 18px;
-                }
-            }
-            .el-textarea {
-                width: 100%;
-                height: 100%;
-                .el-textarea__inner {
-                    min-height: initial !important;
-                    background-color: #ffffff;
-                    border-radius: 3px;
-                    color: #606266;
-                    height: 100%;
-                    caret-color: var(--el-color-primary);
-                }
-            }
-            //日期选择框
-            .el-date-editor.el-input .el-input__wrapper,
-            .el-date-editor.el-date-editor--datetimerange.el-input__wrapper {
-                height: 100%;
-                width: 100%;
-            }
-            //焦点
-            .el-input .el-input__wrapper.is-focus, .el-input .el-input__wrapper:hover,
-            .el-textarea .el-textarea__inner:hover {
-                box-shadow: 0 0 0 1.5px var(--el-input-focus-border-color) inset;
-                background-color: #eddac4;
-            }
-            //公式
-            &[gscolor] {
-                .el-input, .el-textarea .el-textarea__inner {
-                    background-color: #dcdcdc !important;
-                }
-            }
-            //文本选中颜色
-            .el-input .el-input__wrapper input,
-            .el-textarea textarea {
-                &::selection {
-                    background: var(--el-color-primary-light-9);
-                    color: var(--el-color-primary);
-                }
-                &::-moz-selection {
-                    background: var(--el-color-primary-light-9);
-                    color: var(--el-color-primary);
-                }
-            }
-            //下拉框
-            .el-select {
-                width: 100%;
-                height: 100%;
-            }
-        }
-        //非输入框颜色
-        td:not([titlexx]), td[titlexx*=''],
-        td:not([title]), td[title*=''] {
-            background-color: white !important;
-            user-select: none;
-        }
-    }
-    .hc-no-table-form {
-        position: relative;
-        height: 100%;
-        display: flex;
-        justify-content: center;
-        align-items: center;
-        .table-form-no {
-            position: relative;
-            img {
-                width: 350px;
-            }
-            .desc {
-                text-align: center;
-                font-size: 20px;
-                color: #aaa;
-            }
-        }
-    }
-}
-</style>