yk-authpup.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  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. }
  56. }
  57. },
  58. created() {
  59. this.getSystemInfo();
  60. },
  61. methods: {
  62. //获取状态栏高度
  63. getSystemInfo(){
  64. uni.getSystemInfo({
  65. success: function(e) {
  66. this.StatusBar = e.statusBarHeight;
  67. }
  68. })
  69. },
  70. open() {
  71. this.requestPermissions(this.permissionID);
  72. },
  73. close(type) {
  74. this.ani = ''
  75. this.$nextTick(() => {
  76. setTimeout(() => {
  77. this.showPopup = false
  78. }, 300)
  79. })
  80. },
  81. //权限检测
  82. requestPermissions(permissionID) {
  83. let _this = this;
  84. let _permissionID;
  85. _permissionID = 'android.permission.' + permissionID;
  86. // #ifdef APP-PLUS
  87. //判断安卓与ios设备
  88. if ( plus.os.name =='Android') {
  89. plus.android.checkPermission(_permissionID,
  90. granted => {
  91. if (granted.checkResult == -1) {
  92. //还未授权当前查询的权限,打开权限申请目的自定义弹框
  93. _this.showPopup = true;
  94. _this.$nextTick(() => {
  95. setTimeout(() => {
  96. _this.ani = 'uni-' + _this.type
  97. }, 30)
  98. })
  99. }
  100. },
  101. error => {
  102. console.log(error.message);
  103. }
  104. );
  105. plus.android.requestPermissions([_permissionID],
  106. (e) => {
  107. //关闭权限申请目的自定义弹框
  108. _this.ani = '';
  109. _this.$nextTick(() => {
  110. setTimeout(() => {
  111. _this.showPopup = false
  112. }, 300)
  113. })
  114. if (e.granted.length > 0) {
  115. //当前查询权限已授权,此时可以通知页面执行接下来的操作
  116. _this.$emit('changeAuth');
  117. }
  118. })
  119. }else{
  120. //IOS不需要,在配置文件的隐私信息访问的许可描述里可添加
  121. }
  122. // #endif
  123. }
  124. }
  125. }
  126. </script>
  127. <style lang="scss">
  128. .uni-popup {
  129. position: fixed;
  130. /* #ifdef H5 */
  131. top: 0px;
  132. // top: 50px;
  133. /* #endif */
  134. /* #ifndef H5 */
  135. top: 0px;
  136. /* #endif */
  137. bottom: 0;
  138. left: 0;
  139. right: 0;
  140. z-index: 99999;
  141. overflow: hidden;
  142. &__wrapper {
  143. position: absolute;
  144. z-index: 999;
  145. box-sizing: border-box;
  146. &.ani {
  147. transition: all 0.3s;
  148. }
  149. &.top {
  150. top: 0;
  151. left: 0;
  152. width: 100%;
  153. transform: translateY(-100%);
  154. }
  155. &.bottom {
  156. bottom: 0;
  157. left: 0;
  158. width: 100%;
  159. transform: translateY(100%);
  160. }
  161. &.right {
  162. bottom: 0;
  163. left: 0;
  164. width: 70%;
  165. transform: translateY(100%);
  166. }
  167. &.center {
  168. width: 100%;
  169. height: 100%;
  170. display: flex;
  171. justify-content: center;
  172. align-items: center;
  173. transform: scale(1.2);
  174. opacity: 0;
  175. }
  176. &-box {
  177. position: relative;
  178. box-sizing: border-box;
  179. }
  180. &.uni-custom {
  181. & .uni-popup__wrapper-box {
  182. // border-radius: 20upx 20upx 0 0;
  183. padding: 30upx;
  184. background: #fff;
  185. .title{
  186. font-size: 32rpx;
  187. font-weight: bold;
  188. }
  189. .content{
  190. margin-top: 16rpx;
  191. line-height: 1.6;
  192. }
  193. }
  194. &.center {
  195. & .uni-popup__wrapper-box {
  196. position: relative;
  197. max-width: 80%;
  198. max-height: 80%;
  199. overflow-y: scroll;
  200. }
  201. }
  202. &.top,
  203. &.bottom {
  204. & .uni-popup__wrapper-box {
  205. width: 100%;
  206. max-height: 1000upx;
  207. // overflow-y: scroll;
  208. }
  209. }
  210. }
  211. &.uni-top,
  212. &.uni-bottom {
  213. transform: translateY(0);
  214. }
  215. &.uni-center {
  216. transform: scale(1);
  217. opacity: 1;
  218. }
  219. }
  220. }
  221. </style>