yk-authpup.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  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. background-color: #fff;
  151. &__wrapper {
  152. position: absolute;
  153. z-index: 999;
  154. box-sizing: border-box;
  155. &.ani {
  156. transition: all 0.3s;
  157. }
  158. &.top {
  159. top: 0;
  160. left: 0;
  161. width: 100%;
  162. transform: translateY(-100%);
  163. }
  164. &.bottom {
  165. bottom: 0;
  166. left: 0;
  167. width: 100%;
  168. transform: translateY(100%);
  169. }
  170. &.right {
  171. bottom: 0;
  172. left: 0;
  173. width: 70%;
  174. transform: translateY(100%);
  175. }
  176. &.center {
  177. width: 100%;
  178. height: 100%;
  179. display: flex;
  180. justify-content: center;
  181. align-items: center;
  182. transform: scale(1.2);
  183. opacity: 0;
  184. }
  185. &-box {
  186. position: relative;
  187. box-sizing: border-box;
  188. }
  189. &.uni-custom {
  190. & .uni-popup__wrapper-box {
  191. // border-radius: 20upx 20upx 0 0;
  192. padding: 30upx;
  193. background: #fff;
  194. .title{
  195. font-size: 32rpx;
  196. font-weight: bold;
  197. }
  198. .content{
  199. margin-top: 16rpx;
  200. line-height: 1.6;
  201. }
  202. }
  203. &.center {
  204. & .uni-popup__wrapper-box {
  205. position: relative;
  206. max-width: 80%;
  207. max-height: 80%;
  208. overflow-y: scroll;
  209. }
  210. }
  211. &.top,
  212. &.bottom {
  213. & .uni-popup__wrapper-box {
  214. width: 100%;
  215. max-height: 1000upx;
  216. // overflow-y: scroll;
  217. }
  218. }
  219. }
  220. &.uni-top,
  221. &.uni-bottom {
  222. transform: translateY(0);
  223. }
  224. &.uni-center {
  225. transform: scale(1);
  226. opacity: 1;
  227. }
  228. }
  229. }
  230. </style>