巡检-早于巡检时间,禁止提交
This commit is contained in:
@@ -5,8 +5,8 @@
|
||||
<!-- 已选图片 -->
|
||||
<view v-for="(img, index) in innerList" :key="index" class="image-item">
|
||||
<image :src="img.url || img" class="img" mode="aspectFill" @tap="preview(index)"></image>
|
||||
<!-- 删除按钮 -->
|
||||
<view class="delete-btn" @tap.stop="remove(index)">
|
||||
<!-- 删除按钮 禁用时隐藏 -->
|
||||
<view v-if="!props.disabled" class="delete-btn" @tap.stop="remove(index)">
|
||||
<uni-icons type="closeempty" size="16" color="#fff"></uni-icons>
|
||||
</view>
|
||||
<!-- 上传状态 -->
|
||||
@@ -14,19 +14,22 @@
|
||||
<text>上传中...</text>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 添加按钮 -->
|
||||
<view class="add-btn" @tap="choose" v-if="innerList.length < props.limit">
|
||||
<!-- 添加按钮 禁用或者达到上限不显示 -->
|
||||
<view
|
||||
class="add-btn"
|
||||
:class="{ 'add-btn-disabled': props.disabled }"
|
||||
@tap="choose"
|
||||
v-if="innerList.length < props.limit"
|
||||
>
|
||||
<uni-icons color="#a6a6a6" type="plusempty" size="25"></uni-icons>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue'
|
||||
import baseUrl from '@/api/BaseUrl.js'
|
||||
import { requestAuth } from '@/utils/Auth.js'
|
||||
|
||||
// ======================
|
||||
// Props(可配置)
|
||||
// ======================
|
||||
@@ -65,19 +68,21 @@ const props = defineProps({
|
||||
extraData: {
|
||||
type: Object,
|
||||
default: () => ({})
|
||||
},
|
||||
// ✅ 新增:禁用组件
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false
|
||||
}
|
||||
})
|
||||
|
||||
// ======================
|
||||
// Emits
|
||||
// ======================
|
||||
const emit = defineEmits(['update:modelValue', 'success', 'fail', 'remove'])
|
||||
|
||||
// ======================
|
||||
// 内部数据
|
||||
// ======================
|
||||
const innerList = ref([])
|
||||
|
||||
// 监听外部数据变化
|
||||
watch(
|
||||
() => props.modelValue,
|
||||
@@ -91,13 +96,13 @@ watch(
|
||||
},
|
||||
{ immediate: true, deep: true }
|
||||
)
|
||||
|
||||
// ======================
|
||||
// 核心方法
|
||||
// ======================
|
||||
|
||||
// 1. 选择图片
|
||||
function choose() {
|
||||
// 禁用直接返回
|
||||
if (props.disabled) return
|
||||
uni.chooseImage({
|
||||
count: props.limit - innerList.value.length,
|
||||
sourceType: props.sourceType,
|
||||
@@ -146,13 +151,13 @@ function choose() {
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 2. 上传单张图片
|
||||
async function uploadSingle(filePath) {
|
||||
// 禁用不再新增上传
|
||||
if (props.disabled) return
|
||||
// 先添加到列表,标记为上传中
|
||||
const tempItem = { url: filePath, uploading: true }
|
||||
innerList.value = [...innerList.value, tempItem]
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: `${baseUrl}${props.uploadUrl}`,
|
||||
@@ -167,7 +172,6 @@ async function uploadSingle(filePath) {
|
||||
success: res => {
|
||||
try {
|
||||
const data = JSON.parse(res.data)
|
||||
|
||||
// 假设后端返回格式:{ code: 200, url: "https://xxx.com/xxx.png" }
|
||||
// 如果你的后端返回格式不同,请在这里修改
|
||||
if (data.code === 200 || data.url) {
|
||||
@@ -201,9 +205,10 @@ async function uploadSingle(filePath) {
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
// 3. 删除图片
|
||||
function remove(index) {
|
||||
// 禁用禁止删除
|
||||
if (props.disabled) return
|
||||
const removed = innerList.value.splice(index, 1)[0]
|
||||
emit(
|
||||
'update:modelValue',
|
||||
@@ -211,8 +216,7 @@ function remove(index) {
|
||||
)
|
||||
emit('remove', { index, url: removed.url })
|
||||
}
|
||||
|
||||
// 4. 预览图片
|
||||
// 4. 预览图片(预览保留,禁用也可以看)
|
||||
function preview(index) {
|
||||
const urls = innerList.value.map(i => i.url).filter(Boolean)
|
||||
if (urls.length <= 0) return
|
||||
@@ -222,12 +226,10 @@ function preview(index) {
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.simple-uploader {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.image-list {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, 1fr);
|
||||
@@ -236,19 +238,16 @@ function preview(index) {
|
||||
margin-right: 20rpx;
|
||||
margin-bottom: 20rpx;
|
||||
}
|
||||
|
||||
.image-item {
|
||||
position: relative;
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
}
|
||||
|
||||
.img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
border-radius: 8rpx;
|
||||
}
|
||||
|
||||
.delete-btn {
|
||||
position: absolute;
|
||||
top: 0rpx;
|
||||
@@ -261,7 +260,6 @@ function preview(index) {
|
||||
justify-content: center;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.uploading-mask {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
@@ -276,7 +274,6 @@ function preview(index) {
|
||||
color: #fff;
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.add-btn {
|
||||
width: 160rpx;
|
||||
height: 160rpx;
|
||||
@@ -285,4 +282,8 @@ function preview(index) {
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
.add-btn-disabled {
|
||||
background-color: #eee;
|
||||
opacity: 0.6;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user