register.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <template>
  2. <view class="page-box login-box">
  3. <view class="login-form sys-radius-50 sys-background-fff">
  4. <view class="from-box ">
  5. <view class="step-item animate__animated animate__fadeIn" v-if="stepNum===1">
  6. <view class=" input-img">
  7. <button class="head-button" open-type="chooseAvatar" @chooseavatar="onChooseAvatar" >
  8. <image :src="accountData.head_img" class="head-img"></image>
  9. </button>
  10. <view class="head-text text-color-666 sys-size-24">点击上传头像</view>
  11. </view>
  12. <view class="input-item sys-from-background-color sys-radius-30 animate__animated" :class="{'animate__shakeX':shakeNum===1}" >
  13. <en-input type="nickname" class="login-input" placeholder="请输入昵称" v-model="accountData.nickname" ></en-input>
  14. </view>
  15. <view class="input-item sys-from-background-color sys-radius-30 animate__animated" :class="{'animate__shakeX':shakeNum===2}">
  16. <en-input type="text" class="login-input" placeholder="请输入姓名" v-model="accountData.name" ></en-input>
  17. </view>
  18. </view>
  19. <view class="step-item animate__animated animate__fadeIn" v-else>
  20. <view class="back-set" @click="setStepNum(1)">
  21. <image class="back-img" src="/static/img/login/Vector.png" mode="widthFix"></image>
  22. <view class="back-text text-color-dominant sys-size-30 sys-weight-400">返回上一步</view>
  23. </view>
  24. <view class="input-item sys-from-background-color sys-radius-30 animate__animated" :class="{'animate__shakeX':shakeNum===3}" >
  25. <en-input type="number" class="login-input" placeholder="请输入手机号" v-model="accountData.phone" ></en-input>
  26. </view>
  27. <view class="input-item input-send sys-from-background-color sys-radius-30 animate__animated" :class="{'animate__shakeX':shakeNum===4}">
  28. <en-input type="number" class="login-input" placeholder="请输入验证码" v-model="accountData.code" maxlength="6"></en-input>
  29. <view class="login-send text-color-dominant sys-size-28 sys-weight-400" @click="getVerifiedCode" v-if="timeNum<=0">发送验证码</view>
  30. <view class="login-send text-color-dominant sys-size-28 sys-weight-400" v-else>{{ timeNum }} s</view>
  31. </view>
  32. <view class="input-item sys-from-background-color sys-radius-30 animate__animated" :class="{'animate__shakeX':(shakeNum===5 || shakeNum===7)}" >
  33. <en-input type="password" class="login-input" placeholder="请输入密码" v-model="accountData.password" ></en-input>
  34. </view>
  35. <view class="input-item sys-from-background-color sys-radius-30 animate__animated" :class="{'animate__shakeX':(shakeNum===6 || shakeNum===7)}">
  36. <en-input type="password" class="login-input" placeholder="请再次输入密码" v-model="accountData.passwordTwo" ></en-input>
  37. </view>
  38. </view>
  39. </view>
  40. <agreement v-model="isConsent" ref="agreement"></agreement>
  41. <view
  42. v-if="stepNum===1"
  43. class="input-but sys-background-dominant text-color-fff sys-size-30 sys-radius-100 sys-weight-600"
  44. :class="{'sys-selected-but':isRegister,'sys-unselected-but':!isRegister}"
  45. @click="setStepNum(2)"
  46. >下一步</view>
  47. <view
  48. v-else
  49. class="input-but sys-background-dominant text-color-fff sys-size-30 sys-radius-100 sys-weight-600"
  50. :class="{'sys-selected-but':isRegister,'sys-unselected-but':!isRegister}"
  51. @click="register"
  52. >注册</view>
  53. </view>
  54. <view class="register-box">
  55. <view class="register-text sys-weight-400 sys-size-24 text-color-666">已有账号?</view>
  56. <view class="register-text text-color-dominant sys-size-24 sys-weight-400" @click="goToUrl(1)">去登录</view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import EnInput from "../../components/en-from/en-input/index.vue";
  62. import tools from "../../service/tools";
  63. import {commonSend} from "../../api/common";
  64. import Agreement from "@/pages/login/model/agreement.vue";
  65. import {register, wxLogin} from "@/api/login";
  66. import txUploadFile from "@/service/txOssSts";
  67. export default {
  68. components: {Agreement, EnInput},
  69. onPullDownRefresh() {
  70. return false
  71. },
  72. data() {
  73. return {
  74. accountData:{
  75. 'openid':'',
  76. 'phone':'',
  77. 'password':'',
  78. 'passwordTwo':'',
  79. 'code':'',
  80. 'wxCode':'',
  81. 'name':'',
  82. 'nickname':'',
  83. 'head_img':'https://wealfavor-1257406827.cos.ap-beijing.myqcloud.com/app-serve/2024-4-17/gvbknkvhub.png?imageMogr2/quality/20',
  84. },
  85. timeNum:0,
  86. timer:null,
  87. isAJAX:false,
  88. isConsent: false,
  89. isRegister: false,
  90. shakeNum: 0,
  91. stepNum:1,
  92. };
  93. },
  94. watch:{
  95. 'accountData': {
  96. handler() {
  97. this.verifyData(false)
  98. },
  99. deep: true
  100. },
  101. 'isConsent':function () {
  102. this.verifyData(false)
  103. }
  104. },
  105. methods:{
  106. setStepNum(stepNum){
  107. if(stepNum===2){
  108. if( !this.verifyData(true)){
  109. return false
  110. }
  111. }
  112. if(this.stepNum!==stepNum){
  113. this.stepNum=stepNum
  114. }
  115. },
  116. onChooseAvatar(e) {
  117. // console.log(e);
  118. txUploadFile(e.detail.avatarUrl).then((res) => {
  119. console.log('--------------------ok',res)
  120. if (res.Location) {
  121. this.accountData.head_img = res.Location;
  122. tools.hideLoading();
  123. }else {
  124. tools.hideLoading();
  125. tools.error('上传失败')
  126. }
  127. }).catch((err) => {
  128. tools.hideLoading();
  129. })
  130. // this.accountData.head_img = e.detail.avatarUrl;
  131. },
  132. goToUrl(type){
  133. uni.reLaunch({
  134. 'url':'/pages/login/index'
  135. })
  136. },
  137. verifyData(type){
  138. let isRegister=true;
  139. if(this.stepNum===1){
  140. if(!this.accountData.nickname){
  141. isRegister=false
  142. if(type){
  143. this.shakeNum=1
  144. tools.error('请输入昵称');
  145. }
  146. }else if(!this.accountData.name){
  147. isRegister=false
  148. if(type){
  149. this.shakeNum=2
  150. tools.error('请输入姓名');
  151. }
  152. }
  153. }else {
  154. if(!this.accountData.phone){
  155. isRegister=false
  156. if(type){
  157. this.shakeNum=3
  158. tools.error('请输入手机号码');
  159. }
  160. }else if(!this.accountData.password){
  161. isRegister=false
  162. if(type){
  163. this.shakeNum=5
  164. tools.error('请输入密码');
  165. }
  166. }else if(!this.accountData.passwordTwo){
  167. isRegister=false
  168. if(type){
  169. this.shakeNum=6
  170. tools.error('请确认密码');
  171. }
  172. }else if(this.accountData.password!==this.accountData.passwordTwo){
  173. isRegister=false
  174. if(type){
  175. this.shakeNum=7
  176. tools.error('密码输入不一致');
  177. }
  178. }else if(!this.accountData.code){
  179. isRegister=false
  180. if(type){
  181. this.shakeNum=4
  182. tools.error('请输入验证码');
  183. }
  184. }else if(!this.isConsent){
  185. isRegister=false
  186. if(type){
  187. this.shakeNum=8
  188. tools.error('请阅读并同意协议');
  189. this.$refs.agreement.setConsentShake()
  190. }
  191. }
  192. }
  193. if(!isRegister){
  194. setTimeout(()=>{
  195. if(this.shakeNum>0)this.shakeNum=0
  196. },500)
  197. }
  198. this.isRegister=isRegister
  199. return isRegister
  200. },
  201. register(){
  202. this.verifyData(true)
  203. if(!this.isRegister){
  204. return ;
  205. }
  206. if(this.isAJAX){
  207. return
  208. }
  209. this.isAJAX = true
  210. uni.login({
  211. provider: "weixin",
  212. success: (loginRes) => {
  213. this.accountData.wxCode=loginRes.code;
  214. register(this.accountData).then((res)=>{
  215. if(res.code===1){
  216. tools.setLoginData(res.data,false)
  217. tools.success('注册成功')
  218. setTimeout(()=>{
  219. this.isAJAX = false;
  220. uni.reLaunch({
  221. url: '/pages/login/await-audit'
  222. });
  223. },1500)
  224. }else {
  225. this.isAJAX = false;
  226. tools.error(res.msg)
  227. }
  228. })
  229. },
  230. fail: (loginRes) => {
  231. this.isAJAX = false;
  232. tools.error("获取授权信息失败");
  233. },
  234. });
  235. },
  236. getVerifiedCode() {
  237. if (this.timeNum > 0) {
  238. return;
  239. }
  240. if (this.accountData.phone === '') {
  241. tools.error("请输入手机号码")
  242. return;
  243. }
  244. let regPhone = /^(?:(?:\+|00)86)?1\d{10}$/;
  245. if (!regPhone.test(this.accountData.phone)) {
  246. tools.error("手机号码格式错误")
  247. return;
  248. }
  249. commonSend({
  250. 'phone': this.accountData.phone,
  251. 'send_type': 'register'
  252. }).then((res) => {
  253. if (res.code === 1) {
  254. tools.success(res.msg);
  255. this.timeNum = 60;
  256. this.timer = setInterval(() => {
  257. this.timeNum--;
  258. if (this.timeNum <= 0) {
  259. clearInterval(this.timer);
  260. }
  261. }, 1000);
  262. } else {
  263. tools.error(res.msg);
  264. }
  265. })
  266. },
  267. }
  268. }
  269. </script>
  270. <style lang="scss">
  271. @import "/static/css/login.css";
  272. .page-box{
  273. padding-top: 370rpx;
  274. .login-form{
  275. margin: 0 30rpx;
  276. border-radius: 50rpx;
  277. padding: 40rpx 45rpx;
  278. animation-delay: 0.8s;
  279. transition: 0.5s ease;
  280. .back-set{
  281. display: flex;
  282. justify-content: flex-start;
  283. align-items: center;
  284. .back-img{
  285. width: 38rpx;
  286. margin-right: 20rpx;
  287. }
  288. .back-text{
  289. }
  290. }
  291. .input-item{
  292. height: 96rpx;
  293. padding: 28rpx 40rpx;
  294. box-sizing: border-box;
  295. margin-top: 30rpx;
  296. .login-input{
  297. width: 100%;
  298. }
  299. }
  300. .input-item:first-child{
  301. margin-top: 0;
  302. }
  303. .input-send{
  304. display: flex;
  305. justify-content: flex-start;
  306. align-items: center;
  307. .login-input{
  308. width:calc(100% - 140rpx) ;
  309. }
  310. .login-send{
  311. width: 140rpx;
  312. text-align: center;
  313. }
  314. }
  315. .input-but{
  316. margin-top: 40rpx;
  317. width: 100%;
  318. height: 96rpx;
  319. line-height: 96rpx;
  320. text-align: center;
  321. }
  322. .input-img{
  323. display: flex;
  324. flex-direction: column;
  325. justify-content: center;
  326. .head-button{
  327. margin: auto;
  328. padding: 0;
  329. height: 90rpx;
  330. border-radius: 50%;
  331. .head-img{
  332. width: 90rpx;
  333. height: 90rpx;
  334. border-radius: 50%;
  335. }
  336. }
  337. .head-text{
  338. margin-top: 10rpx;
  339. text-align: center;
  340. }
  341. }
  342. }
  343. .register-box{
  344. display: flex;
  345. justify-content: center;
  346. align-items: center;
  347. margin-top: 60rpx;
  348. .register-text{
  349. height: 34rpx;
  350. line-height: 34rpx;
  351. }
  352. .register-text:last-child{
  353. margin-right: 5rpx;
  354. }
  355. }
  356. }
  357. </style>