login.vue 5.3 KB

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