修改 华为商城反馈相机 问题

This commit is contained in:
GGJ
2024-09-06 14:35:06 +08:00
parent a631f060d2
commit a8618d0b5d
10 changed files with 2110 additions and 1617 deletions

View File

@@ -0,0 +1,328 @@
<template>
<view v-if="showPopup" class="uni-popup" :style="{top:isNativeHead?'':StatusBar}">
<view :class="[type, ani, animation ? 'ani' : '']" class="uni-custom uni-popup__wrapper" @click="close(true)">
<view class="uni-popup__wrapper-box">
<view class="title">{{authList[permissionID].title}}</view>
<view class="content">{{authList[permissionID].content}}</view>
</view>
</view>
</view>
</template>
<script>
export default {
name: 'YkAuthpup',
props: {
// 开启动画
animation: {
type: Boolean,
default: true
},
type: {
type: String,
default: 'top'
},
show: {
type: Boolean,
default: true
},
//是否是原生头部
isNativeHead:{
type: Boolean,
default: true
},
permissionID: {
type: [String, Number],
default: ''
}
},
data() {
return {
ani: '',
showPopup: false,
StatusBar:'',
refuseNum:'',//拒绝次数,
authList: {
'WRITE_EXTERNAL_STORAGE': {
title: "灿能物联存储空间/照片权限申请说明",
content: "便于您使用该功能上传您的照片/视频及用于更换头像、扫描二维码等场景中使用。"
},
'ACCESS_FINE_LOCATION': {
title: "XXX对地理位置权限申请说明",
content: "便于应用程序可以提供基于位置的服务、定位导航、附近搜索等功能。"
},
'CAMERA':{
title: "灿能物联对相机/摄像头权限申请说明",
content: "便于您使用该功能拍照上传您的照片/视频及用于更换头像、扫描二维码等场景中使用。"
},
'RECORD_AUDIO':{
title: "XXX对麦克风权限申请说明",
content: "便于您使用该功能进行录音、语音通话、发布语音、与客服语音沟通等场景中使用"
},
'CALL_PHONE': {
title: "XXX对拨打/管理电话权限申请说明",
content: "便于您使用该功能联系买家、骑手或者客服、业务经理与联系等场景下使用"
}
}
}
},
created() {
// #ifdef APP-PLUS
this.getSystemInfo();
// #endif
},
methods: {
//获取状态栏高度
getSystemInfo() {
let _this = this;
uni.getSystemInfo({
success: function(e) {
_this.StatusBar = e.statusBarHeight + 'px'; //用于自定义头部时,给手机状态栏留出位置,可通过isNativeHead这个参数控制
}
})
},
open() {
this.requestPermissions(this.permissionID);
},
close(type) {
this.ani = '';
this.$nextTick(() => {
setTimeout(() => {
this.showPopup = false;
}, 300)
})
},
//权限检测
requestPermissions(permissionID) {
let _this = this;
// #ifdef APP-PLUS
//判断安卓与ios设备
if (plus.os.name == 'Android') {
let _permissionID = 'android.permission.' + permissionID;
plus.android.checkPermission(_permissionID,
granted => {
if (granted.checkResult == -1) {
//还未授权当前查询的权限,打开权限申请目的自定义弹框
_this.showPopup = true;
_this.$nextTick(() => {
setTimeout(() => {
_this.ani = 'uni-' + _this.type
},30)
})
}
},
error => {
console.log(error.message);
}
);
plus.android.requestPermissions([_permissionID],
(e) => {
//关闭权限申请目的自定义弹框
_this.ani = '';
_this.$nextTick(() => {
setTimeout(() => {
_this.showPopup = false
}, 0)
})
console.log(e,'kkkkk')
if (e.granted.length > 0) {
//当前查询权限已授权,此时可以通知页面执行接下来的操作
_this.$emit('changeAuth');
}
if (e.deniedAlways.length > 0) {
//当前查询权限已被永久禁用,此时需要引导用户跳转手机系统设置去开启
uni.showModal({
title: '温馨提示',
content: '还没有该权限,立即去设置开启?',
cancelText: "取消",
confirmText: "去设置",
showCancel: true,
confirmColor: '#000',
cancelColor: '#666',
success: (res) => {
if (res.confirm) {
_this.goSetting();
}
}
})
}
})
} else {
//IOS不需要添加自定义弹框来描述权限目的因为在配置文件的隐私信息访问的许可描述里可添加
//正常可以直接调用uni的API调起权限询问弹框使用各种权限下面的判断使用场景主要是在IOS禁用某权限后这个可以判断有无权限进而引导用户跳转设置开启仅列出了位置、相册、通讯录、相机、录音等权限其他IOS权限可具体参考 https://ext.dcloud.net.cn/plugin?id=15787
let result = 0;
if (permissionID == 'ACCESS_FINE_LOCATION') {
//IOS检测位置权限
let cLLocationManager = plus.ios.importClass("CLLocationManager"),
authStatus = cLLocationManager.authorizationStatus(),
enable = cLLocationManager.locationServicesEnabled();
if (enable && authStatus != 2) {
result = 1;
} else {
result = 0;
}
plus.ios.deleteObject(cLLocationManager);
} else if (permissionID == 'WRITE_EXTERNAL_STORAGE') {
//IOS检测相册权限
let PHPhotoLibrary = plus.ios.importClass("PHPhotoLibrary"),
authStatus = PHPhotoLibrary.authorizationStatus();
if (authStatus === 3) {
result = 1;
} else {
result = 0;
}
plus.ios.deleteObject(PHPhotoLibrary);
} else if (permissionID == 'CAMERA') {
//IOS检测相机/摄像头权限
let avCaptureDevice = plus.ios.importClass("AVCaptureDevice"),
authStatus = avCaptureDevice.authorizationStatusForMediaType("vide");
if (authStatus === 3) {
result = 1;
} else {
result = 0;
}
plus.ios.deleteObject(avCaptureDevice);
} else if (permissionID == 'CALL_PHONE') {
//IOS检测通讯录权限
let contactStore = plus.ios.importClass("CNContactStore"),
authStatus = contactStore.authorizationStatusForEntityType(0);
if (authStatus === 3) {
result = 1;
} else {
result = 0;
}
plus.ios.deleteObject(contactStore);
}else if(permissionID == 'RECORD_AUDIO'){
//IOS检测麦克风权限
let aVAudioSession = plus.ios.importClass("AVAudioSession"),
aVAudio = aVAudioSession.sharedInstance(),
authStatus = aVAudio.recordPermission();
if ([1684369017, 1970168948].includes(authStatus)) {
result = 0;
} else {
result = 1;
}
plus.ios.deleteObject(aVAudioSession);
}
if (result) {
//当前查询权限已授权,此时可以通知页面执行接下来的操作
that.$emit('changeAuth')
} else {
//当前查询的权限已禁用,引导用户跳转手机系统设置去开启
uni.showModal({
title: '温馨提示',
content: '还没有该权限,立即去设置开启?',
cancelText: "取消",
confirmText: "去设置",
showCancel: true,
confirmColor: '#000',
cancelColor: '#666',
success: (res) => {
if (res.confirm) {
_this.goSetting();
}
}
})
}
}
// #endif
},
//跳转手机系统设置
goSetting() {
if (plus.os.name == "iOS") {
var UIApplication = plus.ios.import("UIApplication");
var application2 = UIApplication.sharedApplication();
var NSURL2 = plus.ios.import("NSURL");
var setting2 = NSURL2.URLWithString("app-settings:");
application2.openURL(setting2);
plus.ios.deleteObject(setting2);
plus.ios.deleteObject(NSURL2);
plus.ios.deleteObject(application2);
} else {
var Intent = plus.android.importClass("android.content.Intent");
var Settings = plus.android.importClass("android.provider.Settings");
var Uri = plus.android.importClass("android.net.Uri");
var mainActivity = plus.android.runtimeMainActivity();
var intent = new Intent();
intent.setAction(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
var uri = Uri.fromParts("package", mainActivity.getPackageName(), null);
intent.setData(uri);
mainActivity.startActivity(intent);
}
}
}
}
</script>
<style lang="scss">
.uni-popup {
position: fixed;
top: 20px;
bottom: 0;
left: 0;
right: 0;
z-index: 99999;
overflow: hidden;
&__wrapper {
position: absolute;
z-index: 999;
/* #ifndef APP-NVUE */
box-sizing: border-box;
/* #endif */
&.ani {
/* #ifndef APP-NVUE */
transition: all 0.3s;
/* #endif */
}
&.top {
top: 0;
width:705rpx;
/* #ifdef APP-NVUE */
left:22.5rpx;
/* #endif */
/* #ifndef APP-NVUE */
left:0;
transform: translateY(-705rpx);
/* #endif */
}
&-box {
position: relative;
/* #ifndef APP-NVUE */
box-sizing: border-box;
/* #endif */
}
&.uni-custom {
& .uni-popup__wrapper-box {
width: 705rpx;
/* #ifndef APP-NVUE */
margin: 0 22.5rpx;
/* #endif */
padding: 30upx;
background: #fff;
border: solid 2rpx #ddd;
/* #ifndef APP-NVUE */
box-sizing: border-box;
/* #endif */
border-radius: 16rpx;
.title{
font-size: 32rpx;
font-weight: bold;
}
.content{
margin-top: 16rpx;
line-height: 1.6;
}
}
&.top{
& .uni-popup__wrapper-box {
width: 705rpx;
}
}
}
&.uni-top{
transform: translateY(0);
}
}
}
</style>

View File

@@ -2,8 +2,8 @@
"name" : "灿能物联", "name" : "灿能物联",
"appid" : "__UNI__88BC25B", "appid" : "__UNI__88BC25B",
"description" : "", "description" : "",
"versionName" : "1.5.9", "versionName" : "1.6.0",
"versionCode" : 159, "versionCode" : 160,
"transformPx" : false, "transformPx" : false,
/* 5+App */ /* 5+App */
"app-plus" : { "app-plus" : {
@@ -143,8 +143,8 @@
"proxy" : { "proxy" : {
"/api" : { "/api" : {
"https" : true, "https" : true,
"target" : "https://pqmcn.com:8092/api", // "target" : "https://pqmcn.com:8092/api",
// "target" : "http://192.168.1.126:10215", "target" : "http://192.168.1.126:10215",
"changOrigin" : true, "changOrigin" : true,
"pathRewrite" : { "pathRewrite" : {
"/api" : "" "/api" : ""

View File

@@ -1,16 +1,20 @@
{ {
"dependencies": { "id": "yk-authpup",
"crypto-js": "^4.1.1", "name": "解决软件在运行时,未见向用户告知权限申请的目的,华为等上架被拒问题",
"html2canvas": "^1.4.1", "displayName": "解决软件在运行时,未见向用户告知权限申请的目的,华为等上架被拒问题",
"image-tools": "^1.4.0", "version": "1.0.5",
"jsrsasign": "^10.8.6", "description": "解决软件在运行时,未见向用户告知权限申请的目的,华为等上架被拒问题",
"mqtt": "3.0.0", "keywords": [
"pinyin-pro": "^3.13.2", "uniapp",
"qs": "^6.11.2", "华为上架",
"vconsole": "^3.15.1" "权限",
}, "权限申请",
"devDependencies": { "权限判断"
"@types/html5plus": "^1.0.2", ],
"@types/uni-app": "^1.4.4" "dcloudext": {
} "category": [
"前端组件",
"通用组件"
]
}
} }

File diff suppressed because it is too large Load Diff

View File

@@ -14,7 +14,9 @@
<uni-easyinput type="textarea" v-model="formData.description" placeholder="请输入详细描述"/> <uni-easyinput type="textarea" v-model="formData.description" placeholder="请输入详细描述"/>
</uni-forms-item> </uni-forms-item>
<uni-forms-item label="图片"> <uni-forms-item label="图片">
<uni-file-picker :auto-upload="false" @select="fileChange" @delete="delImg"/> <uni-file-picker :auto-upload="false" @select="fileChange" @delete="delImg">
</uni-file-picker>
</uni-forms-item> </uni-forms-item>
</uni-forms> </uni-forms>
</view> </view>
@@ -54,6 +56,9 @@ export default {
console.log(e); console.log(e);
this.formData.files = this.formData.files.filter(item => item.url !== e.tempFilePath) this.formData.files = this.formData.files.filter(item => item.url !== e.tempFilePath)
}, },
pickerClick(){
console.log(123);
},
fileChange(e) { fileChange(e) {
console.log(e); console.log(e);
e.tempFilePaths.forEach(item => { e.tempFilePaths.forEach(item => {

View File

@@ -120,14 +120,19 @@
<view style="color: #6c6c6c; margin-top: 3rpx; "> 用于相机扫描二维码!</view> <view style="color: #6c6c6c; margin-top: 3rpx; "> 用于相机扫描二维码!</view>
</uni-popup-message> </uni-popup-message>
</uni-popup> </uni-popup>
<yk-authpup ref="authpup" type="top" @changeAuth="changeAuth" permissionID="CAMERA"></yk-authpup>
</view> </view>
</template> </template>
<script> <script>
import { roleUpdate, autoLogin } from '@/common/api/user' import { roleUpdate, autoLogin } from '@/common/api/user'
import { transferDevice, shareDevice } from '@/common/api/device' import { transferDevice, shareDevice } from '@/common/api/device'
import ykAuthpup from "@/components/yk-authpup/yk-authpup";
export default { export default {
components: {
ykAuthpup
},
data() { data() {
return { return {
loading: true, loading: true,
@@ -183,17 +188,24 @@ export default {
}) })
}) })
}, },
changeAuth(){
//这里是权限通过后执行自己的代码逻辑
console.log('权限已授权,可执行自己的代码逻辑了');
// this.handleScon()
this.handleScon()
},
jump(type) { jump(type) {
switch (type) { switch (type) {
case 'scan': case 'scan':
if ( if (
plus.os.name == 'Android' && plus.os.name == 'Android'
plus.navigator.checkPermission('android.permission.CAMERA') === 'undetermined' // && plus.navigator.checkPermission('android.permission.CAMERA') === 'undetermined'
) { ) {
//未授权 //未授权
// this.$refs.alertDialog.open('bottom')
this.$refs['authpup'].open()
// this.$refs.message.open()
this.$refs.message.open()
this.$refs.alertDialog.open('bottom')
} else { } else {
console.log(2) console.log(2)
this.handleScon() this.handleScon()

View File

@@ -4,7 +4,7 @@
<view class="about"> <view class="about">
<image src="/static/logo.png" class="logo"></image> <image src="/static/logo.png" class="logo"></image>
<view class="name">灿能物联</view> <view class="name">灿能物联</view>
<view class="version">Version 1.1.1</view> <view class="version">Version 1.6.0</view>
</view> </view>
</view> </view>
</Cn-page> </Cn-page>

View File

@@ -1,121 +1,147 @@
<template> <template>
<view> <view>
<Cn-page :loading="loading"> <Cn-page :loading="loading">
<view slot="body"> <view slot="body">
<view class="head"> <view class="head">
<image class="head-img" :src="userInfo.avatar" v-if="userInfo.avatar"></image> <image class="head-img" :src="userInfo.avatar" v-if="userInfo.avatar"></image>
<image class="head-img" src="/static/head.png" v-else></image> <image class="head-img" src="/static/head.png" v-else></image>
<view class="head-setup"> <view class="head-setup">
<view class="head-setup-item" @click="take('album')">从相册选一张</view> <view class="head-setup-item" @click="take('album')">从相册选一张</view>
<view class="head-setup-item" @click="take('camera')">拍一张照片</view> <view class="head-setup-item" @click="take('camera')">拍一张照片</view>
</view> </view>
</view> </view>
</view> </view>
</Cn-page> </Cn-page>
<uni-popup ref="alertDialog" type="dialog"> <uni-popup ref="alertDialog" type="dialog">
<uni-popup-dialog <uni-popup-dialog
style="width: 90%; margin: 5%" style="width: 90%; margin: 5%"
cancelText="禁止" cancelText="禁止"
confirmText="允许" confirmText="允许"
title="权限说明" title="权限说明"
content='是否允许"灿能物联"使用相机?' content='是否允许"灿能物联"使用相机?'
@confirm="handleScon('camera')" @confirm="handleScon('camera')"
@close="dialogClose" @close="dialogClose"
></uni-popup-dialog> ></uni-popup-dialog>
</uni-popup> </uni-popup>
<uni-popup ref="message" type="message"> <uni-popup ref="message" type="message">
<uni-popup-message type="info" :duration="0" style="width: 90%; margin: 5%"> <uni-popup-message type="info" :duration="0" style="width: 90%; margin: 5%">
<view style="color: #909399; font-style: 16px">相机权限使用说明:</view> <view style="color: #909399; font-style: 16px">相机权限使用说明:</view>
<view style="color: #6c6c6c; margin-top: 3rpx; "> 用于拍照上传头像!</view> <view style="color: #6c6c6c; margin-top: 3rpx"> 用于拍照上传头像!</view>
</uni-popup-message> </uni-popup-message>
</uni-popup> </uni-popup>
</view> <yk-authpup ref="authpup" type="top" @changeAuth="changeAuth" permissionID="CAMERA"></yk-authpup>
<yk-authpup
ref="authpup1"
type="top"
@changeAuth="changeAuth"
permissionID="WRITE_EXTERNAL_STORAGE"
></yk-authpup>
</view>
</template> </template>
<script> <script>
import { uploadImage, getImageUrl } from '@/common/api/basic' import { uploadImage, getImageUrl } from '@/common/api/basic'
import { apiUpdateUser } from '@/common/api/user' import { apiUpdateUser } from '@/common/api/user'
import ykAuthpup from '@/components/yk-authpup/yk-authpup'
export default { export default {
data() { components: {
return { ykAuthpup,
loading: false, },
userInfo: {}, data() {
} return {
}, loading: false,
methods: { userInfo: {},
take(type) { type: '',
if (type == 'camera') { }
if ( },
plus.os.name == 'Android' && methods: {
plus.navigator.checkPermission('android.permission.CAMERA') === 'undetermined' take(type) {
) { this.type = type
//未授权 if (type == 'camera') {
this.$refs.message.open() if (plus.os.name == 'Android') {
this.$refs.alertDialog.open('bottom') this.$refs['authpup'].open()
} else { //未授权
this.handleScon(type) // this.$refs.message.open()
} // this.$refs.alertDialog.open('bottom')
} else { } else {
this.handleScon(type) this.handleScon(type)
} }
}, } else {
handleScon(type) { if (plus.os.name == 'Android') {
this.$refs.message.close() this.$refs['authpup1'].open()
uni.chooseImage({ //未授权
count: 1, // this.$refs.message.open()
sizeType: ['original', 'compressed'], // this.$refs.alertDialog.open('bottom')
sourceType: [type], } else {
success: (res) => { this.handleScon(type)
}
// this.handleScon(type)、
}
},
changeAuth() {
//这里是权限通过后执行自己的代码逻辑
console.log('权限已授权,可执行自己的代码逻辑了')
// this.handleScon()
this.handleScon(this.type)
},
handleScon(type) {
this.$refs.message.close()
uni.chooseImage({
count: 1,
sizeType: ['original', 'compressed'],
sourceType: [type],
success: (res) => {
uploadImage(res.tempFilePaths[0]).then((res) => {
console.log(res)
let result = JSON.parse(res[1].data)
apiUpdateUser({
headSculpture: result.data.minFileUrl,
}).then((res) => {
console.log(res)
this.userInfo.headSculpture = result.data.minFileUrl
this.userInfo.avatar = this.$config.static + result.data.minFileUrl
uni.setStorageSync(this.$cacheKey.userInfo, this.userInfo)
this.$forceUpdate()
})
})
},
})
},
dialogClose() {
this.$refs.message.close()
},
},
uploadImage(res.tempFilePaths[0]).then((res) => { onLoad(options) {
console.log(res) this.userInfo = uni.getStorageSync(this.$cacheKey.userInfo)
let result = JSON.parse(res[1].data) },
apiUpdateUser({
headSculpture: result.data.minFileUrl,
}).then((res) => {
console.log(res)
this.userInfo.headSculpture = result.data.minFileUrl
this.userInfo.avatar = this.$config.static + result.data.minFileUrl
uni.setStorageSync(this.$cacheKey.userInfo, this.userInfo)
this.$forceUpdate()
})
})
},
})
},
dialogClose() {this.$refs.message.close()},
},
onLoad(options) {
this.userInfo = uni.getStorageSync(this.$cacheKey.userInfo)
},
} }
</script> </script>
<style lang="scss"> <style lang="scss">
.head { .head {
.head-img { .head-img {
height: 750rpx; height: 750rpx;
width: 750rpx; width: 750rpx;
} }
.head-setup { .head-setup {
position: fixed; position: fixed;
bottom: 0; bottom: 0;
left: 0; left: 0;
width: 750rpx; width: 750rpx;
padding-bottom: 60rpx; padding-bottom: 60rpx;
background-color: #fff; background-color: #fff;
.head-setup-item { .head-setup-item {
height: 100rpx; height: 100rpx;
line-height: 100rpx; line-height: 100rpx;
text-align: center; text-align: center;
border-top: 1rpx solid #e8e8e8; border-top: 1rpx solid #e8e8e8;
} }
} }
} }
/deep/ .uni-popup-message__box { /deep/ .uni-popup-message__box {
border-radius: 10rpx !important; border-radius: 10rpx !important;
background-color: #fff; background-color: #fff;
} }
</style> </style>

View File

@@ -1,17 +1,29 @@
<template> <template>
<view class="uni-file-picker__container"> <view class="uni-file-picker__container">
<view class="file-picker__box" v-for="(item,index) in filesList" :key="index" :style="boxStyle"> <view class="file-picker__box" v-for="(item, index) in filesList" :key="index" :style="boxStyle">
<view class="file-picker__box-content" :style="borderStyle"> <view class="file-picker__box-content" :style="borderStyle">
<image class="file-image" :src="item.url" mode="aspectFill" @click.stop="prviewImage(item,index)"></image> <image
class="file-image"
:src="item.url"
mode="aspectFill"
@click.stop="prviewImage(item, index)"
></image>
<view v-if="delIcon && !readonly" class="icon-del-box" @click.stop="delFile(index)"> <view v-if="delIcon && !readonly" class="icon-del-box" @click.stop="delFile(index)">
<view class="icon-del"></view> <view class="icon-del"></view>
<view class="icon-del rotate"></view> <view class="icon-del rotate"></view>
</view> </view>
<view v-if="(item.progress && item.progress !== 100) ||item.progress===0 " class="file-picker__progress"> <view
<progress class="file-picker__progress-item" :percent="item.progress === -1?0:item.progress" stroke-width="4" v-if="(item.progress && item.progress !== 100) || item.progress === 0"
:backgroundColor="item.errMsg?'#ff5a5f':'#EBEBEB'" /> class="file-picker__progress"
>
<progress
class="file-picker__progress-item"
:percent="item.progress === -1 ? 0 : item.progress"
stroke-width="4"
:backgroundColor="item.errMsg ? '#ff5a5f' : '#EBEBEB'"
/>
</view> </view>
<view v-if="item.errMsg" class="file-picker__mask" @click.stop="uploadFiles(item,index)"> <view v-if="item.errMsg" class="file-picker__mask" @click.stop="uploadFiles(item, index)">
点击重试 点击重试
</view> </view>
</view> </view>
@@ -24,269 +36,344 @@
</slot> </slot>
</view> </view>
</view> </view>
<view class="head-setup" v-if="headShow" @click="headShow = false">
<view class="head-setup-box">
<view class="head-setup-item" @click="take('camera')">拍摄</view>
<view class="head-setup-item" @click="take('album')">从相册选择</view>
<view class="head-setup-item" style="margin-top: 25rpx">取消</view>
</view>
</view>
<yk-authpup ref="authpup" type="top" @changeAuth="changeAuth" permissionID="CAMERA"></yk-authpup>
<yk-authpup
ref="authpup1"
type="top"
@changeAuth="changeAuth"
permissionID="WRITE_EXTERNAL_STORAGE"
></yk-authpup>
</view> </view>
</template> </template>
<script> <script>
export default { import ykAuthpup from '@/components/yk-authpup/yk-authpup'
name: "uploadImage", export default {
emits:['uploadFiles','choose','delFile'], components: {
props: { ykAuthpup,
filesList: { },
type: Array, name: 'uploadImage',
default () { emits: ['uploadFiles', 'choose', 'delFile'],
return [] props: {
} filesList: {
type: Array,
default() {
return []
}, },
disabled:{
type: Boolean,
default: false
},
disablePreview: {
type: Boolean,
default: false
},
limit: {
type: [Number, String],
default: 9
},
imageStyles: {
type: Object,
default () {
return {
width: 'auto',
height: 'auto',
border: {}
}
}
},
delIcon: {
type: Boolean,
default: true
},
readonly:{
type:Boolean,
default:false
}
}, },
computed: { disabled: {
styles() { type: Boolean,
let styles = { default: false,
},
disablePreview: {
type: Boolean,
default: false,
},
limit: {
type: [Number, String],
default: 9,
},
imageStyles: {
type: Object,
default() {
return {
width: 'auto', width: 'auto',
height: 'auto', height: 'auto',
border: {} border: {},
} }
return Object.assign(styles, this.imageStyles)
}, },
boxStyle() { },
const { delIcon: {
width = 'auto', type: Boolean,
height = 'auto' default: true,
} = this.styles },
let obj = {} readonly: {
if (height === 'auto') { type: Boolean,
if (width !== 'auto') { default: false,
obj.height = this.value2px(width) },
obj['padding-top'] = 0 },
} else { computed: {
obj.height = 0 styles() {
} let styles = {
} else { width: 'auto',
obj.height = this.value2px(height) height: 'auto',
border: {},
}
return Object.assign(styles, this.imageStyles)
},
boxStyle() {
const { width = 'auto', height = 'auto' } = this.styles
let obj = {}
if (height === 'auto') {
if (width !== 'auto') {
obj.height = this.value2px(width)
obj['padding-top'] = 0 obj['padding-top'] = 0
}
if (width === 'auto') {
if (height !== 'auto') {
obj.width = this.value2px(height)
} else {
obj.width = '33.3%'
}
} else { } else {
obj.width = this.value2px(width) obj.height = 0
} }
} else {
obj.height = this.value2px(height)
obj['padding-top'] = 0
}
let classles = '' if (width === 'auto') {
for(let i in obj){ if (height !== 'auto') {
classles+= `${i}:${obj[i]};` obj.width = this.value2px(height)
}
return classles
},
borderStyle() {
let {
border
} = this.styles
let obj = {}
const widthDefaultValue = 1
const radiusDefaultValue = 3
if (typeof border === 'boolean') {
obj.border = border ? '1px #eee solid' : 'none'
} else { } else {
let width = (border && border.width) || widthDefaultValue obj.width = '33.3%'
width = this.value2px(width)
let radius = (border && border.radius) || radiusDefaultValue
radius = this.value2px(radius)
obj = {
'border-width': width,
'border-style': (border && border.style) || 'solid',
'border-color': (border && border.color) || '#eee',
'border-radius': radius
}
} }
let classles = '' } else {
for(let i in obj){ obj.width = this.value2px(width)
classles+= `${i}:${obj[i]};` }
let classles = ''
for (let i in obj) {
classles += `${i}:${obj[i]};`
}
return classles
},
borderStyle() {
let { border } = this.styles
let obj = {}
const widthDefaultValue = 1
const radiusDefaultValue = 3
if (typeof border === 'boolean') {
obj.border = border ? '1px #eee solid' : 'none'
} else {
let width = (border && border.width) || widthDefaultValue
width = this.value2px(width)
let radius = (border && border.radius) || radiusDefaultValue
radius = this.value2px(radius)
obj = {
'border-width': width,
'border-style': (border && border.style) || 'solid',
'border-color': (border && border.color) || '#eee',
'border-radius': radius,
} }
return classles }
let classles = ''
for (let i in obj) {
classles += `${i}:${obj[i]};`
}
return classles
},
},
data() {
return {
headShow: false,
type:''
}
},
methods: {
uploadFiles(item, index) {
this.$emit('uploadFiles', item)
},
choose() {
this.headShow = true
// this.$emit('choose')
},
take(type) {
this.type = type
if (type == 'camera') {
if (plus.os.name == 'Android') {
this.$refs['authpup'].open()
//未授权
// this.$refs.message.open()
// this.$refs.alertDialog.open('bottom')
} else {
this.$emit('choose',type)
}
} else {
if (plus.os.name == 'Android') {
this.$refs['authpup1'].open()
//未授权
// this.$refs.message.open()
// this.$refs.alertDialog.open('bottom')
} else {
this.$emit('choose',type)
}
// this.handleScon(type)、
} }
}, },
methods: { changeAuth() {
uploadFiles(item, index) { //这里是权限通过后执行自己的代码逻辑
this.$emit("uploadFiles", item) console.log('权限已授权,可执行自己的代码逻辑了')
}, // this.handleScon()
choose() { this.$emit('choose',this.type)
this.$emit("choose") },
}, delFile(index) {
delFile(index) { this.$emit('delFile', index)
this.$emit('delFile', index) },
}, prviewImage(img, index) {
prviewImage(img, index) { let urls = []
let urls = [] if (Number(this.limit) === 1 && this.disablePreview && !this.disabled) {
if(Number(this.limit) === 1&&this.disablePreview&&!this.disabled){ this.$emit('choose')
this.$emit("choose")
}
if(this.disablePreview) return
this.filesList.forEach(i => {
urls.push(i.url)
})
uni.previewImage({
urls: urls,
current: index
});
},
value2px(value) {
if (typeof value === 'number') {
value += 'px'
} else {
if (value.indexOf('%') === -1) {
value = value.indexOf('px') !== -1 ? value : value + 'px'
}
}
return value
} }
} if (this.disablePreview) return
} this.filesList.forEach((i) => {
urls.push(i.url)
})
uni.previewImage({
urls: urls,
current: index,
})
},
value2px(value) {
if (typeof value === 'number') {
value += 'px'
} else {
if (value.indexOf('%') === -1) {
value = value.indexOf('px') !== -1 ? value : value + 'px'
}
}
return value
},
},
}
</script> </script>
<style lang="scss"> <style lang="scss">
.uni-file-picker__container { .uni-file-picker__container {
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
display: flex; display: flex;
box-sizing: border-box; box-sizing: border-box;
/* #endif */ /* #endif */
flex-wrap: wrap; flex-wrap: wrap;
margin: -5px; margin: -5px;
} }
.file-picker__box { .file-picker__box {
position: relative; position: relative;
// flex: 0 0 33.3%; // flex: 0 0 33.3%;
width: 33.3%; width: 33.3%;
height: 0; height: 0;
padding-top: 33.33%; padding-top: 33.33%;
/* #ifndef APP-NVUE */ /* #ifndef APP-NVUE */
box-sizing: border-box; box-sizing: border-box;
/* #endif */ /* #endif */
} }
.file-picker__box-content { .file-picker__box-content {
position: absolute; position: absolute;
top: 0; top: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
left: 0;
margin: 5px;
border: 1px #eee solid;
border-radius: 5px;
overflow: hidden;
}
.file-picker__progress {
position: absolute;
bottom: 0;
left: 0;
right: 0;
/* border: 1px red solid; */
z-index: 2;
}
.file-picker__progress-item {
width: 100%;
}
.file-picker__mask {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
justify-content: center;
align-items: center;
position: absolute;
right: 0;
top: 0;
bottom: 0;
left: 0;
color: #fff;
font-size: 12px;
background-color: rgba(0, 0, 0, 0.4);
}
.file-image {
width: 100%;
height: 100%;
}
.is-add {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
align-items: center;
justify-content: center;
}
.icon-add {
width: 50px;
height: 5px;
background-color: #f1f1f1;
border-radius: 2px;
}
.rotate {
position: absolute;
transform: rotate(90deg);
}
.icon-del-box {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
align-items: center;
justify-content: center;
position: absolute;
top: 3px;
right: 3px;
height: 26px;
width: 26px;
border-radius: 50%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 2;
transform: rotate(-45deg);
}
.icon-del {
width: 15px;
height: 2px;
background-color: #fff;
border-radius: 2px;
}
.head-setup {
background-color: #fff;
position: fixed;
bottom: 0;
left: 0;
z-index: 10;
width: 750rpx;
height: 100vh;
padding-bottom: 60rpx;
background-color: rgba(0, 0, 0, 0.4);
.head-setup-box {
position: fixed;
bottom: 15rpx;
left: 0; left: 0;
margin: 5px; .head-setup-item {
border: 1px #eee solid; z-index: 12;
border-radius: 5px; height: 100rpx;
overflow: hidden; width: 750rpx;
} background-color: #fff;
line-height: 100rpx;
.file-picker__progress { text-align: center;
position: absolute; border-top: 1rpx solid #e8e8e8;
bottom: 0; }
left: 0;
right: 0;
/* border: 1px red solid; */
z-index: 2;
}
.file-picker__progress-item {
width: 100%;
}
.file-picker__mask {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
justify-content: center;
align-items: center;
position: absolute;
right: 0;
top: 0;
bottom: 0;
left: 0;
color: #fff;
font-size: 12px;
background-color: rgba(0, 0, 0, 0.4);
}
.file-image {
width: 100%;
height: 100%;
}
.is-add {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
align-items: center;
justify-content: center;
}
.icon-add {
width: 50px;
height: 5px;
background-color: #f1f1f1;
border-radius: 2px;
}
.rotate {
position: absolute;
transform: rotate(90deg);
}
.icon-del-box {
/* #ifndef APP-NVUE */
display: flex;
/* #endif */
align-items: center;
justify-content: center;
position: absolute;
top: 3px;
right: 3px;
height: 26px;
width: 26px;
border-radius: 50%;
background-color: rgba(0, 0, 0, 0.5);
z-index: 2;
transform: rotate(-45deg);
}
.icon-del {
width: 15px;
height: 2px;
background-color: #fff;
border-radius: 2px;
} }
}
</style> </style>