|
@@ -2,9 +2,9 @@
|
|
|
<div :id="`table-form-item-${keyId}`" v-loading="isLoading" :class="!isTableForm? 'no-scroll-bar' : ''"
|
|
|
:style="tableFormStyle" class="hc-table-form-data-item">
|
|
|
<el-scrollbar v-if="isScroll" class="table-form-item-scrollbar">
|
|
|
- <div :id="`table-form-${keyId}`" class="hc-excel-table-form"/>
|
|
|
+ <div :id="`table-form-${keyId}`" class="hc-excel-table-form" @click.capture="excelTableFormClick"/>
|
|
|
</el-scrollbar>
|
|
|
- <div v-else :id="`table-form-${keyId}`" class="hc-excel-table-form"/>
|
|
|
+ <div v-else :id="`table-form-${keyId}`" class="hc-excel-table-form" @click.capture="excelTableFormClick"/>
|
|
|
<div v-if="!isTableForm" class="hc-no-table-form">
|
|
|
<div class="table-form-no">
|
|
|
<img :src="notableform" alt=""/>
|
|
@@ -19,7 +19,7 @@ import {ref, watch, onMounted, nextTick, onUnmounted} from "vue"
|
|
|
import HTableForm from "~src/plugins/HTableForm"
|
|
|
import notableform from '~src/assets/view/notableform.svg'
|
|
|
import {getStoreData, setStoreData, delStoreData} from "~uti/storage";
|
|
|
-import {getObjNullValue, isString, deepClone, getIndex} from "vue-utils-plus"
|
|
|
+import {getObjNullValue, getArrValue, isString, deepClone, getIndex} from "vue-utils-plus"
|
|
|
|
|
|
//初始
|
|
|
const props = defineProps({
|
|
@@ -54,6 +54,10 @@ const props = defineProps({
|
|
|
type: Boolean,
|
|
|
default: true
|
|
|
},
|
|
|
+ pid: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
//初始变量
|
|
@@ -61,6 +65,7 @@ const keyId = ref(props.pkey)
|
|
|
const noTips = ref(props.noTip)
|
|
|
const isScroll = ref(props.scroll)
|
|
|
const isLoading = ref(props.loading)
|
|
|
+const activeKey = ref(props.pid)
|
|
|
|
|
|
//表单数据
|
|
|
const excelHtml = ref(props.html)
|
|
@@ -73,11 +78,14 @@ const tableFormStyle = ref('')
|
|
|
const isTableForm = ref(false)
|
|
|
|
|
|
//监听
|
|
|
-watch(() => [props.pkey, props.noTip, props.scroll, props.loading, props.width, props.height], ([pkey, tip, scroll, loading, width, height]) => {
|
|
|
+watch(() => [
|
|
|
+ props.pkey, props.noTip, props.scroll, props.loading, props.width, props.height, props.pid
|
|
|
+], ([pkey, tip, scroll, loading, width, height, pid]) => {
|
|
|
keyId.value = pkey
|
|
|
noTips.value = tip
|
|
|
isScroll.value = scroll
|
|
|
isLoading.value = loading
|
|
|
+ activeKey.value = pid
|
|
|
setItemStyle(width, height)
|
|
|
})
|
|
|
|
|
@@ -124,7 +132,12 @@ const setItemStyle = (width, height) => {
|
|
|
}
|
|
|
|
|
|
//事件
|
|
|
-const emit = defineEmits(['rightTap', 'render'])
|
|
|
+const emit = defineEmits(['rightTap', 'render', 'excelBodyTap'])
|
|
|
+
|
|
|
+//表单被点击
|
|
|
+const excelTableFormClick = () => {
|
|
|
+ emit('excelBodyTap', keyId.value)
|
|
|
+}
|
|
|
|
|
|
//获取已填写的数据
|
|
|
const setPickerKey = () => {
|
|
@@ -147,30 +160,31 @@ const setExcelHtml = () => {
|
|
|
|
|
|
//获取模板标签数据
|
|
|
const getExcelHtml = () => {
|
|
|
- const pkeyId = keyId.value
|
|
|
+ const pkeyId = keyId.value, pid = activeKey.value;
|
|
|
const temp = isString(excelHtml.value) ? excelHtml.value : ''
|
|
|
if (temp && pkeyId) {
|
|
|
//渲染表单
|
|
|
isTableForm.value = true
|
|
|
tableFormApp.value = HTableForm.createForm({
|
|
|
+ pid: pid,
|
|
|
template: temp,
|
|
|
tableForm: excelForm.value,
|
|
|
keys: colsKeys.value,
|
|
|
appId: `#table-form-${pkeyId}`,
|
|
|
onRight: (event, KeyName) => {
|
|
|
- onRightClick(pkeyId, event, KeyName)
|
|
|
+ onRightClick(pkeyId, event, KeyName, pid)
|
|
|
},
|
|
|
//表单正则效验
|
|
|
onBlur: (event, key, reg, val, msg) => {
|
|
|
- setTableFormBlurReg(pkeyId, event, key, reg, val, msg)
|
|
|
+ setTableFormBlurReg(pkeyId, event, key, reg, val, msg, pid)
|
|
|
},
|
|
|
onLeftClick: (key) => {
|
|
|
- setShiftTableForm(key)
|
|
|
+ setShiftTableForm(key, pid)
|
|
|
},
|
|
|
})
|
|
|
excelForm.value.isRenderForm = true
|
|
|
nextTick(() => {
|
|
|
- HTableForm.setByClassKeyup(colsKeys.value)
|
|
|
+ HTableForm.setByClassKeyup(colsKeys.value, pid)
|
|
|
})
|
|
|
emit('render', excelForm.value)
|
|
|
} else {
|
|
@@ -182,7 +196,7 @@ const getExcelHtml = () => {
|
|
|
|
|
|
//正则效验
|
|
|
const formRegExpJson = ref({})
|
|
|
-const setTableFormBlurReg = (pkeyId, event, key, reg, val, msg) => {
|
|
|
+const setTableFormBlurReg = (pkeyId, event, key, reg, val, msg, pid) => {
|
|
|
const dom = document.getElementById(key)?.parentElement ?? ''
|
|
|
if (dom) {
|
|
|
if (val && reg) {
|
|
@@ -190,15 +204,15 @@ const setTableFormBlurReg = (pkeyId, event, key, reg, val, msg) => {
|
|
|
let state = regx.test(val);
|
|
|
if (state) {
|
|
|
delete formRegExpJson.value[key]
|
|
|
- HTableForm.setFormStyle(key, 'hc-red-border')
|
|
|
+ HTableForm.setFormStyle(key, 'hc-red-border', pid)
|
|
|
} else {
|
|
|
formRegExpJson.value[key] = {key, reg, val, msg, state}
|
|
|
- HTableForm.setFormStyle(key, 'hc-red-border', true)
|
|
|
+ HTableForm.setFormStyle(key, 'hc-red-border', pid, true)
|
|
|
window?.$message?.warning(msg)
|
|
|
}
|
|
|
} else {
|
|
|
delete formRegExpJson.value[key]
|
|
|
- HTableForm.setFormStyle(key, 'hc-red-border')
|
|
|
+ HTableForm.setFormStyle(key, 'hc-red-border', pid)
|
|
|
}
|
|
|
} else {
|
|
|
delete formRegExpJson.value[key]
|
|
@@ -206,20 +220,20 @@ const setTableFormBlurReg = (pkeyId, event, key, reg, val, msg) => {
|
|
|
}
|
|
|
|
|
|
//鼠标右键事件
|
|
|
-const onRightClick = (pkeyId, event, KeyName) => {
|
|
|
+const onRightClick = (pkeyId, event, KeyName, pid) => {
|
|
|
//取光标位置
|
|
|
- const specialDom = document.getElementById(KeyName + "")
|
|
|
+ const specialDom = HTableForm.getQuerySelector(KeyName, pid)
|
|
|
+ //const specialDom = document.getElementById(KeyName + "")
|
|
|
const startPos = specialDom?.selectionStart || 0
|
|
|
const endPos = specialDom?.selectionEnd || 0
|
|
|
- emit('rightTap', {event, KeyName, startPos, endPos, pkeyId})
|
|
|
+ emit('rightTap', {event, KeyName, startPos, endPos, pkeyId, pid})
|
|
|
}
|
|
|
|
|
|
const isCtrlKey = ref(false)
|
|
|
const checkKeyList = ref([])
|
|
|
-const copyKeyList = ref(getStoreData('TableFormCopyKeyList') || [])
|
|
|
|
|
|
//设置选择数据
|
|
|
-const setShiftTableForm = (key) => {
|
|
|
+const setShiftTableForm = (key, pid) => {
|
|
|
if (isCtrlKey.value) {
|
|
|
const form = excelForm.value
|
|
|
const keys = checkKeyList.value
|
|
@@ -230,94 +244,92 @@ const setShiftTableForm = (key) => {
|
|
|
keys.splice(index, 1)
|
|
|
}
|
|
|
checkKeyList.value = keys
|
|
|
- HTableForm.setCheckKeyStyle(key, index !== -1)
|
|
|
+ HTableForm.setCheckKeyStyle(key, pid, index !== -1)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-//全局按键按下监听
|
|
|
-document.onkeydown = async (event) => {
|
|
|
- const {key, ctrlKey} = event
|
|
|
- //按下ctrl键
|
|
|
- if (ctrlKey && key === 'Control') {
|
|
|
- isCtrlKey.value = true
|
|
|
+//按下ctrl键
|
|
|
+const setIsCtrlKey = (state) => {
|
|
|
+ isCtrlKey.value = state
|
|
|
+ console.log('按下ctrl键')
|
|
|
+}
|
|
|
+
|
|
|
+//按下复制快捷键
|
|
|
+const setCopyKeyList = (event) => {
|
|
|
+ const pid = activeKey.value
|
|
|
+ const keysList = deepClone(checkKeyList.value)
|
|
|
+ if (keysList.length > 0) {
|
|
|
+ event.preventDefault()
|
|
|
+ setStoreData('TableFormCopyKeys', keysList)
|
|
|
+ keysList.forEach(item => {
|
|
|
+ HTableForm.setCheckKeyStyle(item['key'], pid, true)
|
|
|
+ })
|
|
|
+ checkKeyList.value = []
|
|
|
}
|
|
|
- //按下复制快捷键
|
|
|
- if (ctrlKey && key === 'c') {
|
|
|
- const keysList = deepClone(checkKeyList.value)
|
|
|
- if (keysList.length > 0) {
|
|
|
- event.preventDefault()
|
|
|
- setStoreData('TableFormCopyKeyList', keysList)
|
|
|
- copyKeyList.value = keysList
|
|
|
- keysList.forEach(item => {
|
|
|
- HTableForm.setCheckKeyStyle(item['key'], true)
|
|
|
- })
|
|
|
- checkKeyList.value = []
|
|
|
+}
|
|
|
+
|
|
|
+//按下粘贴快捷键
|
|
|
+const setPasteKeyList = async (event) => {
|
|
|
+ let keysList = getArrValue(getStoreData('TableFormCopyKeys'))
|
|
|
+ const checkList = checkKeyList.value
|
|
|
+ if (checkList.length > 0) {
|
|
|
+ event.preventDefault()
|
|
|
+ //粘贴多个
|
|
|
+ if (checkList.length > 1 && keysList.length > 1) {
|
|
|
+ await setMultipleCheckValue(checkList, keysList)
|
|
|
}
|
|
|
- }
|
|
|
- //按下粘贴快捷键
|
|
|
- if (ctrlKey && key === 'v') {
|
|
|
- const keysList = deepClone(copyKeyList.value)
|
|
|
- const checkList = checkKeyList.value
|
|
|
- if (checkList.length > 0) {
|
|
|
- event.preventDefault()
|
|
|
- //粘贴多个
|
|
|
- if (checkList.length > 1 && keysList.length > 1) {
|
|
|
- await setMultipleCheckValue(checkList, keysList)
|
|
|
- }
|
|
|
- //粘贴单个复制
|
|
|
- if (checkList.length > 1 && keysList.length === 1) {
|
|
|
- await setSingleCopyValue(checkList, keysList)
|
|
|
- }
|
|
|
- //复制单个粘贴
|
|
|
- if (checkList.length === 1 && keysList.length > 1) {
|
|
|
- await setCopySingleValue(checkList, keysList)
|
|
|
- }
|
|
|
- //清除缓存
|
|
|
- checkKeyList.value = []
|
|
|
- copyKeyList.value = []
|
|
|
- delStoreData('TableFormCopyKeyList')
|
|
|
+ //粘贴单个复制
|
|
|
+ if (checkList.length > 1 && keysList.length === 1) {
|
|
|
+ await setSingleCopyValue(checkList, keysList)
|
|
|
+ }
|
|
|
+ //复制单个粘贴
|
|
|
+ if (checkList.length === 1 && keysList.length > 1) {
|
|
|
+ await setCopySingleValue(checkList, keysList)
|
|
|
}
|
|
|
+ //清除缓存
|
|
|
+ checkKeyList.value = []
|
|
|
+ delStoreData('TableFormCopyKeys')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//复制单个粘贴
|
|
|
const setCopySingleValue = async (checkList, keysList) => {
|
|
|
+ const keys = deepClone(keysList)
|
|
|
let form_val = '', key = checkList[0]['key']
|
|
|
- const form = excelForm.value
|
|
|
- for (let i = 0; i < keysList.length; i++) {
|
|
|
- const val = form[keysList[i]['key']]
|
|
|
+ for (let i = 0; i < keys.length; i++) {
|
|
|
+ const val = keys[i]['val']
|
|
|
form_val = form_val ? form_val + '、' + val : val
|
|
|
- keysList.splice(0, 1) //删除第一个元素
|
|
|
+ keys.splice(0, 1) //删除第一个元素
|
|
|
}
|
|
|
await setTableFormInfoValue(key, form_val)
|
|
|
- HTableForm.setCheckKeyStyle(key, true)
|
|
|
+ HTableForm.setCheckKeyStyle(key, activeKey.value, true)
|
|
|
}
|
|
|
|
|
|
//粘贴单个复制
|
|
|
const setSingleCopyValue = async (checkList, keysList) => {
|
|
|
- const form = excelForm.value
|
|
|
- const form_val = form[keysList[0]['key']]
|
|
|
+ const keys = deepClone(keysList)
|
|
|
+ const form_val = keys[0]['val']
|
|
|
for (let i = 0; i < checkList.length; i++) {
|
|
|
const {key} = checkList[i]
|
|
|
await setTableFormInfoValue(key, form_val)
|
|
|
- HTableForm.setCheckKeyStyle(key, true)
|
|
|
+ HTableForm.setCheckKeyStyle(key, activeKey.value, true)
|
|
|
}
|
|
|
- keysList.splice(0, 1) //删除第一个元素
|
|
|
+ keys.splice(0, 1) //删除第一个元素
|
|
|
}
|
|
|
|
|
|
//粘贴多个
|
|
|
const setMultipleCheckValue = async (checkList, keysList) => {
|
|
|
- const form = excelForm.value
|
|
|
+ const keys = deepClone(keysList)
|
|
|
for (let i = 0; i < checkList.length; i++) {
|
|
|
const {key, val} = checkList[i]
|
|
|
- if (keysList.length > 0) {
|
|
|
- const form_val = form[keysList[0]['key']]
|
|
|
+ if (keys.length > 0) {
|
|
|
+ const form_val = keys[0]['val']
|
|
|
await setTableFormInfoValue(key, form_val ? form_val : val)
|
|
|
- keysList.splice(0, 1) //删除第一个元素
|
|
|
+ keys.splice(0, 1) //删除第一个元素
|
|
|
} else {
|
|
|
await setTableFormInfoValue(key, val)
|
|
|
}
|
|
|
- HTableForm.setCheckKeyStyle(key, true)
|
|
|
+ HTableForm.setCheckKeyStyle(key, activeKey.value, true)
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -331,20 +343,6 @@ const setTableFormInfoValue = async (key, value) => {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
-//全局键盘放开监听
|
|
|
-document.onkeyup = (event) => {
|
|
|
- const {key, ctrlKey} = event
|
|
|
- if (!ctrlKey && key === 'Control') {
|
|
|
- isCtrlKey.value = false
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-//卸载页面
|
|
|
-onUnmounted(() => {
|
|
|
- document.onkeydown = null
|
|
|
- document.onkeyup = null
|
|
|
-})
|
|
|
-
|
|
|
//获取表单数据
|
|
|
const getFormData = () => {
|
|
|
return excelForm.value
|
|
@@ -385,7 +383,10 @@ defineExpose({
|
|
|
getRegExpJson,
|
|
|
isFormRegExp,
|
|
|
setExcelHtml,
|
|
|
- unmountHtml
|
|
|
+ unmountHtml,
|
|
|
+ setIsCtrlKey,
|
|
|
+ setCopyKeyList,
|
|
|
+ setPasteKeyList
|
|
|
})
|
|
|
</script>
|
|
|
|