yk-authpup.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  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. const appName = '馨美研医'
  39. return {
  40. ani: '',
  41. showPopup: false,
  42. StatusBar:'',
  43. authList: {
  44. 'WRITE_EXTERNAL_STORAGE': {
  45. title: appName + "对存储空间/照片权限申请说明",
  46. content: "便于您使用该功能上传您的照片/图片/视频及用于更换头像、意见反馈、保存相册、分享、客服沟通等场景中读取和写入相册和文件内容。"
  47. },
  48. 'ACCESS_FINE_LOCATION': {
  49. title: appName + "对地理位置权限申请说明",
  50. content: "便于应用程序可以提供基于位置的服务、定位导航、附近搜索等功能。"
  51. },
  52. 'CALL_PHONE': {
  53. title: appName + "对拨打/管理电话权限申请说明",
  54. content: "便于您使用该功能联系客服、业务经理与联系等场景下使用"
  55. },
  56. 'CAMERA': {
  57. title: appName + "对拍摄照片/录制视频权限申请说明",
  58. content: "便于您使用该功能上传您的照片/图片/视频/识别二维码及用于更换头像等场景下使用。"
  59. },
  60. 'RECORD_AUDIO': {
  61. title: appName + "申请获取麦克风权限",
  62. content: "在下方弹窗中选择允许后,你可以在" + appName + "中发送语音消息的场景使用麦克风进行录音。"
  63. }
  64. }
  65. }
  66. },
  67. created() {
  68. this.getSystemInfo();
  69. },
  70. methods: {
  71. //获取状态栏高度
  72. getSystemInfo(){
  73. uni.getSystemInfo({
  74. success: function(e) {
  75. this.StatusBar = e.statusBarHeight;
  76. }
  77. })
  78. },
  79. open() {
  80. this.requestPermissions(this.permissionID);
  81. },
  82. close(type) {
  83. this.ani = ''
  84. this.$nextTick(() => {
  85. setTimeout(() => {
  86. this.showPopup = false
  87. }, 300)
  88. })
  89. },
  90. //权限检测
  91. requestPermissions(permissionID) {
  92. let _this = this;
  93. let _permissionID;
  94. _permissionID = 'android.permission.' + permissionID;
  95. // #ifdef APP-PLUS
  96. //判断安卓与ios设备
  97. if ( plus.os.name =='Android') {
  98. plus.android.checkPermission(_permissionID,
  99. granted => {
  100. if (granted.checkResult == -1) {
  101. //还未授权当前查询的权限,打开权限申请目的自定义弹框
  102. _this.showPopup = true;
  103. _this.$nextTick(() => {
  104. setTimeout(() => {
  105. _this.ani = 'uni-' + _this.type
  106. }, 30)
  107. })
  108. }
  109. },
  110. error => {
  111. console.log(error.message);
  112. }
  113. );
  114. plus.android.requestPermissions([_permissionID],
  115. (e) => {
  116. //关闭权限申请目的自定义弹框
  117. _this.ani = '';
  118. _this.$nextTick(() => {
  119. setTimeout(() => {
  120. _this.showPopup = false
  121. }, 300)
  122. })
  123. if (e.granted.length > 0) {
  124. //当前查询权限已授权,此时可以通知页面执行接下来的操作
  125. _this.$emit('changeAuth');
  126. }
  127. })
  128. }else{
  129. //IOS不需要,在配置文件的隐私信息访问的许可描述里可添加
  130. }
  131. // #endif
  132. }
  133. }
  134. }
  135. </script>
  136. <style lang="scss">
  137. .uni-popup {
  138. position: fixed;
  139. /* #ifdef H5 */
  140. top: 0px;
  141. // top: 50px;
  142. /* #endif */
  143. /* #ifndef H5 */
  144. top: 0px;
  145. /* #endif */
  146. bottom: 0;
  147. left: 0;
  148. right: 0;
  149. z-index: 99999;
  150. overflow: hidden;
  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. width: 100%;
  216. max-height: 1000upx;
  217. // overflow-y: scroll;
  218. }
  219. }
  220. }
  221. &.uni-top,
  222. &.uni-bottom {
  223. transform: translateY(0);
  224. }
  225. &.uni-center {
  226. transform: scale(1);
  227. opacity: 1;
  228. }
  229. }
  230. }
  231. </style>