index.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. <template>
  2. <view class="reg" :style="{ 'height': setHeight + 'px' }">
  3. <view class="title">欢迎注册巴巴礼品网</view>
  4. <div class="form" v-if="step === 1">
  5. <form @submit="submit1" report-submit='true'>
  6. <view class="verify">
  7. <view class="list">
  8. <view class="item">
  9. <input type='number' placeholder='填写手机号码' placeholder-class='placeholder' v-model="phone"></input>
  10. </view>
  11. <view class="item acea-row row-between-wrapper">
  12. <input type='number' placeholder='填写验证码' placeholder-class='placeholder' class="codeIput" v-model="yzm"></input>
  13. <button class="code font-color" :class="disabled === true ? 'on' : ''" :disabled='disabled' @click="code">
  14. {{ text }}
  15. </button>
  16. </view>
  17. </view>
  18. <button form-type="submit" class="confirmBnt">立即注册</button>
  19. </view>
  20. </form>
  21. <view class="login">已有账号,<navigator hover-class="none" url="/pages/users/login/index">立即登录?</navigator></view>
  22. </div>
  23. <div class="form2" v-else>
  24. <view class='avatar acea-row row-center-wrapper row-column' @click='uploadpic'>
  25. <view v-if='avatar ==""'>
  26. <text class='iconfont icon-icon25201'></text>
  27. <view>上传图片</view>
  28. </view>
  29. <view v-else>
  30. <image :src="avatar"></image>
  31. </view>
  32. </view>
  33. <div class="item">
  34. <div class="acea-row row-middle">
  35. <input type="text" placeholder="请输入用户昵称" placeholder-class="placeholder" v-model="nickname" required />
  36. </div>
  37. </div>
  38. <div class="item">
  39. <div class="acea-row row-middle">
  40. <input type="password" placeholder="请输入密码" placeholder-class="placeholder" v-model="password" required />
  41. </div>
  42. </div>
  43. <div class="item">
  44. <div class="acea-row row-middle">
  45. <input type="password" placeholder="再次确认密码" placeholder-class="placeholder" v-model="qrPassword" required />
  46. </div>
  47. </div>
  48. <div class="item">
  49. <div class="acea-row row-middle">
  50. <input type="text" placeholder="请输入您的微信号" placeholder-class="placeholder" v-model="weixin_name" required />
  51. </div>
  52. </div>
  53. <button class="btn" @click="submit2">完成注册</button>
  54. <button class="back" @click="back">返回</button>
  55. <view class="login">已有账号,<navigator hover-class="none" url="/pages/users/login/index">立即登录?</navigator></view>
  56. </div>
  57. </view>
  58. </template>
  59. <script>
  60. import {
  61. registerVerify,
  62. ApiReg1,
  63. ApiReg2
  64. } from '@/api/api.js';
  65. import CryptoJS from "@/libs/CryptoJS";
  66. import sendVerifyCode from "@/mixins/SendVerifyCode";
  67. const BACK_URL = "login_back_url";
  68. export default {
  69. mixins: [sendVerifyCode],
  70. data() {
  71. return {
  72. setHeight: 0,
  73. phone:'',
  74. yzm:'',
  75. step:1,
  76. token: '',
  77. avatar: '',
  78. nickname: '',
  79. password: '',
  80. qrPassword: '',
  81. weixin_name: ''
  82. }
  83. },
  84. mounted() {
  85. let that = this
  86. uni.getSystemInfo({
  87. success: function (res) {
  88. that.setHeight = res.windowHeight
  89. }
  90. })
  91. },
  92. methods: {
  93. async code() {
  94. let that = this;
  95. if (!that.phone) return that.$util.Tips({
  96. title: '请填写手机号码!'
  97. });
  98. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  99. title: '请输入正确的手机号码!'
  100. });
  101. var secret_key = "b1bd7a4b8da3e47ce58e73b9e5f656c4";
  102. var AES = new CryptoJS.AES(secret_key);
  103. await registerVerify({
  104. mobile: that.phone,
  105. token: AES.encrypt(that.phone),
  106. time: new Date().getTime()
  107. }).then(res => {
  108. that.$util.Tips({
  109. title: res.msg
  110. });
  111. that.sendCode();
  112. }).catch(err => {
  113. return that.$util.Tips({
  114. title: err
  115. });
  116. });
  117. },
  118. async submit1() {
  119. let that = this;
  120. if (!that.phone) return that.$util.Tips({
  121. title: '请填写手机号码'
  122. });
  123. if (!(/^1(3|4|5|7|8|9|6)\d{9}$/i.test(that.phone))) return that.$util.Tips({
  124. title: '请输入正确的手机号码'
  125. });
  126. if (!that.yzm) return that.$util.Tips({
  127. title: '请填写验证码'
  128. });
  129. if (!/^[\w\d]+$/i.test(that.yzm)) return that.$util.Tips({
  130. title: '请输入正确的验证码'
  131. });
  132. ApiReg1({
  133. mobile: that.phone,
  134. yzm: that.yzm
  135. }).then(res => {
  136. that.token = res.data.token;
  137. that.step = 2;
  138. }).catch(res => {
  139. that.$util.Tips({
  140. title: res
  141. });
  142. });
  143. },
  144. uploadpic: function () {
  145. let that = this;
  146. that.$util.uploadImageOne('upload/index', function (res) {
  147. that.avatar = res.data.img;
  148. });
  149. },
  150. submit2 () {
  151. let that = this;
  152. if (!that.nickname) return that.$util.Tips({
  153. title: '请输入用户昵称'
  154. });
  155. if (!that.password) return that.$util.Tips({
  156. title: '请输入密码'
  157. });
  158. if (that.password.length < 6) return that.$util.Tips({
  159. title: '密码不能少于6位'
  160. });
  161. if (!that.qrPassword) return that.$util.Tips({
  162. title: '请输入确认密码'
  163. });
  164. if (that.qrPassword !== that.password) return that.$util.Tips({
  165. title: '二次密码不相等'
  166. });
  167. ApiReg2({
  168. token: that.token,
  169. avatar: that.avatar,
  170. nickname: that.nickname,
  171. password: that.password,
  172. qrPassword: that.qrPassword,
  173. weixin_name: that.weixin_name
  174. }).then(res => {
  175. that.$store.commit("LOGIN", {
  176. 'token': res.data.token,
  177. 'time': 30
  178. });
  179. that.$store.commit("UPDATE_USERINFO", res.data.user_info);
  180. const backUrl = that.$Cache.get(BACK_URL) || "/pages/index/index";
  181. that.$Cache.clear(BACK_URL);
  182. }).catch(err => {
  183. that.$util.Tips({
  184. title: err
  185. });
  186. });
  187. },
  188. back(){
  189. this.step = 1;
  190. }
  191. }
  192. }
  193. </script>
  194. <style scoped lang="scss">
  195. .reg{
  196. background: #fff;
  197. }
  198. .title{
  199. font-size: 42rpx;
  200. text-align: center;
  201. padding-top: 60rpx;
  202. }
  203. .verify .phone {
  204. font-size: 32rpx;
  205. font-weight: bold;
  206. text-align: center;
  207. margin-top: 55rpx;
  208. }
  209. .verify .list {
  210. width: 580rpx;
  211. margin: 53rpx auto 0 auto;
  212. }
  213. .verify .list .item {
  214. width: 100%;
  215. height: 110rpx;
  216. border-bottom: 2rpx solid #f0f0f0;
  217. }
  218. .verify .list .item input {
  219. width: 100%;
  220. height: 100%;
  221. font-size: 32rpx;
  222. }
  223. .verify .list .item .placeholder {
  224. color: #b9b9bc;
  225. }
  226. .verify .list .item input.codeIput {
  227. width: 340rpx;
  228. }
  229. .verify .list .item .code {
  230. font-size: 32rpx;
  231. background-color: #fff;
  232. }
  233. .verify .list .item .code.on {
  234. color: #b9b9bc !important;
  235. }
  236. .verify .confirmBnt {
  237. font-size: 32rpx;
  238. width: 580rpx;
  239. height: 90rpx;
  240. border-radius: 45rpx;
  241. color: #fff;
  242. margin: 92rpx auto 0 auto;
  243. text-align: center;
  244. line-height: 90rpx;
  245. background: #ff5c00;
  246. }
  247. .form .login{
  248. display: flex;
  249. justify-content: center;
  250. margin-top: 30rpx;
  251. navigator{
  252. color:#ff5c00;
  253. }
  254. }
  255. .form2{
  256. padding: 40rpx;
  257. .avatar{
  258. width:140rpx;
  259. height:140rpx;
  260. font-size:22rpx;
  261. color:#bbb;
  262. border:1rpx dashed #ddd;
  263. margin: 20rpx auto;
  264. text-align: center;
  265. .iconfont{
  266. font-size: 50rpx;
  267. }
  268. image{
  269. width:140rpx;
  270. height:140rpx;
  271. }
  272. }
  273. .item {
  274. border-bottom: 1rpx solid #ededed;
  275. padding: 45rpx 0 20rpx 0;
  276. image{
  277. width:40rpx;
  278. height:40rpx;
  279. margin-right: 20rpx;
  280. }
  281. input{
  282. flex-grow: 1;
  283. font-size: 28rpx;
  284. }
  285. .placeholder{
  286. color:#ccc;
  287. }
  288. }
  289. .btn {
  290. font-size: 32rpx;
  291. width: 580rpx;
  292. height: 85rpx;
  293. border-radius: 45rpx;
  294. color: #fff;
  295. margin: 80rpx auto 0 auto;
  296. text-align: center;
  297. line-height: 85rpx;
  298. background: #ff5c00;
  299. }
  300. .back{
  301. font-size: 32rpx;
  302. width: 580rpx;
  303. height: 85rpx;
  304. border-radius: 45rpx;
  305. margin: 20rpx auto 0 auto;
  306. text-align: center;
  307. line-height: 85rpx;
  308. border: 1rpx solid #dcdee2;
  309. color:#515a6e;
  310. }
  311. .login{
  312. display: flex;
  313. justify-content: center;
  314. margin-top: 30rpx;
  315. navigator{
  316. color:#ff5c00;
  317. }
  318. }
  319. }
  320. </style>