yk-authpup.vue 5.7 KB

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