123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- <!-- 企业相册 -->
- <template>
- <div v-if="!imgList.length" class="text-center">
- <Empty :elevation="false" message="您还没有企业相册,马上去上传图片吧!"></Empty>
- <v-btn prepend-icon="mdi mdi-upload" color="primary" @click.stop="openFileInput">
- 上传图片/视频
- <input
- type="file"
- ref="fileInput"
- accept="image/png, image/jpg, image/jpeg, video/*"
- style="display: none;"
- @change="handleUploadFile"
- />
- </v-btn>
- </div>
- <div v-else>
- <div class="mb-3">
- <v-btn prepend-icon="mdi mdi-upload" color="primary" @click.stop="openFileInput">
- 上传图片/视频
- <input
- type="file"
- ref="fileInput"
- accept="image/png, image/jpg, image/jpeg, video/*"
- style="display: none;"
- @change="handleUploadFile"
- />
- </v-btn>
- </div>
- <div class="imgItem" v-for="(item, index) in imgList" :key="index">
- <v-img v-if="checkIsImage(item)" width="100%" height="100%" :src="item" @click="handleClick(index)"></v-img>
- <video v-else class="videos-radius mr-3" :src="item" controls height="172" width="172" preload="preload" @click="handleClick(index)"></video>
- <div class="operate">
- <span></span>
- <span class="mdi mdi-trash-can-outline" @click="handleDelete(item)"></span>
- </div>
- </div>
- </div>
- <PreviewImg v-if="showPreview" :current="current" :list="imgList" @close="showPreview = !showPreview"></PreviewImg>
- </template>
- <script setup>
- defineOptions({name: 'informationSettingsComponents-enterpriseAlbum'})
- import { ref } from 'vue'
- import { checkIsImage } from '@/utils'
- import { uploadImage } from '@/api/common'
- import { useI18n } from '@/hooks/web/useI18n'
- import { getEnterpriseBaseInfo, updateEnterpriseAlbum } from '@/api/enterprise'
- import Snackbar from '@/plugins/snackbar'
- import Confirm from '@/plugins/confirm'
- import cloneDeep from 'lodash/cloneDeep'
- const emit = defineEmits(['complete'])
- const { t } = useI18n()
- const imgList = ref([])
- const getInfo = async () => {
- const data = await getEnterpriseBaseInfo()
- // 完成度展示
- emit('complete', {
- totalCount: 10,
- completeCount: data?.albumList?.length ? 10 : 0,
- id: 'enterpriseAlbum'
- })
- if (!data || !data.albumList) return
- imgList.value = data.albumList
- }
- getInfo()
- // 预览
- const showPreview = ref(false)
- const current = ref(0)
- const handleClick = (index) => {
- showPreview.value = !showPreview.value
- current.value = index
- }
- // 删除
- const handleDelete = async (url) => {
- const index = imgList.value.indexOf(url)
- if (index === -1) return
- const albumList = cloneDeep(imgList.value)
- albumList.splice(index, 1)
- Confirm('系统提示', '是否确认删除?').then(async () => {
- await updateEnterpriseAlbum({ albumList })
- Snackbar.success('删除成功')
- imgList.value.splice(index, 1)
- getInfo()
- })
- }
- // 选择文件
- const fileInput = ref()
- const clicked = ref(false)
- const openFileInput = () => {
- if (clicked.value) return
- clicked.value = true
- fileInput.value.click()
- clicked.value = false
- }
- // 上传
- const handleUploadFile = async (e) => {
- if (!e.target.files.length) return
- const file = e.target.files[0]
- const size = file.size
- if (size / (1024*1024) > 10) {
- Snackbar.warning(t('common.fileSizeExceed'))
- return
- }
- const formData = new FormData()
- formData.append('file', file)
- const { data } = await uploadImage(formData)
- if (!data) return
- Snackbar.success(t('common.uploadSucMsg'))
- imgList.value.push(data)
- await updateEnterpriseAlbum({ albumList: imgList.value })
- getInfo()
- }
- </script>
- <style lang="scss" scoped>
- .imgItem {
- width: 172px;
- height: 172px;
- border: 1px solid rgba(188, 188, 188, 0.5);
- border-radius: 5px;
- margin-right: 24px;
- margin-bottom: 24px;
- display: inline-block;
- position: relative;
- cursor: pointer;
- .operate {
- display: none;
- }
- &:hover {
- .operate {
- position: absolute;
- bottom: 0;
- line-height: 32px;
- background-color: #00000080;
- width: 100%;
- display: flex;
- justify-content: space-between;
- padding: 0 4px;
- span {
- color: #fff;
- cursor: pointer;
- }
- }
- }
- }
- .mdi-image-broken-variant {
- font-size: 24px;
- color: rgba(188, 188, 188, 0.8);
- }
- </style>
|