use-form-drawing.js 948 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { computed } from 'vue'
  2. import { getCopyRow } from '../../util'
  3. import { getNextItem } from '@cip/utils/util'
  4. export const useList = ({ props, emit }) => {
  5. const list = computed(() => {
  6. return props.data?.list || []
  7. })
  8. const updateList = (value) => {
  9. emit('updateList', value)
  10. }
  11. return { list, updateList }
  12. }
  13. export const useFormDrawing = ({ list, updateList, emit }) => {
  14. const selectItem = (element) => {
  15. emit('select', element)
  16. }
  17. const deleteItem = (index) => {
  18. const itemList = list.value
  19. const nextItem = getNextItem(list.value, index)
  20. selectItem(nextItem)
  21. itemList.splice(index, 1)
  22. updateList(itemList)
  23. }
  24. const copyItem = (index) => {
  25. const itemList = list.value
  26. const newItem = getCopyRow(itemList[index])
  27. itemList.splice(index + 1, 0, newItem)
  28. updateList(itemList, 'copy')
  29. selectItem(newItem)
  30. }
  31. return {
  32. selectItem,
  33. deleteItem,
  34. copyItem
  35. }
  36. }