vhs-majors-draggable-list.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <view class="mt-10">
  3. <l-drag ref="dragRef" :list="majors" :column="1" gridHeight="56px" :touchHandle="touchHandle" ghost handle
  4. @change="changeSort">
  5. <!-- // 每一项的插槽 grid 的 content 您传入的数据 -->
  6. <template #grid="{ active, content, index }">
  7. <!-- // grid.active 是否为当前拖拽项目 根据自己需要写样式 -->
  8. <view
  9. class="bg-back rounded-6 h-[44px] pl-30 pr-20 relative flex items-center gap-x-16 mb-[10px] border border-solid"
  10. :class="[active ? 'border-primary' : 'border-transparent']">
  11. <view class="text-32 text-fore-placeholder font-bold">{{ toFixedLen(index) }}</view>
  12. <view class="flex-1 w-1 h-full leading-[44px] text-28 text-fore-title font-bold ellipsis-1">
  13. {{ content.marjorName }}[{{ content.marjorBelongs }}]
  14. </view>
  15. <uv-icon name="trash" size="18" color="error" @click="handleDelete(content)" />
  16. <view slot="handle" @touchstart="handleDragStart" @touchend="handleDragEnd">
  17. <uv-icon name="list-dot" size="18" color="primary" />
  18. </view>
  19. </view>
  20. </template>
  21. <template #ghost></template>
  22. </l-drag>
  23. </view>
  24. </template>
  25. <script lang="ts" setup>
  26. import type { VHS } from '@/types';
  27. // import { VOLUNTARY_REFRESHER_ENABLED } from "@/types/injectionSymbols";
  28. const props = defineProps<{
  29. majors: VHS.VoluntaryMajor[];
  30. }>();
  31. // const refresherEnabled = inject(VOLUNTARY_REFRESHER_ENABLED) || ref(false)
  32. const emits = defineEmits<{
  33. (e: "delete", major: VHS.VoluntaryMajor): void;
  34. (e: "update:majors", majors: VHS.VoluntaryMajor[]): void;
  35. (e: "change", majors: VHS.VoluntaryMajor[]): void;
  36. }>();
  37. const touchHandle = ref(false)
  38. const handleDragStart = () => {
  39. touchHandle.value = true;
  40. // refresherEnabled.value = false;
  41. }
  42. const handleDragEnd = () => {
  43. touchHandle.value = false;
  44. // refresherEnabled.value = true;
  45. }
  46. const changeSort = (e: any) => {
  47. const list = e.map((item: any) => item.content);
  48. emits('update:majors', list);
  49. emits('change', list);
  50. }
  51. const handleDelete = (major: VHS.VoluntaryMajor) => {
  52. emits('delete', major);
  53. }
  54. const toFixedLen = (i: number, len: number = 1) => {
  55. return String(i + 1).padStart(len, "0");
  56. }
  57. </script>
  58. <style lang="scss" scoped></style>