login_Wechat.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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"
  19. src="https://teacherapi.cocorobo.cn/teaching-file/static//yym/dui.png" mode="aspectFill">
  20. </image>
  21. </view>
  22. </view>
  23. </view>
  24. <button class="btn" @click="gotoIndex">一键登录</button>
  25. <view class="footer" @click="goto">
  26. <text>手机号登录/账号密码登录</text>
  27. </view>
  28. <view class="popupBlock" v-if="popupShow">
  29. <view class="pop">
  30. <view class="poptit">
  31. 完善信息
  32. </view>
  33. <view class="infoTxt">
  34. <view class="txtcell">
  35. <view class="">
  36. <text class="dian">*</text><text class="celTit">姓名</text>
  37. </view>
  38. <input type="text" class="inpSty" maxlength="10" placeholder="请输入真实姓名"
  39. placeholder-style="font-size: 28rpx; color: rgb(153, 153, 153);"
  40. v-model="userData.username" />
  41. </view>
  42. <view class="txtcell">
  43. <view class="">
  44. <text class="dian">*</text><text class="celTit">联系方式</text>
  45. </view>
  46. <input @blur="handleInput" type="number" class="inpSty" maxlength="11" placeholder="请输入联系方式"
  47. placeholder-style="font-size: 28rpx; color: rgb(153, 153, 153);" v-model="userData.tel" />
  48. </view>
  49. <view class="txtcell">
  50. <view class="">
  51. <text class="dian">*</text><text class="celTit">学校</text>
  52. </view>
  53. <view class="pickerBlock">
  54. <picker mode="selector" @change="schChange" :range="scharray">
  55. <view class="uni-input">{{!userData.sch?'请选择':userData.sch}}</view>
  56. </picker>
  57. <uni-icons type="right" class="icooo" size="20" color='rgba(0, 0, 0, 0.4)'></uni-icons>
  58. </view>
  59. </view>
  60. <view class="txtcell">
  61. <view class="">
  62. <text class="dian">*</text><text class="celTit">专业</text>
  63. </view>
  64. <view class="pickerBlock">
  65. <picker mode="selector" @change="speChange" :range="speList">
  66. <view class="uni-input">{{!userData.spe?'请选择':userData.spe}}</view>
  67. </picker>
  68. <uni-icons type="right" class="icooo" size="20" color='rgba(0, 0, 0, 0.4)'></uni-icons>
  69. </view>
  70. </view>
  71. <view class="txtcell">
  72. <view class="">
  73. <text class="celTit">职称</text><text
  74. style="color: rgba(0, 0, 0, 0.26);padding-left: 10rpx;">(选填)</text>
  75. </view>
  76. <view class="pickerBlock">
  77. <picker mode="selector" @change="rankChange" :range="rankList">
  78. <view class="uni-input">{{!userData.rankl?'请选择':userData.rankl}}</view>
  79. </picker>
  80. <uni-icons type="right" class="icooo" size="20" color='rgba(0, 0, 0, 0.4)'></uni-icons>
  81. </view>
  82. </view>
  83. </view>
  84. <view :class="btnColor" @click="register">
  85. 完善信息并登录
  86. </view>
  87. <view class="logbri">
  88. 完善个人信息后即可加入“丽湖国际双创虚拟教研室”会员,免费获取海量精品资源~
  89. </view>
  90. </view>
  91. </view>
  92. </view>
  93. </template>
  94. <script>
  95. export default {
  96. data() {
  97. return {
  98. logbtn: 'logbtn',
  99. logbtn2: 'logbtn2',
  100. avatarUrl: '',
  101. nickname: '',
  102. // 学校
  103. scharray: ['深圳城市××大学', '深圳××大学', '深圳××大学', '深圳××大学'],
  104. // 专业
  105. speList: ['互联网', '网络通信', '航空', '汽修', '珠宝', '文秘', '设计'],
  106. // 职称
  107. rankList: ['xx', 'xx', 'xx'],
  108. // 默认头像的
  109. isShow: false,
  110. // 完善信息弹窗的
  111. popupShow: false,
  112. navBarData: {
  113. title: '登录',
  114. btn: 1 //判断是否显示返回按钮
  115. },
  116. btnCol: [],
  117. // 第一次登录
  118. userData: {
  119. openid: '',
  120. username: '',
  121. avatar: '',
  122. tel: '',
  123. sch: '',
  124. spe: '',
  125. rankl: '', //职称
  126. }
  127. };
  128. },
  129. computed: {
  130. btnColor() {
  131. let newArr = []
  132. Object.keys(this.userData).forEach(key => {
  133. if (this.userData[key] == '' && key != 'rankl') {
  134. newArr.push(key)
  135. }
  136. });
  137. console.log('newArr.length', newArr.length);
  138. return newArr.length > 0 || this.userData.tel == 11 ? 'logbtn' : 'logbtn2'
  139. }
  140. },
  141. methods: {
  142. // 判断手机号
  143. handleInput(e) {
  144. // console.log(e.target);
  145. const {value} = e.target
  146. const newValue = value.replace(/[^\d]/g, '') // 只允许输入数字
  147. console.log(newValue);
  148. // if (newValue.length <= 11) {
  149. this.userData.tel = newValue
  150. // }
  151. console.log(this.userData.tel);
  152. },
  153. // 选择用户名称
  154. inpvalue(e) {
  155. this.nickname = e.detail.value
  156. },
  157. schChange(e) {
  158. console.log('picker发送选择改变,携带值为', e.detail.value)
  159. this.userData.sch = this.scharray[e.detail.value]
  160. },
  161. speChange(e) {
  162. console.log('picker发送选择改变,携带值为', e.detail)
  163. this.userData.spe = this.speList[e.detail.value]
  164. },
  165. rankChange(e) {
  166. console.log('picker发送选择改变,携带值为', e.detail)
  167. this.userData.rankl = this.rankList[e.detail.value]
  168. },
  169. // 上传图片
  170. onChooseAvatar(e) {
  171. // 获取上传的图片
  172. const {
  173. avatarUrl
  174. } = e.detail
  175. let that = this
  176. const uploadTask = uni.uploadFile({
  177. url: 'http://139.159.246.165:7006/img', // post请求地址
  178. // url: 'https://cxcy.ssti.net.cn/api/UploadFirmFile', // post请求地址
  179. // filePath: tempFilePaths,
  180. filePath: avatarUrl,
  181. name: 'file', // 待确认
  182. header: {
  183. // 不要写这个不然报错
  184. // 'Content-Type': 'multipart/form-data',
  185. },
  186. success: function(res) {
  187. console.log(res);
  188. that.avatarUrl = res.data
  189. },
  190. fail: function(uploadFileFail) {
  191. console.log('Error:', uploadFileFail.data);
  192. },
  193. complete: () => {
  194. // 接口调用结束的回调函数(调用成功、失败都会执行)
  195. // console.log('Complete:');
  196. }
  197. });
  198. // this.avatarUrl = avatarUrl
  199. },
  200. // 登录
  201. gotoIndex() {
  202. if (this.avatarUrl ==
  203. 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
  204. ) {
  205. uni.showToast({
  206. title: '请选择头像',
  207. icon: 'error',
  208. duration: 1000
  209. });
  210. return
  211. }
  212. if (this.nickname == '') {
  213. uni.showToast({
  214. title: '请输入昵称',
  215. icon: 'error',
  216. duration: 1000
  217. });
  218. return
  219. }
  220. if (!this.isShow) return uni.showToast({
  221. title: '请勾选条约',
  222. icon: 'error',
  223. duration: 1000
  224. });
  225. let oId = uni.getStorageSync('oId')
  226. console.log('gotoIndex:', oId);
  227. // let all = []
  228. // 检查是否注册过
  229. this.$request('/selectUser', 'POST', {
  230. oId: oId,
  231. }).then(res => {
  232. console.log('selectUser', res[0]);
  233. console.log(res[0] == false);
  234. // 账号第一次登录,还没注册过
  235. if (res[0] == false) {
  236. console.log('还未注册过,开始注册');
  237. this.userData.openid = oId
  238. this.userData.username = this.nickname
  239. this.userData.avatar = this.avatarUrl
  240. return this.popupShow = true
  241. } else {
  242. console.log('已注册过直接登录', res[0][0]);
  243. // 修改昵称头像
  244. this.$request('/updateUser', "POST", {
  245. openid: oId,
  246. Nme: this.nickname,
  247. avatar: this.avatarUrl
  248. }).then(res => {
  249. console.log('updateUser', res);
  250. this.$request('/selectUser', 'POST', {
  251. oId: oId,
  252. }).then(res => {
  253. this.$store.dispatch('asyncUpdateUser', res[0][0])
  254. uni.switchTab({
  255. url: '/pages/index/index'
  256. })
  257. })
  258. })
  259. }
  260. })
  261. },
  262. register() {
  263. // username: '',
  264. // tel: '',
  265. // sch: '请选择',
  266. // spe: '请选择',
  267. if (this.userData.username == '') return uni.showToast({
  268. title: '请输入姓名',
  269. icon: 'none'
  270. });
  271. if (this.userData.tel == '') return uni.showToast({
  272. title: '请输入联系方式',
  273. icon: 'none'
  274. });
  275. if (this.userData.sch == '') return uni.showToast({
  276. title: '请输入学校',
  277. icon: 'none'
  278. });
  279. if (this.userData.spe == '') return uni.showToast({
  280. title: '请输入专业',
  281. icon: 'none'
  282. });
  283. if (this.userData.tel.length != 11) return uni.showToast({
  284. title: '号码不足11位,请检查',
  285. icon: 'none'
  286. });
  287. // return console.log(this.userData);
  288. let oId = uni.getStorageSync('oId')
  289. this.$request('/login', 'POST', this.userData).then(res => {
  290. console.log('注册成功', res);
  291. // 添加消息页面系统通知提示已加入会员
  292. this.addMessage()
  293. this.$request('/selectUser', 'POST', {
  294. oId: oId,
  295. }).then(res => {
  296. this.$store.dispatch('asyncUpdateUser', res[0][0])
  297. uni.switchTab({
  298. url: '/pages/index/index'
  299. })
  300. })
  301. })
  302. },
  303. // 添加消息页面系统通知提示报名成功
  304. addMessage() {
  305. let opid = uni.getStorageSync('oId')
  306. let data = {
  307. oid: opid,
  308. acid: '',
  309. type: 2,
  310. }
  311. this.$request('/insertMessage', "POST", data).then(res => {
  312. console.log(res);
  313. })
  314. },
  315. // 跳转其他登录方式
  316. goto() {
  317. uni.navigateTo({
  318. url: "/pages/login_two/login_two"
  319. })
  320. },
  321. // 勾选取消条约
  322. isDui() {
  323. this.isShow = !this.isShow
  324. },
  325. getdata() {
  326. this.$request('/selectUserInfo', "POST", {
  327. openid: uni.getStorageSync('oId')
  328. }).then(res => {
  329. console.log('获取渲染数据', res[0][0]);
  330. let data = res[0][0]
  331. console.log(data);
  332. if (!data) {
  333. return
  334. } else {
  335. this.avatarUrl = data.avatar
  336. this.nickname = data.username
  337. }
  338. })
  339. }
  340. },
  341. onLoad() {
  342. this.avatarUrl =
  343. 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0';
  344. this.getdata()
  345. }
  346. }
  347. </script>
  348. <style lang="scss">
  349. .login_Wechat {
  350. width: 750rpx;
  351. height: 100vh;
  352. background-color: #ffffff;
  353. }
  354. .dian {
  355. color: rgba(245, 69, 69, 1);
  356. }
  357. .celTit {
  358. color: rgba(0, 0, 0, 0.8);
  359. }
  360. .icooo {
  361. transform: translate(0, 5rpx);
  362. }
  363. .block {
  364. width: 750rpx;
  365. height: 30vh;
  366. display: flex;
  367. justify-content: center;
  368. align-items: center;
  369. }
  370. .footer {
  371. display: flex;
  372. justify-content: center;
  373. font-size: 14px;
  374. margin: auto;
  375. color: #666666;
  376. }
  377. .avatar-wrapper {
  378. width: 200rpx;
  379. height: 200rpx;
  380. padding: 0;
  381. image {
  382. width: 200rpx;
  383. height: 200rpx;
  384. }
  385. }
  386. .inp {
  387. display: flex;
  388. align-items: center;
  389. padding: 0rpx 50rpx;
  390. .nc {
  391. // width: 150rpx;
  392. text-align: left;
  393. }
  394. .weui-input {}
  395. }
  396. .mid {
  397. display: flex;
  398. justify-content: flex-start;
  399. width: 750rpx;
  400. padding: 0rpx 50rpx;
  401. font-size: 13px;
  402. margin-top: 80rpx;
  403. .quan {
  404. position: absolute;
  405. flex-shrink: 0;
  406. top: 0;
  407. left: -10rpx;
  408. width: 32rpx;
  409. height: 32rpx;
  410. border-radius: 50%;
  411. margin-top: 5rpx;
  412. margin-right: 10rpx;
  413. border: 1px #bdbdbd solid;
  414. display: flex;
  415. justify-content: center;
  416. align-items: center;
  417. .dui {
  418. width: 32rpx;
  419. height: 32rpx;
  420. }
  421. }
  422. text {
  423. color: #4a97f2;
  424. }
  425. }
  426. .btn {
  427. background-color: #0056a8;
  428. color: #ffffff;
  429. border-radius: 30px;
  430. margin: 30rpx 55rpx;
  431. // padding: 10rpx 0;
  432. display: flex;
  433. align-items: center;
  434. justify-content: center;
  435. margin-top: 30rpx;
  436. // padding: 0rpx 10rpx;
  437. font-size: 16px;
  438. }
  439. .popupBlock {
  440. position: absolute;
  441. left: 0;
  442. top: 0;
  443. width: 750rpx;
  444. height: 100vh;
  445. background-color: rgba(0, 0, 0, 0.6);
  446. display: flex;
  447. justify-content: center;
  448. align-items: center;
  449. z-index: 10;
  450. .pop {
  451. width: 690rpx;
  452. height: 936rpx;
  453. background-color: #ffffff;
  454. border-radius: 30rpx;
  455. padding: 30rpx;
  456. .poptit {
  457. text-align: center;
  458. height: 48rpx;
  459. line-height: 48rpx;
  460. color: rgba(0, 0, 0, 0.88);
  461. }
  462. .infoTxt {
  463. width: 100%;
  464. height: 448rpx;
  465. margin-top: 40rpx;
  466. margin-bottom: 40rpx;
  467. display: flex;
  468. flex-direction: column;
  469. justify-content: space-between;
  470. .txtcell {
  471. display: flex;
  472. justify-content: space-between;
  473. align-items: center;
  474. border-bottom: 1rpx rgba(231, 231, 231, 1) solid;
  475. padding-bottom: 20rpx;
  476. .inpSty {
  477. right: 0;
  478. bottom: 0;
  479. text-align: right;
  480. }
  481. .pickerBlock {
  482. display: flex;
  483. align-items: center;
  484. justify-content: flex-start;
  485. color: rgba(0, 0, 0, 0.4);
  486. .uni-input {
  487. width: 100%;
  488. height: 100%;
  489. }
  490. }
  491. }
  492. }
  493. .logbtn2 {
  494. background-color: rgba(0, 86, 168, 1);
  495. width: 580rpx;
  496. height: 88rpx;
  497. border-radius: 60rpx;
  498. display: flex;
  499. justify-content: center;
  500. align-items: center;
  501. color: #fff;
  502. font-size: 36rpx;
  503. margin: 150rpx auto;
  504. margin-bottom: 30rpx;
  505. }
  506. .logbtn {
  507. width: 580rpx;
  508. height: 88rpx;
  509. border-radius: 60rpx;
  510. display: flex;
  511. justify-content: center;
  512. align-items: center;
  513. color: #fff;
  514. font-size: 36rpx;
  515. background-color: rgba(139, 190, 255, 1);
  516. margin: 150rpx auto;
  517. margin-bottom: 30rpx;
  518. }
  519. .logbri {
  520. width: 580rpx;
  521. margin: auto;
  522. text-align: center;
  523. font-size: 24rpx;
  524. color: rgba(48, 129, 232, 1);
  525. }
  526. }
  527. }
  528. </style>