authorization.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <view class="authorization-box">
  3. <Navbar title="微信授权" background-color="#fff" color="#333"></Navbar>
  4. <image class="pic" :src="pic" mode="aspectFill"></image>
  5. <view class="title">
  6. {{ type === 'info' ? '伊兰迪' : (user.nickname ||'微信昵称') }}
  7. </view>
  8. <view class="tip">
  9. {{ type === 'info' ? '申请获得你的公开信息(头像、昵称)' : '绑定手机号可以获取更多服务' }}
  10. </view>
  11. <view class="btn" @click="bindUserInfo" v-if="type === 'info'">微信用户授权</view>
  12. <button @getphonenumber="getPhone" open-type="getPhoneNumber" class="btn" v-else>
  13. 微信手机号快速登录
  14. </button>
  15. <view class="agree">
  16. 注册登录即表示接受<text @click="handleAgree"> 《用户协议》</text>
  17. </view>
  18. <uni-popup ref="agreement" :safe-area="false">
  19. <scroll-view class="agreement-box" :scroll-y="true">
  20. <view class="title">{{ agreement.title }}</view>
  21. <view class="content-styl" v-html="agreement.content"></view>
  22. </scroll-view>
  23. </uni-popup>
  24. </view>
  25. </template>
  26. <script lang="ts">
  27. import {
  28. Component,
  29. Prop,
  30. Vue,
  31. Mixins,
  32. Watch
  33. } from 'vue-property-decorator';
  34. import loginMixin from '@/common/mixins/loginMixin';
  35. import {
  36. namespace
  37. } from 'vuex-class';
  38. import agreement from './agreement';
  39. const baseModule = namespace('base');
  40. @Component({})
  41. export default class authorization extends Mixins(loginMixin) {
  42. @baseModule.Getter('_userInfo') _userInfo: any;
  43. oss_url: any = this.$oss_url; //oss地址
  44. pic: any = this.$oss_url + 'logo.jpg';
  45. type: string = 'info';
  46. agreement: {
  47. title: string;content: string
  48. } = agreement;
  49. phone: string = '';
  50. user = {
  51. nickname: '',
  52. avatar: ''
  53. };
  54. bindUserInfo(): void {
  55. uni.getUserProfile({
  56. desc: '获取你的昵称、头像、地区及性别',
  57. success: (res: any) => {
  58. this.user.avatar = res.userInfo.avatarUrl;
  59. this.user.nickname = res.userInfo.nickName;
  60. uni.showLoading({
  61. title: '加载中',
  62. });
  63. this.$http
  64. .put({
  65. url: this.$api.updateUserInfo,
  66. data: this.user
  67. })
  68. .then((res: any) => {
  69. uni.hideLoading();
  70. this.type = 'phone';
  71. this.pic = this.user.avatar;
  72. });
  73. }
  74. });
  75. }
  76. getPhone({
  77. detail
  78. }: any) {
  79. if (detail.errMsg !== 'getPhoneNumber:ok') return;
  80. this.phone = detail.code;
  81. uni.showLoading({
  82. title: '加载中',
  83. });
  84. this.$http
  85. .post({
  86. url: this.$api.updatePhone,
  87. data: {
  88. auth: {
  89. agent: 1,
  90. way: 2,
  91. },
  92. third: {
  93. way: 1,
  94. phoneCode: this.phone
  95. }
  96. }
  97. })
  98. .then((res: any) => {
  99. uni.hideLoading();
  100. uni.showToast({
  101. title: '授权成功',
  102. icon: 'none'
  103. });
  104. this.getUserInfo().then((res: any) => {
  105. let query = this.$Route.query;
  106. if (query.to) {
  107. if (query.navType === 'pushTab') {
  108. this.$Router.pushTab({
  109. path: query.to,
  110. query: query.data
  111. });
  112. } else {
  113. this.$Router.replace({
  114. path: query.to,
  115. query: query.data
  116. });
  117. }
  118. } else {
  119. this.$Router.back(1);
  120. }
  121. });
  122. });
  123. // console.log(detail)
  124. // this.getUserInfo().then((res: any) => {
  125. // let query = this.$Route.query;
  126. // if (query.to) {
  127. // this.$Router.replace({
  128. // path: query.to,
  129. // query: query.data
  130. // });
  131. // } else {
  132. // this.$Router.back(1);
  133. // }
  134. // });
  135. }
  136. handleAgree() {
  137. (this.$refs.agreement as any).open('bottom');
  138. }
  139. }
  140. </script>
  141. <style lang="scss" scoped>
  142. .authorization-box {
  143. width: 100%;
  144. background: #fff;
  145. @include flex-y();
  146. min-height: 100vh;
  147. box-sizing: border-box;
  148. .pic {
  149. width: vw(100);
  150. height: vw(100);
  151. border-radius: vw(50);
  152. margin-top: 30%;
  153. background: #D8D8D8;
  154. }
  155. .name {
  156. @include word-vw(24, #333);
  157. font-weight: bold;
  158. margin-top: vw(15);
  159. }
  160. .title {
  161. @include word-vw(16, #333);
  162. margin-top: vw(6);
  163. line-height: vw(22);
  164. }
  165. .tip {
  166. @include word-vw(16, #999);
  167. line-height: vw(22);
  168. margin-top: vw(12);
  169. }
  170. .btn {
  171. width: vw(345);
  172. height: vw(44);
  173. border-radius: vw(4);
  174. @include flex-x(center);
  175. @include word-vw(16, #333);
  176. margin-top: vw(25);
  177. background: $bk-color;
  178. }
  179. .agree {
  180. @include word-vw(14, #666);
  181. margin-top: vw(25);
  182. text {
  183. color: #E6644E;
  184. }
  185. }
  186. //用户协议
  187. .agreement-box {
  188. overflow: hidden;
  189. // overflow-y: auto;
  190. height: vw(480);
  191. background: #fff;
  192. border-top-left-radius: vw(5);
  193. border-top-right-radius: vw(5);
  194. padding-bottom: vw(30);
  195. box-sizing: border-box;
  196. .title {
  197. margin: vw(24) 0 vw(30);
  198. text-align: center;
  199. @include word-vw(16, $gray3);
  200. }
  201. .content-styl {
  202. @include word-vw(14, $gray6);
  203. line-height: vw(24);
  204. padding: 0 vw(15);
  205. }
  206. }
  207. }
  208. </style>