|
38 | 38 | --> |
39 | 39 |
|
40 | 40 | <template> |
41 | | - <div class="imgs-upload-container"> |
| 41 | + <div class="imgs-upload-container" v-loading="loading"> |
42 | 42 | <template v-for="(item, i) in itemList"> |
43 | 43 | <template v-if="item.display"> |
44 | 44 | <div class="thumb-item" :key="item.id" :style="boxStyle"> |
|
48 | 48 | :fit="fit" |
49 | 49 | style="width: 100%; height: 100%;"></el-image> |
50 | 50 | <div class="control"> |
51 | | - <i class="el-icon-close del" @click.prevent.stop="delItem(item.id)" title="删除"></i> |
52 | | - <div class="preview" title="更换图片" @click.prevent.stop="handleClick(item.id)"> |
| 51 | + <i v-if="!disabled" class="el-icon-close del" @click.prevent.stop="delItem(item.id)" title="删除"></i> |
| 52 | + <div v-if="!disabled" class="preview" title="更换图片" @click.prevent.stop="handleClick(item.id)"> |
53 | 53 | <i class="el-icon-edit"></i> |
54 | 54 | </div> |
55 | 55 | <div class="control-bottom" v-if="sortable || preview"> |
56 | 56 | <i |
57 | | - v-if="sortable" |
| 57 | + v-if="sortable && !disabled" |
58 | 58 | title="前移" |
59 | 59 | class="control-bottom-btn el-icon-back" |
60 | 60 | :class="{disabled: (i === 0)}" |
|
63 | 63 | v-if="preview" |
64 | 64 | class="control-bottom-btn el-icon-view" |
65 | 65 | title="预览" |
| 66 | + style="cursor: pointer;" |
66 | 67 | @click.stop="previewImg(item)"></i> |
67 | 68 | <i |
68 | | - v-if="sortable" |
| 69 | + v-if="sortable && !disabled" |
69 | 70 | title="后移" |
70 | 71 | class="control-bottom-btn el-icon-right" |
71 | 72 | :class="{disabled: (i === (itemList.length - 1))}" |
@@ -387,25 +388,43 @@ export default { |
387 | 388 | // 初始化 Draggable |
388 | 389 | }, |
389 | 390 | methods: { |
| 391 | + getValue() { |
| 392 | +
|
| 393 | + }, |
| 394 | + /** |
| 395 | + * 删除某项 |
| 396 | + */ |
390 | 397 | delItem(id) { |
391 | | - const { itemList } = this |
| 398 | + const { itemList, isStable } = this |
392 | 399 | // 根据id找到对应项 |
393 | 400 | const index = itemList.findIndex(item => (item.id === id)) |
394 | | - itemList.splice(index, 1) |
| 401 | + if (isStable) { |
| 402 | + // 固定数量图片, 删除后留下空项 |
| 403 | + itemList[index] = createItem() |
| 404 | + this.itemList = [...itemList] |
| 405 | + } else { |
| 406 | + itemList.splice(index, 1) |
| 407 | + } |
395 | 408 | }, |
| 409 | + /** |
| 410 | + * 预览图像, 后续预览组件制作后替换 |
| 411 | + */ |
396 | 412 | previewImg(data) { |
397 | 413 | this.$confirm(`<img src="${data.display}" style="width: 100%; height: 100%" />`, '预览', { |
398 | 414 | dangerouslyUseHTMLString: true, |
399 | 415 | }) |
400 | 416 | }, |
| 417 | + /** |
| 418 | + * 移动图像位置 |
| 419 | + */ |
401 | 420 | move(id, step) { |
402 | | - const { itemList } = this |
| 421 | + const { itemList, isStable } = this |
403 | 422 | // 找到操作的元素 |
404 | 423 | const index = itemList.findIndex(item => (item.id === id)) |
405 | 424 | // 边界检测 |
406 | 425 | if ((index + step) < 0 || (index + step) >= itemList.length) return |
407 | | - // 不可和最后一项输入换位子 |
408 | | - if ((index + step) === (itemList.length - 1)) { |
| 426 | + // 非固定项时, 不可和最后一项输入换位子 |
| 427 | + if (!isStable && (index + step) === (itemList.length - 1)) { |
409 | 428 | if (itemList[itemList.length - 1].status === 'input') return |
410 | 429 | } |
411 | 430 | const i = itemList[index] |
|
0 commit comments