register.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. <template>
  2. <view class="register-box">
  3. <view class="register-logo">
  4. <image class="logo-icon" src="../static/img/img_22.png" mode=""></image>
  5. <image class="logo-name" src="../static/img/img_23.png" mode=""></image>
  6. </view>
  7. <view class="register-from">
  8. <view class="from-lable">
  9. <text @click.stop="setRegisterType(1)"
  10. :class="['lable-title' , registerType === 1 ? 'active-lable-title' : '']">手机注册</text>
  11. <text @click.stop="setRegisterType(2)"
  12. :class="['lable-title' , registerType === 2 ? 'active-lable-title' : '']">邮箱注册</text>
  13. </view>
  14. <view class="from-val">
  15. <view class="from-item" v-show="registerType === 1">
  16. <view class="area">
  17. <text class="area-val">{{ from.areaCode ? `+${from.areaCode}` : '国家地区'}}</text>
  18. <image class="select-area" src="../static/img/img_26.png" mode="aspectFit"></image>
  19. </view>
  20. <input v-model="from.user_string" class="item-input" type="number"
  21. placeholder-class="placeholder-class" placeholder="请输入手机号">
  22. </view>
  23. <view class="from-item" v-show="registerType === 2">
  24. <input v-model="from.user_string" class="item-input" type="text"
  25. placeholder-class="placeholder-class" placeholder="请输入邮箱号">
  26. </view>
  27. <view class="from-item">
  28. <input class="item-input" v-model="from.code" type="number"
  29. placeholder-class="placeholder-class" placeholder="验证码">
  30. <text class="item-code" @click.stop="getCode()">{{ CodeText }}</text>
  31. </view>
  32. <view class="from-item">
  33. <input class="item-input" v-model="from.password" :type="showPass ? 'text' : 'password'"
  34. placeholder-class="placeholder-class" placeholder="请输入密码">
  35. <view class="pass-icon-box" @click.stop="showPass = !showPass">
  36. <image v-show="!showPass" class="pass-icon" src="../static/img/img_25.png" mode="aspectFit">
  37. </image>
  38. <image v-show="showPass" class="pass-icon" src="../static/img/img_24.png" mode="aspectFit">
  39. </image>
  40. </view>
  41. </view>
  42. <view class="from-item">
  43. <input class="item-input" v-model="from.extension_code" type="number"
  44. placeholder-class="placeholder-class" placeholder="邀请码">
  45. </view>
  46. <view class="from-agreement" @click.stop="readAgreement = !readAgreement">
  47. <view class="agreement-status">
  48. <image v-show="readAgreement" class="read-agreement" src="../static/img/img_28.png"
  49. mode="aspectFit">
  50. </image>
  51. </view>
  52. 我已阅读并同意<text class="agreement-name" @click.stop="readAgreementContent()">《服务与隐私条款》</text>
  53. </view>
  54. <view class="from-submit" @click.stop="submitRegister">注册</view>
  55. </view>
  56. </view>
  57. </view>
  58. </view>
  59. </template>
  60. <script>
  61. import {
  62. Api_setRegister,
  63. Api_getEmailCode,
  64. Api_getSmsSend
  65. } from "@/api/index.js"
  66. import {
  67. validPassword,
  68. validPositiveIntegerZero
  69. } from "@/utils/validate.js"
  70. export default {
  71. name: 'register',
  72. data() {
  73. return {
  74. showPass: false,
  75. readAgreement: false,
  76. registerType: 1, // 1: 手机注册 2 : 邮箱注册
  77. CodeText: '获取验证码',
  78. from: {
  79. user_string: '',
  80. password: '',
  81. areaCode: 86,
  82. code: '',
  83. extension_code: ''
  84. },
  85. timeInterval: null
  86. };
  87. },
  88. onLoad(opt) {
  89. this.from.extension_code = opt?.extension_code || ''
  90. },
  91. methods: {
  92. // 校验
  93. verifyVal(type, val) {
  94. let status = true,
  95. msg = ''
  96. switch (type) {
  97. case 'phone':
  98. status = validPositiveIntegerZero(val);
  99. msg = '手机号码格式错误';
  100. break;
  101. case 'email':
  102. status = val ? true : false;
  103. msg = '请输入邮箱号'
  104. break;
  105. case 'code':
  106. status = val ? true : false;
  107. msg = '请输入验证码';
  108. break;
  109. case 'password':
  110. status = validPassword(val);
  111. msg = '密码须同时包含数字,大小写字母,且大于8位'
  112. break;
  113. case 'extension_code':
  114. status = val ? true : false;
  115. msg = '请填写验证码'
  116. break;
  117. }
  118. if (!status) {
  119. console.log('msg = ', msg)
  120. uni.showToast({
  121. title: msg,
  122. icon: 'none'
  123. })
  124. }
  125. return status
  126. },
  127. readAgreementContent() {
  128. uni.navigateTo({
  129. url: '/pages/agreement'
  130. })
  131. },
  132. setRegisterType(type) {
  133. this.from.user_string = '';
  134. this.registerType = type;
  135. },
  136. // validPassword
  137. getCode() {
  138. if (this.CodeText !== '获取验证码') {
  139. return false
  140. }
  141. if (this.registerType === 1) {
  142. if (!this.verifyVal('phone', this.from.user_string) || this.from.user_string.length !== 11) {
  143. return false
  144. }
  145. } else {
  146. if (!this.verifyVal('email', this.from.user_string)) {
  147. return false
  148. }
  149. }
  150. let Api_ = '',
  151. obj = {};
  152. obj.user_string = this.from.user_string;
  153. switch (this.registerType) {
  154. case 1:
  155. // 手机号 - 获取验证码
  156. Api_ = Api_getSmsSend;
  157. obj.area_code = this.from.areaCode;
  158. break;
  159. case 2:
  160. // 邮箱 - 获取验证码
  161. Api_ = Api_getEmailCode;
  162. break;
  163. default:
  164. break;
  165. }
  166. if (Api_) {
  167. Api_(obj).then(res => {
  168. }).catch(err => {
  169. })
  170. let num = 60
  171. this.timeInterval = setInterval(() => {
  172. num--;
  173. if (num <= 0) {
  174. clearInterval(this.timeInterval);
  175. this.CodeText = '重新发送';
  176. return false
  177. };
  178. this.CodeText = `${num}秒后重新发送`;
  179. 123456
  180. }, 1000)
  181. }
  182. },
  183. submitRegister() {
  184. if (this.readAgreement) {
  185. if (this.registerType === 1) {
  186. if (!this.verifyVal('phone', this.from.user_string) || this.from.user_string.length !== 11) {
  187. return false
  188. }
  189. } else {
  190. if (!this.verifyVal('email', this.from.user_string)) {
  191. return false
  192. }
  193. }
  194. if (!this.verifyVal('code', this.from.code)) {
  195. return false
  196. }
  197. if (!this.verifyVal('password', this.from.password)) {
  198. return false
  199. }
  200. if (!this.verifyVal('extension_code', this.from.extension_code)) {
  201. return false
  202. }
  203. const obj = {
  204. user_string: this.from.user_string,
  205. password: this.from.password,
  206. re_password: this.from.password,
  207. extension_code: this.from.extension_code,
  208. code: this.from.code,
  209. type: this.registerType === 1 ? 'mogile' : ' email'
  210. };
  211. uni.showLoading()
  212. Api_setRegister(obj).then(res => {
  213. uni.showToast({
  214. title: '注册成功',
  215. icon: 'none'
  216. })
  217. }).catch(err => {
  218. }).finally(() => {
  219. uni.hideLoading()
  220. })
  221. } else {
  222. uni.showToast({
  223. title: '请先阅读协议',
  224. icon: 'none'
  225. })
  226. }
  227. }
  228. }
  229. }
  230. </script>
  231. <style lang="scss" scoped>
  232. .register-box {
  233. width: 100%;
  234. min-height: 100vh;
  235. background-color: #0D9780;
  236. padding: 126rpx 37rpx 165rpx;
  237. .register-logo {
  238. width: 100%;
  239. display: flex;
  240. justify-content: center;
  241. align-items: center;
  242. .logo-icon {
  243. width: 87rpx;
  244. height: 85rpx;
  245. }
  246. .logo-name {
  247. margin-left: 8rpx;
  248. width: 127rpx;
  249. height: 50rpx;
  250. }
  251. }
  252. .register-from {
  253. width: 100%;
  254. background-color: #fff;
  255. border-radius: 20rpx;
  256. padding-bottom: 63rpx;
  257. margin-top: 46rpx;
  258. .from-lable {
  259. width: 100%;
  260. display: flex;
  261. align-items: stretch;
  262. .lable-title {
  263. flex: 1;
  264. flex-shrink: 0;
  265. height: 114rpx;
  266. line-height: 114rpx;
  267. text-align: center;
  268. font-size: 34rpx;
  269. font-family: PingFang SC, PingFang SC-Bold;
  270. font-weight: 700;
  271. color: #1a1a1a;
  272. letter-spacing: 0.68rpx;
  273. border-bottom: 1rpx solid #e6e6e6;
  274. }
  275. .active-lable-title {
  276. color: #20b482;
  277. border-bottom: 2rpx solid #20b482;
  278. }
  279. }
  280. .from-val {
  281. width: 100%;
  282. padding: 0 43rpx;
  283. .from-item {
  284. width: 100%;
  285. height: 115rpx;
  286. border-bottom: 1rpx solid #e6e6e6;
  287. padding-top: 25rpx;
  288. display: flex;
  289. justify-content: space-between;
  290. align-items: center;
  291. // <view class="area">
  292. // <text class="area-val">国家地区</text>
  293. // <image class="select-area" src="../static/img/img_26.png" mode="aspectFit"></image>
  294. // </view>
  295. .area {
  296. min-width: 160rpx;
  297. .area-val {
  298. font-size: 28rpx;
  299. font-family: PingFang SC, PingFang SC-Regular;
  300. font-weight: 400;
  301. color: #b3b3b3;
  302. letter-spacing: 0.56rpx;
  303. }
  304. .select-area {
  305. width: 20rpx;
  306. height: 20rpx;
  307. }
  308. }
  309. .item-input {
  310. flex-shrink: 0;
  311. font-size: 28rpx;
  312. flex: 1;
  313. height: 100%;
  314. border: none;
  315. font-family: PingFang SC, PingFang SC-Regular;
  316. font-weight: 400;
  317. color: #666666;
  318. letter-spacing: 0.56rpx;
  319. }
  320. .placeholder-class {
  321. font-size: 28rpx;
  322. font-family: PingFang SC, PingFang SC-Regular;
  323. font-weight: 400;
  324. color: #b3b3b3;
  325. letter-spacing: 0.56rpx;
  326. }
  327. .item-code {
  328. font-size: 28rpx;
  329. font-family: PingFang SC, PingFang SC-Regular;
  330. font-weight: 400;
  331. color: #1cac7b;
  332. line-height: 38rpx;
  333. letter-spacing: 0.56rpx;
  334. }
  335. .pass-icon-box {
  336. width: 88rpx;
  337. height: 88rpx;
  338. display: flex;
  339. justify-content: flex-end;
  340. align-items: center;
  341. .pass-icon {
  342. width: 42rpx;
  343. height: 42rpx;
  344. }
  345. }
  346. }
  347. // .<view class="from-agreement">
  348. // <view class="agreement-status">
  349. // </view>
  350. // 我已阅读并同意<text class="agreement-name">《服务与隐私条款》</text>
  351. // </view>\
  352. .from-agreement {
  353. width: 100%;
  354. padding: 52rpx 0;
  355. display: flex;
  356. align-items: center;
  357. font-size: 24rpx;
  358. font-family: PingFang SC, PingFang SC-Regular;
  359. font-weight: 400;
  360. color: #666666;
  361. .agreement-status {
  362. width: 29rpx;
  363. height: 29rpx;
  364. border: 1px solid #3b6afd;
  365. margin-right: 15rpx;
  366. display: flex;
  367. justify-content: center;
  368. align-items: center;
  369. .read-agreement {
  370. width: 19rpx;
  371. height: 14rpx;
  372. }
  373. }
  374. .agreement-name {
  375. color: #3b6afd;
  376. }
  377. }
  378. .from-submit {
  379. width: 100%;
  380. height: 90rpx;
  381. text-align: center;
  382. line-height: 90rpx;
  383. background: #00b99a;
  384. border-radius: 10rpx;
  385. font-size: 32rpx;
  386. font-family: PingFang SC, PingFang SC-Regular;
  387. font-weight: 400;
  388. color: #ffffff;
  389. letter-spacing: 0.64rpx;
  390. }
  391. }
  392. }
  393. }
  394. </style>