register.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. <template>
  2. <page-meta :page-font-size="fontValue+'px'" :root-font-size="fontValue+'px'"></page-meta>
  3. <view class="loginV register">
  4. <view class="content">
  5. <!-- 头部logo -->
  6. <view class="header">
  7. <image src="/static/logo512.png"></image>
  8. <view class="appName">
  9. <text style="letter-spacing: 4rpx;font-style: italic;">AIIM</text>
  10. </view>
  11. </view>
  12. <!-- 主体 -->
  13. <view class="main" style="margin-top: 20rpx;">
  14. <uni-forms ref="userForm" :model="registerForm" :rules="rules" label-width="140upx" label-position="top">
  15. <uni-forms-item class="inputTitle" label="登录名" name="username">
  16. <uni-easyinput class="inputV" type="text" v-model="registerForm.username" placeholder="请输入登录名" :clearable="false"/>
  17. </uni-forms-item>
  18. <uni-forms-item class="inputTitle" label="密码" name="password">
  19. <uni-easyinput class="inputV" type="password" v-model="registerForm.password" placeholder="请输入密码" :clearable="false"/>
  20. </uni-forms-item>
  21. <uni-forms-item class="inputTitle" label="确认密码" name="confirmPassword">
  22. <uni-easyinput class="inputV" type="password" v-model="registerForm.confirmPassword" placeholder="请输入确认密码"
  23. :clearable="false"/>
  24. </uni-forms-item>
  25. <!-- <uni-forms-item label="手机" name="phonenumber">
  26. <uni-easyinput type="text" v-model="registerForm.phonenumber" placeholder="请输入手机" :clearable="false"/>
  27. </uni-forms-item> -->
  28. <!-- <uni-forms-item label="验证码" name="code">
  29. <uni-easyinput type="text" v-model="registerForm.code" placeholder="请输入验证码" :clearable="false"/>
  30. <image :src="codeUrl" mode="widthFix" class="register-img" @tap="getCode"></image>
  31. </uni-forms-item> -->
  32. <uni-forms-item class="inputTitle" label="E-mail" name="email">
  33. <uni-easyinput class="inputV" type="text" v-model="registerForm.email" placeholder="请输入电子邮箱" :clearable="false"/>
  34. </uni-forms-item>
  35. <uni-forms-item class="inputTitle" label="验证码" name="code">
  36. <view class="contentInRowS inputV" style="align-items:center;">
  37. <uni-easyinput style="margin-right: 10rpx;" type="text" v-model="registerForm.code" placeholder="请输入验证码" :clearable="false"/>
  38. <view class="yzmbt" @click="getEmailcodeSele">
  39. <text>{{huoquyzm}}</text>
  40. </view>
  41. </view>
  42. </uni-forms-item>
  43. <view class="margin-top text-center">
  44. <button class="cu-btn bg-zblue lg margin-top-sm" style="border-radius: 40upx;width:100%" @tap="save">注册</button>
  45. </view>
  46. <view class="contentInRowC" style="font-size: 26upx;margin-top: 20px;" @click="login">
  47. <text style="color:darkgray;">已有账号!</text>
  48. <text style="color: #6E75FB;">去登录</text>
  49. </view>
  50. </uni-forms>
  51. </view>
  52. </view>
  53. </view>
  54. </template>
  55. <script setup lang="ts">
  56. import UniForms from "@/uni_modules/uni-forms/components/uni-forms/uni-forms.vue";
  57. import UniEasyinput from "@/uni_modules/uni-easyinput/components/uni-easyinput/uni-easyinput.vue";
  58. import UniFormsItem from "@/uni_modules/uni-forms/components/uni-forms-item/uni-forms-item.vue";
  59. import {ref} from "vue";
  60. import {getCodeImg, register,getEmailcode} from "@/api/Login";
  61. import MessageUtils from "@/utils/MessageUtils";
  62. import Auth from "@/api/Auth";
  63. const fontValue=ref(Auth.getfontSize());
  64. const userForm = ref();
  65. const huoquyzm=ref('获取验证码');
  66. const timeCall=ref(0);
  67. const timer=ref();
  68. // 验证码开关
  69. const captchaOnOff = ref(true);
  70. const codeUrl = ref("");
  71. const equalToPassword = (rule:any, value:any,data:any, callback:any) => {
  72. if (registerForm.value.password !== value) {
  73. callback('两次输入的密码不一致');
  74. } else {
  75. return true;
  76. }
  77. }
  78. const login = () => {
  79. uni.reLaunch({
  80. url: "/pages/login/login"
  81. })
  82. }
  83. const getCode = () => {
  84. getCodeImg().then((res : any) => {
  85. captchaOnOff.value = res.captchaOnOff === undefined ? true : res.captchaOnOff;
  86. if (captchaOnOff.value) {
  87. codeUrl.value = "data:image/gif;base64," + res.img;
  88. registerForm.value.uuid = res.uuid
  89. }
  90. });
  91. }
  92. getCode();
  93. const rules = {
  94. username: {
  95. rules: [{
  96. required: true,
  97. errorMessage: '请输入姓名',
  98. },
  99. {
  100. minLength: 5,
  101. maxLength: 8,
  102. errorMessage: '姓名长度在 {minLength} 到 {maxLength} 个字符',
  103. }
  104. ]
  105. },
  106. password: {
  107. rules: [{
  108. required: true,
  109. errorMessage: '请输入密码',
  110. },
  111. {
  112. minLength: 5,
  113. maxLength: 10,
  114. errorMessage: '密码长度在 {minLength} 到 {maxLength} 个字符',
  115. }
  116. ]
  117. },
  118. repassword: {
  119. rules: [
  120. { required: true, trigger: 'blur', message: '请再次输入您的密码' },
  121. {validateFunction: equalToPassword}
  122. ]
  123. },
  124. phonenumber: {
  125. rules: [{
  126. required: false,
  127. errorMessage: '请输入手机号',
  128. }, {
  129. validateFunction: function (rule: string, value: string, data: string, callback: Function) {
  130. const pattern = /^1[3456789]\d{9}$/
  131. if (!pattern.test(value)) {
  132. return true;
  133. //callback('手机号格式不对')
  134. }
  135. return true
  136. }
  137. }]
  138. },
  139. email: {
  140. rules: [{
  141. required: false,
  142. errorMessage: '邮箱不能为空!!',
  143. }, {
  144. validateFunction: function (rule: string, value: string, data: string, callback: Function) {
  145. const pattern = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$/
  146. if (!pattern.test(value)) {
  147. //return true;
  148. callback('邮箱格式不正确!')
  149. }
  150. return true
  151. }
  152. }]
  153. }
  154. }
  155. const registerForm = ref({
  156. host: '',
  157. username: '',
  158. phonenumber: '',
  159. email:'',
  160. password: '',
  161. confirmPassword: '',
  162. code: '',
  163. uuid: ''
  164. })
  165. const save = () => {
  166. userForm.value.validate().then(() => {
  167. register(registerForm.value)
  168. .then(() => {
  169. MessageUtils.success('注册成功');
  170. uni.reLaunch({
  171. url: "/pages/login/login"
  172. })
  173. })
  174. .catch((err) => {
  175. MessageUtils.error(err.msg);
  176. })
  177. })
  178. }
  179. //邮箱验证码
  180. const getEmailcodeSele = () =>{
  181. var pattern = /^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(.[a-zA-Z0-9_-]+)+$/;
  182. if (pattern.test(registerForm.value.email)) {
  183.   ;
  184. } else {
  185.   console.log("错误的邮箱地址!",registerForm.value.email);
  186. if(registerForm.value.email==''||null==registerForm.value.email||undefined==registerForm.value.email){
  187. }
  188. else{
  189. uni.showToast({
  190. title:'请输入正确的电子邮箱(E-mail)',
  191. icon: 'none',
  192. duration: 3500
  193. })
  194. return;
  195. }
  196. }
  197. if(timeCall.value==0){
  198. getEmailcodeact();
  199. }
  200. else{
  201. return;
  202. }
  203. }
  204. const getEmailcodeact = () =>{
  205. console.log('getEmailcode',registerForm.value.email);
  206. uni.showLoading({
  207. title:'Loading...',
  208. mask:true
  209. })
  210. getEmailcode(registerForm.value.email).then((res : any) => {
  211. console.log('getEmailcode',res);
  212. uni.hideLoading();
  213. if(res.code==200){
  214. timeCall.value=60;
  215. timer.value = setInterval(() => {
  216. timeCall.value=timeCall.value-1;
  217. if(timeCall.value==0){
  218. clearInterval(timer.value);
  219. huoquyzm.value='获取验证码';
  220. }
  221. else{
  222. huoquyzm.value='重新获取'+'('+timeCall.value+')';
  223. }
  224. }, 1000);
  225. }
  226. });
  227. }
  228. </script>
  229. <style scoped>
  230. @import url('@/static/css/main.css');
  231. .register-img{
  232. width: 200upx;
  233. height: 80upx;
  234. }
  235. .uni-forms-item__content{
  236. display: flex!important;
  237. }
  238. .yzmbt{
  239. color: white;
  240. font-size: 26upx;
  241. width: 170rpx;
  242. height: 60rpx;
  243. line-height: 60rpx;
  244. text-align: center;
  245. margin-left: auto;
  246. margin-right: 10rpx;
  247. border-radius: 2rpx;
  248. background-color:#60BA63;
  249. }
  250. .inputTitle{
  251. margin-top: -14rpx;
  252. font-size: 26upx;
  253. font-weight: bold;
  254. }
  255. .inputV{
  256. font-weight:normal;
  257. margin-top: -20rpx;
  258. }
  259. </style>