register.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <view class="normal-login-container regbox" style="padding-top: 120rpx;">
  3. <!-- <view class="logo-content align-center justify-center flex">
  4. <image style="width: 100rpx;height: 100rpx;" :src="globalConfig.appInfo.logo" mode="widthFix">
  5. </image>
  6. <text class="title">若依移动端注册</text>
  7. </view> -->
  8. <view>
  9. <image :src="headimg" class="headimg flex0"></image>
  10. <view class="headtit">注册</view>
  11. </view>
  12. <view class="login-form-content">
  13. <view class="input-item flex align-center">
  14. <view class="iconfont icon-user icon"></view>
  15. <input v-model="registerForm.username" class="input" type="text" placeholder="请输入手机号" maxlength="30" />
  16. </view>
  17. <view class="input-item flex align-center">
  18. <view class="iconfont icon-password icon"></view>
  19. <uni-easyinput type="password" placeholderStyle="font-size: 28rpx;color: grey;" :inputBorder="false" v-model="registerForm.password" placeholder="请输入密码"></uni-easyinput>
  20. </view>
  21. <view class="input-item flex align-center">
  22. <view class="iconfont icon-password icon"></view>
  23. <uni-easyinput type="password" placeholderStyle="font-size: 28rpx;color: grey;" :inputBorder="false" v-model="registerForm.confirmPassword" placeholder="请再次输入您的密码"></uni-easyinput>
  24. </view>
  25. <view class="input-item flex align-center" >
  26. <view class="iconfont icon-password icon"></view>
  27. <input v-model="registerForm.code" class="input" placeholder="请输入短信验证码" maxlength="20" />
  28. <view v-if="timefalg" class="codes">重新发送{{time}}s</view>
  29. <view v-else class="codess" @click="getsendCode">发送验证码</view>
  30. </view>
  31. <view class="input-item flex align-center" style="width: 60%;margin: 0px;" v-if="captchaEnabled">
  32. <view class="iconfont icon-code icon"></view>
  33. <input v-model="registerForm.code" type="number" class="input" placeholder="请输入验证码" maxlength="4" />
  34. <view class="login-code">
  35. <image :src="codeUrl" @click="getCode" class="login-code-img"></image>
  36. </view>
  37. </view>
  38. <view class="titico">*密码必须包含数字、大小写字母、特殊符号且大于8位</view>
  39. <view class="action-btn">
  40. <button @click="handleRegister()" type="primary" class=" rbtn mb24 mt50 btn2" >注册</button>
  41. <!-- <button class="register-btn cu-btn block bg-blue lg round">注册</button> -->
  42. </view>
  43. </view>
  44. <view class="xieyi text-center">
  45. <text @click="handleUserLogin" class="text-blue">使用已有账号登录</text>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. import * as base64 from "base-64"
  51. import { getCodeImg, register,sendSmszcOnly,getInfo } from '@/api/login.js'
  52. export default {
  53. data() {
  54. return {
  55. headimg:require('@/static/logo.png'),
  56. codeUrl: "",
  57. captchaEnabled: true,
  58. timefalg:'',
  59. tucode:'',
  60. time:'',
  61. globalConfig: getApp().globalData.config,
  62. jzflag:true,
  63. registerForm: {
  64. username: "",
  65. password: "",
  66. confirmPassword: "",
  67. code: "",
  68. uuid: ''
  69. }
  70. }
  71. },
  72. created() {
  73. this.getCode()
  74. },
  75. methods: {
  76. // 用户登录
  77. handleUserLogin() {
  78. this.$tab.navigateTo(`/pages/login`)
  79. },
  80. // 获取图形验证码
  81. getCode() {
  82. getCodeImg().then(res => {
  83. this.captchaEnabled = res.captchaEnabled === undefined ? true : res.captchaEnabled
  84. if (this.captchaEnabled) {
  85. this.codeUrl = 'data:image/gif;base64,' + res.img
  86. this.registerForm.uuid = res.uuid
  87. }
  88. })
  89. },
  90. // 获取短信验证码
  91. getsendCode(){
  92. var that=this;
  93. if (!this.registerForm.username ) {
  94. that.$toast("请输入手机号")
  95. return
  96. }
  97. let regphone = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
  98. // 座机号
  99. let reg1=/^(0\d{2,3})-?(\d{7,8})$/
  100. if (this.registerForm.username && !regphone.test(this.registerForm.username)) {
  101. that.$toast("请输入正确的手机号")
  102. return
  103. }
  104. var params={
  105. 'username':this.registerForm.username
  106. }
  107. // getSMS();
  108. // return
  109. sendSmszcOnly(params).then(res=>{
  110. if (res.code == 200) {
  111. // 发送验证码
  112. that.$toast("发送成功")
  113. that.time=60;
  114. that.timefalg=true;
  115. that.setTimein()
  116. } else {
  117. that.$toast(res.msg)
  118. }
  119. })
  120. },
  121. // 验证码倒计时
  122. setTimein(){
  123. var that=this;
  124. clearInterval(that.timer)
  125. that.timer=setInterval(()=>{
  126. if(that.time<=1){
  127. that.timefalg=false;
  128. that.time=60;
  129. clearInterval(that.timer)
  130. }
  131. that.time=that.time-1;
  132. },1000)
  133. },
  134. // 注册方法
  135. async handleRegister() {
  136. let regphone = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/
  137. if (this.registerForm.username === "") {
  138. this.$toast('请输入您的手机号')
  139. } else if (this.registerForm.username && !regphone.test(this.registerForm.username)) {
  140. this.$toast('请输入正确的手机号')
  141. } else if (this.registerForm.password === "") {
  142. this.$toast('请输入您的密码')
  143. } else if (this.registerForm.confirmPassword === "") {
  144. this.$toast('请再次输入您的密码')
  145. } else if (this.registerForm.password !== this.registerForm.confirmPassword) {
  146. this.$toast('两次输入的密码不一致')
  147. // } else if (this.registerForm.code === "" && this.captchaEnabled) {
  148. } else if (this.registerForm.code === "") {
  149. this.$toast('请输入验证码')
  150. } else {
  151. this.$toast('注册中,请耐心等待...')
  152. this.register()
  153. }
  154. },
  155. // 用户注册
  156. async register() {
  157. var that=this;
  158. register(this.registerForm).then(res => {
  159. this.$modal.closeLoading()
  160. uni.showModal({
  161. title: "系统提示",
  162. content: "恭喜你,您的账号 " + this.registerForm.username + " 注册成功!现在登录",
  163. success: function (res) {
  164. if (res.confirm) {
  165. that.pwdLogin()
  166. // uni.redirectTo({ url: `/pages/login` });
  167. }
  168. }
  169. })
  170. }).catch(() => {
  171. if (this.captchaEnabled) {
  172. this.getCode()
  173. }
  174. })
  175. },
  176. // 密码登录
  177. async pwdLogin() {
  178. var that=this;
  179. var params={
  180. username:this.registerForm.username,
  181. password:this.registerForm.password,
  182. type:1,//1:账号密码 2:手机登录
  183. }
  184. this.$store.dispatch('Login', params).then((res) => {
  185. if(that.jzflag){
  186. var newObj={
  187. username:params.username,
  188. password:base64.encode(params.password),
  189. captchaEnabled:that.captchaEnabled,
  190. }
  191. uni.setStorageSync('account', JSON.parse(JSON.stringify(newObj)))
  192. }else{
  193. uni.removeStorageSync('account')
  194. }
  195. this.$modal.closeLoading()
  196. this.$toast('登录成功')
  197. setTimeout(function(){
  198. that.registerSuccess()
  199. },1500)
  200. }).catch((error) => {
  201. })
  202. },
  203. // 注册成功后,处理函数
  204. registerSuccess(result) {
  205. // 设置用户信息
  206. this.$store.dispatch('GetInfo').then(res => {
  207. this.$tab.reLaunch('/pages/index/index')
  208. })
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss">
  214. page {
  215. background-color: #ffffff;
  216. }
  217. .headimg{width: 200rpx;height: 200rpx;margin:0 auto 20rpx;}
  218. .headtit{
  219. font-weight: bold;
  220. font-size: 40rpx;
  221. color: #343434;text-align: center;
  222. }
  223. .rbtn {font-size: 30rpx;
  224. &.btn{background: #9a9c9e;color: #ffffff;}
  225. &.btn2{background: $com-cd3;color: #ffffff;}
  226. }
  227. .codess{font-size: 30rpx;color: $com-cd3;flex: 0 0 auto;min-width: 200rpx;text-align: center;border-left: 2rpx solid #CDCDCD;}
  228. .codes{background: none;font-size: 28rpx;flex: 0 0 auto;width: 180rpx;text-align: center;border-left: 2rpx solid #CDCDCD;}
  229. .titico{font-weight: 500;font-size: 24rpx;color: #FF6969;}
  230. .normal-login-container {
  231. width: 100%;
  232. .logo-content {
  233. width: 100%;
  234. font-size: 21px;
  235. text-align: center;
  236. padding-top: 15%;
  237. image {
  238. border-radius: 4px;
  239. }
  240. .title {
  241. margin-left: 10px;
  242. }
  243. }
  244. .login-form-content {
  245. text-align: center;
  246. margin: 20px auto;
  247. margin-top: 15%;
  248. width: 80%;
  249. .input-item {
  250. margin: 20px auto;
  251. background-color: #f5f6f7;
  252. height: 45px;
  253. border-radius: 20px;
  254. .icon {
  255. font-size: 38rpx;
  256. margin-left: 10px;
  257. color: #999;
  258. }
  259. .input {
  260. width: 100%;
  261. font-size: 14px;
  262. line-height: 20px;
  263. text-align: left;
  264. padding-left: 15px;
  265. }
  266. }
  267. .register-btn {
  268. margin-top: 40px;
  269. height: 45px;
  270. }
  271. .xieyi {
  272. color: #333;
  273. margin-top: 20px;
  274. }
  275. .login-code {
  276. height: 38px;
  277. float: right;
  278. .login-code-img {
  279. height: 38px;
  280. position: absolute;
  281. margin-left: 10px;
  282. width: 200rpx;
  283. }
  284. }
  285. }
  286. }
  287. </style>