el-plus-crud 0.1.38 → 0.1.39

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.
@@ -260,6 +260,7 @@ const computedRules = computed(() => {
260
260
  case 'link':
261
261
  case 'radio':
262
262
  case 'checkbox':
263
+ case 'tree':
263
264
  rules = 'select'
264
265
  break
265
266
  case 'daterange':
@@ -852,7 +853,7 @@ onMounted(async () => {
852
853
  })
853
854
 
854
855
  // 暴露对外方法
855
- defineExpose({ fid: props.fid, submit: handleSubmitForm, getData: getFormData, validate: validateForm, reset, clearValid, clear, changeValidImg, refresh, init })
856
+ defineExpose({ fid: props.fid, formRef: refElPlusForm, submit: handleSubmitForm, getData: getFormData, validate: validateForm, reset, clearValid, clear, changeValidImg, refresh, init })
856
857
  </script>
857
858
  <style lang="scss">
858
859
  .el-plus-form-panel {
@@ -1,5 +1,12 @@
1
1
  <template>
2
- <el-tree ref="treeRef" v-if="isInit" :class="desc.class" :style="desc.style" v-bind="attrs" :disabled="disabled" :default-checked-keys="currentValue" :loading="loading" node-key="id" :data="options" v-on="onEvents" class="el-plus-form-tree" @check-change="handelCheckChange" />
2
+ <div class="el-plus-form-tree">
3
+ <template v-if="attrs.showCheckbox && !attrs.noSelectAll">
4
+ <div class="btns">
5
+ <el-checkbox v-model="selectAll" @change="handelSelectAll" label="全部勾选" border />
6
+ </div>
7
+ </template>
8
+ <el-tree ref="treeRef" v-if="isInit" :class="desc.class" :style="desc.style" v-bind="attrs" :disabled="disabled" :default-checked-keys="currentValue" :loading="loading" node-key="id" :data="options" v-on="onEvents" class="el-plus-form-tree" @check-change="handelCheckChange" />
9
+ </div>
3
10
  </template>
4
11
  <script lang="ts">
5
12
  export default {
@@ -11,13 +18,15 @@ export default {
11
18
  </script>
12
19
  <script lang="ts" setup>
13
20
  import { isEqual } from '../../../util'
14
- import { ref, reactive, useAttrs, onBeforeMount, watch, inject } from 'vue'
21
+ import { ref, reactive, useAttrs, onBeforeMount, watch, inject, nextTick } from 'vue'
15
22
  import { getAttrs, getEvents } from '../mixins'
23
+ import { useVModel } from '@vueuse/core'
24
+ import { cloneDeep } from 'lodash'
16
25
 
17
26
  const globalData = inject('globalData') as any
18
27
 
19
28
  const props = defineProps<{
20
- modelValue?: string
29
+ modelValue?: Array<string>
21
30
  field?: string
22
31
  loading?: boolean
23
32
  desc: { [key: string]: any }
@@ -25,8 +34,8 @@ const props = defineProps<{
25
34
  disabled?: boolean
26
35
  }>()
27
36
 
28
- const emits = defineEmits(['update:modelValue'])
29
- const currentValue = ref(props.modelValue?.split(',') || [])
37
+ const emits = defineEmits(['update:modelValue', 'validateThis'])
38
+ const currentValue = useVModel(props, 'modelValue', emits)
30
39
 
31
40
  const options = reactive([] as any[])
32
41
  const isInit = ref(false)
@@ -34,14 +43,54 @@ const attrs = ref({} as any)
34
43
  const onEvents = ref(getEvents(props))
35
44
 
36
45
  const treeRef = ref()
46
+ const selectAll = ref(false)
47
+ const allIds = ref([] as any[])
37
48
 
38
49
  onBeforeMount(async () => {
39
- attrs.value = await getAttrs(props, { checkStrictly: true, showCheckbox: true, accordion: true, props: { label: 'label', children: 'children' }, ...useAttrs() })
50
+ attrs.value = await getAttrs(props, { checkStrictly: true, showCheckbox: true, accordion: true, noSelectAll: false, props: { label: 'label', children: 'children' }, ...useAttrs() })
51
+ if (attrs.value.showCheckbox && !attrs.value.noSelectAll && options.length) {
52
+ allIds.value = getLoopIds(options)
53
+ }
40
54
  isInit.value = true
41
55
  })
42
56
 
43
- function handelCheckChange() {
44
- emits('update:modelValue', [...treeRef.value!.getCheckedKeys(!(props.desc.isPId ?? true))].join(','))
57
+ /**
58
+ * 处理单个checkbox改变
59
+ */
60
+ function handelCheckChange(item: any, isSelect: boolean) {
61
+ currentValue.value = treeRef.value!.getCheckedKeys(!(props.desc.isPId ?? true))
62
+ nextTick(() => {
63
+ // 这里判断一下全选状态
64
+ selectAll.value = isSelect && allIds.value.length === currentValue.value?.length
65
+ emits('validateThis')
66
+ console.log('validateThis******************')
67
+ })
68
+ }
69
+
70
+ /**
71
+ * 处理权限
72
+ */
73
+ function handelSelectAll() {
74
+ let selectIds = [] as any[]
75
+ if (selectAll.value) selectIds = cloneDeep(allIds.value)
76
+ currentValue.value = selectIds
77
+ treeRef.value!.setCheckedKeys(currentValue.value)
78
+ }
79
+
80
+ /**
81
+ * 递归获取id
82
+ */
83
+ function getLoopIds(list: Array<any>) {
84
+ const tempIds = [] as any[]
85
+ if (list?.length) {
86
+ list.map((item) => {
87
+ if (item[attrs.value.props.children]?.length) {
88
+ tempIds.push(...getLoopIds(item[attrs.value.props.children]))
89
+ }
90
+ tempIds.push(item.id)
91
+ })
92
+ }
93
+ return tempIds
45
94
  }
46
95
 
47
96
  watch(
@@ -59,6 +108,10 @@ watch(
59
108
  } else {
60
109
  options.splice(0, options.length)
61
110
  }
111
+ // 如果是复选,这里重新获取下所有IDs
112
+ if (attrs.value.showCheckbox && !attrs.value.noSelectAll) {
113
+ allIds.value = getLoopIds(options)
114
+ }
62
115
  },
63
116
  { immediate: true }
64
117
  )
@@ -66,14 +119,19 @@ watch(
66
119
  watch(
67
120
  () => props.modelValue,
68
121
  (val) => {
69
- currentValue.value = val?.split(',') || []
70
- treeRef.value!.setCheckedKeys(currentValue.value)
122
+ treeRef.value!.setCheckedKeys(val || [])
71
123
  }
72
124
  )
73
125
  </script>
74
126
  <style lang="scss" scoped>
75
127
  .el-plus-form-tree {
76
128
  width: 100%;
129
+ display: flex;
130
+ flex-direction: column;
131
+ .btns {
132
+ width: 100%;
133
+ padding-left: 12px;
134
+ margin-bottom: 8px;
135
+ }
77
136
  }
78
137
  </style>
79
- ../util/aaaaa
@@ -816,7 +816,7 @@ onMounted(() => {
816
816
  }
817
817
  })
818
818
 
819
- defineExpose({ reload, tableData, changeSelect, resetSelect, initCol })
819
+ defineExpose({ tableRef: elPlusTableRef, reload, tableData, changeSelect, resetSelect, initCol })
820
820
  </script>
821
821
  <style lang="scss">
822
822
  .dark .el-plus-table-content {
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.1.38",
5
+ "version": "0.1.39",
6
6
  "license": "MIT",
7
7
  "private": false,
8
8
  "main": "dist/el-plus-crud.mjs",