setting

关于权限的模块

getSetting

获取指定权限或权限列表

  1. import { getSetting } from '@/util/function/wx/setting'
  2. // 获取权限列表
  3. getSetting().then((res) => {
  4. console.log(res)
  5. })
  6. // 获取相册权限是否存在
  7. getSetting('scope.writePhotosAlbum').then((res) => {
  8. console.log(res)
  9. })

参数

参数 类型 是否必填 说明
scope String N 要验证的权限,如果不传则返回所有权限,如果传则返回 Boolean

authorize

获取某权限

  1. import { authorize } from '@/util/function/wx/setting'
  2. // 获取相册权限
  3. authorize('scope.writePhotosAlbum').then((res) => {
  4. console.log(res)
  5. })

参数

参数 类型 是否必填 说明
scope String Y 字符有效值
‘scope.userInfo’: ‘用户信息’,
‘scope.userLocation’: ‘地理位置’,
‘scope.userLocationBackground’: ‘后台定位’,
‘scope.werun’: ‘微信运动步数’,
‘scope.record’: ‘录音’,
‘scope.writePhotosAlbum’: ‘相册’,
‘scope.camera’: ‘摄像头’,
again Boolean N 是否进行2次授权请求默认 true

openSetting

调起客户端小程序设置界面,返回用户设置的操作结果。设置界面只会出现小程序已经向用户请求过的权限。

  1. import { openSetting } from '@/util/function/wx/setting'
  2. // 获取相册权限
  3. openSetting('scope.writePhotosAlbum').then((res) => {
  4. console.log(res)
  5. })
  6. // 返回所有权限
  7. openSetting('').then((res) => {
  8. console.log(res)
  9. })

参数

参数 类型 是否必填 说明
scope String Y 字符有效值
‘scope.userInfo’: ‘用户信息’,
‘scope.userLocation’: ‘地理位置’,
‘scope.userLocationBackground’: ‘后台定位’,
‘scope.werun’: ‘微信运动步数’,
‘scope.record’: ‘录音’,
‘scope.writePhotosAlbum’: ‘相册’,
‘scope.camera’: ‘摄像头’,
withSubscriptions Boolean N 是否同时获取用户订阅消息的订阅状态,默认不获取。注意:withSubscriptions 只返回用户勾选过订阅面板中的“总是保持以上选择,不再询问”的订阅消息。默认 false

file

微信文件处理

chooseImage

上传图片

  1. import { chooseImage } from '@/util/function/wx/file/index.js';
  2. chooseImage(true, false, {}).then((res) => {
  3. console.log(res[0])
  4. })

参数

参数 类型 是否必填 说明
compress Boolean N 是否进行2次压缩(默认 false
getInfo Boolean N 是否得到详情信息(默认 false
config Object N 默认配置 https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.chooseImage.html

compressImages

压缩图片

  1. import { compressImages } from '@/util/function/wx/file/index.js';
  2. compressImages(url).then((res) => {
  3. console.log(res)
  4. })

参数

参数 类型 是否必填 说明
paths Array/String Y 图片路径或图片路径数组
quality Number N 压缩程度(默认 80 )

getImageInfos

获取图片信息

  1. import { chooseImage } from '@/util/function/wx/file/index.js';
  2. getImageInfos(paths).then((res) => {
  3. console.log(res)
  4. })

参数

参数 类型 是否必填 说明
paths Array / String Y 图片路径数组或图片路径

saveImage

下载单张图片

  1. import { saveImage } from '@/util/function/wx/file/index.js';
  2. saveImage('url').then((res) => {
  3. console.log(res)
  4. })

参数

参数 类型 是否必填 说明
filePath String Y 图片路径

chooseMedia

上传 图片 + 视频

  1. import { chooseMedia } from '@/util/function/wx/file/index.js';
  2. chooseMedia().then((res) => {
  3. console.log(res)
  4. })

参数

参数 类型 是否必填 说明
config Object N 默认配置
https://developers.weixin.qq.com/miniprogram/dev/api/media/video/wx.chooseMedia.html

chooseMessageFile

从客户端会话选择文件。

  1. import { chooseMessageFile } from '@/util/function/wx/file/index.js';
  2. chooseMessageFile().then((res) => {
  3. console.log(res)
  4. })

参数

参数 类型 是否必填 说明
config Object N 默认配置
https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.chooseMessageFile.html