register.vue 9.4 KB

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