register.vue 9.5 KB

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