register-by-email.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <!-- 邮箱验证码注册 -->
  2. <template>
  3. <view class="uni-content">
  4. <match-media :min-width="690">
  5. <view class="login-logo">
  6. <image :src="logo"></image>
  7. </view>
  8. <!-- 顶部文字 -->
  9. <text class="title title-box">邮箱验证码注册</text>
  10. </match-media>
  11. <uni-forms ref="form" :value="formData" :rules="rules" validate-trigger="submit" err-show-type="toast">
  12. <uni-forms-item name="email" required>
  13. <uni-easyinput :inputBorder="false" :focus="focusEmail" @blur="focusEmail = false"
  14. class="input-box" placeholder="请输入邮箱" v-model="formData.email" trim="both" />
  15. </uni-forms-item>
  16. <uni-forms-item name="nickname">
  17. <uni-easyinput :inputBorder="false" :focus="focusNickname" @blur="focusNickname = false" class="input-box" placeholder="请输入用户昵称"
  18. v-model="formData.nickname" trim="both" />
  19. </uni-forms-item>
  20. <uni-forms-item name="password" v-model="formData.password" required>
  21. <uni-easyinput :inputBorder="false" :focus="focusPassword" @blur="focusPassword = false"
  22. class="input-box" maxlength="20" :placeholder="'请输入' + (config.passwordStrength == 'weak'?'6':'8') + '-16位密码'" type="password"
  23. v-model="formData.password" trim="both" />
  24. </uni-forms-item>
  25. <uni-forms-item name="password2" v-model="formData.password2" required>
  26. <uni-easyinput :inputBorder="false" :focus="focusPassword2" @blur="focusPassword2 =false"
  27. class="input-box" placeholder="再次输入密码" maxlength="20" type="password" v-model="formData.password2"
  28. trim="both" />
  29. </uni-forms-item>
  30. <uni-forms-item name="code" >
  31. <uni-id-pages-email-form ref="shortCode" :email="formData.email" type="register" v-model="formData.code">
  32. </uni-id-pages-email-form>
  33. </uni-forms-item>
  34. <uni-id-pages-agreements scope="register" ref="agreements" ></uni-id-pages-agreements>
  35. <button class="uni-btn" type="primary" @click="submit">注册</button>
  36. <button @click="navigateBack" class="register-back">返回</button>
  37. <match-media :min-width="690">
  38. <view class="link-box">
  39. <text class="link" @click="registerByUserName">用户名密码注册</text>
  40. <text class="link" @click="toLogin">已有账号?点此登录</text>
  41. </view>
  42. </match-media>
  43. </uni-forms>
  44. </view>
  45. </template>
  46. <script>
  47. import rules from './validator.js';
  48. import mixin from '@/uni_modules/uni-id-pages/common/login-page.mixin.js';
  49. import config from '@/uni_modules/uni-id-pages/config.js'
  50. import passwordMod from '@/uni_modules/uni-id-pages/common/password.js'
  51. const uniIdCo = uniCloud.importObject("uni-id-co")
  52. export default {
  53. mixins: [mixin],
  54. data() {
  55. return {
  56. formData: {
  57. email: "",
  58. nickname: "",
  59. password: "",
  60. password2: "",
  61. code: ""
  62. },
  63. rules: {
  64. email: {
  65. rules: [{
  66. required: true,
  67. errorMessage: '请输入邮箱',
  68. },{
  69. format:'email',
  70. errorMessage: '邮箱格式不正确',
  71. }
  72. ]
  73. },
  74. nickname: {
  75. rules: [{
  76. minLength: 3,
  77. maxLength: 32,
  78. errorMessage: '昵称长度在 {minLength} 到 {maxLength} 个字符',
  79. },
  80. {
  81. validateFunction: function(rule, value, data, callback) {
  82. // console.log(value);
  83. if (/^1\d{10}$/.test(value) || /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/.test(value)) {
  84. callback('昵称不能是:手机号或邮箱')
  85. };
  86. if (/^\d+$/.test(value)) {
  87. callback('昵称不能为纯数字')
  88. };
  89. // if(/[\u4E00-\u9FA5\uF900-\uFA2D]{1,}/.test(value)){
  90. // callback('昵称不能包含中文')
  91. // }
  92. return true
  93. }
  94. }
  95. ],
  96. label: "昵称"
  97. },
  98. ...passwordMod.getPwdRules(),
  99. code: {
  100. rules: [{
  101. required: true,
  102. errorMessage: '请输入邮箱验证码',
  103. },
  104. {
  105. pattern: /^.{6}$/,
  106. errorMessage: '邮箱验证码不正确',
  107. }
  108. ]
  109. }
  110. },
  111. focusEmail:false,
  112. focusNickname:false,
  113. focusPassword:false,
  114. focusPassword2:false,
  115. logo: "/static/logo.png"
  116. }
  117. },
  118. onReady() {
  119. this.$refs.form.setRules(this.rules)
  120. },
  121. onShow() {
  122. // #ifdef H5
  123. document.onkeydown = event => {
  124. let e = event || window.event;
  125. if (e && e.keyCode == 13) { //回车键的键值为13
  126. this.submit()
  127. }
  128. };
  129. // #endif
  130. },
  131. methods: {
  132. /**
  133. * 触发表单提交
  134. */
  135. submit() {
  136. this.$refs.form.validate().then((res) => {
  137. if (this.needAgreements && !this.agree) {
  138. return this.$refs.agreements.popup(()=>{
  139. this.submitForm(res)
  140. })
  141. }
  142. this.submitForm(res)
  143. }).catch((errors) => {
  144. let key = errors[0].key
  145. key = key.replace(key[0], key[0].toUpperCase())
  146. // console.log(key);
  147. this['focus'+key] = true
  148. })
  149. },
  150. submitForm(params) {
  151. uniIdCo.registerUserByEmail(this.formData).then(e => {
  152. // console.log(e);
  153. uni.navigateTo({
  154. url: '/uni_modules/uni-id-pages/pages/login/login-withpwd',
  155. complete: (e) => {
  156. // console.log(e);
  157. }
  158. })
  159. })
  160. .catch(e => {
  161. // console.log(e);
  162. console.log(e.message);
  163. })
  164. },
  165. navigateBack() {
  166. uni.navigateBack()
  167. },
  168. toLogin() {
  169. uni.navigateTo({
  170. url: '/uni_modules/uni-id-pages/pages/login/login-withpwd'
  171. })
  172. },
  173. registerByUserName() {
  174. uni.navigateTo({
  175. url: '/uni_modules/uni-id-pages/pages/register/register'
  176. })
  177. }
  178. }
  179. }
  180. </script>
  181. <style lang="scss">
  182. @import "@/uni_modules/uni-id-pages/common/login-page.scss";
  183. @media screen and (max-width: 690px) {
  184. .uni-content{
  185. margin-top: 15px;
  186. }
  187. }
  188. @media screen and (min-width: 690px) {
  189. .uni-content{
  190. padding: 30px 40px;
  191. max-height: 650px;
  192. }
  193. .link-box {
  194. /* #ifndef APP-NVUE */
  195. display: flex;
  196. /* #endif */
  197. flex-direction: row;
  198. justify-content: space-between;
  199. margin-top: 10px;
  200. }
  201. .link {
  202. font-size: 12px;
  203. }
  204. }
  205. .uni-content ::v-deep .uni-forms-item__label {
  206. position: absolute;
  207. left: -15px;
  208. }
  209. button {
  210. margin-top: 15px;
  211. }
  212. </style>