zhengyiming
15 小时以前 97f29024ce18babeb4b635c5d73f907ac493976e
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
186
187
188
189
190
191
192
193
194
195
196
<!--
 * @Author: 秦少卫
 * @Date: 2024-05-30 10:48:00
 * @LastEditors: 秦少卫
 * @LastEditTime: 2024-06-09 17:08:48
 * @Description: 模板文件
-->
<template>
  <Tooltip :content="props.name" placement="top">
    <div class="file-type-box">
      <Image
        lazy
        @click="beforeClearTip"
        :src="props.src"
        fit="contain"
        height="100%"
        width="100%"
        :alt="props.name"
      />
      <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>
              <DropdownItem name="transfer">迁移目录</DropdownItem>
            </DropdownMenu>
          </template>
        </Dropdown>
      </div>
    </div>
  </Tooltip>
  <!-- 迁移文件夹 -->
  <Modal v-model="modalVisable" title="请选择迁移目录" @on-ok="transferRequest">
    <TreeSelect v-model="fileTypeId" :data="treeData" v-width="200" />
  </Modal>
  <!--  -->
</template>
 
<script setup name="ImportTmpl">
import useMaterial from '@/hooks/useMaterial';
import { useI18n } from 'vue-i18n';
import useSelect from '@/hooks/select';
import { getUserFileTypeTree, updataTempl } from '@/api/user';
const { t } = useI18n();
const { canvasEditor } = useSelect();
const { reNameFileType, removeTemplInfo, routerToId, getTemplInfo } = useMaterial();
 
import { Modal, Input, Spin, Message } from 'view-ui-plus';
 
const props = defineProps({
  name: {
    type: String,
    default: '',
  },
  src: {
    type: String,
    default: '',
  },
  previewSrc: {
    type: String,
    default: '',
  },
  itemId: {
    type: [Number, String],
    default: '',
  },
  json: {
    type: Object,
    default: () => ({}),
  },
});
 
const emit = defineEmits(['change']);
 
const operation = (value) => {
  const mapActions = {
    reName: reNameFile,
    delete: deleteFile,
    transfer: transfer,
  };
  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 () => {
  await removeTemplInfo(props.itemId);
  emit('change');
};
 
const beforeClearTip = () => {
  Modal.confirm({
    title: t('tip'),
    content: `<p>${t('replaceTip')}</p>`,
    okText: t('ok'),
    cancelText: t('cancel'),
    onOk: () => getTempData(),
  });
};
 
// 获取模板数据
const getTempData = async () => {
  Spin.show({
    render: (h) => h('div', t('alert.loading_data')),
  });
  const data = await getTemplInfo(props.itemId);
  routerToId(props.itemId);
  canvasEditor.loadJSON(JSON.stringify(data.data.attributes.json), Spin.hide);
};
 
const modalVisable = ref(false);
const fileTypeId = ref('');
const treeData = ref([]);
 
const transfer = async () => {
  treeData.value = [];
  fileTypeId.value = '';
  const res = await getUserFileTypeTree();
  treeData.value = [res.data.data];
  modalVisable.value = true;
};
 
const transferRequest = async () => {
  const parentId = fileTypeId.value === 'root' ? '' : fileTypeId.value;
  await updataTempl(props.itemId, {
    data: {
      parentId: String(parentId),
    },
  });
  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 #f1f1f1;
  border-radius: 10px;
  img {
    width: 60px;
    margin-top: 12px;
  }
  div.more {
    position: absolute;
    display: none;
  }
  &: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>