u-wx-auth.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. <template>
  2. <u-popup :show="show" mode="bottom" :round="round" :mask-close-able="maskCloseable" :closeable="closeable" @close="handleClose">
  3. <view class="u-wx-auth">
  4. <view v-if="showHeader" class="u-wx-auth__header">
  5. <u-image :src="logo" width="50rpx" height="50rpx" shape="circle"></u-image>
  6. <text class="u-wx-auth__title">{{ appName || title }} 申请</text>
  7. </view>
  8. <view class="u-wx-auth__body">
  9. <view class="u-wx-auth__content">{{ content }}</view>
  10. <view class="u-wx-auth__tips">{{ tips }}</view>
  11. <view class="u-wx-auth__form">
  12. <u-form label-width="50">
  13. <u-form-item label="头像" :border-bottom="true">
  14. <button
  15. class="u-reset-button"
  16. style="margin: 0; padding: 0; width: auto"
  17. hover-class="none"
  18. open-type="chooseAvatar"
  19. @click="chooseAvatar"
  20. @chooseavatar="chooseAvatar"
  21. >
  22. <u-avatar :src="avatar"></u-avatar>
  23. </button>
  24. </u-form-item>
  25. <u-form-item label="昵称" :border-bottom="true">
  26. <input v-model="nickname" class="h-80rpx" type="nickname" placeholder="请输入昵称" />
  27. </u-form-item>
  28. </u-form>
  29. </view>
  30. </view>
  31. <view class="u-wx-auth__footer">
  32. <u-button :disabled="!avatar || !nickname" :throttle-time="1000" shape="circle" type="primary" hover-class="none" @click="handleSubmit">{{ confirmText }}</u-button>
  33. </view>
  34. </view>
  35. </u-popup>
  36. </template>
  37. <script>
  38. import props from './props.js';
  39. import mixin from '../../libs/mixin/mixin';
  40. import mpMixin from '../../libs/mixin/mpMixin';
  41. /**
  42. * WxAuth 微信授权组件
  43. * @description 微信授权组件,用于获取用户基本信息和权限设置
  44. * @property {Boolean} show 是否显示授权弹窗(默认 false )
  45. * @property {String} logo 应用logo(默认 '' )
  46. * @property {String} title 应用标题(默认 '' )
  47. * @property {String} content 内容(默认 '获取您的昵称、头像' )
  48. * @property {String} tips 提示(默认 '以便为您提供更优质的服务' )
  49. * @property {String} confirmText 确认按钮文本(默认 '保存' )
  50. * @property {Number} round 圆角大小(默认 10 )
  51. * @property {Boolean} closeable 是否可关闭(默认 true )
  52. * @property {Boolean} maskCloseable 是否可点击遮罩关闭(默认 false )
  53. * @event {Function} confirm 确认授权时触发
  54. * @event {Function} close 关闭弹窗时触发
  55. * @example <u-wx-auth :show="show" :logo="logo" :title="title" @confirm="onConfirm"></u-wx-auth>
  56. */
  57. export default {
  58. name: 'u-wx-auth',
  59. mixins: [mpMixin, mixin, props],
  60. data() {
  61. return {
  62. avatar: '',
  63. nickname: '',
  64. }
  65. },
  66. // #ifdef VUE3
  67. emits: ['update:show', 'confirm', 'close', 'chooseAvatar'],
  68. // #endif
  69. methods: {
  70. chooseAvatar(e) {
  71. const path = e.detail.avatarUrl;
  72. if (path) {
  73. this.avatar = path;
  74. this.$emit('chooseAvatar', path);
  75. }
  76. },
  77. // 关闭弹窗
  78. handleClose() {
  79. this.$emit('close');
  80. },
  81. // 提交处理
  82. handleSubmit() {
  83. // 基本信息验证
  84. if (!this.avatar) {
  85. return uni.$u.toast('请上传头像');
  86. }
  87. if (!this.nickname) {
  88. return uni.$u.toast('请输入昵称');
  89. }
  90. this.$emit('confirm', {
  91. avatar: this.avatar,
  92. nickname: this.nickname
  93. });
  94. }
  95. }
  96. }
  97. </script>
  98. <style lang="scss" scoped>
  99. @import '../../libs/css/components.scss';
  100. .u-wx-auth{
  101. padding: 20px;
  102. &__header{
  103. @include flex(row);
  104. align-items: center;
  105. }
  106. &__title{
  107. font-size: 15px;
  108. margin-left: 10px;
  109. font-weight: bold;
  110. }
  111. &__footer{
  112. margin-top: 30px;
  113. }
  114. &__form{
  115. margin-top: 30px;
  116. }
  117. &__content{
  118. margin-top: 10px;
  119. font-weight: bold;
  120. font-size: 14px;
  121. }
  122. &__tips{
  123. margin-top: 5px;
  124. color: $u-tips-color;
  125. font-size: 13px;
  126. }
  127. }
  128. </style>