File size: 4,283 Bytes
f0953a4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<template>
  <div class="resource-select">
    <van-checkbox-group v-model="selectedResourceIds">
      <van-cell-group :border="false">
        <van-cell
          v-for="item in resourceStore.shareInfo.list"
          :key="item.fileId"
          class="resource-item"
          :border="false"
          center
          @click="handleItemClick(item.fileId)"
        >
          <template #title>
            <div class="resource-item__content">
              <van-icon name="folder-o" class="content__icon" />
              <div class="content__info">
                <span class="info__name">{{ item.fileName }}</span>
                <span v-if="item.fileSize" class="info__size">
                  {{ formattedFileSize(item.fileSize) }}
                </span>
              </div>
            </div>
          </template>
          <template #right-icon>
            <van-checkbox
              :name="item.fileId"
              class="resource-item__checkbox"
              @click.stop="handleItemClick(item.fileId)"
            />
          </template>
        </van-cell>
      </van-cell-group>
    </van-checkbox-group>

    <!-- 空状态 -->
    <van-empty v-if="!resourceStore.shareInfo.list?.length" description="暂无可选资源" />
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from "vue";
import { useResourceStore } from "@/stores/resource";
import { formattedFileSize } from "@/utils/index";

const resourceStore = useResourceStore();
const selectedResourceIds = ref<string[]>([]);

// 初始化选中状态
selectedResourceIds.value = resourceStore.resourceSelect
  .filter((x) => x.isChecked)
  .map((x) => x.fileId);

// 监听选中状态变化
watch(selectedResourceIds, (newIds) => {
  const newResourceSelect = [...resourceStore.resourceSelect];
  newResourceSelect.forEach((x) => {
    x.isChecked = newIds.includes(x.fileId);
  });
  resourceStore.setSelectedResource(newResourceSelect);
});

// 添加点击处理函数
const handleItemClick = (fileId: string) => {
  const index = selectedResourceIds.value.indexOf(fileId);
  if (index === -1) {
    selectedResourceIds.value.push(fileId);
  } else {
    selectedResourceIds.value.splice(index, 1);
  }
};
</script>

<style lang="scss" scoped>
// 工具类
@mixin text-ellipsis {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.resource-select {
  height: 100%;
  background: var(--theme-other_background);
  width: 100%;
  overflow-x: hidden;

  .resource-item {
    position: relative;

    &__content {
      display: flex;
      align-items: flex-start;
      gap: 8px;
      padding: 8px 0;
      margin-right: 40px;

      .content__icon {
        flex-shrink: 0;
        font-size: 20px;
        color: var(--theme-theme);
        margin-top: 2px;
      }

      .content__info {
        flex: 1;
        min-width: 0;
        display: flex;
        flex-direction: column;
        gap: 2px;

        .info__name {
          font-size: 15px;
          line-height: 1.4;
          color: var(--van-text-color);
          word-break: break-all;
          white-space: normal;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          overflow: hidden;
        }

        .info__size {
          font-size: 13px;
          color: var(--van-gray-6);
          @include text-ellipsis;
        }
      }
    }

    &__checkbox {
      position: absolute;
      right: 16px;
      top: 50%;
      transform: translateY(-50%);

      :deep(.van-checkbox__icon) {
        font-size: 18px;
        cursor: pointer;

        .van-icon {
          border-radius: 2px;
          transition: all 0.2s;
        }
      }
    }

    &:active {
      background-color: var(--van-active-color);
    }
  }
}

// 深度修改 Vant 组件样式
:deep(.van-cell) {
  align-items: flex-start;
  padding: 0 16px;
  width: 100%;
  box-sizing: border-box;
  min-height: 60px;
  position: relative;

  &::after {
    display: none;
  }

  .van-cell__title {
    flex: 1;
    min-width: 0;
  }
}

:deep(.van-checkbox__icon--checked) {
  .van-icon {
    background-color: var(--theme-theme);
    border-color: var(--theme-theme);
  }
}

:deep(.van-empty) {
  padding: 32px 0;
  background: transparent;
}
</style>