| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264 |
- <template>
- <!-- 这是一个简单组件,只关注视图层 -->
- <div v-show="taskList.length > 0" class="upload-list-component">
- <div class="head">
- <div class="left">
- <i class="iconfont iconmaterial_preview_upload"></i>
- <span class="text">正在上传 {{taskList.length}}</span>
- </div>
- <div class="right">
- <i
- class="iconfont icon-material_preview_upload_collect"
- :class="this.expandSwitch ? '' : 'upsideDown'"
- @click="onClickExpand"></i>
- </div>
- </div>
- <div class="content" v-show="expandSwitch">
- <div
- class="list-item"
- v-for="(taskItem, index) in taskList"
- :key="index"
- >
- <div class="left">
- <img class="type-icon" :src="uploadFieIconUrl" alt=""/>
- <span class="text">{{taskItem.title}}</span>
- </div>
- <div class="right">
- <span :class="{
- 'text-fail': taskItem.status === 'FAIL',
- 'text-loading': taskItem.status === 'LOADING',
- }">
- {{taskItem.statusText}}
- </span>
- <span v-show="taskItem.ifKnowProgress && taskItem.status === 'LOADING'" class="progress-text">{{Math.round(taskItem.progress * 100) + '%'}}</span>
- <img
- v-show="(taskItem.status === 'LOADING' && taskItem.ifKnowProgress) || taskItem.status === 'FAIL'"
- class="cancel-btn"
- :src="require('@/assets/images/icons/material_preview_upload_cancel@2x.png')"
- @click="onClickCancel(taskItem.uid)"
- />
- </div>
- <div class="progress-bar" v-if="taskItem.ifKnowProgress && taskItem.status === 'LOADING'" :style="{width: Math.round(taskItem.progress * 100) + '%'}"></div>
- <div class="progress-bar-unknown" v-if="!taskItem.ifKnowProgress && taskItem.status ==='LOADING'"></div>
- </div>
- </div>
- </div>
- </template>
- <script>
- export default {
- props: {
- fileType: {
- type: String,
- default: 'IMAGE', // 'IMAGE' | 'AUDIO' | 'VIDEO'
- },
- taskList: {
- /**
- * 每个元素的内部结构:{
- * title: String
- * ifKnowProgress: Boolean // false则进度条效果是loading而不是具体进度
- * progress:Number // 进度,0到1之间。
- * status: 'FAIL' | 'LOADING' // 将来可能还需要:'SUCCESS', 'CANCELLED'
- * statusText,
- * uid: String,
- * }
- */
- type: Array,
- default: () => []
- // default: () => [
- // {
- // title: '标题',
- // ifKnowProgress: true,
- // progress: '0.3',
- // status: 'LOADING',
- // statusText: '上传中',
- // uid: 'a'
- // },
- // {
- // title: '标题',
- // ifKnowProgress: false,
- // progress: '0.3',
- // status: 'LOADING',
- // statusText: '后台处理中',
- // uid: 'b'
- // },
- // {
- // title: '标题',
- // ifKnowProgress: true,
- // progress: '0.55',
- // status: 'FAIL',
- // statusText: '失败',
- // },
- // ]
- },
- },
- computed: {
- uploadFieIconUrl() {
- switch (this.fileType) {
- case 'IMAGE':
- return require('@/assets/images/icons/upload-file-type-icon-image@2x.png')
- case 'AUDIO':
- return require('@/assets/images/icons/upload-file-type-icon-audio@2x.png')
- case 'VIDEO':
- return require('@/assets/images/icons/upload-file-type-icon-video@2x.png')
- default:
- return require('@/assets/images/icons/upload-file-type-icon-image@2x.png')
- }
- },
- },
- data() {
- return {
- expandSwitch: true,
- }
- },
- methods: {
- onClickExpand() {
- this.expandSwitch = !this.expandSwitch
- },
- onClickCancel(uid) {
- this.$emit('cancel-task', uid)
- },
- }
- }
- </script>
- <style lang="less" scoped>
- .upload-list-component {
- width: 550px;
- background: #FFFFFF;
- box-shadow: 0px 4px 12px 0px rgba(0, 0, 0, 0.1);
- border-radius: 4px;
- border: 1px solid #E4E7ED;
- .head {
- display: flex;
- justify-content: space-between;
- align-items: center;
- height: 60px;
- padding: 0 26px;
- border-bottom: 1px solid #EBEDF0;
- .left {
- display: flex;
- align-items: center;
- .iconmaterial_preview_upload {
- color: @color;
- font-size: 30px;
- margin-right: 10px;
- animation: spin 2s linear infinite;
- }
- .text {
- font-size: 14px;
- font-family: MicrosoftYaHei;
- color: #323233;
- line-height: 19px;
- }
- }
- .right {
- display: flex;
- align-items: center;
- i {
- color: #979797;
- cursor: pointer;
- font-size: 12px;
- transition: transform 0.2s;
- &.upsideDown {
- transform: rotate(180deg);
- }
- }
- }
- }
- .content {
- padding-left: 26px;
- padding-right: 26px;
- .list-item {
- display: flex;
- justify-content: space-between;
- align-items: center;
- height: 60px;
- border-bottom: 1px solid #EBEDF0;
- position: relative;
- overflow: hidden;
- .left {
- display: flex;
- align-items: center;
- width: 60%;
- .type-icon {
- width: 28px;
- height: 28px;
- margin-right: 10px;
- object-fit: contain;
- }
- .text {
- font-size: 14px;
- font-family: MicrosoftYaHei;
- color: #323233;
- line-height: 19px;
- overflow: hidden;
- text-overflow: ellipsis;
- word-break: keep-all;
- white-space: nowrap;
- max-width: 90%;
- }
- }
- .right {
- display: flex;
- justify-content: flex-end;
- align-items: center;
- width: 40%;
- .text-fail {
- margin-right: 10px;
- font-size: 12px;
- font-family: MicrosoftYaHei;
- color: #FA5555;
- }
- .text-loading {
- margin-right: 10px;
- font-size: 12px;
- font-family: MicrosoftYaHei;
- color: #969799;
- }
- .progress-text {
- margin-right: 10px;
- font-size: 12px;
- font-family: MicrosoftYaHei;
- color: #969799;
- }
- img {
- width: 18px;
- height: 18px;
- cursor: pointer;
- }
- }
- .progress-bar {
- position: absolute;
- left: 0;
- bottom: 0;
- height: 2px;
- background: linear-gradient(144deg, #00AEFB 0%, @color 100%);
- }
- .progress-bar-unknown {
- position: absolute;
- left: 0;
- bottom: 0;
- height: 2px;
- background: linear-gradient(144deg, #00AEFB 0%, @color 100%);
- width: 330px;
- animation: marquee 10s linear infinite
- }
- }
- }
- }
- @keyframes spin {
- 100% {
- transform: rotate(360deg)
- }
- }
- @keyframes marquee {
- 0% {
- transform: translateX(-100%)
- }
- 100% {
- transform: translateX(496px)
- }
- }
- </style>
|