yk-authpup.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view v-if="showPopup" class="uni-popup" @touchmove.stop.prevent="">
  3. <view :class="[type, ani, animation ? 'ani' : '']" class="uni-custom uni-popup__wrapper" @click="close(true)">
  4. <view class="uni-popup__wrapper-box">
  5. <view :style="[{paddingTop: StatusBar+'px'}]">
  6. <view class="title">{{authList[permissionID].title}}</view>
  7. <view class="content">{{authList[permissionID].content}}</view>
  8. </view>
  9. </view>
  10. </view>
  11. </view>
  12. </template>
  13. <script>
  14. export default {
  15. name: 'YkAuthpup',
  16. props: {
  17. // 开启动画
  18. animation: {
  19. type: Boolean,
  20. default: true
  21. },
  22. //弹出层类型,可选值,top: 顶部弹出层;bottom:底部弹出层;center:全屏弹出层,
  23. type: {
  24. type: String,
  25. default: 'center'
  26. },
  27. show: {
  28. type: Boolean,
  29. default: true
  30. },
  31. permissionID: {
  32. type: [String, Number],
  33. default: ''
  34. }
  35. },
  36. data() {
  37. return {
  38. ani: '',
  39. showPopup: false,
  40. StatusBar: '',
  41. authList: {
  42. 'WRITE_EXTERNAL_STORAGE': {
  43. title: "七牛联盟对存储空间/照片权限申请说明",
  44. content: "便于您使用该功能上传您的照片/图片/视频及用于更换头像、意见反馈、保存相册、分享、客服沟通等场景中读取和写入相册和文件内容。"
  45. },
  46. 'ACCESS_FINE_LOCATION': {
  47. title: "七牛联盟对地理位置权限申请说明",
  48. content: "便于应用程序可以提供基于位置的服务、定位导航、附近搜索等功能。"
  49. },
  50. 'CALL_PHONE': {
  51. title: "七牛联盟对拨打/管理电话权限申请说明",
  52. content: "便于您使用该功能联系客服、业务经理与联系等场景下使用"
  53. },
  54. 'CAMERA': {
  55. title: "七牛联盟对拍摄照片/录制视频权限申请说明",
  56. content: "便于您使用该功能上传您的照片/图片/视频及用于更换头像、意见反馈、保存相册、分享、客服沟通等场景下使用。"
  57. },
  58. 'RECORD_AUDIO': {
  59. title: "七牛联盟申请获取麦克风权限",
  60. content: "在下方弹窗中选择允许后,你可以在七牛联盟中发送语音消息的场景使用麦克风进行录音。"
  61. }
  62. }
  63. }
  64. },
  65. created() {
  66. this.getSystemInfo();
  67. },
  68. methods: {
  69. //获取状态栏高度
  70. getSystemInfo() {
  71. uni.getSystemInfo({
  72. success: function(e) {
  73. this.StatusBar = e.statusBarHeight;
  74. }
  75. })
  76. },
  77. open() {
  78. this.requestPermissions(this.permissionID);
  79. },
  80. close(type) {
  81. this.ani = ''
  82. this.$nextTick(() => {
  83. setTimeout(() => {
  84. this.showPopup = false
  85. }, 300)
  86. })
  87. },
  88. //权限检测
  89. requestPermissions(permissionID) {
  90. let _this = this;
  91. let _permissionID;
  92. _permissionID = 'android.permission.' + permissionID;
  93. // #ifdef APP-PLUS
  94. //判断安卓与ios设备
  95. if (plus.os.name == 'Android') {
  96. plus.android.checkPermission(_permissionID,
  97. granted => {
  98. if (granted.checkResult == -1) {
  99. //还未授权当前查询的权限,打开权限申请目的自定义弹框
  100. _this.showPopup = true;
  101. _this.$nextTick(() => {
  102. setTimeout(() => {
  103. _this.ani = 'uni-' + _this.type
  104. }, 30)
  105. })
  106. }
  107. },
  108. error => {
  109. console.log(error.message);
  110. }
  111. );
  112. plus.android.requestPermissions([_permissionID],
  113. (e) => {
  114. //关闭权限申请目的自定义弹框
  115. _this.ani = '';
  116. _this.$nextTick(() => {
  117. setTimeout(() => {
  118. _this.showPopup = false
  119. }, 300)
  120. })
  121. if (e.granted.length > 0) {
  122. //当前查询权限已授权,此时可以通知页面执行接下来的操作
  123. _this.$emit('changeAuth');
  124. } else if (e.deniedAlways.length > 0) {
  125. // console.log(e)
  126. let content = ''
  127. if(permissionID == 'WRITE_EXTERNAL_STORAGE') {
  128. content = '未允许七牛联盟获取存储空间权限,无法访问相册中的图片或视频。'
  129. }
  130. uni.showModal({
  131. title: '提示',
  132. content: content,
  133. confirmText:'去授权',
  134. success(res) {
  135. if (res.confirm) {
  136. uni.openAppAuthorizeSetting({
  137. success: (res) => {
  138. console.log('success')
  139. }
  140. })
  141. }
  142. }
  143. });
  144. }
  145. })
  146. } else {
  147. //IOS不需要,在配置文件的隐私信息访问的许可描述里可添加
  148. }
  149. // #endif
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang="scss">
  155. .uni-popup {
  156. position: fixed;
  157. /* #ifdef H5 */
  158. top: 0px;
  159. // top: 50px;
  160. /* #endif */
  161. /* #ifndef H5 */
  162. top: 0px;
  163. /* #endif */
  164. bottom: 0;
  165. left: 0;
  166. right: 0;
  167. z-index: 99999;
  168. overflow: hidden;
  169. background-color: #fff;
  170. &__wrapper {
  171. position: absolute;
  172. z-index: 999;
  173. box-sizing: border-box;
  174. &.ani {
  175. transition: all 0.3s;
  176. }
  177. &.top {
  178. top: 0;
  179. left: 0;
  180. width: 100%;
  181. transform: translateY(-100%);
  182. }
  183. &.bottom {
  184. bottom: 0;
  185. left: 0;
  186. width: 100%;
  187. transform: translateY(100%);
  188. }
  189. &.right {
  190. bottom: 0;
  191. left: 0;
  192. width: 70%;
  193. transform: translateY(100%);
  194. }
  195. &.center {
  196. width: 100%;
  197. height: 100%;
  198. display: flex;
  199. justify-content: center;
  200. align-items: center;
  201. transform: scale(1.2);
  202. opacity: 0;
  203. }
  204. &-box {
  205. position: relative;
  206. box-sizing: border-box;
  207. }
  208. &.uni-custom {
  209. & .uni-popup__wrapper-box {
  210. // border-radius: 20upx 20upx 0 0;
  211. padding: 30upx;
  212. background: #fff;
  213. .title {
  214. font-size: 32rpx;
  215. font-weight: bold;
  216. }
  217. .content {
  218. margin-top: 16rpx;
  219. line-height: 1.6;
  220. }
  221. }
  222. &.center {
  223. & .uni-popup__wrapper-box {
  224. position: relative;
  225. max-width: 80%;
  226. max-height: 80%;
  227. overflow-y: scroll;
  228. }
  229. }
  230. &.top,
  231. &.bottom {
  232. & .uni-popup__wrapper-box {
  233. width: 100%;
  234. max-height: 1000upx;
  235. // overflow-y: scroll;
  236. }
  237. }
  238. }
  239. &.uni-top,
  240. &.uni-bottom {
  241. transform: translateY(0);
  242. }
  243. &.uni-center {
  244. transform: scale(1);
  245. opacity: 1;
  246. }
  247. }
  248. }
  249. </style>