优化单图选择不显示相机的问题
This commit is contained in:
@@ -1,89 +1,89 @@
|
|||||||
<template>
|
<template>
|
||||||
<view class="upload-file" @click="chooseImage">
|
<view class="upload-file" @click="chooseImage">
|
||||||
<slot v-if="$slots.default"></slot>
|
<slot v-if="$slots.default"></slot>
|
||||||
<view class="icon" v-if="!modelValue"> + </view>
|
<view class="icon" v-if="!modelValue">+</view>
|
||||||
<image class="img" v-else :src="modelValue"></image>
|
<image class="img" v-else :src="modelValue"></image>
|
||||||
|
|
||||||
<view class="close" @click.stop="()=>{}" v-if="modelValue">
|
<view class="close" @click.stop="() => {}" v-if="modelValue">
|
||||||
<up-icon name="close-circle" color="#333" size="14" @click="clearImg" ></up-icon>
|
<up-icon name="close-circle" color="#333" size="14" @click="clearImg"></up-icon>
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { uploadFile } from "@/http/api/index.js";
|
import { uploadFile } from '@/http/api/index.js';
|
||||||
|
|
||||||
import { reactive, ref, watch } from "vue";
|
import { reactive, ref, watch } from 'vue';
|
||||||
|
|
||||||
const modelValue = defineModel({
|
const modelValue = defineModel({
|
||||||
type: String,
|
type: String,
|
||||||
default: "",
|
default: ''
|
||||||
});
|
});
|
||||||
|
|
||||||
function chooseImage() {
|
function chooseImage() {
|
||||||
uni.chooseImage({
|
uni.chooseImage({
|
||||||
count: 1, //默认9
|
count: 1, //默认9
|
||||||
sizeType: ["original", "compressed"], //可以指定是原图还是压缩图,默认二者都有
|
sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
|
||||||
sourceType: ["album", "camera "],
|
sourceType: ['album', 'camera'],
|
||||||
success: async function (res) {
|
success: async function (res) {
|
||||||
uni.showLoading({
|
uni.showLoading({
|
||||||
title: "上传中",
|
title: '上传中'
|
||||||
});
|
});
|
||||||
console.log(res);
|
console.log(res);
|
||||||
const fileRes = await uploadFile(res.tempFiles[0]);
|
const fileRes = await uploadFile(res.tempFiles[0]);
|
||||||
uni.hideLoading();
|
uni.hideLoading();
|
||||||
if (fileRes) {
|
if (fileRes) {
|
||||||
modelValue.value = fileRes;
|
modelValue.value = fileRes;
|
||||||
} else {
|
} else {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
title: "上传失败",
|
title: '上传失败',
|
||||||
icon: "none",
|
icon: 'none'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function clearImg(){
|
function clearImg() {
|
||||||
modelValue.value=""
|
modelValue.value = '';
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss">
|
<style lang="scss">
|
||||||
.upload-file {
|
.upload-file {
|
||||||
$size: 128rpx;
|
$size: 128rpx;
|
||||||
width: $size;
|
width: $size;
|
||||||
height: $size;
|
height: $size;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
border: 1px dashed #d9d9d9;
|
border: 1px dashed #d9d9d9;
|
||||||
border-radius: 8rpx;
|
border-radius: 8rpx;
|
||||||
position: relative;
|
position: relative;
|
||||||
.close{
|
.close {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
right: -10rpx;
|
right: -10rpx;
|
||||||
top: -10rpx;
|
top: -10rpx;
|
||||||
}
|
}
|
||||||
.img {
|
.img {
|
||||||
width: $size;
|
width: $size;
|
||||||
height: $size;
|
height: $size;
|
||||||
}
|
}
|
||||||
.icon {
|
.icon {
|
||||||
width: 36rpx;
|
width: 36rpx;
|
||||||
height: 36rpx;
|
height: 36rpx;
|
||||||
border: 4rpx solid #999;
|
border: 4rpx solid #999;
|
||||||
border-radius: 8rpx;
|
border-radius: 8rpx;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: #999;
|
color: #999;
|
||||||
font-size: 32rpx;
|
font-size: 32rpx;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -213,7 +213,7 @@ function toMiniApp() {
|
|||||||
uni.navigateToMiniProgram({
|
uni.navigateToMiniProgram({
|
||||||
appId: 'wxd88fffa983758a30',
|
appId: 'wxd88fffa983758a30',
|
||||||
path: `/groupBuying/goodsDetail/goodsDetail?wareId=${query.id}&shopId=${query.shopId}`,
|
path: `/groupBuying/goodsDetail/goodsDetail?wareId=${query.id}&shopId=${query.shopId}`,
|
||||||
envVersion: 'release', // 环境版本:release(正式版)、trial(体验版)、develop(开发版)
|
envVersion: 'trial', // 环境版本:release(正式版)、trial(体验版)、develop(开发版)
|
||||||
success: () => {},
|
success: () => {},
|
||||||
fail: () => {}
|
fail: () => {}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ function toMiniApp() {
|
|||||||
uni.navigateToMiniProgram({
|
uni.navigateToMiniProgram({
|
||||||
appId: 'wxd88fffa983758a30',
|
appId: 'wxd88fffa983758a30',
|
||||||
path: `/userPackage/goodsDetail/goodsDetail?id=${query.id}&shopId=${query.shopId}`,
|
path: `/userPackage/goodsDetail/goodsDetail?id=${query.id}&shopId=${query.shopId}`,
|
||||||
envVersion: 'release', // 环境版本:release(正式版)、trial(体验版)、develop(开发版)
|
envVersion: 'trial', // 环境版本:release(正式版)、trial(体验版)、develop(开发版)
|
||||||
success: () => {},
|
success: () => {},
|
||||||
fail: () => {}
|
fail: () => {}
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user