register.vue 11 KB

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