login.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. <template>
  2. <view class="login">
  3. <statusBar :item='navBarData'></statusBar>
  4. <view class="img">
  5. <image src="https://teacherapi.cocorobo.cn/teaching-file/static//yym/image7.png" mode="aspectFill"></image>
  6. </view>
  7. <view class="mid">
  8. <!-- <radio value="r1" @click="radioCheck" size="10" :checked="isOK" /> -->
  9. <view class="" style="position: relative;padding-left:30rpx;">
  10. 我已阅读并同意<text>《教育小程序服务条款》</text>和 <text>《 隐私协议》</text>新用户自动注册
  11. <view class="quan" @click="isDui">
  12. <image v-if="isShow" class="dui" src="https://teacherapi.cocorobo.cn/teaching-file/static//yym/dui.png"
  13. mode="aspectFill"></image>
  14. </view>
  15. </view>
  16. </view>
  17. <!-- <button class="btn" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
  18. 一键登录
  19. </button> -->
  20. <button class="btn" @click="gotoIndex">一键登录</button>
  21. <!-- <button class="btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">一键登录</button> -->
  22. <view class="footer" @click="goto">
  23. <text>手机号登录/账号密码登录</text>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. data() {
  30. return {
  31. avatarUrl: 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0',
  32. isOK: false,
  33. navBarData: {
  34. title: '首页',
  35. btn: 1 //判断是否显示返回按钮
  36. },
  37. isMsg: 0,
  38. isShow: false
  39. };
  40. },
  41. methods: {
  42. onChooseAvatar(e) {
  43. console.log(e);
  44. const {
  45. avatarUrl
  46. } = e.detail
  47. this.avatarUrl = avatarUrl
  48. let openid=uni.getStorageSync('oId')
  49. const uploadTask = uni.uploadFile({
  50. url: 'http://localhost:3001/img', // post请求地址
  51. filePath: avatarUrl,
  52. name: 'file', // 待确认
  53. header: {
  54. // 不要写这个不然报错
  55. // 'Content-Type': 'multipart/form-data',
  56. },
  57. formData: {
  58. // 携带的用户数据
  59. userId: openid, // 用户ID
  60. },
  61. success: function(res) {
  62. return res
  63. let url = JSON.parse(res.data)
  64. console.log(url.data);
  65. url.data = url.data.replace(/\\/g, '/')
  66. that.$store.commit('updateAvatar', url.data)
  67. uni.showToast({
  68. title: '修改成功',
  69. duration: 2000
  70. });
  71. },
  72. fail: function(uploadFileFail) {
  73. console.log('Error:', uploadFileFail.data);
  74. },
  75. complete: () => {
  76. // 接口调用结束的回调函数(调用成功、失败都会执行)
  77. // console.log('Complete:');
  78. }
  79. });
  80. },
  81. getPhoneNumber(e) {
  82. console.log(e.detail.code) // 动态令牌
  83. console.log(e.detail.errMsg) // 回调信息(成功失败都会返回)
  84. console.log(e.detail.errno) // 错误码(失败时返回)
  85. },
  86. gotoIndex() {
  87. let oId=uni.getStorageSync('oId')
  88. console.log('gotoIndex:',oId);
  89. let all=[]
  90. // 检查是否注册过
  91. this.$request('/selectUser', 'POST', {
  92. oId:oId,
  93. }).then(res => {
  94. console.log('selectUser',res[0]);
  95. console.log(res[0]==false);
  96. if(res[0]==false) {
  97. console.log('还未注册过,开始注册');
  98. this.$request('/login', 'POST', {
  99. openid:oId,
  100. Nme:'默认名称',
  101. avatar:'https://teacherapi.cocorobo.cn/teaching-file/static//mine/Avatar_default.png'
  102. }).then(res => {
  103. console.log(res,11111);
  104. uni.setStorageSync('token',res.token)
  105. // 注册过后重新登录
  106. this.gotoIndex()
  107. })
  108. }else{
  109. console.log('登录过了',res[0]);
  110. this.$store.dispatch('asyncUpdateUser',res[0][0])
  111. }
  112. })
  113. uni.switchTab({
  114. url:'/pages/index/index'
  115. })
  116. },
  117. goto() {
  118. uni.navigateTo({
  119. url: "/pages/login_two/login_two"
  120. })
  121. },
  122. radioCheck() {
  123. this.isOK = !this.isOK
  124. },
  125. isDui() {
  126. this.isShow = !this.isShow
  127. }
  128. },
  129. onLoad(opt) {
  130. console.log(opt);
  131. this.isMsg = opt.id
  132. console.log(this.$store.state);
  133. }
  134. }
  135. </script>
  136. <style lang="scss">
  137. .login {
  138. background-color: #ffffff;
  139. height: 100vh;
  140. .avatar-wrapper {
  141. width: 300rpx;
  142. background-color: #fff;
  143. margin: auto;
  144. }
  145. .avatar {
  146. width: 60rpx;
  147. height: 60rpx;
  148. }
  149. .img {
  150. // padding: 10vh 0;
  151. padding-top: 10vh;
  152. margin-bottom: 10vh;
  153. width: 750rpx;
  154. display: flex;
  155. justify-content: center;
  156. image {
  157. width: 200rpx;
  158. height: 200rpx;
  159. border-radius: 50%;
  160. }
  161. }
  162. .mid {
  163. display: flex;
  164. justify-content: flex-start;
  165. width: 750rpx;
  166. padding: 0rpx 50rpx;
  167. font-size: 13px;
  168. .quan {
  169. position: absolute;
  170. flex-shrink: 0;
  171. top: 0;
  172. left: -10rpx;
  173. width: 32rpx;
  174. height: 32rpx;
  175. border-radius: 50%;
  176. margin-top: 5rpx;
  177. margin-right: 10rpx;
  178. border: 1px #bdbdbd solid;
  179. display: flex;
  180. justify-content: center;
  181. align-items: center;
  182. .dui {
  183. width: 32rpx;
  184. height: 32rpx;
  185. }
  186. }
  187. text {
  188. color: #4a97f2;
  189. }
  190. }
  191. .btn {
  192. background-color: #0056a8;
  193. color: #ffffff;
  194. border-radius: 30px;
  195. margin: 30rpx 55rpx;
  196. padding: 10rpx 0;
  197. display: flex;
  198. align-items: center;
  199. justify-content: center;
  200. // padding: 0rpx 10rpx;
  201. font-size: 16px;
  202. }
  203. .footer {
  204. display: flex;
  205. justify-content: center;
  206. font-size: 14px;
  207. margin: auto;
  208. color: #666666;
  209. }
  210. }
  211. </style>