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

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