el-plus-crud 0.0.113 → 0.0.114

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -46,8 +46,8 @@ export default {
46
46
  </script>
47
47
  <script lang="ts" setup>
48
48
  import { ref, computed, useAttrs, nextTick, onMounted, watch, inject, Ref } from 'vue'
49
- import { castArray, isMobile, time, throttle, isPromiseLike } from './util'
50
- import { cloneDeep } from 'lodash'
49
+ import { castArray, isMobile, time, isPromiseLike } from './util'
50
+ import { cloneDeep, throttle } from 'lodash'
51
51
  import * as validates from './util/validate'
52
52
  import { typeList } from './components/index'
53
53
  import ElPlusFormBtn from './components/ElPlusFormBtn.vue'
@@ -106,6 +106,10 @@ export interface IFormProps {
106
106
  idKey?: string
107
107
  // 最大宽度
108
108
  maxWidth?: string
109
+ // 是否是group的Form
110
+ isGroupForm?: boolean
111
+ // 是否禁用最后一个元素的tab
112
+ disabledTab?: boolean
109
113
  // 比如 beforeValidate, beforeRequest, success, requestError, requestEnd
110
114
  // 其他钩子 直接放到attrs里面去了
111
115
  }
@@ -162,7 +166,9 @@ const props = withDefaults(defineProps<IFormProps>(), {
162
166
  // 是否是列表头部的表单
163
167
  isTable: false,
164
168
  // 唯一标识符。默认为id
165
- idKey: 'id'
169
+ idKey: 'id',
170
+ // 是否禁用最后一个元素的tab
171
+ disabledTab: false
166
172
  // 其他钩子 直接放到attrs里面去了
167
173
  // 比如 beforeValidate, beforeRequest, success, requestError, requestEnd
168
174
  })
@@ -275,9 +281,10 @@ const computedRules = computed(() => {
275
281
  const attrMapToTableList = computed(() => {
276
282
  const formLayoutRows = [] as Array<Array<IFormDescItem>>
277
283
  if (props.formDesc) {
284
+ const tempFormDesc = cloneDeep(props.formDesc)
278
285
  let tempData = [] as Array<IFormDescItem>
279
- for (const key in props.formDesc) {
280
- tempData.push({ ...props.formDesc[key], field: key })
286
+ for (const key in tempFormDesc) {
287
+ tempData.push({ ...tempFormDesc[key], field: key })
281
288
  }
282
289
  // 这里处理一下layout的布局-渲染
283
290
  let rowItemList = [] as Array<IFormDescItem>
@@ -302,6 +309,30 @@ const attrMapToTableList = computed(() => {
302
309
  formLayoutRows.push(rowItemList)
303
310
  }
304
311
  }
312
+
313
+ // 这里处理下是否禁用最后一个元素的tab
314
+ if (formLayoutRows?.length && props.disabledTab && (!props.isGroupForm || (props.isGroupForm && props.groupFormDesc))) {
315
+ for (let i = formLayoutRows[formLayoutRows.length - 1].length - 1; i >= 0; i--) {
316
+ const type = formLayoutRows[formLayoutRows.length - 1][i].type || ''
317
+ if (['image', 'link', 'rate', 'status', 'tag', 'text'].indexOf(type) < 0) {
318
+ const eventOn = formLayoutRows[formLayoutRows.length - 1][i].on || {}
319
+ const oldFocus = eventOn.focus
320
+ const oldBlur = eventOn.blur
321
+ eventOn.focus = function () {
322
+ document.onkeydown = (event) => {
323
+ if (event.keyCode == 9) return false
324
+ }
325
+ oldFocus && oldFocus()
326
+ }
327
+ eventOn.blur = function () {
328
+ document.onkeydown = function () {}
329
+ oldBlur && oldBlur()
330
+ }
331
+ formLayoutRows[formLayoutRows.length - 1][i].on = eventOn
332
+ break
333
+ }
334
+ }
335
+ }
305
336
  return formLayoutRows
306
337
  })
307
338
 
@@ -746,7 +777,7 @@ const clear = () => {
746
777
  * @param field
747
778
  */
748
779
  function handelValidateThis(field: string) {
749
- refElPlusForm.value.validateField(field, (err: any) => {
780
+ refElPlusForm.value?.validateField(field, (err: any) => {
750
781
  // console.log('err: ', err)
751
782
  })
752
783
  }
@@ -833,7 +864,7 @@ defineExpose({ fid: props.fid, submit: handleSubmitForm, getData: getFormData, v
833
864
  border-radius: 4px;
834
865
  }
835
866
  .el-plus-form-column-panel {
836
- & > .el-form-item--default {
867
+ & > .el-form-item {
837
868
  margin-bottom: 18px !important;
838
869
  // & > .el-form-item__label-wrap {
839
870
  & > .el-form-item__label {
@@ -7,7 +7,7 @@
7
7
  <slot :name="'title' + indexList[i]">
8
8
  <div class="title-line" v-if="group.title">{{ group.title }}</div>
9
9
  </slot>
10
- <ElPlusForm v-model="currentValue" v-bind="group.formProps" :ref="setComponentRef" @reset="handleReset(group.formProps?.fid || '')">
10
+ <ElPlusForm v-model="currentValue" v-bind="group.formProps" isGroupForm :ref="setComponentRef" @reset="handleReset(group.formProps?.fid || '')">
11
11
  <template v-if="useSlots()['default' + indexList[i]]">
12
12
  <slot :name="'default' + indexList[i]"> </slot>
13
13
  </template>
@@ -38,6 +38,8 @@ const props = defineProps<{
38
38
  formGroup: IFormGroupConfig
39
39
  // 提交状态
40
40
  isLoading?: boolean
41
+ // 是否禁用最后一个元素的tab
42
+ disabledTab?: boolean
41
43
  }>()
42
44
 
43
45
  const formRefs = ref([] as any[])
@@ -100,6 +102,7 @@ const getGroupFowmLayout = computed(() => {
100
102
  tempGroupList.map((item) => {
101
103
  Object.assign(tempFormConfig.groupFormDesc, item.formDesc)
102
104
  })
105
+ tempFormConfig.disabledTab = props.disabledTab
103
106
 
104
107
  // 遍历
105
108
  tempGroupList.map((groupItem, i) => {
@@ -530,7 +530,7 @@ async function getListQueryData() {
530
530
  queryMap.size = pageInfo.size
531
531
  }
532
532
  // 这里处理一下列表Tab的查询条件
533
- if (props.tableConfig?.tabConf && props.tableConfig?.tabConf.prop) {
533
+ if (props.tableConfig?.tabConf && props.tableConfig?.tabConf?.prop) {
534
534
  queryMap[props.tableConfig?.tabConf.prop] = tableTabVal.value
535
535
  }
536
536
 
@@ -751,17 +751,28 @@ function initCol() {
751
751
  }
752
752
 
753
753
  // 监听父类数据变更
754
+ // watch(
755
+ // () => props.modelValue,
756
+ // (data) => {
757
+ // if (!props.tableConfig.fetch) {
758
+ // console.log('watch modelValue data: ', data)
759
+ // }
760
+ // }
761
+ // )
754
762
  watch(
755
763
  () => props.modelValue,
756
764
  (data) => {
757
765
  if (!props.tableConfig.fetch) {
758
- if (JSON.parse(JSON.stringify(data)) !== JSON.parse(JSON.stringify(tableData.value))) {
766
+ // console.log('watch modelValue data: ', data)
767
+ // if (JSON.parse(JSON.stringify(data)) !== JSON.parse(JSON.stringify(tableData.value))) {
768
+ // 优化代码,这里就直接比较一下length就行了
769
+ if (data?.length !== tableData.value?.length) {
759
770
  loadingStatus.value = 2
760
- tableData.value.splice(0, tableData.value.length, ...(data || []))
771
+ tableData.value?.splice(0, tableData.value.length, ...(data || []))
761
772
  }
762
773
  }
763
- },
764
- { deep: true }
774
+ }
775
+ // { deep: true }
765
776
  )
766
777
 
767
778
  watch(
package/package-lock.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "el-plus-crud",
3
- "version": "0.0.113",
3
+ "version": "0.0.114",
4
4
  "lockfileVersion": 3,
5
5
  "requires": true,
6
6
  "packages": {
7
7
  "": {
8
8
  "name": "el-plus-crud",
9
- "version": "0.0.113",
9
+ "version": "0.0.114",
10
10
  "license": "MIT",
11
11
  "dependencies": {
12
12
  "@element-plus/icons-vue": "^2.1.0",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "el-plus-crud",
3
3
  "description": "采用Vue3 + TS,封装的element-plus数据驱动表单、列表组件",
4
4
  "author": "K.D.Jack",
5
- "version": "0.0.113",
5
+ "version": "0.0.114",
6
6
  "license": "MIT",
7
7
  "private": false,
8
8
  "main": "dist/el-plus-crud.mjs",
package/types/index.d.ts CHANGED
@@ -74,6 +74,8 @@ export type IDescItem = {
74
74
  _vif?: boolean
75
75
  // 权限
76
76
  auth?: string
77
+ // 其他字符串
78
+ [key: string]: any
77
79
  }
78
80
 
79
81
  /**
@@ -314,7 +316,7 @@ export interface IStatisticConfig {
314
316
  * 列表的选项卡配置
315
317
  */
316
318
  export interface ITableTabConf {
317
- prop: string
319
+ prop?: string
318
320
  tabs: Array<ITableTabItem>
319
321
  attrs?: IBaseObj | Function
320
322
  // 远程拉取数量信息