my-login.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <view class="container">
  3. <!-- 背景 -->
  4. <!-- <image src="/static/home/BG.jpg" style="position: absolute;height: 100px;width: 96%;left: 2%" @load="loadImg($event)"></image>-->
  5. <!-- <img src="../../static/home/BG.jpg" class="myImg" alt="">-->
  6. <view>
  7. <!-- <van-icon name="https://b.yzcdn.cn/vant/icon-demo-1126.png" size="130px"/> -->
  8. <!-- <uni-icons type="contact-filled" size="100" color="#AFAFAF"></uni-icons> -->
  9. <!-- <button type="primary" class="btn-login" @click="getUserProfile">一键登录</button> -->
  10. <!-- <text class="tips-text">登录后尽享更多权益</text> -->
  11. <!-- <image class="avatar" :src="avatarUrl"></image>-->
  12. <button @click="test" open-type="login" type="primary">
  13. 去登录界面按钮
  14. </button>
  15. <button @click="toLogin" type="primary">按钮新的</button>
  16. <button @click="test" type="default">获取用户信息</button>
  17. <!-- <input type="nickname" class="weui-input" placeholder="请输入昵称"/>-->
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  23. import {mapMutations,mapActions} from "vuex"
  24. export default {
  25. name:"my-login",
  26. data() {
  27. return {
  28. avatarUrl: defaultAvatarUrl,
  29. };
  30. },
  31. methods: {
  32. ...mapMutations('m_user',{updateUserInfo : 'updateUserInfo'}),
  33. ...mapMutations('m_user',{updateToken:'updateToken'}),
  34. // ...mapActions('m_info',{updateLoggedStatus:"updateLoggedStatus"}),
  35. test(){
  36. // console.log('test')
  37. // console.log()
  38. },
  39. // 获取用户信息的方法
  40. getUserInfo(e){
  41. console.log(e);
  42. // return
  43. },
  44. getUserProfile(){
  45. uni.getUserProfile({
  46. desc: '获取你的昵称、头像、地区及性别',
  47. lang:'zh_CN',
  48. success:res=>{
  49. console.log(res.userInfo,"aaa");
  50. console.log('更新');
  51. this.updateUserInfo(res.userInfo)
  52. this.updateLoggedStatus(true)
  53. this.getToken(res)
  54. },
  55. fail: (e) => {
  56. return uni.$showMsg('您取消了登录授权')
  57. }
  58. })
  59. },
  60. async getToken(info){
  61. this.updateToken('Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo')
  62. // this.updateToken('eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIxLUFETUlOIiwiZXhwIjoxNzM5MDk4Njc4fQ.AY9lfdw6dySsEd7TCCS9POx69OyH3Jpm1at0xOq6H8o')
  63. uni.showToast({
  64. title: '登录成功',
  65. icon: 'success',
  66. duration: 2000
  67. });
  68. this.navigateBack()
  69. },
  70. navigateBack(){
  71. if(this.redirectInfo&&this.redirectInfo.openType==='switchTab'){
  72. uni.switchTab({
  73. url:this.redirectInfo.from,
  74. complete: () => {
  75. this.upddateRedirectInfo(null)
  76. }
  77. })
  78. }
  79. },
  80. toLogin(){
  81. console.log('toLogin')
  82. let self =this
  83. uni.navigateTo({
  84. url: '/subpkg/login/login' ,// 跳转至 subpkg 中的 selShop 页面
  85. success() {
  86. console.log('url跳转成功')
  87. setTimeout(() => {
  88. self.getToken();
  89. }, 500); // 延迟 1000 毫秒(即 1 秒)后调用 getToken() 函数
  90. },
  91. fail() {
  92. console.log('url跳转失败')
  93. }
  94. });
  95. },
  96. onChooseAvatar(e) {
  97. const { avatarUrl } = e.detail
  98. // this.setData({
  99. // avatarUrl,
  100. // })
  101. this.avatarUrl=avatarUrl
  102. console.log('少时诵诗书少时诵诗书是撒是撒是撒是撒是撒是撒是撒是撒是撒')
  103. // return
  104. }
  105. },created() {
  106. console.log('页面created执行')
  107. },
  108. beforeUpdate() {
  109. console.log('页面beforeUpdate执行')
  110. },
  111. mounted() {
  112. console.log('页面mounted执行')
  113. },
  114. }
  115. // export default {
  116. // data() {
  117. // return {};
  118. // },
  119. // // mounted () {
  120. // // console.log('加载中')
  121. // // //开启加载
  122. // // console.log('加载中')
  123. // // uni.showLoading({
  124. // // title: '加载中...',
  125. // // mask: true
  126. // // })
  127. // // },
  128. // methods: {
  129. // created() {
  130. // console.log('页面created执行:',this.num);
  131. // },
  132. // beforeMount() {
  133. // console.log('页面beforeMount执行:',this.num);
  134. // },
  135. // // 此方法会在图片加载完成后触发
  136. // loadImg (e) {
  137. // uni.hideLoading()
  138. // console.log('图片信息', e)
  139. // }
  140. // }
  141. // }
  142. </script>
  143. <style lang="scss">
  144. //.container{
  145. // //display: flex;
  146. // .myImg{
  147. // //border-image-width: 80px;
  148. // width: 100px;
  149. // //height: 100vh;
  150. // }
  151. //}
  152. .login-container{
  153. display: flex;
  154. flex-direction: column;
  155. justify-content: center;
  156. align-items: center;
  157. height: 750rpx;
  158. background-color: #f8f8f8;
  159. position: relative;
  160. overflow: hidden;
  161. &::after{
  162. content: ' ';
  163. display: block;
  164. width: 100%;
  165. height: 40px;
  166. background-color: white;
  167. position: absolute;
  168. bottom: 0;
  169. left: 0;
  170. border-radius: 100%;
  171. transform: translateY(50%);
  172. }
  173. .btn-login{
  174. width: 90%;
  175. border-radius: 100px;
  176. margin: 15px 0;
  177. background-color: #c00000;
  178. }
  179. .tips-text{
  180. font-size: 12px;
  181. color: gray;
  182. }
  183. }
  184. </style>