login_Wechat.vue 5.7 KB

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