zhengyiming
3 小时以前 fd06689a59dcdaf03d8f98d9531ad6f2c2b258c3
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
<!--
 * @Author: 秦少卫
 * @Date: 2024-05-30 10:03:30
 * @LastEditors: 秦少卫
 * @LastEditTime: 2024-05-30 18:39:13
 * @Description: 文件夹
-->
 
<template>
  <div class="file-type-box">
    <img :src="fileTypeIcon" />
    <span>{{ props.name }}</span>
    <div class="click-bg" @click="emit('select')"></div>
    <div class="more">
      <Dropdown trigger="click" @on-click="operation">
        <Button size="small" shape="circle" type="text">
          <Icon type="ios-more" :size="24" />
        </Button>
        <template #list>
          <DropdownMenu>
            <DropdownItem name="reName">重命名</DropdownItem>
            <DropdownItem name="delete">删除</DropdownItem>
          </DropdownMenu>
        </template>
      </Dropdown>
    </div>
  </div>
</template>
 
<script setup name="ImportTmpl">
import fileTypeIcon from '@/assets/icon/fileType.png';
import useMaterial from '@/hooks/useMaterial';
 
const { reNameFileType, removeFileType } = useMaterial();
 
import { Modal, Input, Message } from 'view-ui-plus';
 
const props = defineProps({
  name: {
    type: String,
    default: '',
  },
  itemId: {
    type: [Number, String],
    default: '',
  },
});
 
const emit = defineEmits(['change', 'select']);
 
const operation = (value) => {
  const mapActions = {
    reName: reNameFile,
    delete: deleteFile,
  };
  mapActions[value]();
};
const fileName = ref('');
 
const reNameFile = () => {
  fileName.value = props.name;
  Modal.confirm({
    title: '重命名文件夹',
    render: (h) => {
      return h(Input, {
        size: 'large',
        modelValue: fileName,
        autofocus: true,
        placeholder: '请输入文件夹名称',
      });
    },
    onOk: async () => {
      if (fileName.value === '') {
        Message.warning('文件夹名称不能为空');
        return;
      }
      await reNameFileType(fileName.value, props.itemId);
      emit('change');
    },
  });
};
 
const deleteFile = async () => {
  const res = await removeFileType(props.itemId);
  if (res?.data?.msg) {
    Message.error({
      content: res.data?.msg,
      duration: 3,
    });
    return;
  }
  emit('change');
};
</script>
 
<style scoped lang="less">
// 文件夹
.file-type-box {
  width: 134px;
  height: 116px;
  cursor: pointer;
  background: #fff;
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  // border: 1px solid #fff;
  border: 1px solid #f1f1f1;
  border-radius: 10px;
  img {
    width: 60px;
    margin-top: 12px;
  }
  span {
    display: block;
    padding-top: 10px;
    text-align: center;
    width: 90%;
    overflow: hidden; //超出的文本隐藏
    text-overflow: ellipsis; //溢出用省略号显示
    white-space: nowrap; //溢出不换行
  }
  div.more {
    position: absolute;
    display: none;
  }
 
  .click-bg {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }
 
  &:hover {
    background: rgb(243, 245, 249);
    border: 1px solid rgb(225, 230, 239);
    border-radius: 8px;
    img {
      opacity: 0.8;
    }
    div.more {
      display: block;
      top: 5px;
      right: 5px;
    }
  }
}
</style>