|
@@ -0,0 +1,130 @@
|
|
|
+import { createApp } from 'vue/dist/vue.esm-bundler.js'
|
|
|
+
|
|
|
+//自定义组件或二次封装的组件
|
|
|
+import HcTableFormUpload from '~com/plugins/table-form/hc-form-upload.vue'
|
|
|
+import HcFormSelectSearch from '~com/plugins/table-form/hc-form-select-search.vue'
|
|
|
+import HcFormSelectSearch2 from '~com/plugins/table-form/hc-form-select-search2.vue'
|
|
|
+import HcFormCheckboxGroup from '~com/plugins/table-form/hc-form-checkbox-group.vue'
|
|
|
+import ElTimePicker from '~com/plugins/table-form/hc-time-picker.vue'
|
|
|
+import ElDatePicker from '~com/plugins/table-form/hc-date-picker-1.vue'
|
|
|
+import ElRadioGroup from '~com/plugins/table-form/hc-form-radio-group.vue'
|
|
|
+import HcEchart from '~com/plugins/table-form/echart.vue'
|
|
|
+
|
|
|
+const components = {
|
|
|
+ ElDatePicker, ElTimePicker, HcTableFormUpload, ElRadioGroup,
|
|
|
+ HcFormSelectSearch, HcFormSelectSearch2, HcFormCheckboxGroup, HcEchart,
|
|
|
+}
|
|
|
+
|
|
|
+//表单渲染
|
|
|
+export default class HTableForm {
|
|
|
+
|
|
|
+ static tableFormApp = null
|
|
|
+ static tableFormVM = null
|
|
|
+
|
|
|
+ static createForm({ template, tableForm, appId, onRight, onBlur, onLeftClick, onFormDataChange }) {
|
|
|
+ const app = createApp({
|
|
|
+ //自定义组件,需要把饿了么的组件,或者自定义组件手动传递进来绑定,否则渲染时,自定义组件不会生效
|
|
|
+ components,
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ formData: tableForm,
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //监听数据,伪双向绑定(v-model)
|
|
|
+ watch: {
|
|
|
+ formData: {
|
|
|
+ handler(obj) {
|
|
|
+ tableForm = obj
|
|
|
+ this.formDataChange(obj)
|
|
|
+ },
|
|
|
+ deep: true,
|
|
|
+ },
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ //表单数据改变
|
|
|
+ formDataChange(obj) {
|
|
|
+ if (onFormDataChange) {
|
|
|
+ onFormDataChange(obj)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //改变表单数据
|
|
|
+ setFormData(obj) {
|
|
|
+ this.formData = obj
|
|
|
+ },
|
|
|
+ //鼠标右键菜单
|
|
|
+ contextmenuClick(a, b, c, d, e, f, event) {
|
|
|
+ event.preventDefault()
|
|
|
+ },
|
|
|
+ //鼠标右键事件
|
|
|
+ RightClick(a, b, c, d, e, f, event) {
|
|
|
+ setTimeout(() => {
|
|
|
+ const KeyName = event?.target?.getAttribute('keyname') || ''
|
|
|
+ if (onRight) {
|
|
|
+ event.preventDefault()
|
|
|
+ onRight(event, KeyName)
|
|
|
+ }
|
|
|
+ }, 100)
|
|
|
+ },
|
|
|
+ //焦点事件
|
|
|
+ getInformation() {
|
|
|
+ },
|
|
|
+ //日期选择事件
|
|
|
+ datePickerChange() {},
|
|
|
+ //上传完成
|
|
|
+ formUploadSuccess() {},
|
|
|
+ //删除上传的文件
|
|
|
+ delTableFormFile() {},
|
|
|
+ //失去焦点事件
|
|
|
+ getRegularExpression(event, reg, msg, a, b, leng, type, c, d) {
|
|
|
+ const KeyName = event?.target?.getAttribute('keyname') || ''
|
|
|
+ if (onBlur) {
|
|
|
+ onBlur(event, KeyName, reg, this.formData[KeyName], msg, leng, type, c, d)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ //远程搜索处理
|
|
|
+ formRemoteChange() {},
|
|
|
+ //多选框处理
|
|
|
+ checkboxGroupChange() {},
|
|
|
+ //键盘事件 上键
|
|
|
+ keyupShiftUp() {},
|
|
|
+ //键盘事件 下键
|
|
|
+ keyupShiftDown() {},
|
|
|
+ //键盘事件 左键
|
|
|
+ keyupShiftLeft() {},
|
|
|
+ //键盘事件 右键
|
|
|
+ keyupShiftRight() {},
|
|
|
+ //日期时间框键盘事件
|
|
|
+ dateKeydown() {},
|
|
|
+ //输入左键点击事件
|
|
|
+ inputLeftClick(event, key) {
|
|
|
+ setTimeout(() => {
|
|
|
+ if (onLeftClick) {
|
|
|
+ onLeftClick(key)
|
|
|
+ }
|
|
|
+ }, 100)
|
|
|
+ },
|
|
|
+ setChartRefs() {},
|
|
|
+ },
|
|
|
+ //html标签数据
|
|
|
+ template,
|
|
|
+ })
|
|
|
+ const vm = app.mount(appId)
|
|
|
+ this.tableFormApp = app
|
|
|
+ this.tableFormVM = vm
|
|
|
+ return { app, vm }
|
|
|
+ }
|
|
|
+
|
|
|
+ //卸载全局按键监听
|
|
|
+ static unmountEventKey() {
|
|
|
+ document.onkeydown = null
|
|
|
+ document.onkeyup = null
|
|
|
+ }
|
|
|
+
|
|
|
+ //卸载实例
|
|
|
+ static unmountFormApp() {
|
|
|
+ if (this.tableFormApp) {
|
|
|
+ this.tableFormApp?.unmount()
|
|
|
+ this.tableFormApp = null
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|